Permalink
Browse files

testing valid_with_associated?

  • Loading branch information...
1 parent 1585173 commit b74ee49c0a998b7ec1143dfd96ae76ec41931295 @cainlevy committed Dec 12, 2008
Showing with 30 additions and 1 deletion.
  1. +30 −1 test/unit/nested_assignment_validation_test.rb
@@ -1,5 +1,34 @@
require File.dirname(__FILE__) + '/../test_helper'
-class NestedAssignmentValidationTest < ActiveSupport::TestCase
+require 'ruby-debug'
+class NestedAssignmentValidationTest < ActiveSupport::TestCase
+ def test_an_invalid_new_associated_record
+ @user = users(:bob)
+ @user.tasks.build(:name => nil)
+ assert !@user.valid?
+ end
+
+ def test_an_invalid_existing_associated_record
+ @user = users(:bob)
+ @user.tasks[0].name = nil
+ assert !@user.valid?
+ end
+
+ def test_an_invalid_deeply_associated_record
+ @user = users(:bob)
+ @user.tasks[0].tags[0].name = nil
+ assert !@user.valid?
+ assert @user.tasks[0].errors.full_messages.empty?
+ assert @user.tasks[0].tags[0].errors.on(:name)
+ end
+
+ def test_multiple_invalid_associated_records
+ @user = users(:bob)
+ @user.tasks[0].name = nil
+ @user.tasks.build(:name => nil)
+ assert !@user.valid?
+ assert @user.tasks[0].errors.on(:name)
+ assert @user.tasks[1].errors.on(:name)
+ end
end

0 comments on commit b74ee49

Please sign in to comment.