diff --git a/app/models/enterprise_fee.rb b/app/models/enterprise_fee.rb index 8edd76e60b..96b062cdd0 100644 --- a/app/models/enterprise_fee.rb +++ b/app/models/enterprise_fee.rb @@ -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 diff --git a/app/models/product_distribution.rb b/app/models/product_distribution.rb index a5c1438605..44ce0d494b 100644 --- a/app/models/product_distribution.rb +++ b/app/models/product_distribution.rb @@ -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 diff --git a/app/views/spree/admin/products/_distributors_form.html.haml b/app/views/spree/admin/products/_distributors_form.html.haml index e5c867c6e8..d4b655dd59 100644 --- a/app/views/spree/admin/products/_distributors_form.html.haml +++ b/app/views/spree/admin/products/_distributors_form.html.haml @@ -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" diff --git a/spec/factories.rb b/spec/factories.rb index c6462d8f28..5d288a1993 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -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! } diff --git a/spec/features/admin/products_spec.rb b/spec/features/admin/products_spec.rb index 908e5528e3..f7245c1243 100644 --- a/spec/features/admin/products_spec.rb +++ b/spec/features/admin/products_spec.rb @@ -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