frozen_record 0.27.0 → 0.27.2

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
  SHA256:
3
- metadata.gz: 9ad9e1749e0b964178ce78eb8825cc64feddc347d6ac2952b5992cc97b5f4212
4
- data.tar.gz: 107c164a1ba9442bf7ab5fa59c03400502c2e31b8ce2e7429e2cf2992e38fcbc
3
+ metadata.gz: e47fc697be74381e4202860b94854c7634c3dbf689cf32acbe57d5c15bed9f83
4
+ data.tar.gz: 3e78652cd4102592513af618648f555bd936a96c97a71a9cc9af6a33bebd0d74
5
5
  SHA512:
6
- metadata.gz: 2297514000fb2ee38d534084285d16c3768a9795869e0af2955e134c6f08114f77128689d8aa8fd95fa775c7cba8732a9f34917a0b886d3286b07aa6a36f3f4e
7
- data.tar.gz: ce33c77289242c3f1d2341491c644226dad7b14fe709544c2f706d5e37c02c9649a59902f8eab9898e532eea89a0d84905b278bc299b64c217d9a53861d487c5
6
+ metadata.gz: d04577bfa1b97b5a0ada49555147cac4ce31c39187e10acf2e0367c80d00a224f0a5d2ec36d350775d92417fb92b6bfc67fa99c859a01628844805121c9a91e4
7
+ data.tar.gz: bfeed5194bd51706fae613df484de29f8629a314947e96c4abc6b65b1ce7b2eab26d950760c78368daa752b6ae8e1692d21d7383f493ac5a972f3f24049018a3
@@ -12,7 +12,7 @@ jobs:
12
12
  minimal: [ false, true ]
13
13
  name: Ruby ${{ matrix.ruby }} tests, minimal=${{ matrix.minimal }}
14
14
  steps:
15
- - uses: actions/checkout@v3
15
+ - uses: actions/checkout@v4
16
16
  - name: Set up Ruby
17
17
  uses: ruby/setup-ruby@v1
18
18
  with:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Unreleased
2
2
 
3
+ # v0.27.2
4
+
5
+ - Fix a Ruby warning that was emitted when `frozen_record` is loaded.
6
+
7
+ # v0.27.1
8
+
9
+ - TestHelper.unload_fixture: handle models without data.
10
+
3
11
  # v0.27.0
4
12
 
