memory_test_fix 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b763773a933d7ce0b6b2eebdeafb5189177c7b87
4
- data.tar.gz: 0f1b84af28dad943655f40bce6590ef68505af8a
3
+ metadata.gz: d8be77be544a73632c9f612eb7d7742e6df17c24
4
+ data.tar.gz: 7a00be706b1a9616ff236e24afb16a10ccfdc940
5
5
  SHA512:
6
- metadata.gz: 9f129b1ac898e04657445684d28e4a541146ac06b7f5c16ff60919cc71ba406a67c3fdf9e1c1bd62906491feadc493d76b108e2e4c2888f2cdaa8dc20d4ff2af
7
- data.tar.gz: 08948451d5f1a6bdbedb825178812c374c11dbc0c802034490017bab1479f4d630541fca9b7397d729f896bafb79c01e45aa82e1827be9e61c524e7e536c0827
6
+ metadata.gz: 0400082e065eedbc1ca31f2d7cd40b8304fdb4564eb1a1587749f6656835e3ce067cf8258ea12157fba1d1c77185e62f469552be7ee89dfc0bd24d68077e3077
7
+ data.tar.gz: 3024609b21a8db5ee1786b498a25abf1324f58104d7a7c1d0b5b120e8359691264415cf60a8f3451692e084735fa430716dec2a67d6e10411433632ea1f27346
data/README.md CHANGED
@@ -46,9 +46,11 @@ You can also use this with other (testing) environments, not just 'test'.
46
46
 
47
47
  ## Rails Versions
48
48
 
49
- This gem is compatible with Rails 4 and Rails 3. If you're using Rails 2.3, use
50
- version 0.2.2 of this gem. If you're using an even older version of Rails, use
51
- version 0.1.3.
49
+ This gem is compatible with Rails 4 and Rails 3.2. If you're using an older
50
+ version of Rails, your first priority should be upgrading Rails. If that's not
51
+ an option, you can use version 1.1.0 of this gem with Rails 3.1 or 3.0. If
52
+ you're using Rails 2.3, use version 0.2.2. If you're using an even older
53
+ version of Rails, use version 0.1.3.
52
54
 
53
55
  ## Authors
54
56
 
@@ -1,4 +1,5 @@
1
1
  module MemoryTestFix
2
+ # Set up for use with Rails
2
3
  class Railtie < ::Rails::Railtie
3
4
  config.after_initialize do
4
5
  MemoryTestFix::SchemaLoader.init_schema
@@ -1,57 +1,76 @@
1
+ require 'memory_test_fix/schema_file_loader'
2
+ require 'active_support/core_ext/kernel/reporting'
3
+
1
4
  module MemoryTestFix
2
- module SchemaLoader
3
- def self.in_memory_database?
5
+ # Set up database schema into in-memory database.
6
+ class SchemaLoader
7
+ def self.init_schema
8
+ new.init_schema
9
+ end
10
+
11
+ def initialize(options = {})
12
+ @configuration = options[:configuration] || ActiveRecord::Base.connection_config
13
+ @migrator = options[:migrator] || ActiveRecord::Migrator
14
+ @loader = options[:loader] || SchemaFileLoader
15
+ end
16
+
17
+ def init_schema
18
+ return unless in_memory_database?
19
+
20
+ inform_using_in_memory unless silent?
21
+
22
+ if silent? || quiet?
23
+ load_schema_silently
24
+ else
25
+ load_schema
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def in_memory_database?
4
32
  in_memory? && sqlite3?
5
33
  end
6
34
 
7
- def self.in_memory?
8
- configuration[:database] == ':memory:' || configuration[:dbfile] == ':memory:'
35
+ def in_memory?
36
+ @configuration[:database] == ':memory:' || @configuration[:dbfile] == ':memory:'
37
+ end
38
+
39
+ def sqlite3?
40
+ @configuration[:adapter] == 'sqlite3'
9
41
  end
10
42
 
11
- def self.sqlite3?
12
- configuration[:adapter] == 'sqlite3'
43
+ def verbosity
44
+ @configuration[:verbosity]
13
45
  end
14
46
 
15
- def self.configuration
16
- Rails.configuration.database_configuration[Rails.env].with_indifferent_access
47
+ def silent?
48
+ verbosity == "silent"
17
49
  end
