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?

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 rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to