Created
August 4, 2012 18:13
-
-
Save jarl-dk/3259104 to your computer and use it in GitHub Desktop.
patch for rails issue 7247
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From e8488cea1e14bba735773ee30bba2b1108be5f00 Mon Sep 17 00:00:00 2001 | |
From: Jarl Friis <jarl@softace.dk> | |
Date: Sat, 4 Aug 2012 10:50:49 +0200 | |
Subject: [PATCH 1/2] Demonstrating problem of ticket 7247 | |
--- | |
.../validations/association_validation_test.rb | 19 +++++++++++++++++++ | |
1 file changed, 19 insertions(+) | |
diff --git a/activerecord/test/cases/validations/association_validation_test.rb b/activerecord/test/cases/validations/association_validation_test.rb | |
index 768fbc5..de04c9f 100644 | |
--- a/activerecord/test/cases/validations/association_validation_test.rb | |
+++ b/activerecord/test/cases/validations/association_validation_test.rb | |
@@ -6,6 +6,8 @@ require 'models/owner' | |
require 'models/pet' | |
require 'models/man' | |
require 'models/interest' | |
+require 'models/pirate' | |
+require 'models/bird' | |
class AssociationValidationTest < ActiveRecord::TestCase | |
fixtures :topics, :owners | |
@@ -21,6 +23,23 @@ class AssociationValidationTest < ActiveRecord::TestCase | |
assert o.valid? | |
end | |
+ def test_validates_size_of_association_using_nested_attributes | |
+ repair_validations(Pirate) do | |
+ assert_nothing_raised { Pirate.validates_size_of :birds, :minimum => 1 } | |
+ p = Pirate.new('catchphrase' => 'hey!!') | |
+ assert !p.save | |
+ assert p.errors[:birds].any? | |
+ bird = p.birds.build('name' => 'birdname') | |
+ assert p.valid? | |
+ assert p.save | |
+ bird_count = Bird.count | |
+ p.update_attributes :birds_attributes => [ {:_destroy => 1, :id => bird.id} ] | |
+ assert !p.valid? | |
+ assert p.errors[:birds].any? | |
+ assert_equal bird_count, Bird.count | |
+ end | |
+ end | |
+ | |
def test_validates_size_of_association_using_within | |
assert_nothing_raised { Owner.validates_size_of :pets, :within => 1..2 } | |
o = Owner.new('name' => 'nopets') | |
-- | |
1.7.9.5 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 0633b06c9a5bbbf2c4bfc918bd6b948cc6fc482b Mon Sep 17 00:00:00 2001 | |
From: Jarl Friis <jarl@softace.dk> | |
Date: Sat, 4 Aug 2012 20:07:34 +0200 | |
Subject: [PATCH 2/2] workaround for ticket 7247 | |
--- | |
.../validations/association_validation_test.rb | 5 +++++ | |
1 file changed, 5 insertions(+) | |
diff --git a/activerecord/test/cases/validations/association_validation_test.rb b/activerecord/test/cases/validations/association_validation_test.rb | |
index de04c9f..9f71307 100644 | |
--- a/activerecord/test/cases/validations/association_validation_test.rb | |
+++ b/activerecord/test/cases/validations/association_validation_test.rb | |
@@ -26,6 +26,11 @@ class AssociationValidationTest < ActiveRecord::TestCase | |
def test_validates_size_of_association_using_nested_attributes | |
repair_validations(Pirate) do | |
assert_nothing_raised { Pirate.validates_size_of :birds, :minimum => 1 } | |
+ assert_nothing_raised do | |
+ Pirate.validates_each(:birds) do |record, attr, value| | |
+ record.errors.add(attr, :too_short, :count => 1) if value.reject { |v| v.marked_for_destruction? }.size < 1 | |
+ end | |
+ end | |
p = Pirate.new('catchphrase' => 'hey!!') | |
assert !p.save | |
assert p.errors[:birds].any? | |
-- | |
1.7.9.5 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment