Skip to content

Commit

Permalink
Refactor ActiveRecordVersions (#1423)
Browse files Browse the repository at this point in the history
* Remove active_record_enum_supports_prefix_and_suffix method

* Remove active_record_supports_has_secure_password method

* Remove active_record_supports_has_secure_token method

* Remove active_record_supports_array_columns method

* Remove active_record_supports_relations method

* Remove active_record_supports_more_dependent_options method

* Remove active_record_uniqueness_supports_array_columns method

* Remove active_record_supports_optional_for_associations method

* Remove active_record_supports_expression_indexes method
  • Loading branch information
vsppedro authored Mar 9, 2021
1 parent 0e8c059 commit e746f2e
Show file tree
Hide file tree
Showing 9 changed files with 882 additions and 1,192 deletions.
28 changes: 6 additions & 22 deletions spec/support/unit/active_record/create_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ def call

attr_reader :table_name, :columns, :connection, :customizer

delegate(
:active_record_supports_array_columns?,
:active_record_version,
to: UnitTests::ActiveRecordVersions,
)

delegate(
:database_supports_array_columns?,
:database_adapter,
Expand Down Expand Up @@ -99,22 +93,12 @@ def add_column_to_table(table, column_name, column_specification)
column_type = column_specification.delete(:type)
column_options = column_specification.delete(:options) { {} }

if column_options[:array]
if !active_record_supports_array_columns?
raise ArgumentError.new(
'An array column is being added to a table, but this version '\
"of ActiveRecord (#{active_record_version}) "\
'does not support array columns.',
)
end

if !database_supports_array_columns?
raise ArgumentError.new(
'An array column is being added to a table, but this '\
"database adapter (#{database_adapter}) "\
'does not support array columns.',
)
end
if column_options[:array] && !database_supports_array_columns?
raise ArgumentError.new(
'An array column is being added to a table, but this '\
"database adapter (#{database_adapter}) "\
'does not support array columns.',
)
end

if column_specification.any?
Expand Down
36 changes: 0 additions & 36 deletions spec/support/unit/helpers/active_record_versions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,6 @@ def active_record_version
Tests::Version.new(::ActiveRecord::VERSION::STRING)
end

def active_record_enum_supports_prefix_and_suffix?
active_record_version >= 5
end

def active_record_supports_has_secure_password?
active_record_version >= 3.1
end

def active_record_supports_has_secure_token?
active_record_version >= 5.0
end

def active_record_supports_array_columns?
active_record_version > 4.2
end

def active_record_supports_relations?
active_record_version >= 4
end

def active_record_supports_more_dependent_options?
active_record_version >= 4
end

def active_record_uniqueness_supports_array_columns?
active_record_version < 5
end

def active_record_supports_optional_for_associations?
active_record_version >= 5
end

def active_record_supports_expression_indexes?
active_record_version >= 5
end

def active_record_supports_active_storage?
active_record_version >= 5.2
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def self.available_column_types
end
end

if database_supports_array_columns? && active_record_supports_array_columns?
if database_supports_array_columns?
context 'when the column backing the attribute is an array' do
context 'of varchar' do
it 'still works' do
Expand Down
Loading

0 comments on commit e746f2e

Please sign in to comment.