mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
When adding subsequent products, add valid products to cart
This commit is contained in:
@@ -7,7 +7,7 @@ Spree::Order.class_eval do
|
||||
end
|
||||
|
||||
def distributor=(distributor)
|
||||
raise "You cannot change the distributor of an order with products" unless can_change_distributor?
|
||||
raise "You cannot change the distributor of an order with products" unless distributor == self.distributor || can_change_distributor?
|
||||
super(distributor)
|
||||
end
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
%p Distributor
|
||||
= select_tag "distributor_id", options_from_collection_for_select(@product.distributors, "id", "name", current_distributor.andand.id)
|
||||
- else
|
||||
= hidden_field_tag "distributor_id", order.distributor.id
|
||||
.distributor-fixed= "Your distributor for this order is #{order.distributor.name}"
|
||||
%br/
|
||||
= button_tag :class => 'large primary', :id => 'add-to-cart-button', :type => :submit do
|
||||
|
||||
@@ -10,7 +10,9 @@ describe Spree::Order do
|
||||
end
|
||||
|
||||
it "raises an exception if distributor is changed without permission" do
|
||||
p = build(:product)
|
||||
d = build(:distributor)
|
||||
p = build(:product, :distributors => [d])
|
||||
subject.distributor = d
|
||||
subject.add_variant(p.master, 1)
|
||||
subject.can_change_distributor?.should be_false
|
||||
|
||||
|
||||
@@ -83,5 +83,25 @@ feature %q{
|
||||
page.should_not have_selector "button#add-to-cart-button"
|
||||
page.should have_content "Please complete your order at #{d1.name} before shopping with another distributor."
|
||||
end
|
||||
|
||||
it "adds products with valid distributors" do
|
||||
# Given two products, each at the same distributor
|
||||
d = create(:distributor)
|
||||
p1 = create(:product, :distributors => [d])
|
||||
p2 = create(:product, :distributors => [d])
|
||||
|
||||
# When I add the first to my cart
|
||||
visit spree.product_path p1
|
||||
click_button 'Add To Cart'
|
||||
|
||||
# And I add the second
|
||||
visit spree.product_path p2
|
||||
click_button 'Add To Cart'
|
||||
|
||||
# Then both should be in my cart
|
||||
visit spree.cart_path
|
||||
page.should have_selector 'h4 a', :text => p1.name
|
||||
page.should have_selector 'h4 a', :text => p2.name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user