From c46613877cbd365d760109d0db0fddb11213643b Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 2 Aug 2012 14:45:55 +1000 Subject: [PATCH] Add max quantity field to add to cart form, add end-to-end test for max_quantity --- .../spree/products/_add_to_cart.html.haml | 2 ++ spec/requests/consumer/add_to_cart_spec.rb | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/app/views/spree/products/_add_to_cart.html.haml b/app/views/spree/products/_add_to_cart.html.haml index e17be64c62..c5e298c848 100644 --- a/app/views/spree/products/_add_to_cart.html.haml +++ b/app/views/spree/products/_add_to_cart.html.haml @@ -11,6 +11,8 @@ - else %p Quantity = number_field_tag (@product.has_variants? ? :quantity : "variants[#{@product.master.id}]"), 1, :class => 'title', :in => 1..@product.on_hand + %p Max quantity + = number_field_tag (@product.has_variants? ? :max_quantity : "variant_attributes[#{@product.master.id}][max_quantity]"), 1, :class => 'title', :in => 1..@product.on_hand - order = current_order(false) - if order.nil? || order.can_change_distributor? %p Distributor diff --git a/spec/requests/consumer/add_to_cart_spec.rb b/spec/requests/consumer/add_to_cart_spec.rb index 6b5cbd32a8..132071ab0a 100644 --- a/spec/requests/consumer/add_to_cart_spec.rb +++ b/spec/requests/consumer/add_to_cart_spec.rb @@ -105,4 +105,23 @@ feature %q{ page.should have_selector 'h4 a', :text => p2.name end end + + scenario "adding a product to the cart for a group buy" do + # Given a group buy product and a distributor + d = create(:distributor) + p = create(:product, :distributors => [d], :group_buy => true) + + # When I add the item to my cart + visit spree.product_path p + fill_in "variants_#{p.master.id}", :with => 2 + fill_in "variant_attributes_#{p.master.id}_max_quantity", :with => 3 + click_button 'Add To Cart' + + # Then the item should be in my cart with correct quantities + order = Spree::Order.last + li = order.line_items.first + li.product.should == p + li.quantity.should == 2 + li.max_quantity.should == 3 + end end