Taro Kimura
2013-Sep-23 18:48 UTC
redirect on browser success, but redirect on functional test is error
line_items.yml: one: product_id: 1 cart_id: 1 quantity: 1 carts.yml: one: {} product.rb: has_many :line_items cart.rb: has_many :line_items, dependent: :destroy line_item.rb: belongs_to :product belongs_to :cart line_item_controller.rb: def destroy @line_item = LineItem.find(params[:id]) @cart = @line_item.cart @line_item.destroy respond_to do |format| format.html { redirect_to @cart } format.json { head :no_content } end end line_item_controller_test.rb: setup do @line_item = line_items(:one) end test "should destroy line_item" do @cart = @line_item.cart assert_difference(''LineItem.count'', -1) do delete :destroy, id: @line_item end assert_redirected_to @cart end ---------------------------------------------- rake test:functionals 1) Error: test_should_destroy_line_item(LineItemsControllerTest): ActionController::ActionControllerError: Cannot redirect to nil! ------------------------------------------------ @cart in line_items_controller.rb may be nil, when executing functional test. Accessing by browser "line_items/20/ post:delete", correctly redirected show cart that contain line_items(id:20) why is functional test error? -- 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/a49dd91d738b79484db2b2b9319d81c5%40ruby-forum.com. For more options, visit https://groups.google.com/groups/opt_out.
jsnark
2013-Sep-24 12:51 UTC
Re: redirect on browser success, but redirect on functional test is error
carts.yml does not create the cart with id=1 that LineItem.find(1) refers to. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/08dd854c-f181-4974-bd74-577708b40c18%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Maybe Matching Threads
- How to test views with Nested Resources and Partials
- best approach to add form elements dynamically
- Adding extra field in form using ajax causes extra field to be overwritten, any way around that.
- NoMethodError in Store#index
- Problem updating child row from parent model