How do I set HTTP_REFERER when testing in Rails?

后端 未结 7 1288
我在风中等你
我在风中等你 2020-12-05 22:12

I\'m trying to test a controller and I got this error. I understand the error, but don\'t know how to fix it.

test: on CREATE to :user with completely invali         


        
7条回答
  •  时光取名叫无心
    2020-12-05 23:04

    setup do
      @request.env['HTTP_REFERER'] = 'http://test.com/sessions/new'
      post :create, { :user => { :email => 'invalid@abc' } }
    end
    

    In Rails 2.2.2, the above block never ran actual test. Saying that

    post :create, { :user => { :email => 'invalid@abc' } }

    line did not run. You can simply get rid of setup block and use

    @request.env['HTTP_REFERER'] = 'http://test.com/sessions/new'
    post :create, { :user => { :email => 'invalid@abc' } }
    

    instead. And it should set the referer

提交回复
热议问题