ruby on rails - Testing a redirect_to(:back) on successful from completion isn't working -
i'm trying run test has redirect_to(:back)
on successful form completion, error when run line
assert_difference 'comment.count', 1 post comments_path, comment: { body: "optc", commentable_id: 1, commentable_type: 'post'} end
error actioncontroller::redirectbackerror: no http_referer set in request action, redirect_to :back not called successfully. if test, make sure specify request.env["http_referer"].
looking this see need request.env['http_referer'] = 'http://test.com/'
added setup. gives error nomethoderror: undefined method 'env' nil:nilclass
now i'm not sure do. how can first error go away?
update
im using rails 4
here header of test file
require 'test_helper'
class categoryitemshowpagetest < actiondispatch::integrationtest def setup @user = users(:michael) @user1 = users(:archer) @guide = guide.find(1) @category = category.find(1) @category_item = categoryitem.find(1) @mod_relationship = game_mods_relationships(:mod1) request.env['http_referer'] = 'http://test.com/' end
as discussed in comments above, believe, should work ok setting params , http referer in rails 4 integration test:
post comments_path, { comment: { body: "optc", commentable_id: 1, commentable_type: 'post' } }, { 'http_referer' => 'http://www.somewhere.net' }
Comments
Post a Comment