diff options
Diffstat (limited to 'spec/arel/engines/sql/unit/relations/lock_spec.rb')
-rw-r--r-- | spec/arel/engines/sql/unit/relations/lock_spec.rb | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/spec/arel/engines/sql/unit/relations/lock_spec.rb b/spec/arel/engines/sql/unit/relations/lock_spec.rb new file mode 100644 index 0000000000..27239eb1a8 --- /dev/null +++ b/spec/arel/engines/sql/unit/relations/lock_spec.rb @@ -0,0 +1,47 @@ +require 'spec_helper' + +module Arel + describe Lock do + before do + @relation = Table.new(:users) + end + + describe '#to_sql' do + it "manufactures a simple select query lock" do + sql = @relation.lock.to_sql + + adapter_is :mysql do + sql.should be_like(%Q{ + SELECT `users`.`id`, `users`.`name` + FROM `users` FOR UPDATE + }) + end + + adapter_is_not :mysql do + sql.should be_like(%Q{ + SELECT "users"."id", "users"."name" + FROM "users" FOR UPDATE + }) + end + end + + it "manufactures a select query locking with a given lock" do + sql = @relation.lock("LOCK IN SHARE MODE").to_sql + + adapter_is :mysql do + sql.should be_like(%Q{ + SELECT `users`.`id`, `users`.`name` + FROM `users` LOCK IN SHARE MODE + }) + end + + adapter_is_not :mysql do + sql.should be_like(%Q{ + SELECT "users"."id", "users"."name" + FROM "users" LOCK IN SHARE MODE + }) + end + end + end + end +end |