Created
February 20, 2017 23:42
-
-
Save davidimoore/29fd6309969c7fc63a84a6a42eabeaef to your computer and use it in GitHub Desktop.
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 characters
| describe "counter caches" do | |
| it "increments associations when created" do | |
| user = User.create(first_name: "David", last_name: "Moore", email:"david@moore.com") | |
| #creating a thread with the user | |
| user.forum_threads.create(name:"First thread") | |
| expect(user.forum_threads_count).to eq 1 | |
| #create a thread with its own class and associating it to the user | |
| ForumThread.create(name: "Second thread", user: user) | |
| expect(user.forum_threads_count).to eq 2 | |
| #destroy a forum thread and check if form_threads_count is updated | |
| ForumThread.last.destroy | |
| expect(user.forum_threads_count).to eq 1 | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment