aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/locking_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test/locking_test.rb')
-rw-r--r--activerecord/test/locking_test.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/activerecord/test/locking_test.rb b/activerecord/test/locking_test.rb
new file mode 100644
index 0000000000..2b77a29907
--- /dev/null
+++ b/activerecord/test/locking_test.rb
@@ -0,0 +1,34 @@
+require 'abstract_unit'
+require 'fixtures/person'
+
+class LockingTest < Test::Unit::TestCase
+ def setup
+ @people = create_fixtures('people')
+ end
+
+ 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
+end \ No newline at end of file