From d359a07e89a2b33b58af5e30d85d2be11e56766b Mon Sep 17 00:00:00 2001 From: Keenan Brock Date: Wed, 30 Jan 2019 17:48:37 -0500 Subject: [PATCH] Remove references to Tag where possible Tag is based upon classifications, so just use those Mostly replaced the Tag.find() with Classification.find_by(:tag_id) --- spec/requests/categories_spec.rb | 2 +- spec/requests/querying_spec.rb | 4 +-- spec/requests/tags_spec.rb | 55 ++++++++++++++++---------------- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/spec/requests/categories_spec.rb b/spec/requests/categories_spec.rb index 0bd17d5de6..0917d5d699 100644 --- a/spec/requests/categories_spec.rb +++ b/spec/requests/categories_spec.rb @@ -60,7 +60,7 @@ classification = FactoryBot.create(:classification_tag) category = FactoryBot.create(:category, :children => [classification]) tag = classification.tag - Tag.create(:name => "some_other_tag") + FactoryBot.create(:classification, :name => "some_other_tag") api_basic_authorize get(api_category_tags_url(nil, category)) diff --git a/spec/requests/querying_spec.rb b/spec/requests/querying_spec.rb index 4f3a64003d..82e6d0d191 100644 --- a/spec/requests/querying_spec.rb +++ b/spec/requests/querying_spec.rb @@ -650,8 +650,8 @@ def create_vms_by_name(names) end it "can do fuzzy matching on strings with forward slashes" do - tag_1 = FactoryBot.create(:tag, :name => "/managed/foo") - _tag_2 = FactoryBot.create(:tag, :name => "/managed/bar") + tag_1 = FactoryBot.create(:classification, :name => "foo").tag + _tag_2 = FactoryBot.create(:classification, :name => "bar") api_basic_authorize collection_action_identifier(:tags, :read, :get) get(api_tags_url, :params => { :filter => ["name='*/foo'"] }) diff --git a/spec/requests/tags_spec.rb b/spec/requests/tags_spec.rb index c02ac7201d..516af559c5 100644 --- a/spec/requests/tags_spec.rb +++ b/spec/requests/tags_spec.rb @@ -17,7 +17,7 @@ get api_tags_url - expect_query_result(:tags, Tag.count) + expect_query_result(:tags, Classification.count) end context "with an appropriate role" do @@ -26,10 +26,10 @@ category = FactoryBot.create(:classification) options = {:name => "test_tag", :description => "Test Tag", :category => {:href => api_category_url(nil, category)}} - expect { post api_tags_url, :params => options }.to change(Tag, :count).by(1) + expect { post api_tags_url, :params => options }.to change(Classification, :count).by(1) result = response.parsed_body["results"].first - tag = Tag.find(result["id"]) + tag = Classification.find_by!(:tag_id => result["id"]).tag tag_category = tag.category expect(tag_category).to eq(category) expect(result["href"]).to include(api_tag_url(nil, tag)) @@ -42,9 +42,9 @@ expect do post api_tags_url, :params => { :name => "test_tag", :description => "Test Tag", :category => {:id => category.id} } - end.to change(Tag, :count).by(1) + end.to change(Classification, :count).by(1) - tag = Tag.find(response.parsed_body["results"].first["id"]) + tag = Classification.find_by!(:tag_id => response.parsed_body["results"].first["id"]).tag tag_category = tag.category expect(tag_category).to eq(category) @@ -57,9 +57,9 @@ expect do post api_tags_url, :params => { :name => "test_tag", :description => "Test Tag", :category => {:name => category.name} } - end.to change(Tag, :count).by(1) + end.to change(Classification, :count).by(1) - tag = Tag.find(response.parsed_body["results"].first["id"]) + tag = Classification.find_by!(:tag_id => response.parsed_body["results"].first["id"]).tag tag_category = tag.category expect(tag_category).to eq(category) @@ -72,8 +72,8 @@ expect do post(api_category_tags_url(nil, category), :params => { :name => "test_tag", :description => "Test Tag" }) - end.to change(Tag, :count).by(1) - tag = Tag.find(response.parsed_body["results"].first["id"]) + end.to change(Classification, :count).by(1) + tag = Classification.find_by!(:tag_id => response.parsed_body["results"].first["id"]).tag tag_category = tag.category expect(tag_category).to eq(category) @@ -108,8 +108,8 @@ tag = classification.tag expect do - post api_tag_url(nil, tag), :params => gen_request(:edit, :description => "New Description") - end.to change { tag.reload.classification.description }.to("New Description") + post api_tag_url(nil, classification.tag_id), :params => gen_request(:edit, :description => "New Description") + end.to change { classification.reload.description }.to("New Description") expect(response).to have_http_status(:ok) end @@ -119,7 +119,7 @@ classification = FactoryBot.create(:classification_tag) tag = classification.tag - expect { post api_tag_url(nil, tag), :params => { :action => :delete } }.to change(Tag, :count).by(-1) + expect { post api_tag_url(nil, tag), :params => { :action => :delete } }.to change(Classification, :count).by(-1) expect { classification.reload }.to raise_error(ActiveRecord::RecordNotFound) expect(response).to have_http_status(:ok) end @@ -129,7 +129,7 @@ classification = FactoryBot.create(:classification_tag) tag = classification.tag - expect { delete api_tag_url(nil, tag) }.to change(Tag, :count).by(-1) + expect { delete api_tag_url(nil, tag) }.to change(Classification, :count).by(-1) expect { classification.reload }.to raise_error(ActiveRecord::RecordNotFound) expect(response).to have_http_status(:no_content) end @@ -166,7 +166,7 @@ expect do post(api_category_tags_url(nil, category), :params => gen_request(:delete, [{:id => tag1.id}, {:id => tag2.id}])) - end.to change(Tag, :count).by(-2) + end.to change(Classification, :count).by(-2) expect { classification1.reload }.to raise_error(ActiveRecord::RecordNotFound) expect { classification2.reload }.to raise_error(ActiveRecord::RecordNotFound) expect_result_to_match_hash( @@ -190,7 +190,7 @@ expect do post(api_category_tags_url(nil, category), :params => body) - end.to change(Tag, :count).by(-2) + end.to change(Classification, :count).by(-2) expect { classification1.reload }.to raise_error(ActiveRecord::RecordNotFound) expect { classification2.reload }.to raise_error(ActiveRecord::RecordNotFound) expect_result_to_match_hash( @@ -210,36 +210,37 @@ expect do post api_tags_url, :params => { :name => "test_tag", :description => "Test Tag" } - end.not_to change(Tag, :count) + end.not_to change(Classification, :count) expect(response).to have_http_status(:forbidden) end it "cannot update a tag" do api_basic_authorize - tag = Tag.create(:name => "Old name") + classification = Classification.is_category.create(:name => "test_tag", :description => "Test Tag") + tag = classification.tag expect do - post api_tag_url(nil, tag), :params => gen_request(:edit, :name => "New name") - end.not_to change { tag.reload.name } + post api_tag_url(nil, tag), :params => gen_request(:edit, :name => "new_name") + end.not_to change { classification.reload.name } expect(response).to have_http_status(:forbidden) end it "cannot delete a tag through POST" do api_basic_authorize - tag = Tag.create(:name => "Test tag") + tag = Classification.is_category.create(:name => "test_tag", :description => "Test Tag").tag - expect { post api_tag_url(nil, tag), :params => { :action => :delete } }.not_to change(Tag, :count) + expect { post api_tag_url(nil, tag), :params => { :action => :delete } }.not_to change(Classification, :count) expect(response).to have_http_status(:forbidden) end it "cannot delete a tag through DELETE" do api_basic_authorize - tag = Tag.create(:name => "Test tag") + tag = Classification.is_category.create(:name => "test_tag", :description => "Test Tag").tag - expect { delete api_tag_url(nil, tag) }.not_to change(Tag, :count) + expect { delete api_tag_url(nil, tag) }.not_to change(Classification, :count) expect(response).to have_http_status(:forbidden) end @@ -258,14 +259,14 @@ get api_tags_url, :params => { :expand => "resources" } - expect_query_result(:tags, Tag.count, Tag.count) + expect_query_result(:tags, Classification.count, Classification.count) expect_result_resources_to_include_keys("resources", %w(id name)) end it "query tag details with multiple virtual attributes" do api_basic_authorize action_identifier(:tags, :read, :resource_actions, :get) - tag = Tag.last + tag = Classification.is_entry.last.tag attr_list = "category.name,category.description,classification.name,classification.description" get api_tag_url(nil, tag), :params => { :attributes => attr_list } @@ -281,7 +282,7 @@ it "query tag details with categorization" do api_basic_authorize action_identifier(:tags, :read, :resource_actions, :get) - tag = Tag.last + tag = Classification.is_entry.last.tag get api_tag_url(nil, tag), :params => { :attributes => "categorization" } expect_single_resource_query( @@ -302,7 +303,7 @@ get api_tags_url, :params => { :expand => "resources", :attributes => "categorization" } - expect_query_result(:tags, Tag.count, Tag.count) + expect_query_result(:tags, Classification.count, Classification.count) expect_result_resources_to_include_keys("resources", %w(id name categorization)) end end