mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-31 06:31:41 +00:00
Move both OptionValueNamer and VariantAndLineItemNaming to app/services/variant_units
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
require 'open_food_network/scope_variant_to_hub'
|
||||
require 'open_food_network/variant_and_line_item_naming'
|
||||
require 'variant_units/variant_and_line_item_naming'
|
||||
|
||||
Spree::LineItem.class_eval do
|
||||
include OpenFoodNetwork::VariantAndLineItemNaming
|
||||
include VariantUnits::VariantAndLineItemNaming
|
||||
include LineItemBasedAdjustmentHandling
|
||||
has_and_belongs_to_many :option_values, join_table: 'spree_option_values_line_items', class_name: 'Spree::OptionValue'
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
require 'open_food_network/enterprise_fee_calculator'
|
||||
require 'open_food_network/variant_and_line_item_naming'
|
||||
require 'variant_units/variant_and_line_item_naming'
|
||||
require 'concerns/variant_stock'
|
||||
|
||||
Spree::Variant.class_eval do
|
||||
@@ -8,7 +8,7 @@ Spree::Variant.class_eval do
|
||||
# This file may be double-loaded in delayed job environment, so we check before
|
||||
# removing the Spree method to prevent error.
|
||||
remove_method :options_text if instance_methods(false).include? :options_text
|
||||
include OpenFoodNetwork::VariantAndLineItemNaming
|
||||
include VariantUnits::VariantAndLineItemNaming
|
||||
include VariantStock
|
||||
|
||||
has_many :exchange_variants
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
require "open_food_network/i18n_inflections"
|
||||
|
||||
module OpenFoodNetwork
|
||||
module VariantUnits
|
||||
class OptionValueNamer
|
||||
def initialize(variant = nil)
|
||||
@variant = variant
|
||||
@@ -99,7 +99,7 @@ module OpenFoodNetwork
|
||||
end
|
||||
|
||||
def pluralize(unit_name, count)
|
||||
I18nInflections.pluralize(unit_name, count)
|
||||
OpenFoodNetwork::I18nInflections.pluralize(unit_name, count)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -2,9 +2,9 @@
|
||||
# It contains all of our logic for creating and naming option values (which are associated
|
||||
# with both models) and methods for printing human readable "names" for instances of these models.
|
||||
|
||||
require 'open_food_network/option_value_namer'
|
||||
require 'variant_units/option_value_namer'
|
||||
|
||||
module OpenFoodNetwork
|
||||
module VariantUnits
|
||||
module VariantAndLineItemNaming
|
||||
# Copied and modified from Spree::Variant
|
||||
def options_text
|
||||
@@ -103,7 +103,7 @@ module OpenFoodNetwork
|
||||
if has_attribute?(:display_as) && display_as.present?
|
||||
display_as
|
||||
else
|
||||
option_value_namer = OpenFoodNetwork::OptionValueNamer.new self
|
||||
option_value_namer = VariantUnits::OptionValueNamer.new self
|
||||
option_value_namer.name
|
||||
end
|
||||
end
|
||||
@@ -194,11 +194,11 @@ module OrderManagement
|
||||
end
|
||||
|
||||
def option_value_value(line_items)
|
||||
OpenFoodNetwork::OptionValueNamer.new(line_items.first).value
|
||||
VariantUnits::OptionValueNamer.new(line_items.first).value
|
||||
end
|
||||
|
||||
def option_value_unit(line_items)
|
||||
OpenFoodNetwork::OptionValueNamer.new(line_items.first).unit
|
||||
VariantUnits::OptionValueNamer.new(line_items.first).unit
|
||||
end
|
||||
|
||||
def order_billing_address_name(line_items)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
require 'open_food_network/products_and_inventory_report_base'
|
||||
require 'variant_units/option_value_namer'
|
||||
|
||||
module OpenFoodNetwork
|
||||
class LettuceShareReport < ProductsAndInventoryReportBase
|
||||
@@ -27,8 +28,8 @@ module OpenFoodNetwork
|
||||
variant.product.name,
|
||||
variant.full_name,
|
||||
'',
|
||||
OptionValueNamer.new(variant).value,
|
||||
OptionValueNamer.new(variant).unit,
|
||||
VariantUnits::OptionValueNamer.new(variant).value,
|
||||
VariantUnits::OptionValueNamer.new(variant).unit,
|
||||
variant.price,
|
||||
'',
|
||||
gst(variant),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
require 'spec_helper'
|
||||
require 'open_food_network/option_value_namer'
|
||||
require 'variant_units/option_value_namer'
|
||||
|
||||
module Spree
|
||||
describe Variant do
|
||||
@@ -436,7 +436,7 @@ module Spree
|
||||
let!(:v) { create(:variant, product: p, unit_value: 5, unit_description: 'bar', display_as: '') }
|
||||
|
||||
it "requests the name of the new option_value from OptionValueName" do
|
||||
expect_any_instance_of(OpenFoodNetwork::OptionValueNamer).to receive(:name).exactly(1).times.and_call_original
|
||||
expect_any_instance_of(VariantUnits::OptionValueNamer).to receive(:name).exactly(1).times.and_call_original
|
||||
v.update(unit_value: 10, unit_description: 'foo')
|
||||
ov = v.option_values.last
|
||||
expect(ov.name).to eq("10g foo")
|
||||
@@ -448,7 +448,7 @@ module Spree
|
||||
let!(:v) { create(:variant, product: p, unit_value: 5, unit_description: 'bar', display_as: 'FOOS!') }
|
||||
|
||||
it "does not request the name of the new option_value from OptionValueName" do
|
||||
expect_any_instance_of(OpenFoodNetwork::OptionValueNamer).not_to receive(:name)
|
||||
expect_any_instance_of(VariantUnits::OptionValueNamer).not_to receive(:name)
|
||||
v.update!(unit_value: 10, unit_description: 'foo')
|
||||
ov = v.option_values.last
|
||||
expect(ov.name).to eq("FOOS!")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module OpenFoodNetwork
|
||||
module VariantUnits
|
||||
describe OptionValueNamer do
|
||||
describe "generating option value name" do
|
||||
let(:v) { Spree::Variant.new }
|
||||
Reference in New Issue
Block a user