From 0c3db2d1ade37f123c9283bf3df8b497fa6a350c 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/tags_spec.rb | 42 ++++++++++++++++---------------- 2 files changed, 22 insertions(+), 22 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/tags_spec.rb b/spec/requests/tags_spec.rb index c1026e5571..335cd1a3ae 100644 --- a/spec/requests/tags_spec.rb +++ b/spec/requests/tags_spec.rb @@ -26,10 +26,10 @@ category = FactoryBot.create(:category) 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) @@ -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,17 +210,17 @@ 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") + tag = Classification.is_category.create(:name => "test_tag", :description => "Test Tag").tag expect do - post api_tag_url(nil, tag), :params => gen_request(:edit, :name => "New name") + post api_tag_url(nil, tag), :params => gen_request(:edit, :name => "new_name") end.not_to change { tag.reload.name } expect(response).to have_http_status(:forbidden) @@ -228,18 +228,18 @@ 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 @@ -265,7 +265,7 @@ 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 +281,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(