class PostgreSQLReferentialIntegrityTest

Constants

IS_REFERENTIAL_INTEGRITY_SQL

Public Instance Methods

setup() click to toggle source
# File activerecord/test/cases/adapters/postgresql/referential_integrity_test.rb, line 36
def setup
  @connection = ActiveRecord::Base.connection
end
teardown() click to toggle source
# File activerecord/test/cases/adapters/postgresql/referential_integrity_test.rb, line 40
def teardown
  reset_connection
  if ActiveRecord::Base.connection.is_a?(MissingSuperuserPrivileges)
    raise "MissingSuperuserPrivileges patch was not removed"
  end
end
test_does_not_break_nested_transactions() click to toggle source
# File activerecord/test/cases/adapters/postgresql/referential_integrity_test.rb, line 87
def test_does_not_break_nested_transactions
  @connection.extend MissingSuperuserPrivileges

  @connection.transaction do
    @connection.transaction(requires_new: true) do
      @connection.disable_referential_integrity do
        assert_transaction_is_not_broken
      end
    end
    assert_transaction_is_not_broken
  end
end
test_does_not_break_transactions() click to toggle source
# File activerecord/test/cases/adapters/postgresql/referential_integrity_test.rb, line 76
def test_does_not_break_transactions
  @connection.extend MissingSuperuserPrivileges

  @connection.transaction do
    @connection.disable_referential_integrity do
      assert_transaction_is_not_broken
    end
    assert_transaction_is_not_broken
  end
end
test_does_not_print_warning_if_no_invalid_foreign_key_exception_was_raised() click to toggle source
# File activerecord/test/cases/adapters/postgresql/referential_integrity_test.rb, line 62
def test_does_not_print_warning_if_no_invalid_foreign_key_exception_was_raised
  @connection.extend MissingSuperuserPrivileges

  warning = capture(:stderr) do
    e = assert_raises(ActiveRecord::StatementInvalid) do
      @connection.disable_referential_integrity do
        raise ActiveRecord::StatementInvalid, "Should be re-raised"
      end
    end
    assert_equal "Should be re-raised", e.message
  end
  assert warning.blank?, "expected no warnings but got:\n#{warning}"
end
test_only_catch_active_record_errors_others_bubble_up() click to toggle source
# File activerecord/test/cases/adapters/postgresql/referential_integrity_test.rb, line 100
def test_only_catch_active_record_errors_others_bubble_up
  @connection.extend ProgrammerMistake

  assert_raises ArgumentError do
    @connection.disable_referential_integrity {}
  end
end
test_should_reraise_invalid_foreign_key_exception_and_show_warning() click to toggle source
# File activerecord/test/cases/adapters/postgresql/referential_integrity_test.rb, line 47
def test_should_reraise_invalid_foreign_key_exception_and_show_warning
  @connection.extend MissingSuperuserPrivileges

  warning = capture(:stderr) do
    e = assert_raises(ActiveRecord::InvalidForeignKey) do
      @connection.disable_referential_integrity do
        raise ActiveRecord::InvalidForeignKey, "Should be re-raised"
      end
    end
    assert_equal "Should be re-raised", e.message
  end
  assert_match (/WARNING: Quails was not able to disable referential integrity/), warning
  assert_match (/cause: PG::InsufficientPrivilege/), warning
end

Private Instance Methods

assert_transaction_is_not_broken() click to toggle source
# File activerecord/test/cases/adapters/postgresql/referential_integrity_test.rb, line 110
def assert_transaction_is_not_broken
  assert_equal 1, @connection.select_value("SELECT 1")
end