When selecting hub, auto-select order cycle if there is only one option available

This commit is contained in:
Rohan Mitchell
2013-09-17 09:57:44 +10:00
parent a929312979
commit 8a849b8e47
6 changed files with 32 additions and 11 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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