Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Spree::MigrationHelpers Ruby 3.0 compatible #5072

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions core/lib/spree/migration_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ def safe_remove_index(table, column)
remove_index(table, column) if index_exists?(table, column)
end

def safe_add_index(table, column, options = {})
if columns_exist?(table, column) && !index_exists?(table, column, options)
add_index(table, column, options)
def safe_add_index(table, column, **options)
if columns_exist?(table, column) && !index_exists?(table, column, **options)
add_index(table, column, **options)
end
end

Expand Down
33 changes: 33 additions & 0 deletions core/spec/lib/spree/migration_helpers_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require "rails_helper"

RSpec.describe Spree::MigrationHelpers do
let(:helper) do
double.as_null_object.tap do |object|
object.extend(described_class)
object.extend(ActiveRecord::ConnectionAdapters::SchemaStatements)
end
end

subject { helper.safe_add_index(double, double) }

# regression test
describe "#safe_add_index" do
context "when the column exists" do
context "and the index does" do
it "passes compatible arguments to index_exists?" do
expect { subject }.to_not raise_error(ArgumentError)
RyanofWoods marked this conversation as resolved.
Show resolved Hide resolved
end
end

context "and the index does not" do
before do
allow(helper).to receive(:index_exists?).with(any_args).and_return(false)
end

it "passes compatible arguments to add_index" do
expect { subject }.to_not raise_error(ArgumentError)
end
end
end
end
end