memory_test_fix 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a95367960d728d45656a954966125070e58321a9
4
- data.tar.gz: 349871f7052775bc7711eb3f0e18f15a92a25d51
3
+ metadata.gz: b763773a933d7ce0b6b2eebdeafb5189177c7b87
4
+ data.tar.gz: 0f1b84af28dad943655f40bce6590ef68505af8a
5
5
  SHA512:
6
- metadata.gz: eb98875a6b21d3cdba6cf4b29694523159ad1faa6e20386d011a6b0f62c79093afc14c3f98a424779b62066fb7c5407a063a2a8736cb44988990eea0ad10df7b
7
- data.tar.gz: a56398fff47b02ee0145f1d5331aa8f37fee2ce0eecd1464b9d31e83813fe9d41236f2fa878bf4014c5a1e1b34cfeb3bf65849ad59c526431c19544d850aa35a
6
+ metadata.gz: 9f129b1ac898e04657445684d28e4a541146ac06b7f5c16ff60919cc71ba406a67c3fdf9e1c1bd62906491feadc493d76b108e2e4c2888f2cdaa8dc20d4ff2af
7
+ data.tar.gz: 08948451d5f1a6bdbedb825178812c374c11dbc0c802034490017bab1479f4d630541fca9b7397d729f896bafb79c01e45aa82e1827be9e61c524e7e536c0827
data/README.md CHANGED
@@ -3,6 +3,12 @@
3
3
  A simple fix to run your Rails tests with sqlite. From the
