Admin can assign enterprise fees to product distributions

This commit is contained in:
Rohan Mitchell
2013-08-12 10:40:54 +10:00
parent 7ea1122833
commit af6b16ecc4
5 changed files with 13 additions and 9 deletions

View File

@@ -9,4 +9,7 @@ class EnterpriseFee < ActiveRecord::Base
validates_inclusion_of :fee_type, :in => FEE_TYPES
validates_presence_of :name
scope :for_enterprise, lambda { |enterprise| where(enterprise_id: enterprise) }
end

View File

@@ -5,7 +5,7 @@ class ProductDistribution < ActiveRecord::Base
belongs_to :enterprise_fee
validates_presence_of :product_id, :on => :update
validates_presence_of :distributor_id, :shipping_method_id
validates_presence_of :distributor_id, :enterprise_fee_id
validates_uniqueness_of :product_id, :scope => :distributor_id

View File

@@ -11,4 +11,4 @@
= label_tag "#{pd_form.object_name}[_destroy]", pd_form.object.distributor.name
= pd_form.hidden_field :distributor_id
%td
= pd_form.collection_select :shipping_method_id, Spree::ShippingMethod.all, :id, :name, {}, :class => "select2"
= pd_form.collection_select :enterprise_fee_id, EnterpriseFee.for_enterprise(pd_form.object.distributor), :id, :name, {}, :class => "select2"

View File

@@ -77,9 +77,10 @@ FactoryGirl.define do
end
factory :enterprise_fee, :class => EnterpriseFee do
sequence(:name) { |n| "Enterprise fee #{n}" }
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! }

View File

@@ -10,7 +10,7 @@ feature %q{
background do
@supplier = create(:supplier_enterprise, :name => 'New supplier')
@distributors = (1..3).map { create(:distributor_enterprise) }
@shipping_method = create(:shipping_method, :name => 'My shipping method')
@enterprise_fees = (0..2).map { |i| create(:enterprise_fee, enterprise: @distributors[i]) }
end
context "creating a product" do
@@ -25,9 +25,9 @@ feature %q{
select 'New supplier', :from => 'product_supplier_id'
check @distributors[0].name
select 'My shipping method', :from => 'product_product_distributions_attributes_0_shipping_method_id'
select @enterprise_fees[0].name, :from => 'product_product_distributions_attributes_0_enterprise_fee_id'
check @distributors[2].name
select 'My shipping method', :from => 'product_product_distributions_attributes_2_shipping_method_id'
select @enterprise_fees[2].name, :from => 'product_product_distributions_attributes_2_enterprise_fee_id'
click_button 'Create'
@@ -35,7 +35,7 @@ feature %q{
product = Spree::Product.find_by_name('A new product !!!')
product.supplier.should == @supplier
product.distributors.should == [@distributors[0], @distributors[2]]
product.product_distributions.map { |pd| pd.shipping_method }.should == [@shipping_method, @shipping_method]
product.product_distributions.map { |pd| pd.enterprise_fee }.should == [@enterprise_fees[0], @enterprise_fees[2]]
product.group_buy.should be_false
end
@@ -60,7 +60,7 @@ feature %q{
end
describe 'As an enterprise user' do
context "as an enterprise user" do
before(:each) do
@new_user = create_enterprise_user
@@ -87,7 +87,7 @@ feature %q{
end
check @distributors[0].name
select 'My shipping method', :from => 'product_product_distributions_attributes_0_shipping_method_id'
select @enterprise_fees[0].name, :from => 'product_product_distributions_attributes_0_enterprise_fee_id'
# Should only have distributors listed which the user can manage
within "#product_product_distributions_field" do