Neeraj Kumar
2006-Jul-05 04:12 UTC
[Rails] How to write get functional test when there is no action by that name
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. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060705/e3242590/attachment.html
Neeraj Kumar
2006-Jul-05 04:23 UTC
[Rails] Re: How to write get functional test when there is no action by that name
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 ? On 7/5/06, Neeraj Kumar <neeraj.jsr@gmail.com> wrote:> > 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. > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060705/b6e804e4/attachment.html
s.ross
2006-Jul-05 07:07 UTC
[Rails] How to write get functional test when there is no action by that name
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 On 7/4/06 9:12 PM, "Neeraj Kumar" <neeraj.jsr@gmail.com> wrote:> 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_ > <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_ > <http://localhost:3000/event/_jewels_exhibition_> " > assert_response :success > end > > But that doesn''t work either. > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060705/23076ebb/attachment.html