Make tests pass after changes to checkout broke them all

This commit is contained in:
Rob H
2013-01-18 15:29:36 +11:00
parent 63cf128f86
commit 6a45e8be3b
9 changed files with 48 additions and 87 deletions

View File

@@ -29,7 +29,7 @@ class Enterprise < ActiveRecord::Base
end
def available_variants
ProductDistribution.find_all_by_distributor_id( self.id ).map{ |pd| pd.product.variants }.flatten
ProductDistribution.find_all_by_distributor_id( self.id ).map{ |pd| pd.product.variants + [pd.product.master] }.flatten
end

View File

@@ -3,12 +3,11 @@
- if !@product.has_stock? && !Spree::Config[:allow_backorders]
= content_tag('strong', t(:out_of_stock))
- elsif current_order(false) && !order.can_add_product_to_cart?(@product)
- elsif !order.nil? && !order.can_add_product_to_cart?(@product)
.error-distributor
Please complete your order at
= link_to current_distributor.name, root_path
before shopping with another distributor.
- else
%div(class = "columns alpha two")
%div Quantity
@@ -19,12 +18,12 @@
= number_field_tag (@product.has_variants? ? :max_quantity : "variant_attributes[#{@product.master.id}][max_quantity]"), 1, :class => 'title max_quantity', :in => 1..@product.on_hand
%div.cleared
%br
- if order.nil?
- if order.nil? || order.distributor.nil?
%div Distributor for your order:
= select_tag "distributor_id", options_from_collection_for_select([Enterprise.new]+@product.distributors, "id", "name", current_distributor.andand.id)
= select_tag "distributor_id", options_from_collection_for_select([Enterprise.new]+@product.distributors, "id", "name", :include_blank => '')
- else
- available_distributors = DistributorChangeValidator.new(order).available_distributors(@product.distributors)
- if available_distributors.length > 0
- if available_distributors.length > 1
%div Distributor for your order:
= select_tag "distributor_id", options_from_collection_for_select(available_distributors, "id", "name", current_distributor.andand.id)
- else

View File

@@ -12,7 +12,7 @@
- order = current_order(false)
- validator = DistributorChangeValidator.new(order)
- @product.distributors.each do |distributor|
- if distributor == order.distributor
- if !order.nil? && distributor == order.distributor
%tr.odd
%td
%b= link_to(distributor.name, [main_app, distributor])
@@ -21,10 +21,10 @@
- elsif order.nil? || validator.can_change_to_distributor?(distributor)
%tr.even
%td= link_to distributor.name, [main_app, distributor]
%td= link_to "Change to distributor", select_distributor_order_path(distributor)
%td Available
-#%td= link_to "Change to distributor", select_distributor_order_path(distributor)
- else
%tr.even
%td= link_to distributor.name, [main_app, distributor]
%td
%abbr(title="One or more of the products in your cart is not available from this distributor") Unavailable
%td

View File

@@ -19,65 +19,4 @@ describe EnterprisesController do
assigns(:suppliers).should == [s]
end
it "selects distributors" do
d = create(:distributor_enterprise)
spree_get :select_distributor, :id => d.id
response.should be_redirect
order = current_order(false)
order.distributor.should == d
end
it "deselects distributors" do
d = create(:distributor_enterprise)
order = current_order(true)
order.distributor = d
order.save!
spree_get :deselect_distributor
response.should be_redirect
order.reload
order.distributor.should be_nil
end
context "when a product has been added to the cart" do
it "does not allow selecting another distributor" do
# Given some distributors and an order with a product
d1 = create(:distributor_enterprise)
d2 = create(:distributor_enterprise)
p = create(:product, :distributors => [d1])
o = current_order(true)
o.distributor = d1
o.save!
o.add_variant(p.master, 1)
# When I attempt to select a distributor
spree_get :select_distributor, :id => d2.id
# Then my distributor should remain unchanged
o.reload
o.distributor.should == d1
end
it "does not allow deselecting distributors" do
# Given a distributor and an order with a product
d = create(:distributor_enterprise)
p = create(:product, :distributors => [d])
o = current_order(true)
o.distributor = d
o.save!
o.add_variant(p.master, 1)
# When I attempt to deselect the distributor
spree_get :deselect_distributor
# Then my distributor should remain unchanged
o.reload
o.distributor.should == d
end
end
end

