From 920817540ef13e981f7c101f1231dca49dde86f2 Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Tue, 19 Jan 2021 09:37:44 +0100 Subject: [PATCH 1/2] Explicitely require Rails in bin/console To be able to have a working console. For some reason it's not loading Rails correctly, some pieces are missing. --- bin/console | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/console b/bin/console index 4fd503b..72da151 100755 --- a/bin/console +++ b/bin/console @@ -3,6 +3,7 @@ # frozen_string_literal: true require "bundler/setup" +require "rails/all" require "solidus_support" # You can add fixtures and/or initialization code here to make experimenting From 4f3ccabcc2bd1c4d75205fea60cea5c9b256f08f Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Tue, 19 Jan 2021 09:38:54 +0100 Subject: [PATCH 2/2] Add a method to check if combined name is being used This helper method checks if a store is using the old or new way of setting address' name. It will act as a migration support to create conditional code to make extensions work compatible with both versions. We can remove this method when the last 2.x version will reach EOL. --- lib/solidus_support.rb | 10 ++++++++++ spec/solidus_support_spec.rb | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/lib/solidus_support.rb b/lib/solidus_support.rb index 71cf072..3dbb8b3 100644 --- a/lib/solidus_support.rb +++ b/lib/solidus_support.rb @@ -21,6 +21,16 @@ def reset_spree_preferences_deprecated? first_version_without_reset.satisfied_by?(Spree.solidus_gem_version) end + def combined_first_and_last_name_in_address? + versions_before_preference = Gem::Requirement.new('< 2.10') + versions_after_preference = Gem::Requirement.new('>= 3.0.0.alpha') + + return false if versions_before_preference.satisfied_by?(Spree.solidus_gem_version) + return true if versions_after_preference.satisfied_by?(Spree.solidus_gem_version) + + Spree::Config.use_combined_first_and_last_name_in_address + end + def new_gateway_code? first_version_with_new_gateway_code = Gem::Requirement.new('>= 2.3') first_version_with_new_gateway_code.satisfied_by?(Spree.solidus_gem_version) diff --git a/spec/solidus_support_spec.rb b/spec/solidus_support_spec.rb index 1324a9a..c81427e 100644 --- a/spec/solidus_support_spec.rb +++ b/spec/solidus_support_spec.rb @@ -42,4 +42,37 @@ end # rubocop:enable RSpec/NestedGroups end + + describe '.combined_first_and_last_name_in_address?' do + subject { described_class.combined_first_and_last_name_in_address? } + + before do + allow(Spree).to receive(:solidus_gem_version) do + Gem::Version.new(solidus_version) + end + end + + context 'when Solidus did not have the code to combine addresses fields' do + let(:solidus_version) { '2.9.3' } + + it { is_expected.to be_falsey } + end + + context 'when Solidus has preference to choose if combine addresses fields' do + let(:solidus_version) { '2.10.3' } + before do + allow(Spree::Config) + .to receive(:use_combined_first_and_last_name_in_address) + .and_return(true) + end + + it { is_expected.to be_truthy } + end + + context 'when Solidus only has code to combine addresses fields' do + let(:solidus_version) { '3.0.0' } + + it { is_expected.to be_truthy } + end + end end