diff options
author | Lauro Caetano <laurocaetano1@gmail.com> | 2014-04-02 19:27:55 -0300 |
---|---|---|
committer | Lauro Caetano <laurocaetano1@gmail.com> | 2014-04-03 10:26:37 -0300 |
commit | db5d26c9d70fb72b8aa3ea98709224dd13800024 (patch) | |
tree | 418418b89857527e834399ee5d57fc47225c858c /activerecord/test/models | |
parent | 7531404a4401eb649daf274430c79ad7db6aaf9d (diff) | |
download | rails-db5d26c9d70fb72b8aa3ea98709224dd13800024.tar.gz rails-db5d26c9d70fb72b8aa3ea98709224dd13800024.tar.bz2 rails-db5d26c9d70fb72b8aa3ea98709224dd13800024.zip |
Fix error when using `with_options` with lambda.
It was causing error when using `with_options` passing a lambda as its
last argument.
class User < ActiveRecord::Base
with_options dependent: :destroy do |assoc|
assoc.has_many :profiles, -> { where(active: true) }
end
end
It was happening because the `option_merger` was taking the last
argument and checking if it was a Hash. This breaks the HasMany usage,
because its last argument can be a Hash or a Proc.
As the behavior described in this test:
https://github.com/rails/rails/blob/master/activesupport/test/option_merger_test.rb#L69
the method will only accept the lambda, this way it will keep the expected behavior. See 9eaa0a34
Diffstat (limited to 'activerecord/test/models')
-rw-r--r-- | activerecord/test/models/college.rb | 5 | ||||
-rw-r--r-- | activerecord/test/models/student.rb | 1 |
2 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/test/models/college.rb b/activerecord/test/models/college.rb index c7495d7deb..501af4a8dd 100644 --- a/activerecord/test/models/college.rb +++ b/activerecord/test/models/college.rb @@ -1,5 +1,10 @@ require_dependency 'models/arunit2_model' +require 'active_support/core_ext/object/with_options' class College < ARUnit2Model has_many :courses + + with_options dependent: :destroy do |assoc| + assoc.has_many :students, -> { where(active: true) } + end end diff --git a/activerecord/test/models/student.rb b/activerecord/test/models/student.rb index f459f2a9a3..28a0b6c99b 100644 --- a/activerecord/test/models/student.rb +++ b/activerecord/test/models/student.rb @@ -1,3 +1,4 @@ class Student < ActiveRecord::Base has_and_belongs_to_many :lessons + belongs_to :college end |