[rspec-users] testing a post to a controller's create action

Patrick J. Collins patrick at collinatorstudios.com
Sun Nov 20 01:14:35 EST 2011


> Please post the backtrace.

Failures:

  1) PostsController#store_post_params stores the last post params in the session
     Failure/Error: post :create, { :submit_action => submit_type.to_s, :post => { :foo => "bar" } }
     ActiveRecord::UnknownAttributeError:
       unknown attribute: foo
     # ./app/controllers/posts_controller.rb:107:in `new'
     # ./app/controllers/posts_controller.rb:107:in `exposed_for_session'
     # ./app/controllers/posts_controller.rb:9
     # ./app/controllers/posts_controller.rb:37:in `create'
     # ./spec/controllers/post_spec.rb:6:in `do_post'
     # ./spec/controllers/post_spec.rb:25

-------------

and exposed_for_session is:

  def exposed_for_session
    Post.new(session.delete(:last_post_params)) if session[:last_post_params]
  end

Like I said, I tried stubbing out the new class method on post by doing something like:

fake_post = stub('Post', :save => true)
Post.stubs(:new).returns(fake_post)

But I still get that same failure.

Patrick J. Collins
http://collinatorstudios.com


More information about the rspec-users mailing list