4
4
  [example by Chris Roos](http://blog.seagul.co.uk/articles/2006/02/08/in-memory-sqlite-database-for-rails-testing).
5
5
 
6
+ ## Status
7
+
8
+ [![Dependency Status](https://gemnasium.com/mvz/memory_test_fix.png)](https://gemnasium.com/mvz/memory_test_fix)
9
+ [![Build Status](https://travis-ci.org/mvz/memory_test_fix.png?branch=master)](https://travis-ci.org/mvz/memory_test_fix)
10
+ [![Code Climate](https://codeclimate.com/github/mvz/memory_test_fix.png)](https://codeclimate.com/github/mvz/memory_test_fix)
11
+
6
12
  ## Usage
7
13
 
8
14
  Add the gem to your bundle by adding
@@ -27,6 +33,15 @@ You can also adjust the verbosity of the output:
27
33
  database: ":memory:"
28
34
  verbosity: silent
29
35
 
36
+ To use rails migrations instead of loading `db/schema.rb`
37
+
38
+ ```yaml
39
+ test:
40
+ adapter: sqlite3
41
+ database: ":memory:"
42
+ migrate: true
43
+ ```
44
+
30
45
  You can also use this with other (testing) environments, not just 'test'.
31
46
 
32
47
  ## Rails Versions
@@ -37,14 +52,19 @@ version 0.1.3.
37
52
 
38
53
  ## Authors
39
54
 
40
- MemoryTestFix is maintained by [Matijs van Zuijlen](http://www.matijs.net/)
55
+ The [original
56
+ hack](http://chrisroos.co.uk/blog/2006-02-08-in-memory-sqlite-database-for-rails-testing)
57
+ this gem is based on was created by Chris Roos.
58
+
59
+ The hack was adapted as a Rails plugin by [Geoffrey
60
+ Grosenbach](http://nubyonrails.com).
41
61
 
42
- The following people have contributed to this gem:
62
+ The following people have contributed:
43
63
 
44
- * [Original hack](http://chrisroos.co.uk/blog/2006-02-08-in-memory-sqlite-database-for-rails-testing) by Chris Roos
45
- * Adapted by [Geoffrey Grosenbach](http://nubyonrails.com)
46
- * Verbosity patch by Kakutani Shintaro
47
- * Adapted as GemPlugin by Matijs van Zuijlen
48
- * Support for environments besides 'test' by Erik Hanson & Matt Scilipoti
49
- * Support for Rails 3 by Greg Weber
50
- * Fix for Rails 3.2 by Stephan Zalewski
64
+ * Kakutani Shintaro
65
+ * Matijs van Zuijlen
66
+ * Erik Hanson & Matt Scilipoti
67
+ * Greg Weber
68
+ * Stephan Zalewski
69
+
70
+ MemoryTestFix is maintained by [Matijs van Zuijlen](http://www.matijs.net/)
@@ -0,0 +1,7 @@
1
+ module MemoryTestFix
2
+ class Railtie < ::Rails::Railtie
3
+ config.after_initialize do
4
+ MemoryTestFix::SchemaLoader.init_schema
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,58 @@
1
+ module MemoryTestFix
2
+ module SchemaLoader
3
+ def self.in_memory_database?
4
+ in_memory? && sqlite3?
5
+ end
6
+
7
+ def self.in_memory?
8
+ configuration[:database] == ':memory:' || configuration[:dbfile] == ':memory:'
9
+ end
10
+
11
+ def self.sqlite3?
12
+ configuration[:adapter] == 'sqlite3'
13
+ end
14
+
15
+ def self.configuration
16
+ Rails.configuration.database_configuration[Rails.env].with_indifferent_access
17
+ end
18
+
19
+ def self.verbosity
20
+ configuration[:verbosity]
21
+ end
22
+
23
+ def self.migrate
24
+ configuration[:migrate] == true
25
+ end
26
+
27
+ def self.inform_using_in_memory
28
+ puts "Creating sqlite :memory: database"
29
+ end
30
+
31
+ def self.load_schema
32
+ if migrate
33
+ lambda {
34
+ ActiveRecord::Migrator.up('db/migrate') # use migrations
35
+ }
36
+ else
37
+ lambda {
38
+ load "#{Rails.root}/db/schema.rb" # use db agnostic schema by default
39
+ }
40
+ end
41
+ end
42
+
43
+ def self.init_schema
44
+ if in_memory_database?
45
+ case verbosity
46
+ when "silent"
47
+ silence_stream(STDOUT, &load_schema)
48
+ when "quiet"
49
+ inform_using_in_memory
50
+ silence_stream(STDOUT, &load_schema)
51
+ else
52
+ inform_using_in_memory
53
+ load_schema.call
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -1,52 +1,15 @@
1
- module MemoryTestFix
2
- def self.in_memory_database?
3
- in_memory? && sqlite3?
4
- end
5
-
6
- def self.in_memory?
7
- configuration[:database] == ':memory:' || configuration[:dbfile] == ':memory:'
8
- end
1
+ require 'memory_test_fix/schema_loader'
9
2
 
10
- def self.sqlite3?
11
- configuration[:adapter] == 'sqlite3'
12
- end
3
+ if defined?(Rails)
4
+ require 'memory_test_fix/railtie.rb'
13
5
 
14
- def self.configuration
15
- Rails.configuration.database_configuration[Rails.env].with_indifferent_access
16
- end
17
-
18
- def self.verbosity
19
- configuration[:verbosity]
20
- end
21
-
22
- def self.inform_using_in_memory
23
- puts "Creating sqlite :memory: database"
24
- end
25
-
26
- def self.init_schema
27
- if in_memory_database?
28
- load_schema = lambda {
29
- load "#{Rails.root}/db/schema.rb" # use db agnostic schema by default
30
- # ActiveRecord::Migrator.up('db/migrate') # use migrations
31
- }
32
- case verbosity
33
- when "silent"
34
- silence_stream(STDOUT, &load_schema)
35
- when "quiet"
36
- inform_using_in_memory
37
- silence_stream(STDOUT, &load_schema)
38
- else
39
- inform_using_in_memory
40
- load_schema.call
6
+ if Rails.version =~ /^4\.0\./
7
+ ActiveRecord::Base.class_eval do
8
+ def self.establish_connection(*_)
9
+ super.tap do
10
+ MemoryTestFix::SchemaLoader.init_schema
11
+ end
41
12
  end
42
13
  end
43
14
  end
44
15
  end
45
-
46
- if ActiveSupport.respond_to? :on_load
47
- ActiveSupport.on_load(:after_initialize) do
48
- MemoryTestFix.init_schema
49
- end
50
- else
51
- MemoryTestFix.init_schema
52
- end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "memory_test_fix"
3
- s.version = "1.0.0"
3
+ s.version = "1.1.0"
4
4
 
5
5
  if s.respond_to? :required_rubygems_version=
6
6
  s.required_rubygems_version = Gem::Requirement.new(">= 0")
@@ -22,15 +22,16 @@ Gem::Specification.new do |s|
22
22
 
23
23
  s.homepage = "http://wiki.github.com/mvz/memory_test_fix"
24
24
  s.require_paths = ["lib"]
25
- s.files = ["init.rb",
26
- "rails/init.rb",
27
- "lib/memory_test_fix.rb",
25
+ s.files = ["lib/memory_test_fix.rb",
26
+ "lib/memory_test_fix/railtie.rb",
27
+ "lib/memory_test_fix/schema_loader.rb",
28
28
  "README.md",
29
29
  "memory_test_fix.gemspec"]
30
30
  s.has_rdoc = true
31
31
  s.extra_rdoc_files = ['README.md']
32
32
  s.rubygems_version = %q{1.2.0}
33
33
 
34
+ s.add_runtime_dependency('railties', '>= 3.0.0')
34
35
  s.add_development_dependency('rake', '~> 10.2')
35
36
  s.add_development_dependency('minitest', '~> 5.2')
36
37
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: memory_test_fix
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matijs van Zuijlen
@@ -14,34 +14,48 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2014-04-07 00:00:00.000000000 Z
17
+ date: 2014-08-30 00:00:00.000000000 Z
18
18
  dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: railties
21
+ requirement: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: 3.0.0
26
+ type: :runtime
27
+ prerelease: false
28
+ version_requirements: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 3.0.0
19
33
  - !ruby/object:Gem::Dependency
20
34
  name: rake
21
35
  requirement: !ruby/object:Gem::Requirement
22
36
  requirements:
23
- - - ~>
37
+ - - "~>"
24
38
  - !ruby/object:Gem::Version
25
39
  version: '10.2'
26
40
  type: :development
27
41
  prerelease: false
28
42
  version_requirements: !ruby/object:Gem::Requirement
29
43
  requirements:
30
- - - ~>
44
+ - - "~>"
31
45
  - !ruby/object:Gem::Version
32
46
  version: '10.2'
33
47
  - !ruby/object:Gem::Dependency
34
48
  name: minitest
35
49
  requirement: !ruby/object:Gem::Requirement
36
50
  requirements:
37
- - - ~>
51
+ - - "~>"
38
52
  - !ruby/object:Gem::Version
39
53
  version: '5.2'
40
54
  type: :development
41
55
  prerelease: false
42
56
  version_requirements: !ruby/object:Gem::Requirement
43
57
  requirements:
44
- - - ~>
58
+ - - "~>"
45
59
  - !ruby/object:Gem::Version
46
60
  version: '5.2'
47
61
  description: Makes use of SQLite3 in-memory database possible for your Rails tests
@@ -53,10 +67,10 @@ extra_rdoc_files:
53
67
  - README.md
54
68
  files:
55
69
  - README.md
56
- - init.rb
57
70
  - lib/memory_test_fix.rb
71
+ - lib/memory_test_fix/railtie.rb
72
+ - lib/memory_test_fix/schema_loader.rb
58
73
  - memory_test_fix.gemspec
59
- - rails/init.rb
60
74
  homepage: http://wiki.github.com/mvz/memory_test_fix
61
75
  licenses:
62
76
  - MIT
@@ -67,12 +81,12 @@ require_paths:
67
81
  - lib
68
82
  required_ruby_version: !ruby/object:Gem::Requirement
69
83
  requirements:
70
- - - '>='
84
+ - - ">="
71
85
  - !ruby/object:Gem::Version
72
86
  version: '0'
73
87
  required_rubygems_version: !ruby/object:Gem::Requirement
74
88
  requirements:
75
- - - '>='
89
+ - - ">="
76
90
  - !ruby/object:Gem::Version
77
91
  version: '0'
78
92
  requirements: []
data/init.rb DELETED
@@ -1 +0,0 @@
1
- require File.dirname(__FILE__) + "/rails/init"
data/rails/init.rb DELETED
@@ -1,2 +0,0 @@
1
-
2
- require 'memory_test_fix'