From 4c2debba7e4079f86d439989217740f342b66abe Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Sun, 28 Oct 2012 18:00:15 +1100 Subject: [PATCH] Model specs pass --- app/models/spree/order_decorator.rb | 4 +-- spec/factories.rb | 2 +- spec/models/distributors_spec.rb | 36 ---------------------- spec/models/order_spec.rb | 10 +++--- spec/models/product_distribution_spec.rb | 2 +- spec/models/product_spec.rb | 2 +- spec/models/suppliers_spec.rb | 39 ------------------------ 7 files changed, 10 insertions(+), 85 deletions(-) delete mode 100644 spec/models/distributors_spec.rb delete mode 100644 spec/models/suppliers_spec.rb diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index 4cfbd1ddcb..449640a4b6 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -1,5 +1,5 @@ Spree::Order.class_eval do - belongs_to :distributor + belongs_to :distributor, :class_name => 'Enterprise' before_validation :shipping_address_from_distributor after_create :set_default_shipping_method @@ -57,7 +57,7 @@ Spree::Order.class_eval do def shipping_address_from_distributor if distributor - self.ship_address = distributor.pickup_address.clone + self.ship_address = distributor.address.clone if bill_address self.ship_address.firstname = bill_address.firstname diff --git a/spec/factories.rb b/spec/factories.rb index eded25b43c..7ecae25065 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -43,7 +43,7 @@ FactoryGirl.define do factory :product_distribution, :class => ProductDistribution do product { |pd| Spree::Product.first || FactoryGirl.create(:product) } - distributor { |pd| Distributor.first || FactoryGirl.create(:distributor) } + distributor { |pd| Enterprise.is_distributor.first || FactoryGirl.create(:distributor_enterprise) } shipping_method { |pd| Spree::ShippingMethod.where("name != 'Delivery'").first || FactoryGirl.create(:shipping_method) } end diff --git a/spec/models/distributors_spec.rb b/spec/models/distributors_spec.rb deleted file mode 100644 index 64fa93b585..0000000000 --- a/spec/models/distributors_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -require 'spec_helper' - -module Spree - describe Distributor do - - describe "associations" do - it { should belong_to(:pickup_address) } - it { should have_many(:product_distributions) } - it { should have_many(:orders) } - end - - describe "validations" do - it { should validate_presence_of(:name) } - end - - it "should default country to system country" do - distributor = Distributor.new - distributor.pickup_address.country.should == Country.find_by_id(Config[:default_country_id]) - end - - describe "scopes" do - it "returns distributors with products in stock" do - d1 = create(:distributor) - d2 = create(:distributor) - d3 = create(:distributor) - d4 = create(:distributor) - create(:product, :distributors => [d1, d2], :on_hand => 5) - create(:product, :distributors => [d1], :on_hand => 5) - create(:product, :distributors => [d3], :on_hand => 0) - - Distributor.with_active_products_on_hand.sort.should == [d1, d2] - end - end - - end -end diff --git a/spec/models/order_spec.rb b/spec/models/order_spec.rb index aaa3d70c36..335c67a574 100644 --- a/spec/models/order_spec.rb +++ b/spec/models/order_spec.rb @@ -15,7 +15,7 @@ describe Spree::Order do end it "reveals permission for changing distributor" do - d = create(:distributor) + d = create(:distributor_enterprise) p = create(:product, :distributors => [d]) subject.distributor = d @@ -27,7 +27,7 @@ describe Spree::Order do end it "raises an exception if distributor is changed without permission" do - d = create(:distributor) + d = create(:distributor_enterprise) p = create(:product, :distributors => [d]) subject.distributor = d subject.save! @@ -41,8 +41,8 @@ describe Spree::Order do end it "reveals permission for adding products to the cart" do - d1 = create(:distributor) - d2 = create(:distributor) + d1 = create(:distributor_enterprise) + d2 = create(:distributor_enterprise) p_first = create(:product, :distributors => [d1]) p_subsequent_same_dist = create(:product, :distributors => [d1]) @@ -67,7 +67,7 @@ describe Spree::Order do end it "sets attributes on line items for variants" do - d = create(:distributor) + d = create(:distributor_enterprise) p = create(:product, :distributors => [d]) subject.distributor = d diff --git a/spec/models/product_distribution_spec.rb b/spec/models/product_distribution_spec.rb index bcfd131dea..51b5b9a8a2 100644 --- a/spec/models/product_distribution_spec.rb +++ b/spec/models/product_distribution_spec.rb @@ -6,7 +6,7 @@ describe ProductDistribution do pd1.should be_valid new_product = create(:product) - new_distributor = create(:distributor) + new_distributor = create(:distributor_enterprise) pd2 = build(:product_distribution, :product => pd1.product, :distributor => pd1.distributor) pd2.should_not be_valid diff --git a/spec/models/product_spec.rb b/spec/models/product_spec.rb index b78a08c6f0..dd0d8490b9 100644 --- a/spec/models/product_spec.rb +++ b/spec/models/product_spec.rb @@ -22,7 +22,7 @@ describe Spree::Product do context "finders" do it "finds the shipping method for a particular distributor" do shipping_method = create(:shipping_method) - distributor = create(:distributor) + distributor = create(:distributor_enterprise) product = create(:product) product_distribution = create(:product_distribution, :product => product, :distributor => distributor, :shipping_method => shipping_method) product.shipping_method_for_distributor(distributor).should == shipping_method diff --git a/spec/models/suppliers_spec.rb b/spec/models/suppliers_spec.rb deleted file mode 100644 index 7ddc4f8cab..0000000000 --- a/spec/models/suppliers_spec.rb +++ /dev/null @@ -1,39 +0,0 @@ -require 'spec_helper' - -module Spree - describe Supplier do - - describe "associations" do - it { should have_many(:products) } - it { should belong_to(:address) } - end - - describe "validations" do - it { should validate_presence_of(:name) } - end - - it "should default country to system country" do - subject.address.country.should == Country.find_by_id(Config[:default_country_id]) - end - - context "has_products_on_hand?" do - before :each do - @supplier = create(:supplier) - end - - it "returns false when no products" do - @supplier.should_not have_products_on_hand - end - - it "returns false when the product is out of stock" do - create(:product, :supplier => @supplier, :on_hand => 0) - @supplier.should_not have_products_on_hand - end - - it "returns true when the product is in stock" do - create(:product, :supplier => @supplier, :on_hand => 1) - @supplier.should have_products_on_hand - end - end - end -end