Rails functional test: sending URL query parameters in POST request

前端 未结 5 1491
栀梦
栀梦 2021-02-19 20:55

I\'m sending a POST request in a Rails functional test like this:

post :create, collection: { name: \'New Collection\' }

collection

5条回答
  •  醉话见心
    2021-02-19 21:58

    This is also a problem when testing POST actions with RSpec (v3.4).

    A workaround is to mock the return value of request.GET or request.query_string methods.

    it "should recognise a query parameter in post action" do
      allow(subject.request).to receive(:query_string).and_return("api_key=my%20key")  
      @params = {collection: { name: 'New Collection' }}
    
    
      expect(subject.request.query_string).to eq "api_key=my%20key"
    
      post :create, @params
    end
    

提交回复
热议问题