Add Tag to api

This commit is contained in:
Alberto Miedes Garcés
2016-12-29 11:13:57 +01:00
parent 074a8182f6
commit 80c3108a18
3 changed files with 28 additions and 0 deletions

3
app/models/tag.rb Normal file
View File

@@ -0,0 +1,3 @@
class Tag < ActsAsTaggableOn::Tag
scope :public_for_api, -> { where("kind IS NULL OR kind = 'category'") }
end

View File

@@ -5,6 +5,7 @@ API_TYPE_DEFINITIONS = {
Comment => %I[ id commentable_id commentable_type body created_at cached_votes_total cached_votes_up cached_votes_down ancestry confidence_score public_author ], Comment => %I[ id commentable_id commentable_type body created_at cached_votes_total cached_votes_up cached_votes_down ancestry confidence_score public_author ],
Geozone => %I[ id name ] Geozone => %I[ id name ]
ProposalNotification => %I[ title body proposal_id created_at proposal ], ProposalNotification => %I[ title body proposal_id created_at proposal ],
Tag => %I[ id name taggings_count kind ],
} }
type_creator = GraphQL::TypeCreator.new type_creator = GraphQL::TypeCreator.new

24
spec/models/tag_spec.rb Normal file
View File

@@ -0,0 +1,24 @@
require 'rails_helper'
describe 'Tag' do
describe "public_for_api scope" do
it "returns tags whose kind is NULL" do
tag = create(:tag, kind: nil)
expect(Tag.public_for_api).to include(tag)
end
it "returns tags whose kind is 'category'" do
tag = create(:tag, kind: 'category')
expect(Tag.public_for_api).to include(tag)
end
it "blocks other kinds of tags" do
tag = create(:tag, kind: 'foo')
expect(Tag.public_for_api).not_to include(tag)
end
end
end