adds scope for only normal user comments

This commit is contained in:
Juanjo Bazán
2015-11-12 12:15:36 +01:00
parent a881ced801
commit c258a4f3b4
2 changed files with 12 additions and 0 deletions

View File

@@ -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) }

View File

@@ -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