On 20 November 2010 13:47, Neil Bye <[email protected]> wrote: > Colin Law wrote in post #962775: >> On 20 November 2010 13:00, Neil Bye <[email protected]> wrote: >>> => #<Annnette id: 3, story: "neil", created_at: "2010-11-20 12:58:11", >>> updated_at: "2010-11-20 12:58:11"> >> >> I am losing track of this conversation. I think we had better start >> again. Can you explain: >> 1. What the test you wrote is attempting to check. >> 2. What code you have written in the application to perform the >> operation that the test is checking. >> >> Colin > > 1.It should show an error if an attempt is made to create a story > without a story entry. > 2.This is from annnettes_controller.rb > > def create > �...@annnette = Annnette.new(params[:annnette]) > > respond_to do |format| > if @annnette.save > flash[:notice] = 'Annnette was successfully created.' > format.html { redirect_to(@annnette) } > format.xml { render :xml => @annnette, :status => :created, > :location => @annnette } > else > format.html { render :action => "new" } > format.xml { render :xml => @annnette.errors, :status => > :unprocessable_entity } > end > end > end
I don't see anything there stopping a save if there is no story. Anyway this code is not called when you call Annnette.create, the create method of the model is called. As Michael has pointed out you probably want to use new rather than create in the test, but you still need code to stop the save if there is no story. Usually this would be done by a validation in the controller. 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

