aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorMikhail Dieterle <MikDiet@gmail.com>2012-08-26 03:02:05 +0300
committerMikhail Dieterle <MikDiet@gmail.com>2012-08-26 03:02:05 +0300
commit8159bc9cf5f68c7adedb22f86444ec2ae428434e (patch)
tree15c4bb83d1ffd234d2f90a389e599f3e049e1936 /activerecord/test
parent67153430861ca1305d77a73e631a9038049fbfa9 (diff)
downloadrails-8159bc9cf5f68c7adedb22f86444ec2ae428434e.tar.gz
rails-8159bc9cf5f68c7adedb22f86444ec2ae428434e.tar.bz2
rails-8159bc9cf5f68c7adedb22f86444ec2ae428434e.zip
allow to pass Symbol or Proc into :limit option of #accepts_nested_attributes_for
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/nested_attributes_test.rb38
-rw-r--r--activerecord/test/models/pirate.rb2
2 files changed, 32 insertions, 8 deletions
diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb
index 3a234f0cc1..725cff8f01 100644
--- a/activerecord/test/cases/nested_attributes_test.rb
+++ b/activerecord/test/cases/nested_attributes_test.rb
@@ -846,13 +846,7 @@ class TestNestedAttributesOnAHasAndBelongsToManyAssociation < ActiveRecord::Test
include NestedAttributesOnACollectionAssociationTests
end
-class TestNestedAttributesLimit < ActiveRecord::TestCase
- def setup
- Pirate.accepts_nested_attributes_for :parrots, :limit => 2
-
- @pirate = Pirate.create!(:catchphrase => "Don' botharrr talkin' like one, savvy?")
- end
-
+module NestedAttributesLimitTests
def teardown
Pirate.accepts_nested_attributes_for :parrots, :allow_destroy => true, :reject_if => proc { |attributes| attributes.empty? }
end
@@ -876,6 +870,36 @@ class TestNestedAttributesLimit < ActiveRecord::TestCase
end
end
+class TestNestedAttributesLimitNumeric < ActiveRecord::TestCase
+ def setup
+ Pirate.accepts_nested_attributes_for :parrots, :limit => 2
+
+ @pirate = Pirate.create!(:catchphrase => "Don' botharrr talkin' like one, savvy?")
+ end
+
+ include NestedAttributesLimitTests
+end
+
+class TestNestedAttributesLimitSymbol < ActiveRecord::TestCase
+ def setup
+ Pirate.accepts_nested_attributes_for :parrots, :limit => :parrots_limit
+
+ @pirate = Pirate.create!(:catchphrase => "Don' botharrr talkin' like one, savvy?", :parrots_limit => 2)
+ end
+
+ include NestedAttributesLimitTests
+end
+
+class TestNestedAttributesLimitProc < ActiveRecord::TestCase
+ def setup
+ Pirate.accepts_nested_attributes_for :parrots, :limit => proc { 2 }
+
+ @pirate = Pirate.create!(:catchphrase => "Don' botharrr talkin' like one, savvy?")
+ end
+
+ include NestedAttributesLimitTests
+end
+
class TestNestedAttributesWithNonStandardPrimaryKeys < ActiveRecord::TestCase
fixtures :owners, :pets
diff --git a/activerecord/test/models/pirate.rb b/activerecord/test/models/pirate.rb
index 609b9369a9..170fc2ffe3 100644
--- a/activerecord/test/models/pirate.rb
+++ b/activerecord/test/models/pirate.rb
@@ -53,7 +53,7 @@ class Pirate < ActiveRecord::Base
attributes.delete('_reject_me_if_new').present? && !persisted?
end
- attr_accessor :cancel_save_from_callback
+ attr_accessor :cancel_save_from_callback, :parrots_limit
before_save :cancel_save_callback_method, :if => :cancel_save_from_callback
def cancel_save_callback_method
false