How to write get functional test when there is no action by

I have following line in route.rb

#event info for an event name
map.connect ‘event/:name_url’,:controller => ‘home’,:action =>
‘event_info’

It causes a URL like http://localhost:3000/event/jewels_exhibition to
be
sent to the home controller with action as ‘event_info’.

I am trying to test this action. My first gut was to write something
like

def test_event_info
get :event_info
assert_response :success
end

But this doesn’t work.

Does anyone have any idea how to creat a get request whicn transaltes
into "
http://localhost:3000/event/jewels_exhibition ".

I am stuck because of this and can’t proceed with my testing.

I even tried

def test_event_info
get “http://localhost:3000/event/jewels_exhibition
assert_response :success
end

But that doesn’t work either.

This works.

def test_event_info
opts = {:controller => “event”, :action => “jewels_exhibition”}
assert_generates “event/jewels_exhibition”, opts
end

But the question remains how do I send a get request so that I could
test
the other things like instance variables ?

It depends what you want to test. If you want to test the lines of code
between the def and end of your event_info method, then synthesize a url
and
use the get method on it, bypassing the route. If you really want to
push
through the routes, then read up on integration testing, as it might be
more
fruitful.

Here¹s a great article about testing:

http://manuals.rubyonrails.com/read/chapter/28

However, look over integration testing. It seems like the most likely
direction for what you want:

http://jamis.jamisbuck.org/articles/2006/03/09/integration-testing-in-rails-
1-1

HTH

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs