gcnovus
2008-Jan-02 23:14 UTC
assert_recognizes with requirements => {:method => something}
I''m having trouble with my routing, and was wondering if anyone else
had seen something similar.
I''ve got these two routes:
map.login ''/login'', :controller =>
''sessions'', :action =>
''new'', :requirements => { :method => :get }
map.connect ''/login'', :controller =>
''sessions'', :action =>
''create'', :requirements => { :method => :post }
and I have these tests:
a. assert_recognizes({:controller => ''sessions'', :action
=> ''new''},
{:path => ''/login'', :method => :get})
b. assert_recognizes({:controller => ''sessions'', :action
=> ''create''},
{:path => ''/login'', :method => :post})
I get the failure messages:
a. The recognized options <{"action"=>"new",
"method"=>:get,
"controller"=>"sessions"}> did not match
<{"action"=>"new",
"controller"=>"sessions"}>, difference:
<{"method"=>:get}>
b. The recognized options <{"action"=>"new",
"method"=>:get,
"controller"=>"sessions"}> did not match
<{"action"=>"create",
"controller"=>"sessions"}>, difference:
<{"action"=>"create",
"method"=>:post}>
I have two problems:
1. In the API for AssertRouting, it shows these calls without
{ :method => xxx } in the first argument. Changing the first call to
assert_recognizes({:controller => ''sessions'', :action =>
''new'', :method => :get}, {:path =>
''/login'', :method => :get})
works, but I feel like I shouldn''t need to do that.
2. Even if I change the second call to
assert_recognizes({:controller => ''sessions'', :action =>
''create'', :method => :post}, {:path =>
''/login'', :method => :post})
it still fails with the same error. It''s as though Rails is ignoring
the requirements of the first route.
Thanks in advance for any help,
Gaius
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
gcnovus
2008-Jan-03 00:20 UTC
Re: assert_recognizes with requirements => {:method => something}
In case anyone is wondering, the key here is the difference
between :requirements and :conditions. The routes should actually
look like
a. map.login ''/login'', :controller =>
''sessions'', :action =>
''new'', :conditions => { :method => :get }
b. map.connect ''/login'', :controller =>
''sessions'', :action =>
''create'', :conditions => { :method => :post }
:conditions only works on :method, and :requirements only works on
everything else
-Gaius
On Jan 2, 6:14 pm, gcnovus
<james.a.ro...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> I''m having trouble with my routing, and was wondering if anyone
else
> had seen something similar.
>
> I''ve got these two routes:
> map.login ''/login'', :controller =>
''sessions'', :action =>
> ''new'', :requirements => { :method => :get }
> map.connect ''/login'', :controller =>
''sessions'', :action =>
> ''create'', :requirements => { :method => :post }
>
> and I have these tests:
> a. assert_recognizes({:controller => ''sessions'',
:action => ''new''},
> {:path => ''/login'', :method => :get})
>
> b. assert_recognizes({:controller => ''sessions'',
:action => ''create''},
> {:path => ''/login'', :method => :post})
>
> I get the failure messages:
> a. The recognized options <{"action"=>"new",
"method"=>:get,
> "controller"=>"sessions"}> did not match
<{"action"=>"new",
> "controller"=>"sessions"}>, difference:
<{"method"=>:get}>
>
> b. The recognized options <{"action"=>"new",
"method"=>:get,
> "controller"=>"sessions"}> did not match
<{"action"=>"create",
> "controller"=>"sessions"}>, difference:
<{"action"=>"create",
> "method"=>:post}>
>
> I have two problems:
> 1. In the API for AssertRouting, it shows these calls without
> { :method => xxx } in the first argument. Changing the first call to
> assert_recognizes({:controller => ''sessions'', :action
=>
> ''new'', :method => :get}, {:path =>
''/login'', :method => :get})
> works, but I feel like I shouldn''t need to do that.
>
> 2. Even if I change the second call to
> assert_recognizes({:controller => ''sessions'', :action
=>
> ''create'', :method => :post}, {:path =>
''/login'', :method => :post})
> it still fails with the same error. It''s as though Rails is
ignoring
> the requirements of the first route.
>
> Thanks in advance for any help,
> Gaius
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---