Skip to content

Commit

Permalink
Allow string arguments for set_constraints (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmsy committed Sep 11, 2023
1 parent 5852d10 commit 0acce72
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
activerecord-pg-extensions (0.5.2)
activerecord-pg-extensions (0.5.3)
activerecord (~> 7.0.0)
railties (~> 7.0.0)

Expand Down Expand Up @@ -157,4 +157,4 @@ DEPENDENCIES
rubocop-rspec (~> 2.3)

BUNDLED WITH
2.2.17
2.4.19
2 changes: 1 addition & 1 deletion gemfiles/rails_7.0.gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
activerecord-pg-extensions (0.5.1)
activerecord-pg-extensions (0.5.3)
activerecord (~> 7.0.0)
railties (~> 7.0.0)

Expand Down
2 changes: 1 addition & 1 deletion lib/active_record/pg_extensions/postgresql_adapter.rb
Expand Up @@ -10,7 +10,7 @@ module PostgreSQLAdapter
# see https://www.postgresql.org/docs/current/sql-set-constraints.html
def set_constraints(deferred, *constraints)
raise ArgumentError, "deferred must be :deferred or :immediate" unless %i[deferred
immediate].include?(deferred)
immediate].include?(deferred.to_sym)

constraints = constraints.map { |c| quote_table_name(c) }.join(", ")
constraints = "ALL" if constraints.empty?
Expand Down
2 changes: 1 addition & 1 deletion lib/active_record/pg_extensions/version.rb
Expand Up @@ -2,6 +2,6 @@

module ActiveRecord
module PGExtensions
VERSION = "0.5.2"
VERSION = "0.5.3"
end
end
5 changes: 5 additions & 0 deletions spec/postgresql_adapter_spec.rb
Expand Up @@ -14,6 +14,11 @@
expect { connection.set_constraints("garbage") }.to raise_error(ArgumentError)
end

it "allows string arguments" do
expect { connection.set_constraints("deferred") }.not_to raise_error(ArgumentError)
expect { connection.set_constraints("immediate") }.not_to raise_error(ArgumentError)
end

it "defaults to all" do
connection.set_constraints(:deferred)
expect(connection.executed_statements).to eq ["SET CONSTRAINTS ALL DEFERRED"]
Expand Down

0 comments on commit 0acce72

Please sign in to comment.