diff --git a/app/models/comment.rb b/app/models/comment.rb index f486850a6..3771af84a 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -21,6 +21,7 @@ class Comment < ActiveRecord::Base scope :for_render, -> { with_hidden.includes(user: :organization) } scope :with_visible_author, -> { joins(:user).where("users.hidden_at IS NULL") } + scope :not_as_admin_or_moderator, -> { where("administrator_id IS NULL").where("moderator_id IS NULL")} scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) } scope :sort_by_most_voted , -> { order(confidence_score: :desc, created_at: :desc) } diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index cb2c61181..11a02400a 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -117,4 +117,15 @@ describe Comment do expect(comment.author_id).to eq(comment.user.id) end end + + describe "not_as_admin_or_moderator" do + it "returns only comments posted as regular user" do + comment1 = create(:comment) + create(:comment, administrator_id: create(:administrator).id) + create(:comment, moderator_id: create(:moderator).id) + + expect(Comment.not_as_admin_or_moderator.size).to eq(1) + expect(Comment.not_as_admin_or_moderator.first).to eq(comment1) + end + end end