0

I would like to post an xml to a controller from minitest.

The way how it works in normal mode is this:

curl -X POST -H "Content-Type: text/xml" -d "@/Users/boti/Rails/clients/kevin/search_server/db/search.xml" localhost:3000/search

I tried by doing this:

test "search with invalid xml" do
  path_to_file = File.join Rails.root.to_s, 'test', 'search_invalid.xml'
  xml = File.read( path_to_file )
  @request.env['RAW_POST_DATA'] = xml
  post "/search/search", xml, {"Content-type" => "text/xml"}

But that way I get this exception:

NoMethodError: undefined method `symbolize_keys' for #<String:0x007fbd7d863188>
Boti
  • 3,275
  • 1
  • 29
  • 54

1 Answers1

1

I am doing this way in my tests:

path_to_file = File.join Rails.root.to_s, 'test', 'search_invalid_xml.xml'
xml = File.read( path_to_file )
@request.env['RAW_POST_DATA'] = xml
post :search, nil, {"Content-type" => "text/xml"}

Then this way in my controller:

search_doc = Nokogiri::XML.parse request.raw_post
Boti
  • 3,275
  • 1
  • 29
  • 54