fireflyman
2009-Aug-26 01:58 UTC
Ruby on Rails > test:integration Expected response to be a <:redirect>, but was <404>
Hello, I''m trying to write some tests and I get a failure error on one test, which I am not sure why or where is my mistake. In my test/integration/product_test.rb I have: require ''test_helper'' class ProductTest < ActionController::IntegrationTest fixtures :all test "product_administartion_by_admin" do category = Category.create(:name => ''Parts'') quentin = new_session_as(:quentin) product = quentin.add_product :product => { :title => ''Clip'', :category_id => category.id, :sku => 54321, :desctription => ''some text'', :price => 8.71 } end private module ProductTestDSL attr_writer :name def add_product(parameters) post "/product/create", parameters assert_response :redirect follow_redirect! assert_response :success assert_template "/product/show" return Product.find_by_title(parameters[:product][:title]) end end def new_session_as(name) open_session do |session| session.extend(ProductTestDSL) session.name = name yield session if block_given? end end end ------------------------------------ The error I get is: 1) Failure: test_product_administartion_by_admin(ProductTest) [/test/integration/product_test.rb:26:in `add_product'' /test/integration/product_test.rb:10:in `test_product_administartion_by_admin'']: Expected response to be a <:redirect>, but was <404> 1 tests, 1 assertions, 1 failures, 0 errors rake aborted! ------------------------------------ Looking around -- someone had a problem that the new object was not created or saved. One of the tests in products_controller_test.rb has no problem creating a new product. What am I missing?
Nik Cool
2009-Aug-26 06:16 UTC
Re: Ruby on Rails > test:integration Expected response to be a <:redirect>, but was <404>
> Looking around -- someone had a problem that the new object was not > created or saved. One of the tests in products_controller_test.rb has > no problem creating a new product. > > What am I missing?try this..... this may work test "product_administartion_by_admin" do category = Category.create(:name => ''Parts'') quentin = new_session_as(:quentin) quentin.add_product end private module ProductTestDSL attr_writer :name def add_product params ={:product => { :title => ''Clip'', :category_id => category.id, :sku => 54321, :desctription => ''some text'', :price => 8.71}} post "/product/create", params assert_response :redirect follow_redirect! assert_response :success assert_template "/product/show" return Product.find_by_title(parameters[:product][:title]) end end def new_session_as(name) open_session do |session| session.extend(ProductTestDSL) session.name = name yield session if block_given? end end end -- Posted via http://www.ruby-forum.com/.
fireflyman
2009-Aug-26 09:58 UTC
Re: Ruby on Rails > test:integration Expected response to be a <:redirect>, but was <404>
Thanks! 2009/8/26 Nik Cool <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>> > > > Looking around -- someone had a problem that the new object was not > > created or saved. One of the tests in products_controller_test.rb has > > no problem creating a new product. > > > > What am I missing? > > try this..... > this may work > > > test "product_administartion_by_admin" do > category = Category.create(:name => ''Parts'') > quentin = new_session_as(:quentin) > quentin.add_product > > end > > private > > module ProductTestDSL > attr_writer :name > > def add_product > params ={:product => { > :title => ''Clip'', > :category_id => category.id, > :sku => 54321, > :desctription => ''some text'', > :price => 8.71}} > post "/product/create", params > assert_response :redirect > follow_redirect! > assert_response :success > assert_template "/product/show" > return Product.find_by_title(parameters[:product][:title]) > end > end > > def new_session_as(name) > open_session do |session| > session.extend(ProductTestDSL) > session.name = name > yield session if block_given? > end > end > end > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---