Selecting an order cycle highlights valid distributor choices

This commit is contained in:
Rohan Mitchell
2013-02-01 14:12:46 +11:00
parent 74e2b70d3a
commit e1b2490259
6 changed files with 54 additions and 5 deletions

View File

@@ -76,6 +76,13 @@ nav#filters {
.distributors {
float: left;
margin-right: 4em;
option.local {
background-color: #cfc;
}
option.remote {
background-color: #fcc;
}
}
.order-cycles {

View File

@@ -18,7 +18,11 @@ Spree::OrdersController.class_eval do
redirect_to request.referer
elsif params[:commit] == 'Choose Order Cycle'
# TODO
order_cycle = OrderCycle.active.find params[:order][:order_cycle_id]
@order.order_cycle = order_cycle
@order.save!
flash[:notice] = 'Your order cycle has been selected.'
redirect_to request.referer
end
end

View File

@@ -1,10 +1,14 @@
module OrderCyclesHelper
def current_order_cycle
@current_order_cycle ||= current_order(false).andand.order_cycle
end
def coordinating_enterprises
Enterprise.is_distributor.order('name')
end
def order_cycle_local_remote_class(distributor, order_cycle)
if distributor.nil?
if distributor.nil? || order_cycle.nil?
''
elsif order_cycle.distributors.include? distributor
' local'
@@ -12,4 +16,10 @@ module OrderCyclesHelper
' remote'
end
end
def distributor_options(distributors, current_distributor, order_cycle)
options = distributors.map { |d| [d.name, d.id, {:class => order_cycle_local_remote_class(d, order_cycle).strip}] }
options_for_select(options, current_distributor)
end
end

View File

@@ -5,7 +5,7 @@
<%= form_for current_order(true) do |f| %>
<div class="distributors">
<h2>Active Hubs</h2>
<%= f.collection_select :distributor_id, @distributors, :id, :name %>
<%= f.select :distributor_id, distributor_options(@distributors, f.object.distributor_id, current_order_cycle) %>
<br />
<%= f.submit 'Choose Hub' %>
</div>

View File

@@ -68,7 +68,34 @@ feature %q{
end
end
scenario "selecting an order cycle highlights valid distributor choices"
scenario "selecting an order cycle highlights valid distributor choices" do
# When I go to the product listing page
visit spree.products_path
# And I choose an order cycle
choose @oc1.name
click_button 'Choose Order Cycle'
# Then the associated distributor should be highlighted
page.should have_content "Your order cycle has been selected."
within '#distribution-choice' do
page.should have_selector "option.local[value='#{@d1.id}']"
page.should have_selector "option.remote[value='#{@d2.id}']"
end
# When I choose the other order cycle
choose @oc2.name
click_button 'Choose Order Cycle'
# Then the associated distributor should be highlighted
page.should have_content "Your order cycle has been selected."
within '#distribution-choice' do
page.should have_selector "option.remote[value='#{@d1.id}']"
page.should have_selector "option.local[value='#{@d2.id}']"
end
end
scenario "selecing an invalid distributor clears the order cycle"
scenario "selecing an invalid order cycle clears the distributor"
end

View File

@@ -7,8 +7,9 @@ describe OrderCyclesHelper do
end
describe "generating local/remote classes for order cycle selection" do
it "returns blank when no distributor selected" do
it "returns blank when no distributor or order cycle is selected" do
subject.order_cycle_local_remote_class(nil, double(:order_cycle)).should == ''
subject.order_cycle_local_remote_class(double(:distributor), nil).should == ''
end
it "returns local when the order cycle includes the current distributor" do