Methods
B
F
R
T
Included Modules
Instance Public methods
build_class(callback)
# File activesupport/test/callbacks_test.rb, line 809
def build_class(callback)
  Class.new {
    include ActiveSupport::Callbacks
    define_callbacks :foo
    set_callback :foo, :before, :foo, :if => callback
    def foo; end
    def run; run_callbacks :foo; end
  }
end
foo()
# File activesupport/test/callbacks_test.rb, line 814
def foo; end
run()
# File activesupport/test/callbacks_test.rb, line 815
def run; run_callbacks :foo; end
test_class()

FIXME: do we really want to support classes as conditionals? There were no tests for it previous to this.

# File activesupport/test/callbacks_test.rb, line 841
def test_class
  z = []
  klass = build_class Class.new {
    define_singleton_method(:before) { |o| z << o }
  }
  object = klass.new
  object.run
  assert_equal [object], z
end
test_class_conditional_with_scope()

FIXME: do we really want to support classes as conditionals? There were no tests for it previous to this.

# File activesupport/test/callbacks_test.rb, line 821
def test_class_conditional_with_scope
  z = []
  callback = Class.new {
    define_singleton_method(:foo) { |o| z << o }
  }
  klass = Class.new {
    include ActiveSupport::Callbacks
    define_callbacks :foo, :scope => [:name]
    set_callback :foo, :before, :foo, :if => callback
    def run; run_callbacks :foo; end
    private
    def foo; end
  }
  object = klass.new
  object.run
  assert_equal [object], z
end
test_proc_arity0()
# File activesupport/test/callbacks_test.rb, line 858
def test_proc_arity0
  z = []
  object = build_class(->() { z << 0 }).new
  object.run
  assert_equal [0], z
end
test_proc_arity1()
# File activesupport/test/callbacks_test.rb, line 865
def test_proc_arity1
  z = []
  object = build_class(->(x) { z << x }).new
  object.run
  assert_equal [object], z
end
test_proc_arity2()
# File activesupport/test/callbacks_test.rb, line 872
def test_proc_arity2
  assert_raises(ArgumentError) do
    object = build_class(->(a,b) { }).new
    object.run
  end
end
test_proc_negative_arity()
# File activesupport/test/callbacks_test.rb, line 851
def test_proc_negative_arity # passes an empty list if *args
  z = []
  object = build_class(->(*args) { z << args }).new
  object.run
  assert_equal [], z.flatten
end