diff options
Diffstat (limited to 'activerecord/test')
-rwxr-xr-x | activerecord/test/fixtures/db_definitions/mysql.sql | 6 | ||||
-rw-r--r-- | activerecord/test/fixtures/db_definitions/postgresql.sql | 7 | ||||
-rw-r--r-- | activerecord/test/fixtures/db_definitions/sqlite.sql | 6 | ||||
-rw-r--r-- | activerecord/test/fixtures/db_definitions/sqlserver.sql | 6 | ||||
-rw-r--r-- | activerecord/test/fixtures/people.yml | 3 | ||||
-rw-r--r-- | activerecord/test/fixtures/person.rb | 1 | ||||
-rw-r--r-- | activerecord/test/locking_test.rb | 34 |
7 files changed, 62 insertions, 1 deletions
diff --git a/activerecord/test/fixtures/db_definitions/mysql.sql b/activerecord/test/fixtures/db_definitions/mysql.sql index 7bd06e6243..ec27a52445 100755 --- a/activerecord/test/fixtures/db_definitions/mysql.sql +++ b/activerecord/test/fixtures/db_definitions/mysql.sql @@ -110,3 +110,9 @@ CREATE TABLE `mixins` ( `type` varchar(40) default NULL, PRIMARY KEY (`id`) ); + +CREATE TABLE `people` ( + `id` INTEGER NOT NULL PRIMARY KEY, + `first_name` VARCHAR(40) NOT NULL, + `lock_version` INTEGER NOT NULL DEFAULT 0 +);
\ No newline at end of file diff --git a/activerecord/test/fixtures/db_definitions/postgresql.sql b/activerecord/test/fixtures/db_definitions/postgresql.sql index 305852ba7f..6d8222cfd6 100644 --- a/activerecord/test/fixtures/db_definitions/postgresql.sql +++ b/activerecord/test/fixtures/db_definitions/postgresql.sql @@ -127,3 +127,10 @@ CREATE TABLE mixins ( updated_at timestamp, PRIMARY KEY (id) ); + +CREATE TABLE people ( + id serial, + first_name text, + lock_version integer default 0, + PRIMARY KEY (id) +);
\ No newline at end of file diff --git a/activerecord/test/fixtures/db_definitions/sqlite.sql b/activerecord/test/fixtures/db_definitions/sqlite.sql index 9bab9d9a15..5c27832056 100644 --- a/activerecord/test/fixtures/db_definitions/sqlite.sql +++ b/activerecord/test/fixtures/db_definitions/sqlite.sql @@ -99,4 +99,8 @@ CREATE TABLE 'mixins' ( 'updated_at' DATETIME DEFAULT NULL ); - +CREATE TABLE 'people' ( + 'id' INTEGER NOT NULL PRIMARY KEY, + 'first_name' VARCHAR(40) DEFAULT NULL, + 'lock_version' INTEGER NOT NULL DEFAULT 0 +);
\ No newline at end of file diff --git a/activerecord/test/fixtures/db_definitions/sqlserver.sql b/activerecord/test/fixtures/db_definitions/sqlserver.sql index 4152ef59cb..74cd381ba3 100644 --- a/activerecord/test/fixtures/db_definitions/sqlserver.sql +++ b/activerecord/test/fixtures/db_definitions/sqlserver.sql @@ -110,3 +110,9 @@ CREATE TABLE mixins ( ); +CREATE TABLE people ( + id int NOT NULL IDENTITY(1, 1), + first_name varchar(40) NULL, + lock_version int default 0, + PRIMARY KEY (id) +);
\ No newline at end of file diff --git a/activerecord/test/fixtures/people.yml b/activerecord/test/fixtures/people.yml new file mode 100644 index 0000000000..22c64afb70 --- /dev/null +++ b/activerecord/test/fixtures/people.yml @@ -0,0 +1,3 @@ +michael: + id: 1 + first_name: Michael
\ No newline at end of file diff --git a/activerecord/test/fixtures/person.rb b/activerecord/test/fixtures/person.rb new file mode 100644 index 0000000000..4fa5811c71 --- /dev/null +++ b/activerecord/test/fixtures/person.rb @@ -0,0 +1 @@ +class Person < ActiveRecord::Base; end 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 |