Do not give order cycle choice when there is only one option

This commit is contained in:
Rohan Mitchell
2013-05-28 16:35:39 +10:00
parent 54fe63e7f3
commit cb703c2a66
3 changed files with 41 additions and 3 deletions

View File

@@ -17,14 +17,17 @@
- if available_distributors.length > 1 || order.andand.distributor.nil?
= render 'add_to_cart_distributor_choice', distributor_collection: available_distributors
- else
- distributor = available_distributors.first
- changing_distributor = distributor != order.andand.distributor
= render 'add_to_cart_distributor_fixed', distributor: distributor, changing_distributor: changing_distributor
= render 'add_to_cart_order_cycle_choice', order_cycle_collection: available_order_cycles
- if available_order_cycles.length > 1 || order.andand.order_cycle.nil?
= render 'add_to_cart_order_cycle_choice', order_cycle_collection: available_order_cycles
- else
- order_cycle = available_order_cycles.first
- changing_order_cycle = order_cycle != order.andand.order_cycle
= render 'add_to_cart_order_cycle_fixed', order_cycle: order_cycle, changing_order_cycle: changing_order_cycle
%br
= button_tag :class => 'large primary', :id => 'add-to-cart-button', :type => :submit do

View File

@@ -0,0 +1,6 @@
= hidden_field_tag "order_cycle_id", order_cycle.id
- if changing_order_cycle
.order-cycle-fixed= "Your order cycle for this order will be changed to #{order_cycle.name} if you add this product to your cart."
- else
.order-cycle-fixed= "Your order cycle for this order is #{order_cycle.name}"

View File

@@ -247,6 +247,35 @@ feature %q{
page.should have_selector "#current-distribution a", :text => d2.name
page.should have_selector "#current-distribution a", :text => oc2.name
end
it "when the only valid order cycle is the chosen one, does not allow the user to choose an order cycle" do
# Given two products, each at the same distributor
d = create(:distributor_enterprise)
p1 = create(:product)
p2 = create(:product)
oc = create(:simple_order_cycle, :distributors => [d],
:variants => [p1.master, p2.master])
# When I add the first to my cart
visit spree.product_path p1
select d.name, :from => 'distributor_id'
select oc.name, :from => 'order_cycle_id'
click_button 'Add To Cart'
# And I go to add the second, I should not have a choice of distributor or order cycle
visit spree.product_path p2
page.should_not have_selector 'select#distributor_id'
page.should have_selector '.distributor-fixed', :text => "Your distributor for this order is #{d.name}"
page.should_not have_selector 'select#order_cycle_id'
page.should have_selector '.order-cycle-fixed', :text => "Your order cycle for this order is #{oc.name}"
# When I add the second, both should be in my cart
click_button 'Add To 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
it "allows us to add two products from the same distributor" do