aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
authorLauro Caetano <laurocaetano1@gmail.com>2014-04-02 19:27:55 -0300
committerLauro Caetano <laurocaetano1@gmail.com>2014-04-03 10:26:37 -0300
commitdb5d26c9d70fb72b8aa3ea98709224dd13800024 (patch)
tree418418b89857527e834399ee5d57fc47225c858c /activesupport/lib/active_support
parent7531404a4401eb649daf274430c79ad7db6aaf9d (diff)
downloadrails-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 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/option_merger.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/option_merger.rb b/activesupport/lib/active_support/option_merger.rb
index e55ffd12c3..dea84e437f 100644
--- a/activesupport/lib/active_support/option_merger.rb
+++ b/activesupport/lib/active_support/option_merger.rb
@@ -12,7 +12,7 @@ module ActiveSupport
private
def method_missing(method, *arguments, &block)
- if arguments.last.is_a?(Proc)
+ if arguments.first.is_a?(Proc)
proc = arguments.pop
arguments << lambda { |*args| @options.deep_merge(proc.call(*args)) }
else