From 48984601320124aef2ee0b133cf069df267d33fd Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 22 Nov 2013 14:00:04 +1100 Subject: [PATCH] Fix failing spec with table reorder, lambda-fy scopes that use time --- app/models/order_cycle.rb | 6 +++--- spec/features/admin/order_cycles_spec.rb | 25 +++++++++++++++++------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/app/models/order_cycle.rb b/app/models/order_cycle.rb index 64b835334b..362f1eb05a 100644 --- a/app/models/order_cycle.rb +++ b/app/models/order_cycle.rb @@ -27,9 +27,9 @@ class OrderCycle < ActiveRecord::Base joins(:exchanges).merge(Exchange.outgoing).where('exchanges.receiver_id = ?', distributor) } - scope :soonest_closing, active.order('order_cycles.orders_close_at ASC') - scope :most_recently_closed, closed.order('order_cycles.orders_close_at DESC') - scope :soonest_opening, upcoming.order('order_cycles.orders_open_at ASC') + scope :soonest_closing, lambda { active.order('order_cycles.orders_close_at ASC') } + scope :most_recently_closed, lambda { closed.order('order_cycles.orders_close_at DESC') } + scope :soonest_opening, lambda { upcoming.order('order_cycles.orders_open_at ASC') } scope :managed_by, lambda { |user| diff --git a/spec/features/admin/order_cycles_spec.rb b/spec/features/admin/order_cycles_spec.rb index efbbda00aa..34a8e72c85 100644 --- a/spec/features/admin/order_cycles_spec.rb +++ b/spec/features/admin/order_cycles_spec.rb @@ -347,19 +347,30 @@ feature %q{ scenario "updating many order cycle opening/closing times at once" do # Given three order cycles - 3.times { create(:order_cycle) } + oc1 = create(:order_cycle) + oc2 = create(:order_cycle) + oc3 = create(:order_cycle) # When I go to the order cycles page login_to_admin_section click_link 'Order Cycles' # And I fill in some new opening/closing times and save them - fill_in 'order_cycle_set_collection_attributes_0_orders_open_at', :with => '2012-12-01 12:00:00' - fill_in 'order_cycle_set_collection_attributes_0_orders_close_at', :with => '2012-12-01 12:00:01' - fill_in 'order_cycle_set_collection_attributes_1_orders_open_at', :with => '2012-12-01 12:00:02' - fill_in 'order_cycle_set_collection_attributes_1_orders_close_at', :with => '2012-12-01 12:00:03' - fill_in 'order_cycle_set_collection_attributes_2_orders_open_at', :with => '2012-12-01 12:00:04' - fill_in 'order_cycle_set_collection_attributes_2_orders_close_at', :with => '2012-12-01 12:00:05' + within("tr.order-cycle-#{oc1.id}") do + all('input').first.set '2012-12-01 12:00:00' + all('input').last.set '2012-12-01 12:00:01' + end + + within("tr.order-cycle-#{oc2.id}") do + all('input').first.set '2012-12-01 12:00:02' + all('input').last.set '2012-12-01 12:00:03' + end + + within("tr.order-cycle-#{oc3.id}") do + all('input').first.set '2012-12-01 12:00:04' + all('input').last.set '2012-12-01 12:00:05' + end + click_button 'Update' # Then my times should have been saved