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

Rename currently_valid to prioritized_for_default #4109

Closed
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
4 changes: 2 additions & 2 deletions backend/app/controllers/spree/admin/prices_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ def index

@search = @product.prices.accessible_by(current_ability, :index).ransack(params[:q])
@master_prices = @search.result
.currently_valid
.prioritized_for_default
.for_master
.order(:variant_id, :country_iso, :currency)
.page(params[:page]).per(Spree::Config.admin_variants_per_page)
@variant_prices = @search.result
.currently_valid
.prioritized_for_default
.for_variant
.order(:variant_id, :country_iso, :currency)
.page(params[:page]).per(Spree::Config.admin_variants_per_page)
Expand Down
4 changes: 2 additions & 2 deletions core/app/models/concerns/spree/default_price.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def self.default_price_attributes
# Returns `#prices` prioritized for being considered as default price
#
# @return [ActiveRecord::Relation<Spree::Price>]
def currently_valid_prices
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should deprecate this method instead of removing it.

prices.currently_valid
def prioritized_for_default_prices
prices.prioritized_for_default
end

# Returns {#default_price} or builds it from {Spree::Variant.default_price_attributes}
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/price.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Price < Spree::Base
validates :currency, inclusion: { in: ::Money::Currency.all.map(&:iso_code), message: :invalid_code }
validates :country, presence: true, unless: -> { for_any_country? }

scope :currently_valid, -> { order(Arel.sql("country_iso IS NULL")).order(updated_at: :DESC, id: :DESC) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's deprecate this as well!

scope :prioritized_for_default, -> { order(Arel.sql("country_iso IS NULL")).order(updated_at: :DESC, id: :DESC) }
scope :for_master, -> { joins(:variant).where(spree_variants: { is_master: true }) }
scope :for_variant, -> { joins(:variant).where(spree_variants: { is_master: false }) }
scope :for_any_country, -> { where(country: nil) }
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/variant/price_selector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def price_for(price_options)
# @param [Spree::Variant::PricingOptions] price_options Pricing Options to abide by
# @return [Spree::Price, nil] The most specific price for this set of pricing options.
def price_for_options(price_options)
variant.currently_valid_prices.detect do |price|
variant.prioritized_for_default_prices.detect do |price|
(price.country_iso == price_options.desired_attributes[:country_iso] ||
price.country_iso.nil?
) && price.currency == price_options.desired_attributes[:currency]
Expand Down
6 changes: 3 additions & 3 deletions core/spec/models/spree/price_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@
end
end

describe '.currently_valid' do
describe '.prioritized_for_default' do
it 'prioritizes first those associated to a country' do
price_1 = create(:price, country: create(:country))
price_2 = create(:price, country: nil) { |price| price.touch }

result = described_class.currently_valid
result = described_class.prioritized_for_default

expect(
result.index(price_1) < result.index(price_2)
Expand All @@ -115,7 +115,7 @@
price_2 = create(:price, country: nil)
price_1.touch

result = described_class.currently_valid
result = described_class.prioritized_for_default

expect(
result.index(price_1) < result.index(price_2)
Expand Down
4 changes: 2 additions & 2 deletions core/spec/models/spree/variant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,13 @@
end
end

describe '#currently_valid_prices' do
describe '#prioritized_for_default_prices' do
it 'returns prioritized prices' do
price_1 = create(:price, country: create(:country))
price_2 = create(:price, country: nil)
variant = create(:variant, prices: [price_1, price_2])

result = variant.currently_valid_prices
result = variant.prioritized_for_default_prices

expect(
result.index(price_1) < result.index(price_2)
Expand Down
4 changes: 2 additions & 2 deletions core/spec/support/concerns/default_price.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
end
end

describe '#currently_valid_prices' do
describe '#prioritized_for_default_prices' do
it 'returns prioritized prices' do
price_1 = create(:price, country: create(:country))
price_2 = create(:price, country: nil)
variant = create(:variant, prices: [price_1, price_2])

result = variant.currently_valid_prices
result = variant.prioritized_for_default_prices

expect(
result.index(price_1) < result.index(price_2)
Expand Down