18
50
 
19
- def self.verbosity
20
- configuration[:verbosity]
51
+ def quiet?
52
+ verbosity == "quiet"
21
53
  end
22
54
 
23
- def self.migrate
24
- configuration[:migrate] == true
55
+ def migrate
56
+ @configuration[:migrate] == true
25
57
  end
26
58
 
27
- def self.inform_using_in_memory
59
+ def inform_using_in_memory
28
60
  puts "Creating sqlite :memory: database"
29
61
  end
30
62
 
31
- def self.load_schema
63
+ def load_schema
32
64
  if migrate
33
- lambda {
34
- ActiveRecord::Migrator.up('db/migrate') # use migrations
35
- }
65
+ @migrator.up('db/migrate')
36
66
  else
37
- lambda {
38
- load "#{Rails.root}/db/schema.rb" # use db agnostic schema by default
39
- }
67
+ @loader.load_schema
40
68
  end
41
69
  end
42
70
 
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
71
+ def load_schema_silently
72
+ silence_stream STDOUT do
73
+ load_schema
55
74
  end
56
75
  end
57
76
  end
@@ -1,24 +1,26 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "memory_test_fix"
3
- s.version = "1.1.0"
3
+ s.version = "1.2.0"
4
4
 
5
5
  if s.respond_to? :required_rubygems_version=
6
6
  s.required_rubygems_version = Gem::Requirement.new(">= 0")
7
7
  end
8
8
 
9
- s.authors = [ "Matijs van Zuijlen",
10
- "Chris Roos",
11
- "Geoffrey Grosenbach",
12
- "Kakutani Shintaro",
13
- "Erik Hanson and Matt Scilipoti",
14
- "Greg Weber",
15
- "Stephan Zalewski" ]
9
+ s.authors = ["Matijs van Zuijlen",
10
+ "Chris Roos",
11
+ "Geoffrey Grosenbach",
12
+ "Kakutani Shintaro",
13
+ "Erik Hanson and Matt Scilipoti",
14
+ "Greg Weber",
15
+ "Stephan Zalewski"]
16
16
  s.email = "matijs@matijs.net"
17
17
 
18
18
  s.license = 'MIT'
19
19
 
20
20
  s.summary = "Use SQLite3 in-memory database for Rails tests."
21
- s.description = "Makes use of SQLite3 in-memory database possible for your Rails tests by preloading the schema."
21
+ s.description =
22
+ "Makes use of SQLite3 in-memory database possible for your" \
23
+ " Rails tests by preloading the schema."
22
24
 
23
25
  s.homepage = "http://wiki.github.com/mvz/memory_test_fix"
24
26
  s.require_paths = ["lib"]
@@ -29,9 +31,11 @@ Gem::Specification.new do |s|
29
31
  "memory_test_fix.gemspec"]
30
32
  s.has_rdoc = true
31
33
  s.extra_rdoc_files = ['README.md']
32
- s.rubygems_version = %q{1.2.0}
34
+ s.rubygems_version = '1.2.0'
33
35
 
34
36
  s.add_runtime_dependency('railties', '>= 3.0.0')
37
+ s.add_runtime_dependency('activerecord', '>= 3.0.0')
35
38
  s.add_development_dependency('rake', '~> 10.2')
36
39
  s.add_development_dependency('minitest', '~> 5.2')
40
+ s.add_development_dependency('rspec', '~> 3.1.0')
37
41
  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.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matijs van Zuijlen
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2014-08-30 00:00:00.000000000 Z
17
+ date: 2014-09-07 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: railties
@@ -30,6 +30,20 @@ dependencies:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 3.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: activerecord
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 3.0.0
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 3.0.0
33
47
  - !ruby/object:Gem::Dependency
34
48
  name: rake
35
49
  requirement: !ruby/object:Gem::Requirement
@@ -58,6 +72,20 @@ dependencies:
58
72
  - - "~>"
59
73
  - !ruby/object:Gem::Version
60
74
  version: '5.2'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 3.1.0
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 3.1.0
61
89
  description: Makes use of SQLite3 in-memory database possible for your Rails tests
62
90
  by preloading the schema.
63
91
  email: matijs@matijs.net