aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2015-03-11 14:34:53 +0100
committerYves Senn <yves.senn@gmail.com>2015-03-11 14:34:53 +0100
commit0c7c6286f653b947db8a2a17c11f0c213a8d23ea (patch)
tree3ff630928f57b8874dd5781b51c4282d7a795409 /activerecord/test
parent598b841882cbfe1d88c55b9cc49a5a188735d0b1 (diff)
downloadrails-0c7c6286f653b947db8a2a17c11f0c213a8d23ea.tar.gz
rails-0c7c6286f653b947db8a2a17c11f0c213a8d23ea.tar.bz2
rails-0c7c6286f653b947db8a2a17c11f0c213a8d23ea.zip
pg, `disable_referential_integrity` only catches AR errors.
This change was prompted by 598b841.
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/adapters/postgresql/referential_integrity_test.rb24
1 files changed, 23 insertions, 1 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/referential_integrity_test.rb b/activerecord/test/cases/adapters/postgresql/referential_integrity_test.rb
index 98291f1bbf..71ee2d9bab 100644
--- a/activerecord/test/cases/adapters/postgresql/referential_integrity_test.rb
+++ b/activerecord/test/cases/adapters/postgresql/referential_integrity_test.rb
@@ -6,9 +6,13 @@ class PostgreSQLReferentialIntegrityTest < ActiveRecord::TestCase
include ConnectionHelper
+ IS_REFERENTIAL_INTEGRITY_SQL = lambda do |sql|
+ sql.match(/DISABLE TRIGGER ALL/) || sql.match(/ENABLE TRIGGER ALL/)
+ end
+
module MissingSuperuserPrivileges
def execute(sql)
- if sql.match(/DISABLE TRIGGER ALL/) || sql.match(/ENABLE TRIGGER ALL/)
+ if IS_REFERENTIAL_INTEGRITY_SQL.call(sql)
super "BROKEN;" rescue nil # put transaction in broken state
raise ActiveRecord::StatementInvalid, 'PG::InsufficientPrivilege'
else
@@ -17,6 +21,16 @@ class PostgreSQLReferentialIntegrityTest < ActiveRecord::TestCase
end
end
+ module ProgrammerMistake
+ def execute(sql)
+ if IS_REFERENTIAL_INTEGRITY_SQL.call(sql)
+ raise ArgumentError, 'something is not right.'
+ else
+ super
+ end
+ end
+ end
+
def setup
@connection = ActiveRecord::Base.connection
end
@@ -81,6 +95,14 @@ class PostgreSQLReferentialIntegrityTest < ActiveRecord::TestCase
end
end
+ def test_only_catch_active_record_errors_others_bubble_up
+ @connection.extend ProgrammerMistake
+
+ assert_raises ArgumentError do
+ @connection.disable_referential_integrity {}
+ end
+ end
+
private
def assert_transaction_is_not_broken