aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activemodel/lib/active_model/callbacks.rb12
-rw-r--r--activerecord/test/cases/callbacks_test.rb6
2 files changed, 11 insertions, 7 deletions
diff --git a/activemodel/lib/active_model/callbacks.rb b/activemodel/lib/active_model/callbacks.rb
index d612743c44..fde3381df2 100644
--- a/activemodel/lib/active_model/callbacks.rb
+++ b/activemodel/lib/active_model/callbacks.rb
@@ -128,27 +128,27 @@ module ActiveModel
def _define_before_model_callback(klass, callback)
klass.define_singleton_method("before_#{callback}") do |*args, **options, &block|
- options.assert_valid_keys :if, :unless, :prepend
- set_callback(:"#{callback}", :before, *args, **options, &block)
+ options.assert_valid_keys(:if, :unless, :prepend)
+ set_callback(:"#{callback}", :before, *args, options, &block)
end
end
def _define_around_model_callback(klass, callback)
klass.define_singleton_method("around_#{callback}") do |*args, **options, &block|
- options.assert_valid_keys :if, :unless, :prepend
- set_callback(:"#{callback}", :around, *args, **options, &block)
+ options.assert_valid_keys(:if, :unless, :prepend)
+ set_callback(:"#{callback}", :around, *args, options, &block)
end
end
def _define_after_model_callback(klass, callback)
klass.define_singleton_method("after_#{callback}") do |*args, **options, &block|
- options.assert_valid_keys :if, :unless, :prepend
+ options.assert_valid_keys(:if, :unless, :prepend)
options[:prepend] = true
conditional = ActiveSupport::Callbacks::Conditionals::Value.new { |v|
v != false
}
options[:if] = Array(options[:if]) << conditional
- set_callback(:"#{callback}", :after, *args, **options, &block)
+ set_callback(:"#{callback}", :after, *args, options, &block)
end
end
end
diff --git a/activerecord/test/cases/callbacks_test.rb b/activerecord/test/cases/callbacks_test.rb
index e10a7b34c8..253c3099d6 100644
--- a/activerecord/test/cases/callbacks_test.rb
+++ b/activerecord/test/cases/callbacks_test.rb
@@ -477,21 +477,25 @@ class CallbacksTest < ActiveRecord::TestCase
assert child.after_save_called
end
- def test_on_isnt_allowed
+ def test_before_save_doesnt_allow_on_option
exception = assert_raises ArgumentError do
Class.new(ActiveRecord::Base) do
before_save(on: :create) {}
end
end
assert_equal "Unknown key: :on. Valid keys are: :if, :unless, :prepend", exception.message
+ end
+ def test_around_save_doesnt_allow_on_option
exception = assert_raises ArgumentError do
Class.new(ActiveRecord::Base) do
around_save(on: :create) {}
end
end
assert_equal "Unknown key: :on. Valid keys are: :if, :unless, :prepend", exception.message
+ end
+ def test_after_save_doesnt_allow_on_option
exception = assert_raises ArgumentError do
Class.new(ActiveRecord::Base) do
after_save(on: :create) {}