Sha256: 2d3637ddb01ad42ba10e0c78809edb9eabb21ed3de560d1e0b57a3386dcbcf12
Contents?: true
Size: 1.79 KB
Versions: 1
Compression:
Stored size: 1.79 KB
Contents
require "cases/helper" class CallbacksTest < ActiveModel::TestCase class CallbackValidator def around_create(model) model.callbacks << :before_around_create yield model.callbacks << :after_around_create end end class ModelCallbacks attr_reader :callbacks extend ActiveModel::Callbacks define_model_callbacks :create define_model_callbacks :initialize, :only => :after before_create :before_create around_create CallbackValidator.new after_create do |model| model.callbacks << :after_create end after_create "@callbacks << :final_callback" def initialize(valid=true) @callbacks, @valid = [], valid end def before_create @callbacks << :before_create end def create _run_create_callbacks do @callbacks << :create @valid end end end test "complete callback chain" do model = ModelCallbacks.new model.create assert_equal model.callbacks, [ :before_create, :before_around_create, :create, :after_around_create, :after_create, :final_callback] end test "after callbacks are always appended" do model = ModelCallbacks.new model.create assert_equal model.callbacks.last, :final_callback end test "after callbacks are not executed if the block returns false" do model = ModelCallbacks.new(false) model.create assert_equal model.callbacks, [ :before_create, :before_around_create, :create, :after_around_create] end test "only selects which types of callbacks should be created" do assert !ModelCallbacks.respond_to?(:before_initialize) assert !ModelCallbacks.respond_to?(:around_initialize) assert ModelCallbacks.respond_to?(:after_initialize) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
cassandra_object-0.6.0.pre | vendor/activemodel/test/cases/callbacks_test.rb |