title: Rails 5 - Rspec Expect Change Count Not Working
body: <p>This might be something really simple, but I can't get Rspec's expect change count to detect when a new record is created through the controller's create method.</p>
  
  <p>Here is my test:</p>
  
  <pre><code>it "saves the new Post in the database" do
    expect{
      process :create, method: :post, params: { post: attributes_for(:post) }
    }.to change{Post.count}.by(1)  
  end
  </code></pre>
  
  <p>it just errors with:</p>
  
  <pre><code>expected result to have changed by 1, but was changed by 0
  </code></pre>
  
  <p>Looking at the test.log it doesnt seem to show any errors when the post is created:</p>
  
  <pre><code>  [1m[35m (0.0ms)[0m  [1m[36mbegin transaction[0m
    [1m[35m (0.1ms)[0m  [1m[34mSELECT COUNT(*) FROM "posts"[0m
    Processing by PostsController#create as HTML
    Parameters: {"post"=&gt;{"content"=&gt;"Quas adipisci illum repellat sapiente eos. Quae temporibus facilis. Corporis odit eaque reiciendis eum tempora. Nam dolor sint pariatur.", "excerpt"=&gt;"Dicta veritatis voluptate at. Sed voluptatem corrupti sed impedit quae consequatur. Velit voluptates nisi est nihil. Explicabo qui animi expedita rerum.", "image_url"=&gt;"https://hd.unsplash.com/photo-1413781892741-08a142b23dfe", "keywords"=&gt;"blog, post, key, words", "post_type"=&gt;"article", "published"=&gt;"false", "title"=&gt;"Pariatur laborum ut nostrum quis rem sunt libero."}}
    [1m[35m (0.0ms)[0m  [1m[35mSAVEPOINT active_record_1[0m
    [1m[36mPost Exists (0.1ms)[0m  [1m[34mSELECT  1 AS one FROM "posts" WHERE "posts"."title" = ? LIMIT ?[0m  [["title", "Pariatur laborum ut nostrum quis rem sunt libero."], ["LIMIT", 1]]
    [1m[35m (0.0ms)[0m  [1m[31mROLLBACK TO SAVEPOINT active_record_1[0m
    Rendering /home/nitrous/code/blog/app/views/posts/index.html.haml within layouts/application
    Rendered /home/nitrous/code/blog/app/views/posts/index.html.haml within layouts/application (0.0ms)
    Completed 200 OK in 9ms (Views: 0.6ms | ActiveRecord: 0.2ms)
    [1m[35m (0.1ms)[0m  [1m[34mSELECT COUNT(*) FROM "posts"[0m
    [1m[35m (0.1ms)[0m  [1m[31mrollback transaction[0m
  </code></pre>
  
  <p>The post model validates that the title is unique.</p>
  
  <p>I can see that the log says 'Post Exists' but if it does and this is the reason it's not saving a new Post. Why is that?</p>