Sha256: 600c50418504db5b1a330e602f65ad1dce3bc316534167596d13d293d9bf8fe8

Contents?: true

Size: 1.46 KB

Versions: 80

Compression:

Stored size: 1.46 KB

Contents

$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
require 'test/unit'
require 'rubygems'
require 'activerecord'
require 'after_commit'
require 'after_commit/active_record'
require 'after_commit/connection_adapters'

ActiveRecord::Base.establish_connection({"adapter" => "sqlite3", "database" => 'test.sqlite3'})
begin
  ActiveRecord::Base.connection.execute("drop table mock_records");
rescue
end
ActiveRecord::Base.connection.execute("create table mock_records(id int)");

require File.dirname(__FILE__) + '/../init.rb'

class MockRecord < ActiveRecord::Base
  attr_accessor :after_commit_on_create_called
  attr_accessor :after_commit_on_update_called
  attr_accessor :after_commit_on_destroy_called

  after_commit_on_create :do_create
  def do_create
    self.after_commit_on_create_called = true
  end

  after_commit_on_update :do_update
  def do_update
    self.after_commit_on_update_called = true
  end

  after_commit_on_create :do_destroy
  def do_destroy
    self.after_commit_on_destroy_called = true
  end
end

class AfterCommitTest < Test::Unit::TestCase
  def test_after_commit_on_create_is_called
    assert_equal true, MockRecord.create!.after_commit_on_create_called
  end

  def test_after_commit_on_update_is_called
    record = MockRecord.create!
    record.save
    assert_equal true, record.after_commit_on_update_called
  end

  def test_after_commit_on_destroy_is_called
    assert_equal true, MockRecord.create!.destroy.after_commit_on_destroy_called
  end
end

Version data entries

80 entries across 80 versions & 15 rubygems

Version Path
DrMark-thinking-sphinx-1.1.14 vendor/after_commit/test/after_commit_test.rb
DrMark-thinking-sphinx-1.1.15 vendor/after_commit/test/after_commit_test.rb
DrMark-thinking-sphinx-1.1.6 vendor/after_commit/test/after_commit_test.rb
DrMark-thinking-sphinx-1.2.5 vendor/after_commit/test/after_commit_test.rb
DrMark-thinking-sphinx-1.2.6 vendor/after_commit/test/after_commit_test.rb
bterlson-thinking-sphinx-1.2.8 vendor/after_commit/test/after_commit_test.rb
dpickett-thinking-sphinx-1.1.12 vendor/after_commit/test/after_commit_test.rb
dpickett-thinking-sphinx-1.1.23 vendor/after_commit/test/after_commit_test.rb
dpickett-thinking-sphinx-1.1.4 vendor/after_commit/test/after_commit_test.rb
ebeigarts-thinking-sphinx-1.1.21 vendor/after_commit/test/after_commit_test.rb
ebeigarts-thinking-sphinx-1.1.22 vendor/after_commit/test/after_commit_test.rb
ebeigarts-thinking-sphinx-1.2.10 vendor/after_commit/test/after_commit_test.rb
factorylabs-thinking-sphinx-1.2.7 vendor/after_commit/test/after_commit_test.rb
freelancing-god-thinking-sphinx-0.9.11 vendor/after_commit/test/after_commit_test.rb
freelancing-god-thinking-sphinx-0.9.12 vendor/after_commit/test/after_commit_test.rb
freelancing-god-thinking-sphinx-0.9.13 vendor/after_commit/test/after_commit_test.rb
freelancing-god-thinking-sphinx-1.1.0 vendor/after_commit/test/after_commit_test.rb
freelancing-god-thinking-sphinx-1.1.1 vendor/after_commit/test/after_commit_test.rb
freelancing-god-thinking-sphinx-1.1.10 vendor/after_commit/test/after_commit_test.rb
freelancing-god-thinking-sphinx-1.1.11 vendor/after_commit/test/after_commit_test.rb