Add Tag to api
This commit is contained in:
3
app/models/tag.rb
Normal file
3
app/models/tag.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class Tag < ActsAsTaggableOn::Tag
|
||||
scope :public_for_api, -> { where("kind IS NULL OR kind = 'category'") }
|
||||
end
|
||||
@@ -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 ],
|
||||
Geozone => %I[ id name ]
|
||||
ProposalNotification => %I[ title body proposal_id created_at proposal ],
|
||||
Tag => %I[ id name taggings_count kind ],
|
||||
}
|
||||
|
||||
type_creator = GraphQL::TypeCreator.new
|
||||
|
||||
24
spec/models/tag_spec.rb
Normal file
24
spec/models/tag_spec.rb
Normal 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
|
||||
Reference in New Issue
Block a user