views:

116

answers:

2

For several of my cuke scenarios, I want to POST the user to a page with an object in the params, so that Rails will make a new object in the database. Is there a convenient way to send a POST+params to an action (either using something in cucumber or rails) or do I have to write my own function using Net::Http?

A: 

It sounds like you don't have a form for this action? If you do have a form, you just complete the interaction via the web UI (using the tool of your choice ... webrat etc etc)

Otherwise, if this is to setup some test data, it's probably better to create the object directly in a step.

Given that an object exists
Do ...

Under the "Given" step, create the necessary object too meet the assumption in the rest of the test steps.

Toby Hede
Yeah, I know how to do it that way... but what I would like to do is create the object without using a form, by supplying the object details in the params. Someone told me there's no way to do this without using a form. That's hard to believe!
Jason
A: 

Just visit the controller you want to post some parameters to in order to create an object.

You certainly do not need a form to do this. Just post the values to whatever controller is handling these posts and continue on with your testing. All the controller cares about is getting params to work with, however they get posted.

visit "/user", :post, :firstName => "Foo", :lastName => "Bar"

As detailed in the webrat documentation:

visit (url = nil, http_method = :get, data = {})
mczepiel
Excellent, thanks!
Jason