rails_2_preload 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/rails_2_preload/spin.rb +33 -0
  2. metadata +2 -1
@@ -0,0 +1,33 @@
1
+ require 'rails_2_preload'
2
+
3
+ module Rails2Preload
4
+ module Spin
5
+
6
+ # Called from .spin.rb to add all hooks necessary to integrate
7
+ # Rails2Preload.
8
+ def self.add_spin_hooks
9
+ # Inside the context of Spin, we'll preload until the application classes
10
+ # (i.e. models) are loaded. This is optimal for unit testing.
11
+ Rails2Preload.preload_until(:load_application_classes)
12
+ ::Spin.hook(:before_preload) { Rails2Preload.prepare_rails }
13
+
14
+ ::Spin.hook(:after_preload) do
15
+ if Rails2Preload.preload_methods.include? :load_application_classes
16
+ # If classes are preloaded, empty the connection pool so forked
17
+ # processes are forced to establish new connections. Otherwise, the
18
+ # second time a test is run, an exception like this is raised:
19
+ # ActiveRecord::StatementInvalid PGError: no connection to the server
20
+ ActiveRecord::Base.connection_pool.disconnect!
21
+ end
22
+ end
23
+
24
+ ::Spin.hook(:after_fork) do
25
+ # Create a new initializer instance, but reuse the configuration already
26
+ # established by the preload phase.
27
+ initializer = ::Rails::Initializer.new(::Rails.configuration)
28
+ initializer.postload
29
+ end
30
+ end
31
+
32
+ end
33
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_2_preload
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -19,6 +19,7 @@ executables: []
19
19
  extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
+ - lib/rails_2_preload/spin.rb
22
23
  - lib/rails_2_preload.rb
23
24
  homepage: https://github.com/paperlesspost/rails-2-preload
24
25
  licenses: []