Skip to content

Commit

Permalink
fix tests for rails 7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
rkrage committed Nov 17, 2023
1 parent 68a0ae8 commit 4557043
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/pg_ha_migrations/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def self.from_table_and_columns(table, columns)
# modified from https://github.com/rails/rails/pull/47753
if name.bytesize > MAX_NAME_SIZE
hashed_identifier = "_#{OpenSSL::Digest::SHA256.hexdigest(name).first(10)}"
description = name.sub("index_#{table.name}_on", "ix_on")
description = name.sub("index_#{table.name}_on", "idx_on")

short_limit = MAX_NAME_SIZE - hashed_identifier.bytesize
short_description = description.mb_chars.limit(short_limit).to_s
Expand Down
8 changes: 4 additions & 4 deletions spec/safe_statements_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1832,19 +1832,19 @@ def up
end

it "generates index name with hashed identifier when default child index name is too large" do
create_range_partitioned_table("x" * 43, migration_klass, with_partman: true)
create_range_partitioned_table("x" * 42, migration_klass, with_partman: true)

test_migration = Class.new(migration_klass) do
def up
safe_add_concurrent_partitioned_index "x" * 43, :updated_at
safe_add_concurrent_partitioned_index "x" * 42, :updated_at
end
end

allow(ActiveRecord::Base.connection).to receive(:execute).and_call_original

aggregate_failures do
expect(ActiveRecord::Base.connection).to receive(:execute).with(/CREATE INDEX "index_#{"x" * 43}_on_updated_at" ON ONLY/).once.ordered
expect(ActiveRecord::Base.connection).to receive(:execute).with(/CREATE INDEX CONCURRENTLY "ix_on_updated_at_\w{10}/).exactly(10).times.ordered
expect(ActiveRecord::Base.connection).to receive(:execute).with(/CREATE INDEX "index_#{"x" * 42}_on_updated_at" ON ONLY/).once.ordered
expect(ActiveRecord::Base.connection).to receive(:execute).with(/CREATE INDEX CONCURRENTLY "idx_on_updated_at_\w{10}/).exactly(10).times.ordered
expect(ActiveRecord::Base.connection).to receive(:execute).with(/ALTER INDEX .+\nATTACH PARTITION/).exactly(10).times.ordered
end

Expand Down

0 comments on commit 4557043

Please sign in to comment.