# Rails restful query and rspec

**URL:** <https://www.ruby-forum.com/t/rails-restful-query-and-rspec/125417>\
**Category:** Rails\
**Created:** [January 8, 2008, 10:46pm UTC](https://www.ruby-forum.com/t/rails-restful-query-and-rspec/125417 "2008-01-08T22:46:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dhf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3be4f8/32.png) [@dhf](https://www.ruby-forum.com/u/dhf)\
**Post date:** [January 8, 2008, 10:46pm UTC](https://www.ruby-forum.com/t/rails-restful-query-and-rspec/125417/1 "2008-01-08T22:46:44Z")

</div>

I am working on a project that searches for an item number. But the  
item number is not unique. Which is better to do:

/search/12345 or /search?id=12345 I would prefer to use the first  
one.  
I have a route for it as map.search “/search/:item\_number”

I have made both work with manual testing. I do have a problem in  
rSpec testing though. I do not understand how to request the page from  
the controller.

I tried:

in the public\_controller I have:

def search  
@items = Item.all\_items(params(:item\_number))  
…  
end

and in the rspec for the controller:

describe PublicController do

#Delete these examples and add some real ones  
it “should use PublicController” do  
controller.should be\_an\_instance\_of(PublicController)  
end

describe “GET ‘index’” do  
it “should be successful” do  
get ‘index’  
response.should be\_success  
end  
end

describe “GET /search/:item\_number” do  
it “should be successful” do  
get :search, :item\_number =\> “12345” # also tried ‘search’  
response.should be\_success  
end  
end  
end

it errors with:  
ArgumentError in ‘PublicController GET /search/:item\_number should be  
successful’  
wrong number of arguments (1 for 0)

where have I gone wrong?

Don F.

---

<div class="post-metadata">

**Author:** ![dhf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3be4f8/32.png) [@dhf](https://www.ruby-forum.com/u/dhf)\
**Post date:** [January 8, 2008, 11:46pm UTC](https://www.ruby-forum.com/t/rails-restful-query-and-rspec/125417/2 "2008-01-08T23:46:32Z")

</div>

try get ‘search’, { :item\_number =\> “12345” }

On Jan 9, 2008 8:16 AM, dhf [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> the controller.  
> and in the rspec for the controller:  
> it “should be successful” do  
> end
> 
> >

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

Feel free to add me to MSN and/or GTalk as this email.

---

<div class="post-metadata">

**Author:** ![dhf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3be4f8/32.png) [@dhf](https://www.ruby-forum.com/u/dhf)\
**Post date:** [January 9, 2008, 12:01am UTC](https://www.ruby-forum.com/t/rails-restful-query-and-rspec/125417/3 "2008-01-09T00:01:44Z")

</div>

used: get “search”, {:item\_number =\> “12345”} and it gave the  
same error.

dhf

---

<div class="post-metadata">

**Author:** ![dhf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3be4f8/32.png) [@dhf](https://www.ruby-forum.com/u/dhf)\
**Post date:** [January 9, 2008, 12:03am UTC](https://www.ruby-forum.com/t/rails-restful-query-and-rspec/125417/4 "2008-01-09T00:03:30Z")

</div>

Could I have the backtrace on the error please?

On Jan 9, 2008 9:30 AM, dhf [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > …
> > 
> > > response.should be\_success
> > 
> > > Don F.
> > 
> > –  
> > Ryan B.[http://www.frozenplague.net](http://www.frozenplague.net)  
> > Feel free to add me to MSN and/or GTalk as this email.

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

Feel free to add me to MSN and/or GTalk as this email.

---

<div class="post-metadata">

**Author:** ![dhf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3be4f8/32.png) [@dhf](https://www.ruby-forum.com/u/dhf)\
**Post date:** [January 9, 2008, 12:14am UTC](https://www.ruby-forum.com/t/rails-restful-query-and-rspec/125417/5 "2008-01-09T00:14:40Z")

</div>

We can talk gtalk if you want.

/Users/dhf/NetBeansProjects/snr/app/controllers/public\_controller.rb:  
8:in `params' /Users/dhf/NetBeansProjects/snr/app/controllers/public_controller.rb: 8:in`search’  
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/  
base.rb:1158:in `send' /Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ base.rb:1158:in`perform\_action\_without\_filters’  
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/  
filters.rb:697:in `call_filters' /Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ filters.rb:689:in`perform\_action\_without\_benchmark’  
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/  
benchmarking.rb:68:in `perform_action_without_rescue' /Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ benchmarking.rb:68:in`perform\_action\_without\_rescue’  
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/  
rescue.rb:199:in `perform_action_without_caching' /Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ caching.rb:678:in`perform\_action’  
/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active\_record/  
connection\_adapters/abstract/query\_cache.rb:33:in `cache' /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/ query_cache.rb:8:in`cache’  
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/  
caching.rb:677:in `perform_action' /Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ base.rb:524:in`send’  
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/  
base.rb:524:in `process_without_filters' /Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ filters.rb:685:in`process\_without\_session\_management\_support’  
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/  
session\_management.rb:123:in `process_without_test' /Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ test_process.rb:15:in`process’  
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action\_controller/  
test\_process.rb:393:in `process' /Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ test_process.rb:364:in`get’  
./spec/controllers/public\_controller\_spec.rb:20:

---

<div class="post-metadata">

**Author:** ![dhf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3be4f8/32.png) [@dhf](https://www.ruby-forum.com/u/dhf)\
**Post date:** [January 9, 2008, 12:19am UTC](https://www.ruby-forum.com/t/rails-restful-query-and-rspec/125417/6 "2008-01-09T00:19:20Z")

</div>

Log file shows:

Processing PublicController#search (for 0.0.0.0 at 2008-01-08  
13:15:29) [GET]  
Session ID:  
Parameters: {“action”=\>“search”, “controller”=\>“public”,  
“item\_number”=\>“12345”}  
SQL (0.000206) ROLLBACK
