Skip to content

Commit

Permalink
load GeneralSettingsHelper#all_units from WeightsAndMeasures::UNITS
Browse files Browse the repository at this point in the history
  • Loading branch information
abdellani committed Nov 1, 2023
1 parent 77d9c39 commit b2afd9f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
8 changes: 3 additions & 5 deletions app/helpers/spree/admin/general_settings_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ module Admin
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
Expand Down
12 changes: 12 additions & 0 deletions spec/helpers/spree/admin/general_settings_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -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
8 changes: 0 additions & 8 deletions spec/services/weights_and_measures_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,4 @@
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

0 comments on commit b2afd9f

Please sign in to comment.