Thanks for the reply, Frederick. However, if I remove the validates_presence_of validation then the Section can be saved without a name. Is there a different way I should validating that the :name exists and is :unique?
Thanks again. -B On Jan 1, 4:06 am, Frederick Cheung <[email protected]> wrote: > On 1 Jan 2009, at 02:13, bdeverea <[email protected]> wrote: > > > > > Greetings, > > I have a simple model called "Section" with integration tests that > > pass. However, when I add a simple validation to the model > > (validates_presence_of :name) the integration test fails. This makes > > no sense to me because I am passing in a name. > > > Does anyone know why that validation breaks my integration test? > > Because you've also got a validates_uniqueness_of and you're reusing > the name of an existing section. > > Fred > > > > > INTEGRATION TEST > > > require "#{File.dirname(__FILE__)}/../test_helper" > > > class SectionsTest < ActionController::IntegrationTest > > > fixtures :sections > > > def test_user_creates_new_section > > #Navigate to new Section form > > get '/sections/new' > > assert_response :success > > > #Submit new Section form with params > > post '/sections/create', :name => sections(:Home).name > > assert_response :redirect > > follow_redirect! > > > #Test that Section was created successfully and user was > > redirected to show page > > assert_template 'sections/show' > > assert_equal 'Section was successfully created.', flash[:notice] > > > end > > end > > > MODEL CODE > > class Section < ActiveRecord::Base > > has_many :pages > > > before_create :set_create_user > > before_save :set_modified_user > > > validates_presence_of :name #Adding this line causes the integration > > test above fail > > validates_uniqueness_of :name > > > private > > > def set_create_user > > self.created_by = 1 > > end > > > def set_modified_user > > self.modified_by = 2 > > end > > end > > > Thanks for any help you can provide! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

