Skip to content

Commit

Permalink
Remove references to Tag where possible
Browse files Browse the repository at this point in the history
Tag is based upon classifications, so just use those

Mostly replaced the Tag.find() with Classification.find_by(:tag_id)
  • Loading branch information
kbrock committed Jan 30, 2019
1 parent 1adee20 commit 0c3db2d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion spec/requests/categories_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
42 changes: 21 additions & 21 deletions spec/requests/tags_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -210,36 +210,36 @@

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)
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
Expand All @@ -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 }

Expand All @@ -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(
Expand Down

0 comments on commit 0c3db2d

Please sign in to comment.