Skip to content

Commit

Permalink
fix: Adjust validate options when managing columns and tables in migr…
Browse files Browse the repository at this point in the history
…ation

This commit adjusts the way we manage columns and tables in migrations
to account for the changes in Rails 7.1.0, it was introduced in this
Rails version a validation around the options passed to tables and
columns in migrations, so we need to adjust our code to skip this
validation.

This PR introduced this new validation on the migrations:
rails/rails#46178
  • Loading branch information
matsales28 committed Oct 6, 2023
1 parent 6373da1 commit 2be4162
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/shoulda/matchers/rails_shim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ def supports_full_attributes_api?(model)
model.respond_to?(:attribute_types)
end

def validates_column_options?
active_record_version >= '7.1.0'
end

private

def simply_generate_validation_message(
Expand Down
1 change: 1 addition & 0 deletions spec/support/unit/active_record/create_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def add_column_to_table(table, column_name, column_specification)
column_specification = column_specification.dup
column_type = column_specification.delete(:type)
column_options = column_specification.delete(:options) { {} }
column_options.merge!({ _skip_validate_options: true }) if Shoulda::Matchers::RailsShim.validates_column_options?

if column_options[:array] && !database_supports_array_columns?
raise ArgumentError.new(
Expand Down
2 changes: 1 addition & 1 deletion spec/support/unit/attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Attribute
DEFAULT_COLUMN_TYPE = :string
DEFAULT_COLUMN_OPTIONS = {
null: false,
array: false,
array: false
}.freeze

def initialize(args)
Expand Down

0 comments on commit 2be4162

Please sign in to comment.