7stud --
2012-Aug-30 21:29 UTC
How can an rspec test for a view pass if there is no action for the view in the controller?
The rspec test looks like this: require ''spec_helper'' describe "Static pages" do describe "Home page" do it "should have the h1 ''Sample App''" do visit ''/static_pages/home'' page.should have_selector(''h1'', :text => ''Sample App'') end end end My controller looks like this: class StaticPagesController < ApplicationController end -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Colin Law
2012-Aug-31 06:04 UTC
Re: How can an rspec test for a view pass if there is no action for the view in the controller?
On 30 August 2012 22:29, 7stud -- <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> The rspec test looks like this: > > > require ''spec_helper'' > > describe "Static pages" do > > describe "Home page" do > > it "should have the h1 ''Sample App''" do > visit ''/static_pages/home'' > page.should have_selector(''h1'', :text => ''Sample App'') > end > > end > > end > > > My controller looks like this: > > class StaticPagesController < ApplicationController > endIf you go to that url in the browser does it show a page with the header? Is there a page in public/static_pages that matches that url? In which case that will be served without the need for a controller action. What does test.log show when you run the test? Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
7stud --
2012-Aug-31 18:49 UTC
Re: How can an rspec test for a view pass if there''s no action for the view in the controller?
1) Yes, the page shows when I start rails server, and then use the url: http://localhost:300/static_pages/home 2) Everything in public/ was created by rails new: $ ls public/ 404.html 500.html index.html 422.html favicon.ico robots.txt 3) test.log: Started GET "/static_pages/home" for 127.0.0.1 at 2012-08-31 10:04:28 -0700 Processing by StaticPagesController#home as HTML Rendered static_pages/home.html.erb within layouts/application (3.7ms) Completed 200 OK in 21ms (Views: 20.0ms | ActiveRecord: 0.0ms) [1m[35m (0.1ms)[0m rollback transaction [1m[36m (0.1ms)[0m [1mbegin transaction[0m Started GET "/static_pages/home" for 127.0.0.1 at 2012-08-31 10:04:28 -0700 Processing by StaticPagesController#home as HTML Completed 200 OK in 2ms (Views: 1.6ms | ActiveRecord: 0.0ms) [1m[35m (0.1ms)[0m rollback transaction [1m[36m (0.1ms)[0m [1mbegin transaction[0m Yet here is my controller: class StaticPagesController < ApplicationController end Previously, I had actions in my controller, but I wanted to see if the tests would fail without the actions, and I fully expected them to fail, but they won''t. I have everything at github: https://github.com/7stud/sample_app25 Curiously, if I write a test for a non-existent view, I get three errors: First, no route; then after I add the route: get ''/static_pages/something'' I get an error saying there''s no action; then after I add the action, I get an error saying there''s no view; then after adding a view, the test passes. Subsequently, if I delete the action for that view, the test still passes. Why? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Walter Lee Davis
2012-Aug-31 18:58 UTC
Re: How can an rspec test for a view pass if there''s no action for the view in the controller?
On Aug 31, 2012, at 2:49 PM, 7stud -- wrote:> 1) Yes, the page shows when I start rails server, and then use the url: > > http://localhost:300/static_pages/home > > 2) Everything in public/ was created by rails new: > > $ ls public/ > 404.html 500.html index.html > 422.html favicon.ico robots.txt > > > 3) test.log: > > Started GET "/static_pages/home" for 127.0.0.1 at 2012-08-31 10:04:28 > -0700 > Processing by StaticPagesController#home as HTML > Rendered static_pages/home.html.erb within layouts/application (3.7ms) > Completed 200 OK in 21ms (Views: 20.0ms | ActiveRecord: 0.0ms) > [1m[35m (0.1ms)[0m rollback transaction > [1m[36m (0.1ms)[0m [1mbegin transaction[0m > > > Started GET "/static_pages/home" for 127.0.0.1 at 2012-08-31 10:04:28 > -0700 > Processing by StaticPagesController#home as HTML > Completed 200 OK in 2ms (Views: 1.6ms | ActiveRecord: 0.0ms) > [1m[35m (0.1ms)[0m rollback transaction > [1m[36m (0.1ms)[0m [1mbegin transaction[0m > > > > Yet here is my controller: > > class StaticPagesController < ApplicationController > end > > Previously, I had actions in my controller, but I wanted to see if the > tests would fail without the actions, and I fully expected them to fail, > but they won''t. I have everything at github: > > https://github.com/7stud/sample_app25 > > Curiously, if I write a test for a non-existent view, I get three > errors: First, no route; then after I add the route: > > get ''/static_pages/something'' > > I get an error saying there''s no action; then after I add the action, I > get an error saying there''s no view; then after adding a view, the test > passes. Subsequently, if I delete the action for that view, the test > still passes. Why?What''s in your routes.rb? This could be a catch-all route firing. In Ryan Bates'' Railscast on semi-static pages, he mentions that a completely empty controller will work as long as there is a properly named view file at the expected path. I tried it in a quick test app, but it didn''t work in vanilla 3.2. Walter -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
7stud --
2012-Aug-31 20:10 UTC
Re: How can an rspec test for a view pass if there''s no action for the view in the controller?
Thanks for the response. Here is my routes.rb: SampleApp25::Application.routes.draw do get "static_pages/home" get "static_pages/help" get "static_pages/about" get "static_pages/contact" # The priority is based upon order of creation: # first created -> highest priority. # Sample of regular route: # match ''products/:id'' => ''catalog#view'' # Keep in mind you can assign values other than :controller and :action # Sample of named route: # match ''products/:id/purchase'' => ''catalog#purchase'', :as => :purchase # This route can be invoked with purchase_url(:id => product.id) # Sample resource route (maps HTTP verbs to controller actions automatically): # resources :products # Sample resource route with options: # resources :products do # member do # get ''short'' # post ''toggle'' # end # # collection do # get ''sold'' # end # end # Sample resource route with sub-resources: # resources :products do # resources :comments, :sales # resource :seller # end # Sample resource route with more complex sub-resources # resources :products do # resources :comments # resources :sales do # get ''recent'', :on => :collection # end # end # Sample resource route within a namespace: # namespace :admin do # # Directs /admin/products/* to Admin::ProductsController # # (app/controllers/admin/products_controller.rb) # resources :products # end # You can have the root of your site routed with "root" # just remember to delete public/index.html. # root :to => ''welcome#index'' # See how all your routes lay out with "rake routes" # This is a legacy wild controller route that''s not recommended for RESTful applications. # Note: This route will make all actions in every controller accessible via GET requests. # match '':controller(/:action(/:id))(.:format)'' end -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Walter Lee Davis
2012-Aug-31 20:27 UTC
Re: How can an rspec test for a view pass if there''s no action for the view in the controller?
On Aug 31, 2012, at 4:10 PM, 7stud -- wrote:> Thanks for the response. Here is my routes.rb: > > > SampleApp25::Application.routes.draw do > get "static_pages/home" > get "static_pages/help" > get "static_pages/about" > get "static_pages/contact"Yup. I can confirm that with a similar route here in an otherwise entirely empty controller and a matching view in the correct folder, this just works without any logic at all. Let''s hear it for convention over configuration! Walter -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
7stud --
2012-Aug-31 21:32 UTC
Re: How can an rspec test for a view pass if there''s no action for the view in the controller?
So this is a route "problem"? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Walter Lee Davis
2012-Aug-31 21:46 UTC
Re: Re: How can an rspec test for a view pass if there''s no action for the view in the controller?
It''s a feature of Rails. It''s a problem if it causes problems. With the sort of routing you have, it''s only going to expose the views you indicate in your routes.rb file. If you had a more liberal route like match ''info/:action'' => ''info#action'' then it would show any action.html you placed in the views/info folder, as long as it was requested properly. Walter On Aug 31, 2012, at 5:32 PM, 7stud -- wrote:> So this is a route "problem"? > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit https://groups.google.com/groups/opt_out. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
7stud --
2012-Sep-01 22:05 UTC
Re: How can an rspec test for a view pass if there''s no action for the view in the controller?
> It''s a feature of Rails. It''s a problem if it causes problems.(Note: nothing in this post has anything to do with rspec.) For me, that routing behavior is causing problems. Here''s why: if I add a route such as: get "static_pages/dog" ...and then enter the url http://localhost:3000/static_pages/dog in my browser, rails complains that there''s no action called dog in the StaticPagesController: ==Unknown action The action ''dog'' could not be found for StaticPagesController == Then if I add the dog action to the controller, then create a view, everything works fine and dandy. But if I then delete the dog action, and then use the same url, http://localhost:3000/static_pages/dog, in my browser, this time I get a different result--instead of getting an error the view displays. For me, that inconsistent behavior is not right, and it should not be that way. So I want to know whether there were reasons for the rails team to institute that inconsistent behavior, or whether it is a bug. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Frederick Cheung
2012-Sep-02 00:45 UTC
Re: How can an rspec test for a view pass if there''s no action for the view in the controller?
On Saturday, September 1, 2012 11:05:36 PM UTC+1, Ruby-Forum.com User wrote:> > === > Unknown action > > The action ''dog'' could not be found for StaticPagesController > === > > Then if I add the dog action to the controller, then create a view, > everything works fine and dandy. > >You can skip the adding an action bit and go straight to creating a view> But if I then delete the dog action, and then use the same url, > http://localhost:3000/static_pages/dog, in my browser, this time I get a > different result--instead of getting an error the view displays. For > me, that inconsistent behavior is not right, and it should not be that > way. So I want to know whether there were reasons for the rails team > to institute that inconsistent behavior, or whether it is a bug. > > This is a long standing rails feature (right back to 1.x at least): railsdoesn''t make you define an empty action. I don''t think it''s a feature that gets a whole lot of use, but it''s definitely intentional (documented here: http://guides.rubyonrails.org/layouts_and_rendering.html#rendering-by-default-convention-over-configuration-in-action ) Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/E6utBi8UjJcJ. For more options, visit https://groups.google.com/groups/opt_out.
7stud --
2012-Sep-02 01:41 UTC
Re: How can an rspec test for a view pass if there''s no action for the view in the controller?
Thanks for the response Frederick Cheung. I don''t like this ''default rendering'', nor the misleading error message saying the action is missing--but I guess I''ll have to live with it. A route and view is all that''s necessary to render a page. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Colin Law
2012-Sep-02 07:48 UTC
Re: Re: How can an rspec test for a view pass if there''s no action for the view in the controller?
On 1 September 2012 23:05, 7stud -- <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:>> It''s a feature of Rails. It''s a problem if it causes problems. > > (Note: nothing in this post has anything to do with rspec.) > > For me, that routing behavior is causing problems. Here''s why: if I add > a route such as: > > get "static_pages/dog" > > ...and then enter the url http://localhost:3000/static_pages/dog in my > browser, rails complains that there''s no action called dog in the > StaticPagesController: > > ==> Unknown action > > The action ''dog'' could not be found for StaticPagesController > ==> > Then if I add the dog action to the controller, then create a view, > everything works fine and dandy. > > But if I then delete the dog action, and then use the same url, > http://localhost:3000/static_pages/dog, in my browser, this time I get a > different result--instead of getting an error the view displays. For > me, that inconsistent behavior is not right, and it should not be that > way. So I want to know whether there were reasons for the rails team > to institute that inconsistent behavior, or whether it is a bug.It is not inconsistent. You started with no action and no view and url fails. You added action and view and url works. You deleted only the action and the view continues to work. If you delete the view then it will fail again. Perfectly consistent. In fact the empty action is just not needed. Rails assumes that since you have provided a route and a view that you would like them to work and saves you the effort of providing an empty action. I never intentionally rely on that myself as I find it a little confusing, but it is not inconsistent. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
7stud --
2012-Sep-03 03:29 UTC
Re: How can an rspec test for a view pass if there''s no action for the view in the controller?
> It is not inconsistent.Okay, perhaps it''s more correct to say that Rails is flat out wrong. Rails complains that I need an action when there isn''t one, which is false. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Colin Law
2012-Sep-03 08:12 UTC
Re: Re: How can an rspec test for a view pass if there''s no action for the view in the controller?
On 3 September 2012 04:29, 7stud -- <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:>> It is not inconsistent. > > Okay, perhaps it''s more correct to say that Rails is flat out wrong. > Rails complains that I need an action when there isn''t one, which is > false.What do you mean it complains that you need an action? I thought your problem was that it did /not/ complain that there is no action in the model. Colin> > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit https://groups.google.com/groups/opt_out. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
7stud --
2012-Sep-03 16:02 UTC
Re: How can an rspec test for a view pass if there''s no action for the view in the controller?
If you don''t even know what the posts in this thread say, why bother posting anything? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Colin Law
2012-Sep-03 16:17 UTC
Re: Re: How can an rspec test for a view pass if there''s no action for the view in the controller?
On 3 September 2012 17:02, 7stud -- <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> If you don''t even know what the posts in this thread say, why bother > posting anything?I couldn''t agree more. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.