Test each distinct distributor/order cycle invalid combination case

This commit is contained in:
Rohan Mitchell
2013-06-21 11:06:21 +10:00
parent 3386da4b4c
commit bc40b2c856

View File

@@ -4,7 +4,7 @@ describe Spree::OrdersController do
def current_user
controller.current_user
end
it "selects distributors" do
d = create(:distributor_enterprise)
p = create(:product, :distributors => [d])
@@ -37,7 +37,41 @@ describe Spree::OrdersController do
@request.env["HTTP_REFERER"] = 'http://test.host/'
end
it "produces an error when the distributor does not distribute the product" do
it "errors when an invalid distributor is selected" do
# Given a product and some distributors
d1 = create(:distributor_enterprise)
d2 = create(:distributor_enterprise)
p = create(:product, :price => 12.34)
oc = create(:simple_order_cycle, :distributors => [d1], :variants => [p.master])
# When I attempt to add the product to the cart with an invalid distributor, it should not be added
expect do
spree_post :populate, variants: {p.master.id => 1}, distributor_id: d2.id, order_cycle_id: oc.id
response.should redirect_to :back
end.to change(self, :num_items_in_cart).by(0)
# And I should see an error
flash[:error].should == "That product is not available from the chosen distributor or order cycle."
end
it "errors when an invalid order cycle is selected" do
# Given a product and some order cycles
d = create(:distributor_enterprise)
p = create(:product, :price => 12.34)
oc1 = create(:simple_order_cycle, :distributors => [d], :variants => [p.master])
oc2 = create(:simple_order_cycle, :distributors => [d], :variants => [])
# When I attempt to add the product to my cart with an invalid order cycle, it should not be added
expect do
spree_post :populate, variants: {p.master.id => 1}, distributor_id: d.id, order_cycle_id: oc2.id
response.should redirect_to :back
end.to change(self, :num_items_in_cart).by(0)
# And I should see an error
flash[:error].should == "That product is not available from the chosen distributor or order cycle."
end
it "errors when distribution is valid for the new product but does not cover the cart" do
# Given two products with different distributors
d1 = create(:distributor_enterprise)
d2 = create(:distributor_enterprise)
@@ -54,36 +88,12 @@ describe Spree::OrdersController do
# And I attempt to add the second, then the product should not be added to my cart
expect do
spree_post :populate, variants: {p2.master.id => 1}, distributor_id: d1.id, order_cycle_id: oc1.id
spree_post :populate, variants: {p2.master.id => 1}, distributor_id: d2.id, order_cycle_id: oc2.id
response.should redirect_to :back
end.to change(self, :num_items_in_cart).by(0)
# And I should see an error
flash[:error].should == "That product is not available from the chosen distributor or order cycle."
end
it "produces an error when the order cycle does not distribute the product" do
# Given two products with the same distributor but different order cycles
d = create(:distributor_enterprise)
p1 = create(:product, :price => 12.34)
p2 = create(:product, :price => 23.45)
oc1 = create(:simple_order_cycle, :distributors => [d], :variants => [p1.master])
oc2 = create(:simple_order_cycle, :distributors => [d], :variants => [p2.master])
# When I add the first to my cart
expect do
spree_post :populate, variants: {p1.master.id => 1}, distributor_id: d.id, order_cycle_id: oc1.id
response.should redirect_to spree.cart_path
end.to change(self, :num_items_in_cart).by(1)
# And I attempt to add the second, then the product should not be added to my cart
expect do
spree_post :populate, variants: {p2.master.id => 1}, distributor_id: d.id, order_cycle_id: oc1.id
response.should redirect_to :back
end.to change(self, :num_items_in_cart).by(0)
# And I should see an error
flash[:error].should == "That product is not available from the chosen distributor or order cycle."
flash[:error].should == "That distributor or order cycle can't supply all the products in your cart. Please choose another."
end
end