For example: it "re-renders the ''new'' template" do # Trigger the behavior that occurs when invalid params are submitted Sector.any_instance.stub(:save).and_return(false) post :create, :sector => {} response.should render_template("new") end I have the new template under app/views/sectors but the test says: SectorsController POST create with invalid params re-renders the ''new'' template Failure/Error: response.should render_template("new") expecting <"new"> but rendering with <""> -- 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On May 28, 12:59 pm, Mauro <mrsan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> For example: > > it "re-renders the ''new'' template" do > # Trigger the behavior that occurs when invalid params are submitted > Sector.any_instance.stub(:save).and_return(false) > post :create, :sector => {} > response.should render_template("new") > end > > I have the new template under app/views/sectors but the test says: > > SectorsController POST create with invalid params re-renders the ''new'' template > Failure/Error: response.should render_template("new") > expecting <"new"> but rendering with <"">Please post the controller action so we can see what''s missing. -- 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On May 28, 1:59 pm, Mauro <mrsan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> For example: > > it "re-renders the ''new'' template" do > # Trigger the behavior that occurs when invalid params are submitted > Sector.any_instance.stub(:save).and_return(false) > post :create, :sector => {} > response.should render_template("new") > end > > I have the new template under app/views/sectors but the test says: > > SectorsController POST create with invalid params re-renders the ''new'' template > Failure/Error: response.should render_template("new") > expecting <"new"> but rendering with <"">It sounds like the test is working and that your code is at fault by the looks of it. Do you have a "render"/redirect_to method being called in your ''create'' controller action? Where is it going? -- 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 29 May 2011 10:45, egervari <ken.egervari-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On May 28, 1:59 pm, Mauro <mrsan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> For example: >> >> it "re-renders the ''new'' template" do >> # Trigger the behavior that occurs when invalid params are submitted >> Sector.any_instance.stub(:save).and_return(false) >> post :create, :sector => {} >> response.should render_template("new") >> end >> >> I have the new template under app/views/sectors but the test says: >> >> SectorsController POST create with invalid params re-renders the ''new'' template >> Failure/Error: response.should render_template("new") >> expecting <"new"> but rendering with <""> > > It sounds like the test is working and that your code is at fault by > the looks of it. Do you have a "render"/redirect_to method being > called in your ''create'' controller action? Where is it going?I''m using inherited_resources so in my controller I don''t have any action defined. The controller is simply: class SectorsController < InheritedResources::Base def destroy destroy!(:notice => t(''Sector'')+" deleted.") rescue flash[:error] = t(''Sector'')+" is not deleted." end end -- 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 29 May 2011 19:35, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 29 May 2011 10:45, egervari <ken.egervari-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> On May 28, 1:59 pm, Mauro <mrsan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> For example: >>> >>> it "re-renders the ''new'' template" do >>> # Trigger the behavior that occurs when invalid params are submitted >>> Sector.any_instance.stub(:save).and_return(false) >>> post :create, :sector => {} >>> response.should render_template("new") >>> end >>> >>> I have the new template under app/views/sectors but the test says: >>> >>> SectorsController POST create with invalid params re-renders the ''new'' template >>> Failure/Error: response.should render_template("new") >>> expecting <"new"> but rendering with <""> >> >> It sounds like the test is working and that your code is at fault by >> the looks of it. Do you have a "render"/redirect_to method being >> called in your ''create'' controller action? Where is it going? > > I''m using inherited_resources so in my controller I don''t have any > action defined. > The controller is simply: > > class SectorsController < InheritedResources::Base > > def destroy > destroy!(:notice => t(''Sector'')+" deleted.") > rescue > flash[:error] = t(''Sector'')+" is not deleted." > end > end >If I launch the application and I try to create an invalid sector, it renders the new template correctly I have another application and this test: it "re-renders the ''new'' template" do UnsafeBuilding.stub(:new) { mock_unsafe_building(:save => false) } post :create, :unsafe_building => {} response.should render_template("new") end This works and the controller uses inherited_resources too. I don''t understand why the test in the first application doens''t work while the one in the second application works. -- 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.