Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Deprecate category #552

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/controllers/api/categories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ class CategoriesController < BaseController
before_action :set_additional_attributes, :only => [:index, :show, :update]

def edit_resource(type, id, data = {})
raise ForbiddenError if Category.find(id).read_only?
raise ForbiddenError if Classification.is_category.find(id).read_only?
super
end

def delete_resource(type, id, data = {})
raise ForbiddenError if Category.find(id).read_only?
raise ForbiddenError if Classification.is_category.find(id).read_only?
super
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def fetch_category(data)
unless category_id
raise BadRequestError, "Category id, href or name needs to be specified for creating a new tag resource"
end
Category.find_by(:id => category_id)
Classification.is_category.find_by(:id => category_id)
end

def destroy_tag_and_classification(tag_id)
Expand Down
2 changes: 1 addition & 1 deletion config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@
:options:
- :collection
:verbs: *gpd
:klass: Category
:klass: Classification
:subcollections:
- :tags
:collection_actions:
Expand Down
17 changes: 9 additions & 8 deletions spec/requests/categories_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
RSpec.describe "categories API" do
it "can list all the categories" do
categories = FactoryBot.create_list(:category, 2)
FactoryBot.create(:classification_tag, :parent => categories.first)
api_basic_authorize collection_action_identifier(:categories, :read, :get)

get api_categories_url
Expand Down Expand Up @@ -78,7 +79,7 @@

expect do
post api_categories_url, :params => { :name => "test", :description => "Test" }
end.to change(Category, :count).by(1)
end.to change(Classification, :count).by(1)

expect(response).to have_http_status(:ok)
end
Expand Down Expand Up @@ -107,7 +108,7 @@
api_basic_authorize collection_action_identifier(:categories, :create)

post api_categories_url, :params => { :name => "test", :description => "Test" }
category = Category.find(response.parsed_body["results"].first["id"])
category = Classification.is_category.find(response.parsed_body["results"].first["id"])

expect(category.tag.name).to eq("/managed/test")
end
Expand All @@ -130,7 +131,7 @@

expect do
post api_category_url(nil, category), :params => gen_request(:delete)
end.to change(Category, :count).by(-1)
end.to change(Classification, :count).by(-1)

expect(response).to have_http_status(:ok)
end
Expand All @@ -141,7 +142,7 @@

expect do
delete api_category_url(nil, category)
end.to change(Category, :count).by(-1)
end.to change(Classification, :count).by(-1)

expect(response).to have_http_status(:no_content)
end
Expand All @@ -153,7 +154,7 @@

expect do
post api_category_url(nil, category), :params => gen_request(:delete)
end.not_to change(Category, :count)
end.not_to change(Classification, :count)

expect(response).to have_http_status(:forbidden)
end
Expand All @@ -176,7 +177,7 @@

expect do
post api_categories_url, :params => { :name => "test", :description => "Test" }
end.not_to change(Category, :count)
end.not_to change(Classification, :count)

expect(response).to have_http_status(:forbidden)
end
Expand All @@ -198,7 +199,7 @@

expect do
post api_category_url(nil, category), :params => gen_request(:delete)
end.not_to change(Category, :count)
end.not_to change(Classification, :count)

expect(response).to have_http_status(:forbidden)
end
Expand All @@ -209,7 +210,7 @@

expect do
delete api_category_url(nil, category)
end.not_to change(Category, :count)
end.not_to change(Classification, :count)

expect(response).to have_http_status(:forbidden)
end
Expand Down
10 changes: 6 additions & 4 deletions spec/requests/collections_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ def test_collection_bulk_query(collection, collection_url, klass, id = nil)
end

it "query Categories" do
FactoryBot.create(:category)
test_collection_query(:categories, api_categories_url, Category)
category = FactoryBot.create(:category)
FactoryBot.create(:classification_tag, :parent => category)
test_collection_query(:categories, api_categories_url, Classification.is_category)
end

it "query Chargebacks" do
Expand Down Expand Up @@ -411,8 +412,9 @@ def test_collection_bulk_query(collection, collection_url, klass, id = nil)
end

