title: Rspec: Failure/Error: expect(assigns(:user)).to be_persisted
body: <p>I have a simple controller Rspec test. I'm testing the User controller create action. </p>
  
  <p>But i receive this error</p>
  
  <pre><code>$ rspec spec/controllers/users_controller_spec.rb
  .....F
  
  Failures:
  
    1) UsersController POST #create user created
       Failure/Error: expect(assigns(:user)).to be_persisted
         expected `#&lt;User id: nil, username: "username27", email: "user27@factory.com", created_at: nil, updated_at: nil, password_digest: nil, remember_digest: nil, admin: false, activation_digest: nil, activated: false, activated_at: nil, reset_digest: nil, &gt;: nil, reset_sent_at: nil, avatar_file_name: nil, avatar_content_type: nil, avatar_file_size: nil, avatar_updated_at: nil, description: nil, header_image_file_name: nil, header_image_content_type: nil, header_image_file_size: nil, header_image_updated_at: nil&gt;.persisted?` to return true, got false
       # ./spec/controllers/users_controller_spec.rb:58:in `block (3 levels) in &lt;top (required)&gt;'
  
  Finished in 0.49926 seconds (files took 2.6 seconds to load)
  </code></pre>
  
  <p>Here is the test</p>
  
  <pre><code>require "rails_helper"
  
  RSpec.describe UsersController, type: :controller do
    let!(:admin) { create(:user, password: "Password123", admin: true) }
    let!(:user) { create(:user, password: "Password456", admin: false) }
  
    let!(:users) do
      [admin, user] + 3.times.map { create(:user) }
    end
  
    let!(:user_params) { user.attributes }
  
    describe "POST #create" do
      before do
        post :create, user: user_params
      end
  
      it "user created" do
        expect(assigns(:user)).to be_persisted
      end
    end
  end
  </code></pre>
  
  <p><strong>When i put a binding.pry at the create action. Then run User.new(user_params).valid? = false</strong></p>
  
  <pre><code>$ rspec spec/controllers/users_controller_spec.rb
  .....
  From: /Users/joseph/Documents/Safsy/Website/Safsy/Safsy/app/controllers/users_controller.rb @ line 26 UsersController#create:
  
      24: def create
      25:   @user = User.new(user_params)
   =&gt; 26:   binding.pry
      27:   if @user.save
      28:     @user.send_activation_email
      29:     flash[:info] = "Please check your email to activate your account."
      30:     redirect_to root_url
      31:   else
      32:     render 'new'
      33:   end
      34: end
  
  [1] pry(#&lt;UsersController&gt;)&gt; User.new(user_params)
  =&gt; #&lt;User:0x007fa749fc1b18
   id: nil,
   username: "username27",
   email: "user27@factory.com",
   created_at: nil,
   updated_at: nil,
   password_digest: nil,
   remember_digest: nil,
   admin: false,
   activation_digest: nil,
   activated: false,
   activated_at: nil,
   reset_digest: nil,
   &gt;: nil,
   reset_sent_at: nil,
   avatar_file_name: nil,
   avatar_content_type: nil,
   avatar_file_size: nil,
   avatar_updated_at: nil,
   description: "Vel aperiam et dolorem aliquid est perspiciatis.",
   header_image_file_name: nil,
   header_image_content_type: nil,
   header_image_file_size: nil,
   header_image_updated_at: nil&gt;
  </code></pre>
  
  <p><strong>Any clues how to fix it? Its like only some of my attributes for the user_params in my tests are getting passed too the create action</strong></p>
  
  <pre><code>Here are is a binding.pry at the Test
  
      50:   end
      51:
      52:   describe "POST #create" do
      53:     before do
      54:       post :create, user: user_params
   =&gt; 55:       binding.pry
      56:     end
      57:
      58:     it "user created" do
      59:       expect(assigns(:user)).to be_persisted
      60:     end
  
  [1] pry(#&lt;RSpec::ExampleGroups::UsersController::POSTCreate&gt;)&gt; user_params
  =&gt; {"id"=&gt;2,
   "username"=&gt;"username27",
   "email"=&gt;"user27@factory.com",
   "created_at"=&gt;Wed, 07 Oct 2015 12:24:01 UTC +00:00,
   "updated_at"=&gt;Wed, 07 Oct 2015 12:24:01 UTC +00:00,
   "password_digest"=&gt;"$2a$04$Y627EwOml9cix7NdPITnpem0nZV8fta.JNyuezRsLNF2ucKfdC3GC",
   "remember_digest"=&gt;nil,
   "admin"=&gt;false,
   "activation_digest"=&gt;"$2a$04$LHRBD82Lm0bj20nrwHDVveVlUa7zWq0WYIlmTMivT1h9UIcjwv9FO",
   "activated"=&gt;true,
   "activated_at"=&gt;nil,
   "reset_digest"=&gt;nil,
   "&gt;"=&gt;nil,
   "reset_sent_at"=&gt;nil,
   "avatar_file_name"=&gt;nil,
   "avatar_content_type"=&gt;nil,
   "avatar_file_size"=&gt;nil,
   "avatar_updated_at"=&gt;nil,
   "description"=&gt;"Nihil eligendi ab debitis iure.",
   "header_image_file_name"=&gt;nil,
   "header_image_content_type"=&gt;nil,
   "header_image_file_size"=&gt;nil,
   "header_image_updated_at"=&gt;nil}
  </code></pre>
  
  <p><strong>Look at the user_params here in the test then look at them in the create action. They're the same. Just some attributes like password and password confirmation aren't being passed.</strong></p>