5
13
  - Allow to define some richer attibute types, somewhat akin to Active Record `serialize` attributes. See the README for more information.
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # FrozenRecord
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/byroot/frozen_record.svg)](http://travis-ci.org/byroot/frozen_record)
4
- [![Gem Version](https://badge.fury.io/rb/frozen_record.svg)](http://badge.fury.io/rb/frozen_record)
3
+ [![Build Status](https://secure.travis-ci.org/byroot/frozen_record.svg)](https://travis-ci.org/byroot/frozen_record)
4
+ [![Gem Version](https://badge.fury.io/rb/frozen_record.svg)](https://badge.fury.io/rb/frozen_record)
5
5
 
6
6
  Active Record-like interface for **read only** access to static data files of reasonable size.
7
7
 
@@ -42,9 +42,27 @@ class Country < FrozenRecord::Base
42
42
  end
43
43
  ```
44
44
 
45
- You can also specify a custom backend. Backends are classes that know how to
46
- load records from a static file. By default FrozenRecord expects an YAML file,
47
- but this option can be changed per model:
45
+ FrozenRecord has two built-in backends, for JSON and YAML.
46
+ Backends are classes that know how to load records from a static file.
47
+
48
+ The default backend is YAML and it expects a file that looks like this:
49
+
50
+ ```yaml
51
+ - id: 'se'
52
+ name: 'Sweden'
53
+ region: 'Europe'
54
+ language: 'Swedish'
55
+ population: 10420000
56
+ - id: 'de'
57
+ name: 'Germany'
58
+ region: 'Europe'
59
+ language: 'German'
60
+ population: 83200000
61
+
62
+ # …
63
+ ```
64
+
65
+ You can also specify a custom backend:
48
66
 
49
67
  ```ruby
50
68
  class Country < FrozenRecord::Base
@@ -74,18 +92,18 @@ end
74
92
 
75
93
  FrozenRecord aim to replicate only modern Active Record querying interface, and only the non "string typed" ones.
76
94
 
77
- e.g
78
95
  ```ruby
79
96
  # Supported query interfaces
80
97
  Country.
81
98
  where(region: 'Europe').
82
99
  where.not(language: 'English').
100
+ where(population: 10_000_000..).
83
101
  order(id: :desc).
84
102
  limit(10).
85
103
  offset(2).
86
104
  pluck(:name)
87
105
 
88
- # Non supported query interfaces
106
+ # Non-supported query interfaces
89
107
  Country.
90
108
  where('region = "Europe" AND language != "English"').
91
109
  order('id DESC')
@@ -217,7 +235,7 @@ FrozenRecord::TestHelper.unload_fixtures
217
235
  Here's a Rails-specific example:
218
236
 
219
237
  ```ruby
220
- require "test_helper"
238
+ require 'test_helper'
221
239
  require 'frozen_record/test_helper'
222
240
 
223
241
  class CountryTest < ActiveSupport::TestCase
@@ -230,7 +248,7 @@ class CountryTest < ActiveSupport::TestCase
230
248
  FrozenRecord::TestHelper.unload_fixtures
231
249
  end
232
250
 
233
- test "countries have a valid name" do
251
+ test 'countries have a valid name' do
234
252
  # ...
235
253
  ```
236
254
 
@@ -39,7 +39,7 @@ module FrozenRecord
39
39
 
40
40
  self.backend = FrozenRecord::Backends::Yaml
41
41
 
42
- attribute_method_suffix -'?'
42
+ attribute_method_suffix '?'
43
43
 
44
44
  class ThreadSafeStorage
45
45
 
@@ -12,7 +12,7 @@ module FrozenRecord
12
12
 
13
13
  return if @cache.key?(model_class)
14
14
 
15
- @cache[model_class] ||= model_class.base_path
15
+ @cache[model_class] = base_path_if_file_present(model_class)
16
16
 
17
17
  model_class.base_path = alternate_base_path
18
18
  model_class.load_records(force: true)
@@ -26,9 +26,10 @@ module FrozenRecord
26
26
  return unless @cache.key?(model_class)
27
27
 
28
28
  old_base_path = @cache[model_class]
29
- model_class.base_path = old_base_path
30
- model_class.load_records(force: true)
31
-
29
+ if old_base_path
30
+ model_class.base_path = old_base_path
31
+ model_class.load_records(force: true)
32
+ end
32
33
  @cache.delete(model_class)
33
34
  end
34
35
 
@@ -40,6 +41,19 @@ module FrozenRecord
40
41
 
41
42
  private
42
43
 
44
+ # Checks for the existence of the file for the frozen_record in the default directory.
45
+ # Returns the base_path if the file is present, otherwise nil.
46
+ # Some tests define specific test classes that do ONLY exist in the alternate directory.
47
+ # As `unload_fixture(s)` tries to force load the default file, it would raise an error for
48
+ # the "test only" fixtures. The nil value in the cache handles that case gracefully.
49
+ def base_path_if_file_present(model_class)
50
+ if File.exist?(model_class.file_path)
51
+ model_class.base_path
52
+ else
53
+ nil
54
+ end
55
+ end
56
+
43
57
  def ensure_model_class_is_frozenrecord(model_class)
44
58
  unless model_class < FrozenRecord::Base
45
59
  raise ArgumentError, "Model class (#{model_class}) does not inherit from #{FrozenRecord::Base}"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FrozenRecord
4
- VERSION = '0.27.0'
4
+ VERSION = '0.27.2'
5
5
  end
@@ -0,0 +1,3 @@
1
+ ---
2
+ - id: 1
3
+ name: Some continent
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ $VERBOSE = true
2
+
1
3
  lib = File.expand_path('../lib', __FILE__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
 
@@ -49,6 +49,18 @@ describe 'test fixture loading' do
49
49
  expect(Continent.count).to be == 1
50
50
  expect(Country.count).to be == 3
51
51
  end
52
+
53
+ context "when the test fixture does not exist in normal base path" do
54
+ class OnlyInTest < FrozenRecord::Base; end
55
+ before do
56
+ test_fixtures_base_path = File.join(File.dirname(__FILE__), 'fixtures', 'test_helper')
57
+ FrozenRecord::TestHelper.load_fixture(OnlyInTest, test_fixtures_base_path)
58
+ end
59
+ it 'unload fixture gracefully recovers from an ' do
60
+
61
+ expect { FrozenRecord::TestHelper.unload_fixture(OnlyInTest) }.not_to raise_error
62
+ end
63
+ end
52
64
  end
53
65
 
54
66
  describe '.unload_fixtures' do
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.27.0
4
+ version: 0.27.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean Boussier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-08 00:00:00.000000000 Z
11
+ date: 2024-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -95,6 +95,7 @@ files:
95
95
  - spec/fixtures/prices.yml.erb
96
96
  - spec/fixtures/test_helper/continents.yml.erb
97
97
  - spec/fixtures/test_helper/countries.yml.erb
98
+ - spec/fixtures/test_helper/only_in_tests.yml.erb
98
99
  - spec/frozen_record_spec.rb
99
100
  - spec/scope_spec.rb
100
101
  - spec/spec_helper.rb
@@ -124,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
125
  - !ruby/object:Gem::Version
125
126
  version: '0'
126
127
  requirements: []
127
- rubygems_version: 3.4.6
128
+ rubygems_version: 3.5.9
128
129
  signing_key:
129
130
  specification_version: 4
130
131
  summary: ActiveRecord like interface to read only access and query static YAML files
@@ -136,6 +137,7 @@ test_files:
136
137
  - spec/fixtures/prices.yml.erb
137
138
  - spec/fixtures/test_helper/continents.yml.erb
138
139
  - spec/fixtures/test_helper/countries.yml.erb
140
+ - spec/fixtures/test_helper/only_in_tests.yml.erb
139
141
  - spec/frozen_record_spec.rb
140
142
  - spec/scope_spec.rb
141
143
  - spec/spec_helper.rb