Skip to content

Commit

Permalink
Remove DatabaseCleaner in favor of single-threaded transaction specs
Browse files Browse the repository at this point in the history
Use warden's login_as in feature specs instead of always logging in via
the form.

This shaves about ~25 seconds off the total test run speed
 * 20 from transactional fixtures
 * 5 from login_as
  • Loading branch information
tjgrathwell committed Jun 28, 2013
1 parent 6d58ead commit 28a6e48
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 55 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ group :test do
gem 'capybara', '>= 2.0.1'
gem "poltergeist"
gem "launchy"
gem "database_cleaner"
gem 'shoulda-matchers'
gem "faker"
gem 'capybara-screenshot'
Expand Down
2 changes: 0 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ GEM
coffee-script-source (1.5.0)
crack (0.3.2)
daemons (1.1.9)
database_cleaner (0.9.1)
devise (2.2.3)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.1)
Expand Down Expand Up @@ -285,7 +284,6 @@ DEPENDENCIES
capybara (>= 2.0.1)
capybara-screenshot
coffee-rails
database_cleaner
devise (~> 2.2.3)
factory_girl_rails
faker
Expand Down
32 changes: 13 additions & 19 deletions spec/features/profiles_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,23 @@
describe "Profile" do
before do
@user = create(:user)
@user.profile.update_attributes( :childcaring => true,
:writing => true,
:designing => true,
:outreach => true,
:mentoring => true,
:macosx => true,
:windows => true,
:linux => true,
:other => "This is a note in other",
:bio => "This is a Bio"
@user.profile.update_attributes(:childcaring => true,
:writing => true,
:designing => true,
:outreach => true,
:mentoring => true,
:macosx => true,
:windows => true,
:linux => true,
:other => "This is a note in other",
:bio => "This is a Bio"
)

sign_in_as(@user)
end

it "when a user is logged in the Profile link should be displayed" do
page.should have_link("Profile")
end

it "and the user clicks the Profile link" do
click_link "Profile"
end

it "when user visits the profile show page should see" do
visit "/"
click_link "Profile"
page.should have_content(@user.full_name)
page.should have_content(@user.profile.bio)
Expand All @@ -44,6 +37,7 @@
end

it "user should be able to add his/her skills" do
visit "/"
click_link "Profile"
click_link "Edit Profile"
page.should have_content("Profile edit #{@user.full_name}")
Expand Down Expand Up @@ -82,7 +76,7 @@
end

it "should be able to see workshop history" do
click_link "Profile"
visit user_profile_path(@user)
page.should have_content("Workshop History")
page.should have_content("BridgeBridge")
end
Expand Down
16 changes: 8 additions & 8 deletions spec/features/sign_in_menu_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
it "should be hidden" do
page.all('#sign_in_dialog', :visible => false)
end

it "should show on home page on click" do
visit "/"
click_link('Sign In')
page.find('#sign_in_dialog', :visible => true)
visit "/"
click_link('Sign In')
page.find('#sign_in_dialog', :visible => true)
end

it "should not show if signed in" do
sign_in_as(@user)
visit "/"
page.should have_link("Sign Out")
page.should_not have_link("Sign in")
end
Expand All @@ -26,8 +27,8 @@
before do
@user = create(:user)
end
it "should be able to sign in from the home page" do

it "should be able to sign in from the home page" do
visit "/"
within("#sign_in_dialog") do
fill_in "Email", :with => @user.email
Expand All @@ -37,4 +38,3 @@
page.should have_content("Signed in successfully")
end
end

39 changes: 21 additions & 18 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,35 @@
RSpec.configure do |config|
config.mock_with :rspec

config.use_transactional_fixtures = false

config.before(:suite) do
DatabaseCleaner.strategy = :truncation
end
config.use_transactional_fixtures = true

config.before(:each) do
DatabaseCleaner.start
WebMock.disable_net_connect!(:allow_localhost => true)
end

config.after(:each) do
DatabaseCleaner.clean
end

Rails.application.routes.default_url_options[:host] = 'localhost:3000'

# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
#config.infer_base_class_for_anonymous_controllers = false

#Uncomment if need to write tests using devise helpers
#config.extend ControllerMacros, :type => :controller
config.include Devise::TestHelpers, :type => :controller

config.include FactoryGirl::Syntax::Methods
end

# Monkey-patch to force single DB connection even in multithreaded
# tests (selenium/capybara-webkit/poltergeist)
ActiveRecord::ConnectionAdapters::ConnectionPool.class_eval do
def current_connection_id
Thread.main.object_id
end
end

[:feature, :request].each do |type|
config.include Warden::Test::Helpers, type: type
end

config.before do
Warden.test_mode! if example.metadata[:js]
end

config.after do
Warden.test_reset! if example.metadata[:js]
end
end
18 changes: 11 additions & 7 deletions spec/support/sign_in_helper.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
def sign_in_as(user)
visit new_user_session_path
within("#sign-in-page") do
fill_in "Email", :with => user.email
fill_in "Password", :with => user.password
click_button "Sign in"
def sign_in_as(user, options={})
if options[:slowly]
visit new_user_session_path
within("#sign-in-page") do
fill_in "Email", :with => user.email
fill_in "Password", :with => user.password
click_button "Sign in"
end
page.should have_content("Signed in successfully")
else
login_as user, scope: :user
end
page.should have_content("Signed in successfully")
end

def sign_in_stub(fake_user)
Expand Down

0 comments on commit 28a6e48

Please sign in to comment.