Created
June 2, 2016 13:19
-
-
Save aldesantis/8553209a509d4177b77cce5ae982231c to your computer and use it in GitHub Desktop.
This file contains 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 characters
RSpec.describe Review do | |
let(:book) { Book.create! } | |
subject { Review.new(book: book) } | |
it "increments the book's reviews_count when saving" do | |
expect { | |
subject.save! | |
}.to change(book, :reviews_count).by(1) | |
end | |
it "decrements the book's reviews_count when destroying" do | |
subject.save! | |
expect { | |
subject.destroy! | |
}.to change(book, :reviews_count).by(-1) | |
end | |
it "moves the entry when changing book" do | |
book2 = Book.create! | |
subject.save! | |
expect { | |
subject.update! book: book2 | |
}.to change(book, :reviews_count).by(-1) && change(book2, :reviews_count).by(1) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment