load GeneralSettingsHelper#all_units from WeightsAndMeasures::UNITS

This commit is contained in:
Mohamed ABDELLANI
2023-11-01 09:53:47 +01:00
parent fb24678654
commit e10d441153
3 changed files with 15 additions and 13 deletions

View File

@@ -5,11 +5,9 @@ module Spree
module GeneralSettingsHelper
def all_units
[
"mg", "g", "kg", "T",
"oz", "lb",
"mL", "cL", "dL", "L", "kL",
"gal"
]
WeightsAndMeasures::UNITS['weight'].values.pluck('name'),
WeightsAndMeasures::UNITS['volume'].values.pluck('name')
].flatten.uniq
end
end
end

View File

@@ -0,0 +1,12 @@
# frozen_string_literal: true
require 'spec_helper'
describe Spree::Admin::GeneralSettingsHelper, type: :helper do
describe "#all_units" do
it "returns all units" do
expect(helper.all_units).to eq(["mg", "g", "kg", "T", "oz", "lb", "mL", "cL", "dL", "L",
"kL", "gal"])
end
end
end

View File

@@ -90,12 +90,4 @@ describe WeightsAndMeasures do
end
end
end
describe "UNITS" do
include Spree::Admin::GeneralSettingsHelper
it "should include all the available untis" do
units = WeightsAndMeasures::UNITS.values.flat_map(&:values).pluck("name").sort.uniq
expect(units).to eq(all_units.sort.uniq)
end
end
end