Skip to content

Commit

Permalink
Fixing the tests in MySQL
Browse files Browse the repository at this point in the history
  • Loading branch information
ancorgs committed Apr 9, 2014
1 parent 13ffa3d commit c07b2db
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 21 deletions.
6 changes: 4 additions & 2 deletions app/models/comment.rb
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions app/models/state_change.rb
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions spec/features/acceptance_info_spec.rb
Expand Up @@ -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"
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions spec/features/budget_limits_spec.rb
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions spec/features/comments_spec.rb
Expand Up @@ -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))

Expand All @@ -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"
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion spec/features/reimbursement_process_spec.rb
Expand Up @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions spec/features/request_process_spec.rb
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions spec/features/state_adjustments_spec.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/models/state_adjustment_spec.rb
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion spec/spec_helper.rb
Expand Up @@ -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
#
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit c07b2db

Please sign in to comment.