Rename option_type_for_variant_unit to variant_unit_option_type

This commit is contained in:
Rohan Mitchell
2014-01-07 10:31:53 +11:00
parent 1084862139
commit 6a4c112cf2
2 changed files with 20 additions and 10 deletions

View File

@@ -102,29 +102,32 @@ Spree::Product.class_eval do
end
end
def variant_unit_option_type
if variant_unit.present?
option_type_name = "unit_#{variant_unit}"
option_type_presentation = variant_unit.capitalize
Spree::OptionType.find_by_name(option_type_name) ||
Spree::OptionType.create!(name: option_type_name,
presentation: option_type_presentation)
end
end
private
def set_available_on_to_now
self.available_on ||= Time.now
end
def update_units
if variant_unit_changed?
option_types.delete self.class.all_variant_unit_option_types
option_types << option_type_for_variant_unit if variant_unit.present?
option_types << variant_unit_option_type if variant_unit.present?
variants.each { |v| v.delete_unit_option_values }
end
end
def option_type_for_variant_unit
option_type_name = "unit_#{variant_unit}"
option_type_presentation = variant_unit.capitalize
Spree::OptionType.find_by_name(option_type_name) ||
Spree::OptionType.create!(name: option_type_name, presentation: option_type_presentation)
end
def self.all_variant_unit_option_types
Spree::OptionType.where('name LIKE ?', 'unit_%%')
end

View File

@@ -396,6 +396,13 @@ module Spree
end
end
describe "returning the variant unit option type" do
it "returns nil when variant_unit is not set" do
p = create(:simple_product, variant_unit: nil)
p.variant_unit_option_type.should be_nil
end
end
it "finds all variant unit option types" do
ot1 = create(:option_type, name: 'unit_weight', presentation: 'Weight')
ot2 = create(:option_type, name: 'unit_volume', presentation: 'Volume')