Find enterprise fees with per-order calculators

This commit is contained in:
Rohan Mitchell
2014-02-26 13:48:51 +11:00
parent 890af85d30
commit 5057e236a9
2 changed files with 24 additions and 1 deletions

View File

@@ -6,6 +6,8 @@ class EnterpriseFee < ActiveRecord::Base
attr_accessible :enterprise_id, :fee_type, :name, :calculator_type
FEE_TYPES = %w(packing transport admin sales)
PER_ORDER_CALCULATORS = ['Spree::Calculator::FlatRate', 'Spree::Calculator::FlexiRate']
validates_inclusion_of :fee_type, :in => FEE_TYPES
validates_presence_of :name
@@ -22,7 +24,10 @@ class EnterpriseFee < ActiveRecord::Base
}
scope :per_item, lambda {
joins(:calculator).where('spree_calculators.type NOT IN (?)', ['Spree::Calculator::FlatRate', 'Spree::Calculator::FlexiRate'])
joins(:calculator).where('spree_calculators.type NOT IN (?)', PER_ORDER_CALCULATORS)
}
scope :per_order, lambda {
joins(:calculator).where('spree_calculators.type IN (?)', PER_ORDER_CALCULATORS)
}
def self.clear_all_adjustments_for(line_item)

View File

@@ -27,6 +27,24 @@ describe EnterpriseFee do
EnterpriseFee.per_item.sort.should == [ef1, ef2, ef3, ef4].sort
end
end
describe "finding per-order enterprise fees" do
it "returns fees with FlatRate and FlexiRate calculators" do
ef1 = create(:enterprise_fee, calculator: Spree::Calculator::FlatRate.new)
ef2 = create(:enterprise_fee, calculator: Spree::Calculator::FlexiRate.new)
EnterpriseFee.per_order.sort.should == [ef1, ef2].sort
end
it "does not return fees with any other calculator" do
ef1 = create(:enterprise_fee, calculator: Spree::Calculator::DefaultTax.new)
ef2 = create(:enterprise_fee, calculator: Spree::Calculator::FlatPercentItemTotal.new)
ef3 = create(:enterprise_fee, calculator: Spree::Calculator::PerItem.new)
ef4 = create(:enterprise_fee, calculator: Spree::Calculator::PriceSack.new)
EnterpriseFee.per_order.should be_empty
end
end
end
describe "clearing all enterprise fee adjustments for a line item" do