diff --git a/app/controllers/enterprises_controller.rb b/app/controllers/enterprises_controller.rb index 6659e6e2ce..b59afaa07e 100644 --- a/app/controllers/enterprises_controller.rb +++ b/app/controllers/enterprises_controller.rb @@ -51,6 +51,10 @@ class EnterprisesController < BaseController end order.distributor = distributor + + order_cycle_options = OrderCycle.active.with_distributor(distributor) + order.order_cycle = order_cycle_options.first if order_cycle_options.count == 1 + order.save! redirect_to main_app.enterprise_path(distributor) diff --git a/spec/controllers/enterprises_controller_spec.rb b/spec/controllers/enterprises_controller_spec.rb index f728210e2e..8f35633651 100644 --- a/spec/controllers/enterprises_controller_spec.rb +++ b/spec/controllers/enterprises_controller_spec.rb @@ -15,6 +15,8 @@ describe EnterprisesController do before(:each) do @current_distributor = create(:distributor_enterprise) @distributor = create(:distributor_enterprise) + @order_cycle1 = create(:simple_order_cycle, distributors: [@distributor]) + @order_cycle2 = create(:simple_order_cycle, distributors: [@distributor]) controller.current_order(true).distributor = @current_distributor end @@ -22,6 +24,7 @@ describe EnterprisesController do spree_get :shop, {id: @distributor} controller.current_order.distributor.should == @distributor + controller.current_order.order_cycle.should be_nil end it "empties an order that was set for a previous distributor, when shopping at a new distributor" do @@ -31,6 +34,7 @@ describe EnterprisesController do spree_get :shop, {id: @distributor} controller.current_order.distributor.should == @distributor + controller.current_order.order_cycle.should be_nil controller.current_order.line_items.size.should == 0 end @@ -43,7 +47,17 @@ describe EnterprisesController do spree_get :shop, {id: @current_distributor} controller.current_order.distributor.should == @current_distributor + controller.current_order.order_cycle.should be_nil controller.current_order.line_items.size.should == 1 end + + it "sets order cycle if only one is available at the chosen distributor" do + @order_cycle2.destroy + + spree_get :shop, {id: @distributor} + + controller.current_order.distributor.should == @distributor + controller.current_order.order_cycle.should == @order_cycle1 + end end end diff --git a/spec/features/consumer/browse_products_spec.rb b/spec/features/consumer/browse_products_spec.rb index 214d674dbf..28a4b66170 100644 --- a/spec/features/consumer/browse_products_spec.rb +++ b/spec/features/consumer/browse_products_spec.rb @@ -80,7 +80,6 @@ feature %q{ # When I am in that order cycle visit root_path click_link d.name - select_by_value oc.id, from: 'order_order_cycle_id' # And I view the product click_link p.name diff --git a/spec/features/consumer/checkout_spec.rb b/spec/features/consumer/checkout_spec.rb index b9d8f264aa..6cced00d18 100644 --- a/spec/features/consumer/checkout_spec.rb +++ b/spec/features/consumer/checkout_spec.rb @@ -113,8 +113,6 @@ feature %q{ login_to_consumer_section click_link "FruitAndVeg" - select_by_value @order_cycle.id, :from => 'order_order_cycle_id' - # When I add some bananas and zucchini to my cart click_link 'Bananas' click_button 'Add To Cart' @@ -358,8 +356,6 @@ feature %q{ login_to_consumer_section click_link 'FruitAndVeg' - select_by_value @order_cycle.id, :from => 'order_order_cycle_id' - click_link 'Bananas' click_button 'Add To Cart' click_link 'Continue shopping' @@ -436,8 +432,6 @@ feature %q{ click_link 'Logout' click_link 'FruitAndVeg' - select_by_value @order_cycle.id, :from => 'order_order_cycle_id' - click_link 'Bananas' click_button 'Add To Cart' click_link 'Continue shopping' diff --git a/spec/features/consumer/distributors_spec.rb b/spec/features/consumer/distributors_spec.rb index 1871af4a72..b8c62f7428 100644 --- a/spec/features/consumer/distributors_spec.rb +++ b/spec/features/consumer/distributors_spec.rb @@ -99,9 +99,6 @@ feature %q{ visit spree.root_path click_link d1.name - # And when I choose an order cycle - select_by_value order_cycle.id, :from => 'order_order_cycle_id' - # Then I should see the distributor details page.should have_selector 'h1', :text => d1.name page.should have_selector 'div.enterprise-description', :text => 'Hello, world!' diff --git a/spec/features/consumer/order_cycles_spec.rb b/spec/features/consumer/order_cycles_spec.rb index d353e9394b..850dec0101 100644 --- a/spec/features/consumer/order_cycles_spec.rb +++ b/spec/features/consumer/order_cycles_spec.rb @@ -32,6 +32,20 @@ feature %q{ end + scenario "selecting order cycle when multiple options are available", js: true do + d = create(:distributor_enterprise, name: 'Green Grass') + oc1 = create(:simple_order_cycle, name: 'oc 1', distributors: [d]) + oc2 = create(:simple_order_cycle, name: 'oc 2', distributors: [d]) + + visit spree.root_path + click_link d.name + + page.should have_select 'order_order_cycle_id' + select_by_value oc1.id, from: 'order_order_cycle_id' + page.should have_content 'Your order will be ready on' + end + + scenario "changing order cycle", js: true do s = create(:supplier_enterprise) d = create(:distributor_enterprise, name: 'Green Grass') @@ -40,7 +54,6 @@ feature %q{ visit spree.root_path click_link d.name - select_by_value oc.id, from: 'order_order_cycle_id' click_link p.name click_button 'Add To Cart'