frozen_record 0.11.0 → 0.12.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 +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +3 -5
- data/frozen_record.gemspec +1 -1
- data/lib/frozen_record/test_helper.rb +40 -0
- data/lib/frozen_record/version.rb +1 -1
- data/spec/fixtures/test_helper/countries.yml +9 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/test_helper_spec.rb +51 -0
- metadata +11 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67e64312afdfd4c73a509f158999cda26d2f33ad
|
4
|
+
data.tar.gz: d2dece97641dd7a82863f091d9d157f770cb4135
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 249a5e72ada5b1bed9ffd20028a3dfc5662b45f0f6501f71eebf314cd18214e3383c035f418a57dcc4e4a891c3b26c94e50628acb8d6cc284d162d154dc9f540
|
7
|
+
data.tar.gz: dfadb3c6375a7a6b6800219542fd49161b5525209336b62d8723b9d5d805193b1fcab3bd4c713c9d2009972c2b85b2d78134bc68606bbdbcf234ec8d2a18c8c2
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/frozen_record.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.require_paths = ['lib']
|
19
19
|
|
20
20
|
spec.add_runtime_dependency 'activemodel'
|
21
|
-
spec.add_development_dependency 'bundler'
|
21
|
+
spec.add_development_dependency 'bundler'
|
22
22
|
spec.add_development_dependency 'rake'
|
23
23
|
spec.add_development_dependency 'rspec'
|
24
24
|
spec.add_development_dependency 'pry'
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module FrozenRecord
|
2
|
+
module TestHelper
|
3
|
+
NoFixturesLoaded = Class.new(StandardError)
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def load_fixture(model_class, alternate_base_path)
|
7
|
+
@cache ||= {}
|
8
|
+
|
9
|
+
ensure_model_class_is_frozenrecord(model_class)
|
10
|
+
|
11
|
+
return if @cache.key?(model_class)
|
12
|
+
|
13
|
+
@cache[model_class] = {
|
14
|
+
old_base_path: model_class.base_path,
|
15
|
+
old_auto_reloading: model_class.auto_reloading,
|
16
|
+
}
|
17
|
+
|
18
|
+
model_class.auto_reloading = true
|
19
|
+
model_class.base_path = alternate_base_path
|
20
|
+
end
|
21
|
+
|
22
|
+
def unload_fixtures
|
23
|
+
@cache.each do |model_class, cached_values|
|
24
|
+
model_class.base_path = cached_values[:old_base_path]
|
25
|
+
model_class.load_records
|
26
|
+
model_class.auto_reloading = cached_values[:old_auto_reloading]
|
27
|
+
end
|
28
|
+
|
29
|
+
@cache = nil
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def ensure_model_class_is_frozenrecord(model_class)
|
35
|
+
return if model_class < FrozenRecord::Base
|
36
|
+
raise ArgumentError, "Model class (#{model_class}) does not inherit from #{FrozenRecord::Base}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'test fixture loading' do
|
4
|
+
describe 'by default' do
|
5
|
+
it 'uses the default fixtures' do
|
6
|
+
expect(Country.count).to be == 3
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '.load_fixture' do
|
11
|
+
it 'uses alternate test fixtures' do
|
12
|
+
test_fixtures_base_path = File.join(File.dirname(__FILE__), 'fixtures', 'test_helper')
|
13
|
+
|
14
|
+
FrozenRecord::TestHelper.load_fixture(Country, test_fixtures_base_path)
|
15
|
+
expect(Country.count).to be == 1
|
16
|
+
|
17
|
+
FrozenRecord::TestHelper.unload_fixtures # Note: This is called just to ensure a clean teardown between tests.
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'raises an ArgumentError if the model class does not inherit from FrozenRecord::Base' do
|
21
|
+
expect {
|
22
|
+
some_class = Class.new
|
23
|
+
FrozenRecord::TestHelper.load_fixture(some_class, 'some/path')
|
24
|
+
}.to raise_error(ArgumentError)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'uses test fixtures that were loaded first, and ignores repeat calls to load_fixture' do
|
28
|
+
test_fixtures_base_path = File.join(File.dirname(__FILE__), 'fixtures', 'test_helper')
|
29
|
+
FrozenRecord::TestHelper.load_fixture(Country, test_fixtures_base_path)
|
30
|
+
expect(Country.count).to be == 1
|
31
|
+
|
32
|
+
# Note: If we actually loaded this fixture, we'd expect 3 Countries to be loaded. Instead, we continue to get 3.
|
33
|
+
test_fixtures_base_path = File.join(File.dirname(__FILE__), 'fixtures')
|
34
|
+
FrozenRecord::TestHelper.load_fixture(Country, test_fixtures_base_path)
|
35
|
+
expect(Country.count).to be == 1
|
36
|
+
|
37
|
+
FrozenRecord::TestHelper.unload_fixtures
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '.unload_fixtures' do
|
42
|
+
it 'restores the default fixtures' do
|
43
|
+
test_fixtures_base_path = File.join(File.dirname(__FILE__), 'fixtures', 'test_helper')
|
44
|
+
|
45
|
+
FrozenRecord::TestHelper.load_fixture(Country, test_fixtures_base_path)
|
46
|
+
FrozenRecord::TestHelper.unload_fixtures
|
47
|
+
|
48
|
+
expect(Country.count).to be == 3
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: frozen_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jean Boussier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -113,10 +113,12 @@ files:
|
|
113
113
|
- lib/frozen_record/backends/yaml.rb
|
114
114
|
- lib/frozen_record/base.rb
|
115
115
|
- lib/frozen_record/scope.rb
|
116
|
+
- lib/frozen_record/test_helper.rb
|
116
117
|
- lib/frozen_record/version.rb
|
117
118
|
- spec/fixtures/animals.json
|
118
119
|
- spec/fixtures/cars.yml
|
119
120
|
- spec/fixtures/countries.yml
|
121
|
+
- spec/fixtures/test_helper/countries.yml
|
120
122
|
- spec/frozen_record_spec.rb
|
121
123
|
- spec/scope_spec.rb
|
122
124
|
- spec/spec_helper.rb
|
@@ -124,6 +126,7 @@ files:
|
|
124
126
|
- spec/support/animal.rb
|
125
127
|
- spec/support/car.rb
|
126
128
|
- spec/support/country.rb
|
129
|
+
- spec/test_helper_spec.rb
|
127
130
|
homepage: https://github.com/byroot/frozen_record
|
128
131
|
licenses:
|
129
132
|
- MIT
|
@@ -152,6 +155,7 @@ test_files:
|
|
152
155
|
- spec/fixtures/animals.json
|
153
156
|
- spec/fixtures/cars.yml
|
154
157
|
- spec/fixtures/countries.yml
|
158
|
+
- spec/fixtures/test_helper/countries.yml
|
155
159
|
- spec/frozen_record_spec.rb
|
156
160
|
- spec/scope_spec.rb
|
157
161
|
- spec/spec_helper.rb
|
@@ -159,3 +163,4 @@ test_files:
|
|
159
163
|
- spec/support/animal.rb
|
160
164
|
- spec/support/car.rb
|
161
165
|
- spec/support/country.rb
|
166
|
+
- spec/test_helper_spec.rb
|