diff --git a/app/models/comment.rb b/app/models/comment.rb index daa29ce7..74aa6216 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -17,8 +17,10 @@ class Comment < ActiveRecord::Base after_create :notify_creation after_initialize :set_default_attrs, :if => :new_record? - scope :oldest_first, -> { order("created_at asc") } - scope :newest_first, -> { order("created_at desc") } + # The precision of 'created_at' is one second. For comments in the same second + # we must use the id for fine-tuning + scope :oldest_first, -> { order("created_at asc, id asc") } + scope :newest_first, -> { order("created_at desc, id desc") } scope :public, -> {where(:private => false) } # List of roles with access to private comments diff --git a/app/models/state_change.rb b/app/models/state_change.rb index c295cfc0..114fa7f3 100644 --- a/app/models/state_change.rb +++ b/app/models/state_change.rb @@ -24,8 +24,10 @@ class StateChange < ActiveRecord::Base validates :from, :to, :user, :machine, :presence => true - scope :oldest_first, -> { order("created_at asc") } - scope :newest_first, -> { order("created_at desc") } + # The precision of 'created_at' is one second. For changes in the same second + # we must use the id for fine-tuning + scope :oldest_first, -> { order("created_at asc, id asc") } + scope :newest_first, -> { order("created_at desc, id desc") } # Short and human readable explanation of the change. To be implemented by # subclasses. diff --git a/spec/features/acceptance_info_spec.rb b/spec/features/acceptance_info_spec.rb index 8f110e7f..c12a4afe 100644 --- a/spec/features/acceptance_info_spec.rb +++ b/spec/features/acceptance_info_spec.rb @@ -12,7 +12,7 @@ page.should_not have_content "You will be able to update this document" end - scenario "is displayed when acceptance is required" do + scenario "is displayed when acceptance is required", :js => true do adjust_state(reimb, "approved") find_reimbursement_as(users(:wedge), reimb) page.should have_content "An updated signed version of the reimbursement request is required" @@ -21,7 +21,7 @@ # Use rack_test to force everything to run in the same thread, so capybara # checks are aware of the changes in the database - scenario "is displayed for probably outdated acceptance", :driver => :rack_test do + scenario "is displayed for probably outdated acceptance" do set_acceptance_file reimb reimb.save! find_reimbursement_as(users(:wedge), reimb) diff --git a/spec/features/budget_limits_spec.rb b/spec/features/budget_limits_spec.rb index a2ad293d..878c712e 100644 --- a/spec/features/budget_limits_spec.rb +++ b/spec/features/budget_limits_spec.rb @@ -4,7 +4,7 @@ feature "Budget limits", "" do fixtures :all - scenario "Trying to approve too much money" do + scenario "Trying to approve too much money", :js => true do sign_in_as_user(users(:tspmember)) visit request_path(requests(:wedge_for_party)) click_link "Edit" @@ -23,7 +23,7 @@ page.should have_content "approved amount exceeds the budget" end - scenario "Approving the right amount" do + scenario "Approving the right amount", :js => true do sign_in_as_user(users(:tspmember)) visit request_path(requests(:wedge_for_party)) click_link "Edit" @@ -42,7 +42,7 @@ page.should have_content "From submitted to approved" end - scenario "Choosing the currency" do + scenario "Choosing the currency", :js => true do sign_in_as_user(users(:tspmember)) visit request_path(requests(:wedge_for_party)) click_link "Edit" diff --git a/spec/features/comments_spec.rb b/spec/features/comments_spec.rb index 463b1d9f..1dca5797 100644 --- a/spec/features/comments_spec.rb +++ b/spec/features/comments_spec.rb @@ -4,7 +4,7 @@ feature "Comments", "" do fixtures :all - scenario "Empty comment" do + scenario "Empty comment", :js => true do sign_in_as_user(users(:wedge)) visit request_path(requests(:wedge_for_yavin)) @@ -14,7 +14,7 @@ page.should have_content "Some error prevented the comment to be added" end - scenario "Add comment as requester" do + scenario "Add comment as requester", :js => true do sign_in_as_user(users(:wedge)) visit request_path(requests(:wedge_for_yavin)) find("h1").should have_content "request" @@ -36,7 +36,7 @@ ActionMailer::Base.deliveries.size.should == @deliveries + 3 end - scenario "Add private comment" do + scenario "Add private comment", :js => true do sign_in_as_user(users(:tspmember)) visit request_path(requests(:wedge_for_yavin)) find("h1").should have_content "request" diff --git a/spec/features/reimbursement_process_spec.rb b/spec/features/reimbursement_process_spec.rb index 3fda5566..6dfee28c 100644 --- a/spec/features/reimbursement_process_spec.rb +++ b/spec/features/reimbursement_process_spec.rb @@ -4,7 +4,7 @@ feature "Reimbursements", "" do fixtures :all - scenario "Full reimbursement process" do + scenario "Full reimbursement process", :js => true do sign_in_as_user(users(:luke)) visit request_path(requests(:luke_for_yavin)) click_link "Ask for reimbursement" diff --git a/spec/features/request_process_spec.rb b/spec/features/request_process_spec.rb index 66c377b6..93634f03 100644 --- a/spec/features/request_process_spec.rb +++ b/spec/features/request_process_spec.rb @@ -4,7 +4,7 @@ feature "Requests", "" do fixtures :all - scenario "Full request process" do + scenario "Full request process", :js => true do sign_in_as_user(users(:luke)) visit event_path(events(:dagobah_camp)) click_link "Apply" @@ -26,12 +26,12 @@ click_button "Create request" page.should have_content "request was successfully created" page.should have_content "request must be explicitly submitted." - @request = Request.order(:created_at).last + @request = Request.order(:created_at, :id).last # Testing audits, just in case - @request.audits.last.user.should == users(:luke) - @request.expenses.first.audits.last.user.should == users(:luke) - @request.expenses.last.audits.last.owner.should == @request + @request.audits.order("created_at, id").last.user.should == users(:luke) + @request.expenses.first.audits.order("created_at, id").last.user.should == users(:luke) + @request.expenses.last.audits.order("created_at, id").last.owner.should == @request # Failed submission click_link "Action" diff --git a/spec/features/state_adjustments_spec.rb b/spec/features/state_adjustments_spec.rb index ee459f0e..f016012d 100644 --- a/spec/features/state_adjustments_spec.rb +++ b/spec/features/state_adjustments_spec.rb @@ -4,7 +4,7 @@ feature "State adjustments", "" do fixtures :all - scenario "Adjust a request" do + scenario "Adjust a request", :js => true do find_request_as users(:supervisor), requests(:luke_for_party) click_link "Adjust state" select "canceled", :from => :state_adjustment_to @@ -17,7 +17,7 @@ end end - scenario "Invalid adjustment" do + scenario "Invalid adjustment", :js => true do find_reimbursement_as users(:supervisor), reimbursements(:wedge_for_training_reim) click_link "Adjust state" select "incomplete", :from => :state_adjustment_to diff --git a/spec/models/state_adjustment_spec.rb b/spec/models/state_adjustment_spec.rb index b53c11a4..69b9f263 100644 --- a/spec/models/state_adjustment_spec.rb +++ b/spec/models/state_adjustment_spec.rb @@ -24,6 +24,7 @@ describe "which is valid" do before(:each) do @adjustment.to = "submitted" + sleep 2 # To ensure that we can compare timestamps @adjustment.save @request.reload end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b85c3c39..010f8c9b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -14,7 +14,7 @@ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} RSpec.configure do |config| - Capybara.default_driver = :webkit + Capybara.javascript_driver = :webkit # ## Mock Framework # @@ -44,6 +44,14 @@ # --seed 1234 config.order = "random" + config.before(:each) do + DatabaseCleaner.strategy = :transaction + end + + config.before(:each, :js => true) do + DatabaseCleaner.strategy = :deletion + end + config.before(:each) do DatabaseCleaner.start end @@ -56,6 +64,7 @@ FileUtils.rm_rf("public/spec") FileUtils.mkdir("public/spec") FileUtils.cp_r("spec/support/uploads", "public/spec") + DatabaseCleaner.clean_with(:deletion) # Just in case end config.after(:all) do