Skip to content

Commit

Permalink
Add a method to check if combined name is being used
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kennyadsl committed Jan 19, 2021
1 parent 9208175 commit 4f3ccab
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/solidus_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
33 changes: 33 additions & 0 deletions spec/solidus_support_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4f3ccab

Please sign in to comment.