diff --git a/app/models/spree/variant_decorator.rb b/app/models/spree/variant_decorator.rb index 2ffb07d4e1..8701990bb7 100644 --- a/app/models/spree/variant_decorator.rb +++ b/app/models/spree/variant_decorator.rb @@ -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 diff --git a/app/views/home/_fat.html.haml b/app/views/home/_fat.html.haml index 186361104b..aa41eef2cc 100644 --- a/app/views/home/_fat.html.haml +++ b/app/views/home/_fat.html.haml @@ -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 diff --git a/app/views/shop/products/_summary.html.haml b/app/views/shop/products/_summary.html.haml index ca9557d42a..144a41f640 100644 --- a/app/views/shop/products/_summary.html.haml +++ b/app/views/shop/products/_summary.html.haml @@ -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 diff --git a/spec/lib/open_food_network/option_value_namer_spec.rb b/spec/lib/open_food_network/option_value_namer_spec.rb index c0758d2a37..930f918986 100644 --- a/spec/lib/open_food_network/option_value_namer_spec.rb +++ b/spec/lib/open_food_network/option_value_namer_spec.rb @@ -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" diff --git a/spec/models/spree/variant_spec.rb b/spec/models/spree/variant_spec.rb index 535508ebe2..932630d640 100644 --- a/spec/models/spree/variant_spec.rb +++ b/spec/models/spree/variant_spec.rb @@ -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') }