mardi 29 septembre 2015

How is header information and post data in rails tests set?

I'm running Ruby 1.9.3 and Rails 3.1. I can successfully manually test my usage of the Washout gem by sending myself XML payloads. I am trying to recreate the following bash command in a rails test:

curl -H "Content-Type: text/xml; charset=utf-8" -H "SOAPAction:soap_submit_contract" -d@test/fixtures/soap/success.xml http://localhost/soap/action

As you can see, it sets some header data and sends the data in the file test/fixtures/soap/success.xml

All the other examples I see for POSTs look like this:

post :parse_pdf,
  :terminal_key => @terminal_key,
  :contract_pdf => load_pdf(pdf)

But in my case the file data isn't a named parameter, and this doesn't seem to be setting the header information.

How can I submit a post exactly the same way the curl command does?

Our test suite is using the default ActionController::TestCase as such:

class SoapControllerTest < ActionController::TestCase
  fixtures :terminals

  test "soap_succeeds" do 
    # request.set_header_information ???
    post :action, # file data ???

    assert_match(/success/, @response.body)
  end

end

Aucun commentaire:

Enregistrer un commentaire