adds scope for only normal user comments
This commit is contained in:
@@ -21,6 +21,7 @@ class Comment < ActiveRecord::Base
|
|||||||
|
|
||||||
scope :for_render, -> { with_hidden.includes(user: :organization) }
|
scope :for_render, -> { with_hidden.includes(user: :organization) }
|
||||||
scope :with_visible_author, -> { joins(:user).where("users.hidden_at IS NULL") }
|
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_flags, -> { order(flags_count: :desc, updated_at: :desc) }
|
||||||
|
|
||||||
scope :sort_by_most_voted , -> { order(confidence_score: :desc, created_at: :desc) }
|
scope :sort_by_most_voted , -> { order(confidence_score: :desc, created_at: :desc) }
|
||||||
|
|||||||
@@ -117,4 +117,15 @@ describe Comment do
|
|||||||
expect(comment.author_id).to eq(comment.user.id)
|
expect(comment.author_id).to eq(comment.user.id)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user