Add calculator to EnterpriseFee, test passes for listing enterprise fees

This commit is contained in:
Rohan Mitchell
2012-11-16 16:07:40 +11:00
parent 6247bd2541
commit 98143ffe5b
7 changed files with 67 additions and 2 deletions

View File

@@ -1,10 +1,16 @@
module Admin
class EnterpriseFeesController < ResourceController
before_filter :load_enterprise_fees_set, :only => :index
before_filter :load_data
private
def load_enterprise_fees_set
@enterprise_fees_set = ModelSet.new EnterpriseFee.all, :collection => collection
end
def load_data
@calculators = EnterpriseFee.calculators.sort_by(&:name)
end
end
end

View File

@@ -1,6 +1,9 @@
class EnterpriseFee < ActiveRecord::Base
belongs_to :enterprise
calculated_adjustments
has_one :calculator, :as => :calculable, :dependent => :destroy, :class_name => 'Spree::Calculator'
FEE_TYPES = %w(packing transport admin sales)
validates_inclusion_of :fee_type, :in => FEE_TYPES

View File

@@ -15,6 +15,9 @@
%td= f.collection_select :enterprise_id, Enterprise.all, :id, :name
%td= f.select :fee_type, enterprise_fee_options
%td= f.text_field :name
%td TODO
%td TODO
%td= f.collection_select :calculator_type, @calculators, :name, :description
%td
- if !enterprise_fee.new_record?
= f.fields_for :calculator do |calculator_form|
= preference_fields(enterprise_fee.calculator, calculator_form)
%td TODO

View File

@@ -28,6 +28,13 @@ module Openfoodweb
initializer "spree.register.calculators" do |app|
app.config.spree.calculators.shipping_methods << OpenFoodWeb::Calculator::Itemwise
app.config.spree.calculators.shipping_methods << OpenFoodWeb::Calculator::Weight
app.config.spree.calculators.enterprise_fees = [Spree::Calculator::FlatPercentItemTotal,
Spree::Calculator::FlatRate,
Spree::Calculator::FlexiRate,
Spree::Calculator::PerItem,
Spree::Calculator::PriceSack,
OpenFoodWeb::Calculator::Weight]
end

View File

@@ -26,3 +26,17 @@ Spree.config do |config|
# Auto-capture payments. Without this option, payments must be manually captured in the paypal interface.
config.auto_capture = true
end
# Add calculators category for enterprise fees
module Spree
module Core
class Environment
class Calculators
include EnvironmentExtension
attr_accessor :enterprise_fees
end
end
end
end

View File

@@ -24,6 +24,9 @@ FactoryGirl.define do
enterprise { Enterprise.first || FactoryGirl.create(:supplier_enterprise) }
fee_type 'packing'
name '$0.50 / kg'
calculator { FactoryGirl.build(:weight_calculator) }
after_create { |ef| ef.calculator.save! }
end
factory :product_distribution, :class => ProductDistribution do
@@ -39,6 +42,12 @@ FactoryGirl.define do
factory :itemwise_calculator, :class => OpenFoodWeb::Calculator::Itemwise do
end
factory :weight_calculator, :class => OpenFoodWeb::Calculator::Weight do
after_build { |c| c.set_preference(:per_kg, 0.5) }
after_create { |c| c.set_preference(:per_kg, 0.5); c.save! }
end
end

View File

@@ -0,0 +1,23 @@
require 'spec_helper'
feature %q{
As an administrator
I want to manage enterprise fees
} do
include AuthenticationWorkflow
include WebHelper
scenario "listing enterprise fees" do
fee = create(:enterprise_fee)
login_to_admin_section
click_link 'Configuration'
click_link 'Enterprise Fees'
page.should have_selector 'option', :text => fee.enterprise.name
page.should have_selector 'option', :text => 'Packing'
page.should have_selector "input[value='$0.50 / kg']"
page.should have_selector 'option', :text => 'Weight (per kg)'
page.should have_selector "input[value='0.5']"
end
end