mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-04 22:16:08 +00:00
Set distributor and order cycle in one step, avoiding validation errors. Update spec with new error messages.
This commit is contained in:
@@ -28,6 +28,12 @@ Spree::Order.class_eval do
|
||||
save!
|
||||
end
|
||||
|
||||
def set_distribution!(distributor, order_cycle)
|
||||
self.distributor = distributor
|
||||
self.order_cycle = order_cycle
|
||||
save!
|
||||
end
|
||||
|
||||
def set_variant_attributes(variant, attributes)
|
||||
line_item = find_line_item_by_variant(variant)
|
||||
|
||||
|
||||
@@ -62,8 +62,7 @@ Spree::OrderPopulator.class_eval do
|
||||
# to be set to zero
|
||||
@order = Spree::Order.find @order.id
|
||||
|
||||
@order.set_distributor! distributor
|
||||
@order.set_order_cycle! order_cycle if order_cycle
|
||||
@order.set_distribution! distributor, order_cycle
|
||||
end
|
||||
|
||||
def distribution_can_supply_products_in_cart(distributor, order_cycle)
|
||||
|
||||
@@ -226,10 +226,10 @@ feature %q{
|
||||
click_button 'Add To Cart'
|
||||
|
||||
# Then I should see an error message
|
||||
page.should have_content "That order cycle is not available at the distributor that you chose. Please choose another."
|
||||
page.should have_content "That product is not available from the chosen distributor or order cycle."
|
||||
|
||||
# And the product should not be in my cart
|
||||
Spree::Order.last.should be_nil
|
||||
Spree::Order.last.line_items.should be_empty
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -164,8 +164,7 @@ module Spree
|
||||
|
||||
it "sets cart distributor and order cycle" do
|
||||
Spree::Order.should_receive(:find).with(order.id).and_return(order)
|
||||
order.should_receive(:set_distributor!).with(distributor)
|
||||
order.should_receive(:set_order_cycle!).with(order_cycle)
|
||||
order.should_receive(:set_distribution!).with(distributor, order_cycle)
|
||||
|
||||
op.send(:set_cart_distributor_and_order_cycle, distributor, order_cycle)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user