Sha256: f7eb138df0a611431eebfebb4870259992e4ed7712c137123d89a7452d4b7bbf

Contents?: true

Size: 945 Bytes

Versions: 5

Compression:

Stored size: 945 Bytes

Contents

require 'abstract_unit'
require 'fixtures/person'
require 'fixtures/legacy_thing'

class LockingTest < Test::Unit::TestCase
  fixtures :people, :legacy_things

  def test_lock_existing
    p1 = Person.find(1)
    p2 = Person.find(1)
    
    p1.first_name = "Michael"
    p1.save
    
    assert_raises(ActiveRecord::StaleObjectError) {
      p2.first_name = "should fail"
      p2.save
    }
  end

  def test_lock_new
    p1 = Person.create({ "first_name"=>"anika"})
    p2 = Person.find(p1.id)
    assert_equal p1.id, p2.id
    p1.first_name = "Anika"
    p1.save
    
    assert_raises(ActiveRecord::StaleObjectError) {
      p2.first_name = "should fail"
      p2.save
    }
  end
  
  def test_lock_column_name_existing
    t1 = LegacyThing.find(1)
    t2 = LegacyThing.find(1)
    t1.tps_report_number = 400
    t1.save

    assert_raises(ActiveRecord::StaleObjectError) {
      t2.tps_report_number = 300
      t2.save
    }
  end 

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
activerecord-1.14.0 test/locking_test.rb
activerecord-1.14.1 test/locking_test.rb
activerecord-1.14.3 test/locking_test.rb
activerecord-1.14.2 test/locking_test.rb
activerecord-1.14.4 test/locking_test.rb