diff options
author | Lauro Caetano <laurocaetano1@gmail.com> | 2014-01-30 22:58:00 -0200 |
---|---|---|
committer | Lauro Caetano <laurocaetano1@gmail.com> | 2014-01-31 00:29:48 -0200 |
commit | 4506dd2f07be824fd7e0eb6165c29994aeb1bfcd (patch) | |
tree | 3595afcd1b68b2d86891644a298e0a70ccf94077 /activerecord/test/cases/associations | |
parent | f64c50a092394917ad9a79abc563aa2bef22ce94 (diff) | |
download | rails-4506dd2f07be824fd7e0eb6165c29994aeb1bfcd.tar.gz rails-4506dd2f07be824fd7e0eb6165c29994aeb1bfcd.tar.bz2 rails-4506dd2f07be824fd7e0eb6165c29994aeb1bfcd.zip |
Associations now raise `ArgumentError` on name conflicts.
Dangerous association names conflicts include instance or class
methods already defined by `ActiveRecord::Base`.
Diffstat (limited to 'activerecord/test/cases/associations')
3 files changed, 30 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb index 2283ba66db..9340bc0a83 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -853,4 +853,14 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase assert post.save assert_equal post.author_id, author2.id end + + test 'dangerous association name raises ArgumentError' do + [:errors, 'errors', :save, 'save'].each do |name| + assert_raises(ArgumentError, "Association #{name} should not be allowed") do + Class.new(ActiveRecord::Base) do + belongs_to name + end + end + end + end end diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index cf1e50890e..a86fb15719 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -1820,4 +1820,14 @@ class HasManyAssociationsTest < ActiveRecord::TestCase topic.approved_replies.create! end end + + test 'dangerous association name raises ArgumentError' do + [:errors, 'errors', :save, 'save'].each do |name| + assert_raises(ArgumentError, "Association #{name} should not be allowed") do + Class.new(ActiveRecord::Base) do + has_many name + end + end + end + end end diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb index d4edef03d6..a4650ccdf2 100644 --- a/activerecord/test/cases/associations/has_one_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_associations_test.rb @@ -564,4 +564,14 @@ class HasOneAssociationsTest < ActiveRecord::TestCase end end end + + test 'dangerous association name raises ArgumentError' do + [:errors, 'errors', :save, 'save'].each do |name| + assert_raises(ArgumentError, "Association #{name} should not be allowed") do + Class.new(ActiveRecord::Base) do + has_one name + end + end + end + end end |