diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2006-06-20 19:54:35 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2006-06-20 19:54:35 +0000 |
commit | ef77ec77109a22361b5ee30b851eb3e5c8871eaa (patch) | |
tree | 584ed14e9cb47e57e348e56c1b4d4bfc528fa5da | |
parent | 7a101c1fc3c6a255ef7fed9fdb0830590a035ffb (diff) | |
download | rails-ef77ec77109a22361b5ee30b851eb3e5c8871eaa.tar.gz rails-ef77ec77109a22361b5ee30b851eb3e5c8871eaa.tar.bz2 rails-ef77ec77109a22361b5ee30b851eb3e5c8871eaa.zip |
r4669@asus: jeremy | 2006-06-20 12:53:36 -0700
Getting picayune with locking_test. Closes #4871.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4472 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r-- | activerecord/test/locking_test.rb | 56 |
1 files changed, 35 insertions, 21 deletions
diff --git a/activerecord/test/locking_test.rb b/activerecord/test/locking_test.rb index 1923ff590d..35c557e19d 100644 --- a/activerecord/test/locking_test.rb +++ b/activerecord/test/locking_test.rb @@ -8,39 +8,53 @@ class OptimisticLockingTest < Test::Unit::TestCase def test_lock_existing p1 = Person.find(1) p2 = Person.find(1) + assert_equal 0, p1.lock_version + assert_equal 0, p2.lock_version - p1.first_name = "Michael" - p1.save + p1.save! + assert_equal 1, p1.lock_version + assert_equal 0, p2.lock_version - assert_raises(ActiveRecord::StaleObjectError) { - p2.first_name = "should fail" - p2.save - } + assert_raises(ActiveRecord::StaleObjectError) { p2.save! } end def test_lock_new - p1 = Person.create({ "first_name"=>"anika"}) + p1 = Person.new(:first_name => 'anika') + assert_equal 0, p1.lock_version + + p1.save! 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 - } + assert_equal 0, p1.lock_version + assert_equal 0, p2.lock_version + + p1.save! + assert_equal 1, p1.lock_version + assert_equal 0, p2.lock_version + + assert_raises(ActiveRecord::StaleObjectError) { 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_equal 0, t1.version + assert_equal 0, t2.version + + t1.save! + assert_equal 1, t1.version + assert_equal 0, t2.version + + assert_raises(ActiveRecord::StaleObjectError) { t2.save! } + end + + def test_lock_column_is_mass_assignable + p1 = Person.create(:first_name => 'bianca') + assert_equal 0, p1.lock_version + assert_equal p1.lock_version, Person.new(p1.attributes).lock_version - assert_raises(ActiveRecord::StaleObjectError) { - t2.tps_report_number = 300 - t2.save - } + p1.save! + assert_equal 1, p1.lock_version + assert_equal p1.lock_version, Person.new(p1.attributes).lock_version end end |