mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Improve nil-safety in variant naming methods
This commit is contained in:
@@ -22,7 +22,8 @@ module VariantUnits
|
||||
end
|
||||
|
||||
def product_and_full_name
|
||||
return "#{product.name} - #{full_name}" unless full_name.start_with? product.name
|
||||
return product.name if full_name.blank?
|
||||
return "#{product.name} - #{full_name}" unless full_name.start_with?(product.name)
|
||||
|
||||
full_name
|
||||
end
|
||||
@@ -51,7 +52,7 @@ module VariantUnits
|
||||
return display_as if has_attribute?(:display_as) && display_as.present?
|
||||
return variant.display_as if variant_display_as?
|
||||
|
||||
options_text
|
||||
options_text.to_s
|
||||
end
|
||||
|
||||
def assign_units
|
||||
|
||||
@@ -432,6 +432,20 @@ describe Spree::Variant do
|
||||
expect(variant.product_and_full_name).to eq "Apple - Pink Lady"
|
||||
end
|
||||
end
|
||||
|
||||
context "when related naming values are nil" do
|
||||
before do
|
||||
product.name = "Apples"
|
||||
product.display_as = nil
|
||||
variant.display_as = nil
|
||||
variant.unit_presentation = nil
|
||||
end
|
||||
|
||||
it "returns empty string or product name" do
|
||||
expect(variant.full_name).to eq ""
|
||||
expect(variant.product_and_full_name).to eq product.name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "calculating the price with enterprise fees" do
|
||||
|
||||
Reference in New Issue
Block a user