1
0
Fork 0
mirror of https://github.com/kaminari/kaminari.git synced 2022-11-09 13:44:37 -05:00

Speed up the test suite by bulk-inserting fixture data

This commit is contained in:
Yuki Nishijima 2018-07-15 21:42:00 -04:00
parent a43335cc31
commit 734a73aae4
2 changed files with 11 additions and 1 deletions

View file

@ -2,6 +2,8 @@
require 'test_helper' require 'test_helper'
if defined? ActiveRecord if defined? ActiveRecord
require 'activerecord-import'
class ActiveRecordModelExtensionTest < ActiveSupport::TestCase class ActiveRecordModelExtensionTest < ActiveSupport::TestCase
test 'Changing page_method_name' do test 'Changing page_method_name' do
begin begin
@ -30,8 +32,11 @@ if defined? ActiveRecord
class << self class << self
def startup def startup
[User, GemDefinedModel, Device].each do |m| [User, GemDefinedModel, Device].each do |m|
1.upto(100) {|i| m.create! name: "user#{'%03d' % i}", age: (i / 10)} collection = 1.upto(100).map {|i| m.new(name: "user#{'%03d' % i}", age: (i / 10)) }
insert(collection)
end end
super super
end end
@ -39,6 +44,10 @@ if defined? ActiveRecord
[User, GemDefinedModel, Device].each(&:delete_all) [User, GemDefinedModel, Device].each(&:delete_all)
super super
end end
def insert(collection)
collection.first.class.import collection
end
end end
[User, Admin, GemDefinedModel, Device].each do |model_class| [User, Admin, GemDefinedModel, Device].each do |model_class|

View file

@ -27,4 +27,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rake', '>= 0' spec.add_development_dependency 'rake', '>= 0'
spec.add_development_dependency 'rr', '>= 0' spec.add_development_dependency 'rr', '>= 0'
spec.add_development_dependency 'capybara', '>= 1.0' spec.add_development_dependency 'capybara', '>= 1.0'
spec.add_development_dependency 'activerecord-import'
end end