diff options
Diffstat (limited to 'activerecord/test/cases/base_test.rb')
-rw-r--r-- | activerecord/test/cases/base_test.rb | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index b74bd93f37..4938b6865f 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -1490,31 +1490,37 @@ class BasicsTest < ActiveRecord::TestCase end test "creating a record raises if preventing writes" do - assert_raises ActiveRecord::ReadOnlyError do + error = assert_raises ActiveRecord::ReadOnlyError do ActiveRecord::Base.connection.while_preventing_writes do Bird.create! name: "Bluejay" end end + + assert_match %r/\AWrite query attempted while in readonly mode: INSERT /, error.message end test "updating a record raises if preventing writes" do bird = Bird.create! name: "Bluejay" - assert_raises ActiveRecord::ReadOnlyError do + error = assert_raises ActiveRecord::ReadOnlyError do ActiveRecord::Base.connection.while_preventing_writes do bird.update! name: "Robin" end end + + assert_match %r/\AWrite query attempted while in readonly mode: UPDATE /, error.message end test "deleting a record raises if preventing writes" do bird = Bird.create! name: "Bluejay" - assert_raises ActiveRecord::ReadOnlyError do + error = assert_raises ActiveRecord::ReadOnlyError do ActiveRecord::Base.connection.while_preventing_writes do bird.destroy! end end + + assert_match %r/\AWrite query attempted while in readonly mode: DELETE /, error.message end test "selecting a record does not raise if preventing writes" do @@ -1524,4 +1530,22 @@ class BasicsTest < ActiveRecord::TestCase assert_equal bird, Bird.where(name: "Bluejay").first end end + + test "an explain query does not raise if preventing writes" do + Bird.create!(name: "Bluejay") + + ActiveRecord::Base.connection.while_preventing_writes do + assert_queries(2) { Bird.where(name: "Bluejay").explain } + end + end + + test "an empty transaction does not raise if preventing writes" do + ActiveRecord::Base.connection.while_preventing_writes do + assert_queries(2, ignore_none: true) do + Bird.transaction do + ActiveRecord::Base.connection.materialize_transactions + end + end + end + end end |