Model specs pass

This commit is contained in:
Rohan Mitchell
2012-10-28 18:00:15 +11:00
parent abe3feb996
commit 4c2debba7e
7 changed files with 10 additions and 85 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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