Sha256: fd653643e0a1ee9f77bd29cd13b55911af50572922a77c34abdfddecdd0d64be

Contents?: true

Size: 785 Bytes

Versions: 76

Compression:

Stored size: 785 Bytes

Contents

require "cases/helper"

class Comment < ActiveRecord::Base
  attr_accessor :callers

  before_validation :record_callers

  def after_validation
    record_callers
  end

  def record_callers
    callers << self.class if callers
  end
end

class CommentObserver < ActiveRecord::Observer
  attr_accessor :callers

  def after_validation(model)
    callers << self.class if callers
  end
end

class CallbacksObserversTest < ActiveRecord::TestCase
  def test_model_callbacks_fire_before_observers_are_notified
    callers = []

    comment = Comment.new
    comment.callers = callers

    CommentObserver.instance.callers = callers

    comment.valid?

    assert_equal [Comment, Comment, CommentObserver], callers, "model callbacks did not fire before observers were notified"
  end
end

Version data entries

76 entries across 73 versions & 16 rubygems

Version Path
p8-castronaut-0.6.1.1 vendor/activerecord/test/cases/callbacks_observers_test.rb
relevance-castronaut-0.6.0 vendor/activerecord/test/cases/callbacks_observers_test.rb
relevance-castronaut-0.6.1 vendor/activerecord/test/cases/callbacks_observers_test.rb
relevance-castronaut-0.7.4 vendor/activerecord/test/cases/callbacks_observers_test.rb
relevance-castronaut-0.7.5 vendor/activerecord/test/cases/callbacks_observers_test.rb
activerecord-2.3.18 test/cases/callbacks_observers_test.rb
activerecord_csi-2.3.5.p8 test/cases/callbacks_observers_test.rb
activerecord-2.3.17 test/cases/callbacks_observers_test.rb
activerecord_csi-2.3.5.p7 test/cases/callbacks_observers_test.rb
activerecord_csi-2.3.5.p6 test/cases/callbacks_observers_test.rb
activerecord-2.3.16 test/cases/callbacks_observers_test.rb
activerecord-2.3.15 test/cases/callbacks_observers_test.rb
radiant-1.0.0 ruby-debug/ruby/1.8/gems/activerecord-2.3.14/test/cases/callbacks_observers_test.rb
vanity-1.7.1 vendor/ruby/1.9.1/gems/activerecord-2.3.12/test/cases/callbacks_observers_test.rb
activerecord-2.3.14 test/cases/callbacks_observers_test.rb
kajam-1.0.3.rc2 vendor/rails/activerecord/test/cases/callbacks_observers_test.rb
activerecord-2.3.12 test/cases/callbacks_observers_test.rb
radiant-1.0.0.rc2 vendor/rails/activerecord/test/cases/callbacks_observers_test.rb
radiant-1.0.0.rc1 vendor/rails/activerecord/test/cases/callbacks_observers_test.rb
webroar-0.5.0 src/admin_panel/vendor/rails/activerecord/test/cases/callbacks_observers_test.rb