frozen_record 0.11.0 → 0.12.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: dbd18f511d8e1c4d74d1a6b3ca092e0b88875952
4
- data.tar.gz: 294012724b6be40e9cf6315228cadd5608f0528a
3
+ metadata.gz: 67e64312afdfd4c73a509f158999cda26d2f33ad
4
+ data.tar.gz: d2dece97641dd7a82863f091d9d157f770cb4135
5
5
  SHA512:
6
- metadata.gz: 6375c4aebad69d87aaed28115e5198dcfa750fb0ed9d43c9b8fd0cc17c1021cd39c0a90bb6bd02fff979d21b846fb3db63a101b80e01fbd9f364de1c371ea30c
7
- data.tar.gz: b25b20a098416977d776b5b00e5cd4f4936efd277172d0b6ace8291da094a11f9fcb2753faedd53eea1407b84a4ebc4403b80d347c4a2876f86f7b4de274412a
6
+ metadata.gz: 249a5e72ada5b1bed9ffd20028a3dfc5662b45f0f6501f71eebf314cd18214e3383c035f418a57dcc4e4a891c3b26c94e50628acb8d6cc284d162d154dc9f540
7
+ data.tar.gz: dfadb3c6375a7a6b6800219542fd49161b5525209336b62d8723b9d5d805193b1fcab3bd4c713c9d2009972c2b85b2d78134bc68606bbdbcf234ec8d2a18c8c2
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ vendor
data/.travis.yml CHANGED
@@ -1,7 +1,5 @@
1
1
  sudo: false
2
- before_install:
3
- - gem install bundler
4
2
  rvm:
5
- - '2.2.3'
6
- - '2.3.3'
7
- - '2.4.0'
3
+ - '2.4.5'
4
+ - '2.5.3'
5
+ - '2.6.1'
@@ -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', '~> 1.5'
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
@@ -1,3 +1,3 @@
1
1
  module FrozenRecord
2
- VERSION = '0.11.0'
2
+ VERSION = '0.12.0'
3
3
  end
@@ -0,0 +1,9 @@
1
+ ---
2
+ - id: 1
3
+ name: Some country
4
+ capital: <%= 'Somewhere' %>
5
+ density: 1.0
6
+ population: 42
7
+ founded_on: 2019-01-01
8
+ updated_at: 2019-01-01T19:08:06-05:00
9
+ king: Bob Smith
data/spec/spec_helper.rb CHANGED
@@ -11,6 +11,7 @@ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
11
11
  SimpleCov.start
12
12
 
13
13
  require 'frozen_record'
14
+ require 'frozen_record/test_helper'
14
15
 
15
16
  FrozenRecord::Base.base_path = File.join(File.dirname(__FILE__), 'fixtures')
16
17
 
@@ -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.11.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: 2018-12-12 00:00:00.000000000 Z
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: '1.5'
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: '1.5'
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