[rspec] How to pass route parameters to post method?

Hello,

I am trying to spec an action in a controller, and rspec doesn’t find
a route.
It seems that problem is in “:viewtype”. If I change a line
“/:viewtype/asset/add”
into “/context/asset/add” in routes it works.

I tried also
post “/context/asset/add”, no luck.

Could you please let me know how I can call the action through
that route with post method?

Thank you in advance,
Evgeny

map.with_options(:controller => “assets”, :conditions =>{:method
=> :post}) do |m|
m.create_asset ‘/:viewtype/asset/
add’, :action => ‘create’
end

describe AssetsController, “when working with formats” do
it “should call a find_asset_format for some actions” do
post :create
end
end

Hi Evgeny,

You didn’t include the error message in your email, so this is just a
guess,
but from your example, it looks like you need to specify :viewtype in
your
call to post, like so:

post :create, :viewtype => ‘context’

The HTTP verb methods require you to specify the route parameters in
order
to work.

Mike

On Jun 2, 2009 3:53 AM, “Evgeny Bogdanov” [email protected]
wrote:

Hello,

I am trying to spec an action in a controller, and rspec doesn’t find
a route.
It seems that problem is in “:viewtype”. If I change a line
“/:viewtype/asset/add”
into “/context/asset/add” in routes it works.

I tried also
post “/context/asset/add”, no luck.

Could you please let me know how I can call the action through
that route with post method?

Thank you in advance,
Evgeny

map.with_options(:controller => “assets”, :conditions =>{:method
=> :post}) do |m|
m.create_asset ‘/:viewtype/asset/
add’, :action => ‘create’
end

describe AssetsController, “when working with formats” do
it “should call a find_asset_format for some actions” do
post :create
end
end

Hello Mike,

Thank you for your hint. Obviously, it worked!
Laughing at myself now: how post method was supposed to know what I
mean by :viewtype if don’t specify it :slight_smile:

Best,
Evgeny