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

Add a method to check if combined address name is being used #58

Merged
merged 2 commits into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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