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

Refactor ActiveRecordVersions #1423

Merged
merged 9 commits into from
Mar 9, 2021
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