Set distributor and order cycle in one step, avoiding validation errors. Update spec with new error messages.

This commit is contained in:
Rohan Mitchell
2013-06-21 11:36:24 +10:00
parent 72f1c52b3e
commit ae43fd1333
4 changed files with 10 additions and 6 deletions

View File

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

View File

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

View File

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

View File

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