frozen_record 0.12.0 → 0.12.1

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: 67e64312afdfd4c73a509f158999cda26d2f33ad
4
- data.tar.gz: d2dece97641dd7a82863f091d9d157f770cb4135
3
+ metadata.gz: 933e76edb412172ed157cf1ed9e574707fa7061f
4
+ data.tar.gz: 8b515acc39df4dd9de0e09d5fb8318fe9003ba1b
5
5
  SHA512:
6
- metadata.gz: 249a5e72ada5b1bed9ffd20028a3dfc5662b45f0f6501f71eebf314cd18214e3383c035f418a57dcc4e4a891c3b26c94e50628acb8d6cc284d162d154dc9f540
7
- data.tar.gz: dfadb3c6375a7a6b6800219542fd49161b5525209336b62d8723b9d5d805193b1fcab3bd4c713c9d2009972c2b85b2d78134bc68606bbdbcf234ec8d2a18c8c2
6
+ metadata.gz: e91cf29881b8d0f5b972df7e849cf0f3b621ac6f2ce64b6cf6dba771c3cf247add9c91f9d3fe044b9244b1f9009545e117463352559ce96153ea3374636f8087
7
+ data.tar.gz: 4496c6d25dc7e487df51efeabd808e0df16cde00cd834eee0d46ab11d51e25cf7f5a36fc56e274e8d18086477c123ff819624457e663e450017266db5dd7653e
@@ -84,8 +84,8 @@ module FrozenRecord
84
84
  load_records
85
85
  end
86
86
 
87
- def load_records
88
- if auto_reloading && file_changed?
87
+ def load_records(force: false)
88
+ if force || (auto_reloading && file_changed?)
89
89
  @records = nil
90
90
  undefine_attribute_methods
91
91
  end
@@ -6,24 +6,24 @@ module FrozenRecord
6
6
  def load_fixture(model_class, alternate_base_path)
7
7
  @cache ||= {}
8
8
 
9
- ensure_model_class_is_frozenrecord(model_class)
9
+ unless model_class < FrozenRecord::Base
10
+ raise ArgumentError, "Model class (#{model_class}) does not inherit from #{FrozenRecord::Base}"
11
+ end
10
12
 
11
13
  return if @cache.key?(model_class)
12
14
 
13
- @cache[model_class] = {
14
- old_base_path: model_class.base_path,
15
- old_auto_reloading: model_class.auto_reloading,
16
- }
15
+ @cache[model_class] ||= model_class.base_path
17
16
 
18
- model_class.auto_reloading = true
19
17
  model_class.base_path = alternate_base_path
18
+ model_class.load_records(force: true)
20
19
  end
21
20
 
22
21
  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]
22
+ return unless defined?(@cache) && @cache
23
+
24
+ @cache.each do |model_class, old_base_path|
25
+ model_class.base_path = old_base_path
26
+ model_class.load_records(force: true)
27
27
  end
28
28
 
29
29
  @cache = nil
@@ -32,8 +32,6 @@ module FrozenRecord
32
32
  private
33
33
 
34
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
35
  end
38
36
  end
39
37
  end
@@ -1,3 +1,3 @@
1
1
  module FrozenRecord
2
- VERSION = '0.12.0'
2
+ VERSION = '0.12.1'
3
3
  end
@@ -24,4 +24,6 @@ RSpec.configure do |config|
24
24
  config.filter_run :focus
25
25
 
26
26
  config.order = 'random'
27
+
28
+ config.before { FrozenRecord::TestHelper.unload_fixtures }
27
29
  end
@@ -47,5 +47,11 @@ describe 'test fixture loading' do
47
47
 
48
48
  expect(Country.count).to be == 3
49
49
  end
50
+
51
+ it 'does has no effect if no alternate fixtures were loaded' do
52
+ FrozenRecord::TestHelper.unload_fixtures
53
+
54
+ expect(Country.count).to be == 3
55
+ end
50
56
  end
51
57
  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.12.0
4
+ version: 0.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean Boussier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-06 00:00:00.000000000 Z
11
+ date: 2019-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel