62 lines
1.5 KiB
Ruby
62 lines
1.5 KiB
Ruby
require 'rails_helper'
|
|
|
|
describe Comment do
|
|
|
|
let(:comment) { build(:comment) }
|
|
|
|
it "should be valid" do
|
|
expect(comment).to be_valid
|
|
end
|
|
|
|
describe "#children_count" do
|
|
let(:comment) { create(:comment) }
|
|
let(:debate) { comment.debate }
|
|
|
|
it "should count first level children" do
|
|
parent = comment
|
|
|
|
3.times do
|
|
create(:comment, commentable: debate).
|
|
move_to_child_of(parent)
|
|
parent = parent.children.first
|
|
end
|
|
|
|
expect(comment.children_count).to eq(1)
|
|
expect(debate.comment_threads.count).to eq(4)
|
|
end
|
|
|
|
it "should increase children count" do
|
|
expect do
|
|
create(:comment, commentable: debate).
|
|
move_to_child_of(comment)
|
|
end.to change { comment.children_count }.from(0).to(1)
|
|
end
|
|
|
|
it "should decrease children count" do
|
|
new_comment = create(:comment, commentable: debate).move_to_child_of(comment)
|
|
|
|
expect { new_comment.destroy }.to change { comment.children_count }.from(1).to(0)
|
|
end
|
|
end
|
|
|
|
describe "#as_administrator?" do
|
|
it "should be true if comment has administrator_id, false otherway" do
|
|
expect(comment).not_to be_as_administrator
|
|
|
|
comment.administrator_id = 33
|
|
|
|
expect(comment).to be_as_administrator
|
|
end
|
|
end
|
|
|
|
describe "#as_moderator?" do
|
|
it "should be true if comment has moderator_id, false otherway" do
|
|
expect(comment).not_to be_as_moderator
|
|
|
|
comment.moderator_id = 21
|
|
|
|
expect(comment).to be_as_moderator
|
|
end
|
|
end
|
|
end
|