# Assert\_recognizes with requirements =\> {:method =\> something}

**URL:** <https://www.ruby-forum.com/t/assert-recognizes-with-requirements-method-something/124837>\
**Category:** Rails\
**Created:** [January 3, 2008, 12:15am UTC](https://www.ruby-forum.com/t/assert-recognizes-with-requirements-method-something/124837 "2008-01-03T00:15:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gcnovus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/779978/32.png) [@gcnovus](https://www.ruby-forum.com/u/gcnovus)\
**Post date:** [January 3, 2008, 12:15am UTC](https://www.ruby-forum.com/t/assert-recognizes-with-requirements-method-something/124837/1 "2008-01-03T00:15:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gcnovus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/779978/32.png) [@gcnovus](https://www.ruby-forum.com/u/gcnovus)\
**Post date:** [January 3, 2008, 1:21am UTC](https://www.ruby-forum.com/t/assert-recognizes-with-requirements-method-something/124837/2 "2008-01-03T01:21:20Z")

</div>

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
