I am trying to be a good RORer and write all my tests to achieve 100% coverage with rcov. However, I have run up against something that really confuses me. In my test file <code> def test_should_mark_task_done task = tasks(:tasks_001) post_with_user(''admin'', :mark_done, {:id => task.id} ) assert_response :success assert_equal flash[:notice], ''Task was successfully updated.'' task.reload assert_equal task.done end </code> In my controller: <code> def mark_done @task = Task.find(params[:id]) @task.done = true @task.save flash[:notice] = ''Task was successfully updated.'' respond_to do |format| format.js # mark_done.js.rjs format.html { redirect_to :action => "index" } format.xml { head :ok } end end </code> The assert_response :success passes (as it should) The assert_equal flash[:notice] passes (as it should) The assert_equal task.done fails (HUH?!?!?!?!) The code works in practice (ie, it modifies the done column of the record.) Any suggestions of where to look? Thanks, Alan --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi -- On Wed, 23 Apr 2008, Alan Smith wrote:> > I am trying to be a good RORer and write all my tests to achieve 100% > coverage with rcov. > > However, I have run up against something that really confuses me. > > In my test file > <code> > def test_should_mark_task_done > task = tasks(:tasks_001) > post_with_user(''admin'', :mark_done, {:id => task.id} ) > assert_response :success > assert_equal flash[:notice], ''Task was successfully updated.'' > task.reload > assert_equal task.done > end > </code> > > In my controller: > <code> > def mark_done > @task = Task.find(params[:id]) > @task.done = true > @task.save > flash[:notice] = ''Task was successfully updated.'' > respond_to do |format| > format.js # mark_done.js.rjs > format.html { redirect_to :action => "index" } > format.xml { head :ok } > end > end > </code> > > The assert_response :success passes (as it should) > The assert_equal flash[:notice] passes (as it should) > The assert_equal task.done fails (HUH?!?!?!?!) > > The code works in practice (ie, it modifies the done column of the record.) > > Any suggestions of where to look?You''re not saying what you think it''s equal to. Maybe just: assert task.done is what you need? David -- Rails training from David A. Black and Ruby Power and Light: INTRO TO RAILS June 9-12 Berlin ADVANCING WITH RAILS June 16-19 Berlin INTRO TO RAILS June 24-27 London (Skills Matter) See http://www.rubypal.com for details and updates! --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I apologize, the actual code says assert task_done It was a typo on my part in the email. --Alan On Wed, Apr 23, 2008 at 9:01 PM, David A. Black <dblack-0o/XNnkTkwhBDgjK7y7TUQ@public.gmane.org> wrote:> > Hi -- > > > > On Wed, 23 Apr 2008, Alan Smith wrote: > > > > > I am trying to be a good RORer and write all my tests to achieve 100% > > coverage with rcov. > > > > However, I have run up against something that really confuses me. > > > > In my test file > > <code> > > def test_should_mark_task_done > > task = tasks(:tasks_001) > > post_with_user(''admin'', :mark_done, {:id => task.id} ) > > assert_response :success > > assert_equal flash[:notice], ''Task was successfully updated.'' > > task.reload > > assert_equal task.done > > end > > </code> > > > > In my controller: > > <code> > > def mark_done > > @task = Task.find(params[:id]) > > @task.done = true > > @task.save > > flash[:notice] = ''Task was successfully updated.'' > > respond_to do |format| > > format.js # mark_done.js.rjs > > format.html { redirect_to :action => "index" } > > format.xml { head :ok } > > end > > end > > </code> > > > > The assert_response :success passes (as it should) > > The assert_equal flash[:notice] passes (as it should) > > The assert_equal task.done fails (HUH?!?!?!?!) > > > > The code works in practice (ie, it modifies the done column of the record.) > > > > Any suggestions of where to look? > > You''re not saying what you think it''s equal to. Maybe just: > > assert task.done > > is what you need? > > > David > > -- > Rails training from David A. Black and Ruby Power and Light: > INTRO TO RAILS June 9-12 Berlin > ADVANCING WITH RAILS June 16-19 Berlin > INTRO TO RAILS June 24-27 London (Skills Matter) > See http://www.rubypal.com for details and updates! > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 24 Apr 2008, at 14:19, Alan Smith wrote:> > I apologize, the actual code says > assert task_done >I assume that''s another typo and you mean assert task.done Have you tried changing the save to a save! (so that you get an exception saying why it has failed) ? 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You are correct, it should be assert task.done I know that the save in the actual controller works, because flash[:notice] gets set appropriately. Just for grins, I changed it from save, to save! in the controller with no difference. Thanks for helping me with this! --Alan On Thu, Apr 24, 2008 at 9:11 AM, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On 24 Apr 2008, at 14:19, Alan Smith wrote: > > > > > I apologize, the actual code says > > assert task_done > > > I assume that''s another typo and you mean assert task.done > Have you tried changing the save to a save! (so that you get an > exception saying why it has failed) ? > > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I just realized that my post is not clear, I still have the problem that assert task.done fails On Thu, Apr 24, 2008 at 9:18 AM, Alan Smith <alan0412-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You are correct, it should be assert task.done > > I know that the save in the actual controller works, because > flash[:notice] gets set appropriately. Just for grins, I changed it > from save, to save! in the controller with no difference. > > Thanks for helping me with this! > > --Alan > > > > > On Thu, Apr 24, 2008 at 9:11 AM, Frederick Cheung > <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > On 24 Apr 2008, at 14:19, Alan Smith wrote: > > > > > > > > I apologize, the actual code says > > > assert task_done > > > > > I assume that''s another typo and you mean assert task.done > > Have you tried changing the save to a save! (so that you get an > > exception saying why it has failed) ? > > > > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 24 Apr 2008, at 15:18, Alan Smith wrote:> > You are correct, it should be assert task.done > > I know that the save in the actual controller works, because > flash[:notice] gets set appropriately. Just for grins, I changed it > from save, to save! in the controller with no difference. >Can you see a matching update query in the test logs ? Fred> Thanks for helping me with this! > > --Alan > > > On Thu, Apr 24, 2008 at 9:11 AM, Frederick Cheung > <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> >> On 24 Apr 2008, at 14:19, Alan Smith wrote: >> >>> >>> I apologize, the actual code says >>> assert task_done >>> >> I assume that''s another typo and you mean assert task.done >> Have you tried changing the save to a save! (so that you get an >> exception saying why it has failed) ? >> >> 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thank you VERY VERY VERY VERY VERY much. I hadn''t even thought about looking in the logs. It turns out there was no update query. It ended up being that my fixtures had bad data in it. I don''t know why the save! wasn''t complaining the first time, but it is now. Thanks again, Alan On Thu, Apr 24, 2008 at 11:05 AM, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On 24 Apr 2008, at 15:18, Alan Smith wrote: > > > > > You are correct, it should be assert task.done > > > > I know that the save in the actual controller works, because > > flash[:notice] gets set appropriately. Just for grins, I changed it > > from save, to save! in the controller with no difference. > > > Can you see a matching update query in the test logs ? > > Fred > > > > Thanks for helping me with this! > > > > --Alan > > > > > > On Thu, Apr 24, 2008 at 9:11 AM, Frederick Cheung > > <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> > >> > >> On 24 Apr 2008, at 14:19, Alan Smith wrote: > >> > >>> > >>> I apologize, the actual code says > >>> assert task_done > >>> > >> I assume that''s another typo and you mean assert task.done > >> Have you tried changing the save to a save! (so that you get an > >> exception saying why it has failed) ? > >> > >> 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---