Created
March 5, 2014 15:14
-
-
Save ozgg/9369182 to your computer and use it in GitHub Desktop.
Revisions
-
ozgg created this gist
Mar 5, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ require 'spec_helper' describe Comment do let(:comment) { build(:comment) } let(:user) { create(:user) } let(:dream) { create(:dream) } context "integrity" do it "has non-blank body" do comment.body = ' ' comment.valid? expect(comment.errors).to have_key(:body) end it "is invalid without entry_id" do comment.valid? expect(comment.errors).to have_key(:entry) end end context "when saved" do before(:each) do comment.entry = dream comment.user = user end it "increments user's comments_count" do expect { comment.save }.to change(user, :comments_count).by(1) end it "increments entry's comments_count" do expect { comment.save }.to change(dream, :comments_count).by(1) end end context "when destroyed" do before(:each) do comment.entry = dream comment.user = user comment.save end it "decrements user's comments_count" it "decrements entry's comments_count" end end