caching comment counts

This commit is contained in:
shlok007 2016-12-29 03:17:33 -05:00 committed by Shlok Srivastava
parent 89840d0bab
commit 9c6286182e
5 changed files with 36 additions and 2 deletions

View file

@ -98,6 +98,29 @@ describe Event do
end
end
describe '#comments_count' do
context 'has a valid counter cache' do
before do
create(:comment, commentable: event)
end
it 'successfully increments comments_count' do
expected = expect do
create(:comment, commentable: event)
end
expected.to change { event.comments_count }.by(1)
end
it 'successfully decrements comments_count' do
expected = expect do
event.comment_threads.last.destroy
event.reload
end
expected.to change { event.comments_count }.by(-1)
end
end
end
describe 'scope ' do
context 'confirmed' do
it 'returns only confirmed events' do