it "bulk query Categories" do
FactoryBot.create(:category)
test_collection_bulk_query(:categories, api_categories_url, Category)
category = FactoryBot.create(:category)
FactoryBot.create(:classification_tag, :parent => category) # should not come back
test_collection_bulk_query(:categories, api_categories_url, Classification.is_category)
end

it "bulk query Chargebacks" do
Expand Down
24 changes: 12 additions & 12 deletions spec/requests/tags_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,58 +23,58 @@
context "with an appropriate role" do
it "can create a tag with category by href" do
api_basic_authorize collection_action_identifier(:tags, :create)
category = FactoryBot.create(:category)
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)

result = response.parsed_body["results"].first
tag = Tag.find(result["id"])
tag_category = Category.find(tag.category.id)
tag_category = tag.category
expect(tag_category).to eq(category)
expect(result["href"]).to include(api_tag_url(nil, tag))
expect(response).to have_http_status(:ok)
end

it "can create a tag with a category by id" do
api_basic_authorize collection_action_identifier(:tags, :create)
category = FactoryBot.create(:category)
category = FactoryBot.create(:classification)

expect do
post api_tags_url, :params => { :name => "test_tag", :description => "Test Tag", :category => {:id => category.id} }
end.to change(Tag, :count).by(1)

tag = Tag.find(response.parsed_body["results"].first["id"])
tag_category = Category.find(tag.category.id)
tag_category = tag.category
expect(tag_category).to eq(category)

expect(response).to have_http_status(:ok)
end

it "can create a tag with a category by name" do
api_basic_authorize collection_action_identifier(:tags, :create)
category = FactoryBot.create(:category)
category = FactoryBot.create(:classification)

expect do
post api_tags_url, :params => { :name => "test_tag", :description => "Test Tag", :category => {:name => category.name} }
end.to change(Tag, :count).by(1)

tag = Tag.find(response.parsed_body["results"].first["id"])
tag_category = Category.find(tag.category.id)
tag_category = tag.category
expect(tag_category).to eq(category)

expect(response).to have_http_status(:ok)
end

it "can create a tag as a subresource of a category" do
api_basic_authorize collection_action_identifier(:tags, :create)
category = FactoryBot.create(:category)
category = FactoryBot.create(:classification)

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"])
tag_category = Category.find(tag.category.id)
tag_category = tag.category
expect(tag_category).to eq(category)

expect(response).to have_http_status(:ok)
Expand All @@ -91,7 +91,7 @@
it "can update a tag's name" do
api_basic_authorize action_identifier(:tags, :edit)
classification = FactoryBot.create(:classification_tag)
category = FactoryBot.create(:category, :children => [classification])
category = FactoryBot.create(:classification, :children => [classification])
tag = classification.tag

expect do
Expand All @@ -104,7 +104,7 @@
it "can update a tag's description" do
api_basic_authorize action_identifier(:tags, :edit)
classification = FactoryBot.create(:classification_tag)
FactoryBot.create(:category, :children => [classification])
FactoryBot.create(:classification, :children => [classification])
tag = classification.tag

expect do
Expand Down Expand Up @@ -160,7 +160,7 @@
api_basic_authorize action_identifier(:tags, :delete)
classification1 = FactoryBot.create(:classification_tag)
classification2 = FactoryBot.create(:classification_tag)
category = FactoryBot.create(:category, :children => [classification1, classification2])
category = FactoryBot.create(:classification, :children => [classification1, classification2])
tag1 = classification1.tag
tag2 = classification2.tag

Expand All @@ -183,7 +183,7 @@
api_basic_authorize action_identifier(:tags, :delete)
classification1 = FactoryBot.create(:classification_tag)
classification2 = FactoryBot.create(:classification_tag)
category = FactoryBot.create(:category, :children => [classification1, classification2])
category = FactoryBot.create(:classification, :children => [classification1, classification2])
tag1 = classification1.tag
tag2 = classification2.tag
body = gen_request(:delete, [{:name => tag1.name}, {:name => tag2.name}])
Expand Down