Sha256: 51455256578f43dc720c093b9d217ccc3dbf45676b0c64ef3cf3f4c7034bb32f

Contents?: true

Size: 1.38 KB

Versions: 9

Compression:

Stored size: 1.38 KB

Contents

require 'test_helper'

class ObservableMockRecord < ActiveRecord::Base
  set_table_name 'mock_records'

  attr_accessor :after_commit_called
  attr_accessor :after_commit_on_create_called
  attr_accessor :after_commit_on_update_called
  attr_accessor :after_commit_on_destroy_called
end

class ObservableMockRecordObserver < ActiveRecord::Observer
  def after_commit(model)
    model.after_commit_called = true
  end

  def after_commit_on_create(model)
    model.after_commit_on_create_called = true
  end

  def after_commit_on_update(model)
    model.after_commit_on_update_called = true
  end

  def after_commit_on_destroy(model)
    model.after_commit_on_destroy_called = true
  end
end

class ObserverTest < Test::Unit::TestCase
  def setup
    ObservableMockRecord.add_observer ObservableMockRecordObserver.instance
  end

  def test_after_commit_is_called
    record = ObservableMockRecord.create!

    assert record.after_commit_called
  end

  def test_after_commit_on_create_is_called
    record = ObservableMockRecord.create!

    assert record.after_commit_on_create_called
  end

  def test_after_commit_on_update_is_called
    record = ObservableMockRecord.create!
    record.save

    assert record.after_commit_on_update_called
  end

  def test_after_commit_on_destroy_is_called
    record = ObservableMockRecord.create!.destroy

    assert record.after_commit_on_destroy_called
  end
end

Version data entries

9 entries across 9 versions & 3 rubygems

Version Path
after_commit-1.0.11 test/observer_test.rb
after_commit-1.0.10 test/observer_test.rb
after_commit-1.0.9 test/observer_test.rb
after_commit-1.0.8 test/observer_test.rb
aleksi-after_commit-1.0.8 test/observer_test.rb
after_commit-1.0.7 test/observer_test.rb
after_commit-1.0.6 test/observer_test.rb
larsklevan-after_commit-1.0.6 test/observer_test.rb
larsklevan-after_commit-1.0.5 test/observer_test.rb