mirror of
https://github.com/tildeverse/lobsters
synced 2024-06-16 13:47:07 +00:00
5f5fa8ef03
Matches impact of the comment/story by using the vote count as a penalty. Flags effectively count extra because they -1 when applied and -2 when the mod removes.
68 lines
1.8 KiB
Ruby
68 lines
1.8 KiB
Ruby
require "rails_helper"
|
|
|
|
describe Comment do
|
|
it "should get a short id" do
|
|
c = create(:comment)
|
|
|
|
expect(c.short_id).to match(/^\A[a-zA-Z0-9]{1,10}\z/)
|
|
end
|
|
|
|
describe "hat" do
|
|
it "can't be worn if user doesn't have that hat" do
|
|
comment = build(:comment, hat: build(:hat))
|
|
comment.valid?
|
|
expect(comment.errors[:hat]).to eq(['not wearable by user'])
|
|
end
|
|
|
|
it "can be one of the user's hats" do
|
|
hat = create(:hat)
|
|
user = hat.user
|
|
comment = create(:comment, user: user, hat: hat)
|
|
comment.valid?
|
|
expect(comment.errors[:hat]).to be_empty
|
|
end
|
|
end
|
|
|
|
it "validates the length of short_id" do
|
|
comment = Comment.new(short_id: "01234567890")
|
|
expect(comment).to_not be_valid
|
|
end
|
|
|
|
it "is not valid without a comment" do
|
|
comment = Comment.new(comment: nil)
|
|
expect(comment).to_not be_valid
|
|
end
|
|
|
|
it "validates the length of markeddown_comment" do
|
|
comment = build(:comment, markeddown_comment: "a" * 16_777_216)
|
|
expect(comment).to_not be_valid
|
|
end
|
|
|
|
describe ".accessible_to_user" do
|
|
it "when user is a moderator" do
|
|
moderator = build(:user, :moderator)
|
|
|
|
expect(Comment.accessible_to_user(moderator)).to eq(Comment.all)
|
|
end
|
|
|
|
it "when user does not a moderator" do
|
|
user = build(:user)
|
|
|
|
expect(Comment.accessible_to_user(user)).to eq(Comment.active)
|
|
end
|
|
end
|
|
|
|
it "subtracts karma if mod intervenes" do
|
|
author = create(:user)
|
|
voter = create(:user)
|
|
mod = create(:user, :moderator)
|
|
c = create(:comment, user: author)
|
|
expect {
|
|
Vote.vote_thusly_on_story_or_comment_for_user_because(1, c.story_id, c.id, voter.id, nil)
|
|
}.to change { author.reload.karma }.by(1)
|
|
expect {
|
|
c.delete_for_user(mod, "Troll")
|
|
}.to change { author.reload.karma }.by(-4)
|
|
end
|
|
end
|