Sha256: b03cc539c1e4aa738597672e6e22db9286b3d362a854296a6cfdf5fb7f23f6a0

Contents?: true

Size: 1.72 KB

Versions: 9

Compression:

Stored size: 1.72 KB

Contents

require 'test_helper'

class TransactionChangesTest < MiniTest::Unit::TestCase
  def setup
    @user = User.new(:name => "Dylan", :occupation => "Developer")
    @user.save!
    @user.stored_transaction_changes = nil
  end

  def teardown
    User.delete_all
  end

  def test_transaction_changes_for_create
    user = User.new(:name => "Dylan")
    user.save!
    assert_equal [nil, "Dylan"], user.stored_transaction_changes["name"]
  end

  def test_transaction_changes_for_update
    @user.name = "Dillon"
    @user.save!
    assert_equal ["Dylan", "Dillon"], @user.stored_transaction_changes["name"]
  end

  def test_transaction_changes_for_double_save
    @user.transaction do
      @user.name = "Dillon"
      @user.save!

      @user.occupation = "Tester"
      @user.save!
    end
    assert_equal ["Dylan", "Dillon"], @user.stored_transaction_changes["name"]
    assert_equal ["Developer", "Tester"], @user.stored_transaction_changes["occupation"]
  end

  def test_transaction_changes_for_rollback
    @user.transaction do
      @user.name = "Dillon"
      @user.save!
      raise ActiveRecord::Rollback
    end
    assert_equal nil, @user.stored_transaction_changes
  end

  def test_transaction_changes_after_reload_saved
    @user.transaction do
      @user.name = "Dillon"
      @user.save!

      @user.reload
    end
    assert_equal ["Dylan", "Dillon"], @user.stored_transaction_changes["name"]
  end

  def test_transaction_changes_after_reload_unsaved
    @user.transaction do
      @user.name = "Dillon"
      @user.save!

      @user.name = "Andrew"
      assert_equal "Dylan", @user.transaction_changed_attributes["name"]
      @user.reload
    end
    assert_equal ["Dylan", "Dillon"], @user.stored_transaction_changes["name"]
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ar_transaction_changes-1.1.0 test/transaction_changes_test.rb
ar_transaction_changes-1.0.3 test/transaction_changes_test.rb
ar_transaction_changes-1.0.2 test/transaction_changes_test.rb
ar_transaction_changes-1.0.1 test/transaction_changes_test.rb
ar_transaction_changes-1.0.0 test/transaction_changes_test.rb
ar_transaction_changes-0.0.4 test/transaction_changes_test.rb
ar_transaction_changes-0.0.3 test/transaction_changes_test.rb
ar_transaction_changes-0.0.2 test/transaction_changes_test.rb
ar_transaction_changes-0.0.1 test/transaction_changes_test.rb