View File

@@ -7,7 +7,32 @@ describe Spree::OrdersController do
def current_user
controller.current_user
end
it "selects distributors" do
d = create(:distributor_enterprise)
p = create(:product, :distributors => [d])
spree_get :select_distributor, :id => d.id
response.should be_redirect
order = current_order(false)
order.distributor.should == d
end
it "deselects distributors" do
d = create(:distributor_enterprise)
p = create(:product, :distributors => [d])
order = current_order(true)
order.distributor = d
order.save!
spree_get :deselect_distributor
response.should be_redirect
order.reload
order.distributor.should be_nil
end
context "adding the first product to the cart" do
it "does not add the product if the user does not specify a distributor" do

View File

@@ -118,7 +118,7 @@ feature %q{
click_button 'Save and Continue'
# -- Checkout: Payment
click_button 'Save and Continue'
click_button 'Process My Order'
# -- Checkout: Order complete
page.should have_content('Your order has been processed successfully')

View File

@@ -67,11 +67,10 @@ feature %q{
it "displays the distributor's name on the home page" do
# Given a distributor with a product
d = create(:distributor_enterprise, :name => 'Melb Uni Co-op', :description => '<p>Hello, world!</p>')
create(:product, :distributors => [d])
p1 = create(:product, :distributors => [d])
# When I select the distributor
visit spree.root_path
click_link d.name
visit spree.select_distributor_order_path(d)
visit spree.root_path
# Then I should see the name of the distributor that I've selected
@@ -90,8 +89,7 @@ feature %q{
p2 = create(:product, :distributors => [d2], :taxons => [taxon])
# When I select the first distributor
visit spree.root_path
click_link d1.name
visit spree.select_distributor_order_path(d1)
visit spree.root_path
# Then I should see products split by local/remote distributor
@@ -112,11 +110,11 @@ feature %q{
it "allows the user to leave the distributor" do
# Given a distributor with a product
d = create(:distributor_enterprise, :name => 'Melb Uni Co-op')
create(:product, :distributors => [d])
p1 = create(:product, :distributors => [d])
# When I select the distributor and then leave it
visit spree.select_distributor_order_path(d)
visit spree.root_path
click_link d.name
click_button 'Browse All Distributors'
# Then I should have left the distributor
@@ -139,16 +137,17 @@ feature %q{
it "displays the local distributor as the default choice when available for the current product" do
# Given a distributor and a product under it
distributor = create(:distributor_enterprise)
product = create(:product, :distributors => [distributor])
distributor1 = create(:distributor_enterprise)
distributor2 = create(:distributor_enterprise)
product = create(:product, :distributors => [distributor1,distributor2])
# When we select the distributor and view the product
visit spree.root_path
click_link distributor.name
visit spree.select_distributor_order_path(distributor1)
visit spree.product_path(product)
binding.pry
# Then we should see our distributor as the default option when adding the item to our cart
page.should have_selector "select#distributor_id option[value='#{distributor.id}'][selected='selected']"
page.should have_selector "select#distributor_id option[value='#{distributor1.id}'][selected='selected']"
end
it "works when viewing a product from a remote distributor" do

View File

@@ -36,8 +36,7 @@ feature %q{
d = create(:distributor_enterprise)
p = create(:product, :distributors => [d])
visit spree.root_path
click_link d.name
visit spree.select_distributor_order_path(d)
visit spree.product_path p
within '#product-distributor-details' do

View File

@@ -49,7 +49,7 @@ feature %q{
2.times { create(:product, :taxons => [taxon_three], :distributors => [my_distributor]) }
# When I visit the home page and select my distributor
visit spree.root_path
visit spree.select_distributor_order_path(my_distributor)
click_link my_distributor.name
page.should have_content 'You are shopping at My Distributor'