diff --git a/core/app/models/spree/option_value.rb b/core/app/models/spree/option_value.rb index d9ffdefaa09..0f063616722 100644 --- a/core/app/models/spree/option_value.rb +++ b/core/app/models/spree/option_value.rb @@ -2,9 +2,7 @@ module Spree class OptionValue < Spree::Base - # TODO: Remove optional on Solidus v4.0. Don't forget adding a migration to - # enforce at the database layer - belongs_to :option_type, class_name: 'Spree::OptionType', inverse_of: :option_values, optional: true + belongs_to :option_type, class_name: 'Spree::OptionType', inverse_of: :option_values acts_as_list scope: :option_type has_many :option_values_variants, dependent: :destroy @@ -15,15 +13,8 @@ class OptionValue < Spree::Base after_save :touch, if: :saved_changes? after_touch :touch_all_variants - after_save do - Spree::Deprecation.warn <<~MSG if option_type.nil? - Having an option_value with no associated option_type will be deprecated - on Solidus v4.0 - MSG - end - # TODO: Remove allow_nil once option_type is required on Solidus v4.0 - delegate :name, :presentation, to: :option_type, prefix: :option_type, allow_nil: true + delegate :name, :presentation, to: :option_type, prefix: :option_type self.allowed_ransackable_attributes = %w[name presentation] diff --git a/core/db/migrate/20230321161854_change_column_null_option_values_option_type_id.rb b/core/db/migrate/20230321161854_change_column_null_option_values_option_type_id.rb new file mode 100644 index 00000000000..6cd9ec1f7f5 --- /dev/null +++ b/core/db/migrate/20230321161854_change_column_null_option_values_option_type_id.rb @@ -0,0 +1,5 @@ +class ChangeColumnNullOptionValuesOptionTypeId < ActiveRecord::Migration[5.2] + def change + change_column_null(:spree_option_values, :option_type_id, false) + end +end diff --git a/core/spec/models/spree/option_value_spec.rb b/core/spec/models/spree/option_value_spec.rb index 6c42f441102..f55dae08e0f 100644 --- a/core/spec/models/spree/option_value_spec.rb +++ b/core/spec/models/spree/option_value_spec.rb @@ -50,9 +50,9 @@ end end - it 'deprecates creating an option_value with no associated option_type' do - expect(Spree::Deprecation).to receive(:warn).with(/deprecated/) - - create(:option_value, option_type: nil) + it 'raises when creating an option_value with no associated option_type' do + expect { + create(:option_value, option_type: nil) + }.to raise_error(ActiveRecord::RecordInvalid) end end