diff --git a/app/models/tag.rb b/app/models/tag.rb new file mode 100644 index 000000000..8f34a8696 --- /dev/null +++ b/app/models/tag.rb @@ -0,0 +1,3 @@ +class Tag < ActsAsTaggableOn::Tag + scope :public_for_api, -> { where("kind IS NULL OR kind = 'category'") } +end diff --git a/config/initializers/graphql.rb b/config/initializers/graphql.rb index b899476f7..a7e1bfa85 100644 --- a/config/initializers/graphql.rb +++ b/config/initializers/graphql.rb @@ -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 diff --git a/spec/models/tag_spec.rb b/spec/models/tag_spec.rb new file mode 100644 index 000000000..fa26b7622 --- /dev/null +++ b/spec/models/tag_spec.rb @@ -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