mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Move option value naming logic into separate lib class
This commit is contained in:
@@ -56,8 +56,9 @@ Spree::Variant.class_eval do
|
||||
delete_unit_option_values
|
||||
|
||||
option_type = self.product.variant_unit_option_type
|
||||
option_value_namer = OpenFoodNetwork::OptionValueNamer.new self
|
||||
if option_type
|
||||
name = option_value_name
|
||||
name = option_value_namer.name
|
||||
ov = Spree::OptionValue.where(option_type_id: option_type, name: name, presentation: name).first || Spree::OptionValue.create!({option_type: option_type, name: name, presentation: name}, without_protection: true)
|
||||
option_values << ov
|
||||
end
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
Shop for
|
||||
%p.trans-sentence
|
||||
%span.fat-taxons{"ng-repeat" => "taxon in hub.taxons"}
|
||||
%img{"bo-src" => "taxon.icon",
|
||||
name: "{{taxon.name}}", alt: "{{taxon.name}}"}
|
||||
%object.taxon{"data" => "{{taxon.icon}}", type: "image/svg+xml"}
|
||||
{{taxon.name}}
|
||||
{{taxon.name}}
|
||||
.columns.small-4
|
||||
%h5 Delivery options
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
%img{"bo-src" => "product.master.images[0].small_url"}
|
||||
|
||||
.small-4.columns.summary-header
|
||||
%img{"bo-src" => "product.primary_taxon.icon",
|
||||
"ng-click" => "ordering.order = 'primary_taxon.name'",
|
||||
name: "{{product.primary_taxon.name}}"}
|
||||
%object.taxon{"data" => "{{taxon.icon}}", type: "image/svg+xml",
|
||||
"ng-click" => "ordering.order = 'primary_taxon.name'"}
|
||||
{{taxon.name}}
|
||||
= render partial: "modals/product"
|
||||
|
||||
.small-5.columns
|
||||
|
||||
@@ -3,32 +3,53 @@ require 'spec_helper'
|
||||
module OpenFoodNetwork
|
||||
describe OptionValueNamer do
|
||||
describe "generating option value name" do
|
||||
<<<<<<< HEAD
|
||||
let(:v) { Spree::Variant.new }
|
||||
let(:subject) { OptionValueNamer.new v }
|
||||
|
||||
it "when description is blank" do
|
||||
v.stub(:unit_description) { nil }
|
||||
=======
|
||||
it "when description is blank" do
|
||||
v = Spree::Variant.new unit_description: nil
|
||||
subject = OptionValueNamer.new v
|
||||
>>>>>>> Move option value naming logic into separate lib class
|
||||
subject.stub(:value_scaled?) { true }
|
||||
subject.stub(:option_value_value_unit) { %w(value unit) }
|
||||
subject.name.should == "valueunit"
|
||||
end
|
||||
|
||||
it "when description is present" do
|
||||
<<<<<<< HEAD
|
||||
v.stub(:unit_description) { 'desc' }
|
||||
=======
|
||||
v = Spree::Variant.new unit_description: 'desc'
|
||||
subject = OptionValueNamer.new v
|
||||
>>>>>>> Move option value naming logic into separate lib class
|
||||
subject.stub(:option_value_value_unit) { %w(value unit) }
|
||||
subject.stub(:value_scaled?) { true }
|
||||
subject.name.should == "valueunit desc"
|
||||
end
|
||||
|
||||
it "when value is blank and description is present" do
|
||||
<<<<<<< HEAD
|
||||
v.stub(:unit_description) { 'desc' }
|
||||
=======
|
||||
v = Spree::Variant.new unit_description: 'desc'
|
||||
subject = OptionValueNamer.new v
|
||||
>>>>>>> Move option value naming logic into separate lib class
|
||||
subject.stub(:option_value_value_unit) { [nil, nil] }
|
||||
subject.stub(:value_scaled?) { true }
|
||||
subject.name.should == "desc"
|
||||
end
|
||||
|
||||
it "spaces value and unit when value is unscaled" do
|
||||
<<<<<<< HEAD
|
||||
v.stub(:unit_description) { nil }
|
||||
=======
|
||||
v = Spree::Variant.new unit_description: nil
|
||||
subject = OptionValueNamer.new v
|
||||
>>>>>>> Move option value naming logic into separate lib class
|
||||
subject.stub(:option_value_value_unit) { %w(value unit) }
|
||||
subject.stub(:value_scaled?) { false }
|
||||
subject.name.should == "value unit"
|
||||
|
||||
@@ -209,7 +209,6 @@ module Spree
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when the variant already has a value set (and all required option values exist)" do
|
||||
let!(:p0) { create(:simple_product, variant_unit: 'weight', variant_unit_scale: 1) }
|
||||
let!(:v0) { create(:variant, product: p0, unit_value: 10, unit_description: 'foo') }
|
||||
|
||||
Reference in New Issue
Block a user