truncate table rather than delete_all in specs

This shaves a few seconds off each selenium spec in my local env

Change-Id: I73af04e18a75c5964474bf396ea7bafc8527d384
Reviewed-on: https://gerrit.instructure.com/4083
Tested-by: Hudson <hudson@instructure.com>
Tested-by: Selenium <selenium@instructure.com>
Reviewed-by: JT Olds <jt@instructure.com>
This commit is contained in:
Brian Palmer 2011-06-06 09:32:11 -06:00
parent c3ac6835a5
commit 210795b339
2 changed files with 16 additions and 7 deletions

View File

@ -225,11 +225,11 @@ shared_examples_for "all selenium tests" do
end
self.use_transactional_fixtures = false
append_after(:each) do
ALL_MODELS.each &:delete_all
ALL_MODELS.each { |m| truncate_table(m) }
end
append_before(:all) do
@selenium_driver = setup_selenium
end

View File

@ -30,10 +30,6 @@ ALL_MODELS = Dir.glob(File.expand_path(File.dirname(__FILE__) + '/../app/models'
eval(model) rescue nil
}.find_all{|x| x.respond_to? :delete_all and x.count >= 0 rescue false}
# wipe out the test db, in case some non-transactional tests crapped out before
# cleaning up after themselves
ALL_MODELS.each &:delete_all
# rspec aliases :describe to :context in a way that it's pretty much defined
# globally on every object. :context is already heavily used in our application,
# so we remove rspec's definition.
@ -41,6 +37,19 @@ module Spec::DSL::Main
remove_method :context
end
def truncate_table(model)
case model.connection.adapter_name
when "SQLite"
model.delete_all
else
model.connection.execute("TRUNCATE TABLE #{model.connection.quote_table_name(model.table_name)}")
end
end
# wipe out the test db, in case some non-transactional tests crapped out before
# cleaning up after themselves
ALL_MODELS.each { |m| truncate_table(m) }
Spec::Runner.configure do |config|
# If you're not using ActiveRecord you should remove these
# lines, delete config/database.yml and disable :active_record