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)