frozen_record 0.12.1 → 0.13.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: 933e76edb412172ed157cf1ed9e574707fa7061f
4
- data.tar.gz: 8b515acc39df4dd9de0e09d5fb8318fe9003ba1b
3
+ metadata.gz: a2caf0ce8ea29240d70604b68d7e1edeaa8b331c
4
+ data.tar.gz: 4ccec1e2b69e9a882d48cbbad9df73c9732b5fae
5
5
  SHA512:
6
- metadata.gz: e91cf29881b8d0f5b972df7e849cf0f3b621ac6f2ce64b6cf6dba771c3cf247add9c91f9d3fe044b9244b1f9009545e117463352559ce96153ea3374636f8087
7
- data.tar.gz: 4496c6d25dc7e487df51efeabd808e0df16cde00cd834eee0d46ab11d51e25cf7f5a36fc56e274e8d18086477c123ff819624457e663e450017266db5dd7653e
6
+ metadata.gz: 62e573bedb84600e916de3784e764eeb9400555c8f11118dc27787ef7f642f15e927a6e304e96e118eb8c1f3317c57613c1bd395fc6330d2b59ad36d014c653c
7
+ data.tar.gz: c225c4584ee248a86cd88e5f888618745d6275fdd27582a47fbedf405095d521c16a7d8484c6866b1c4ce2e618d921a772b0d45335253f4b50d3bc4c1a2d385a
data/README.md CHANGED
@@ -151,6 +151,41 @@ FrozenRecord::Base.auto_reloading = true # Activate reloading for all models
151
151
  Country.auto_reloading # Activate reloading for `Country` only
152
152
  ```
153
153
 
154
+ ## Testing
155
+
156
+ Testing your FrozenRecord-backed models with test fixtures is made easier with:
157
+
158
+ ```ruby
159
+ require 'frozen_record/test_helper'
160
+
161
+ # During test/spec setup
162
+ test_fixtures_base_path = 'alternate/fixture/path'
163
+ FrozenRecord::TestHelper.load_fixture(Country, test_fixtures_base_path)
164
+
165
+ # During test/spec teardown
166
+ FrozenRecord::TestHelper.unload_fixtures
167
+ ```
168
+
169
+ Here's a Rails-specific example:
170
+
171
+ ```ruby
172
+ require "test_helper"
173
+ require 'frozen_record/test_helper'
174
+
175
+ class CountryTest < ActiveSupport::TestCase
176
+ setup do
177
+ test_fixtures_base_path = Rails.root.join(%w(test support fixtures))
178
+ FrozenRecord::TestHelper.load_fixture(Country, test_fixtures_base_path)
179
+ end
180
+
181
+ teardown do
182
+ FrozenRecord::TestHelper.unload_fixtures
183
+ end
184
+
185
+ test "countries have a valid name" do
186
+ # ...
187
+ ```
188
+
154
189
  ## Contributors
155
190
 
156
191
  FrozenRecord is a from scratch reimplementation of a [Shopify](https://github.com/Shopify) project from 2007 named `YamlRecord`.
@@ -72,7 +72,7 @@ module FrozenRecord
72
72
  end
73
73
 
74
74
  def respond_to_missing?(name, *)
75
- if name.to_s =~ FIND_BY_PATTERN
75
+ if name =~ FIND_BY_PATTERN
76
76
  load_records # ensure attribute methods are defined
77
77
  return true if $1.split('_and_').all? { |attr| instance_method_already_implemented?(attr) }
78
78
  end
@@ -93,7 +93,10 @@ module FrozenRecord
93
93
  @records ||= begin
94
94
  records = backend.load(file_path)
95
95
  define_attribute_methods(list_attributes(records))
96
- records.map(&method(:new)).freeze
96
+ records.map do |attributes|
97
+ attributes.symbolize_keys!
98
+ new(attributes)
99
+ end.freeze
97
100
  end
98
101
  end
99
102
 
@@ -110,7 +113,7 @@ module FrozenRecord
110
113
  end
111
114
 
112
115
  def method_missing(name, *args)
113
- if name.to_s =~ FIND_BY_PATTERN
116
+ if name =~ FIND_BY_PATTERN
114
117
  return dynamic_match($1, args, $2.present?)
115
118
  end
116
119
  super
@@ -125,7 +128,7 @@ module FrozenRecord
125
128
  attributes = Set.new
126
129
  records.each do |record|
127
130
  record.keys.each do |key|
128
- attributes.add(key.to_s)
131
+ attributes.add(key.to_sym)
129
132
  end
130
133
  end
131
134
  attributes.to_a
@@ -133,10 +136,13 @@ module FrozenRecord
133
136
 
134
137
  end
135
138
 
136
- attr_reader :attributes
137
-
138
139
  def initialize(attrs = {})
139
- @attributes = attrs.stringify_keys
140
+ @attributes = attrs
141
+ end
142
+
143
+ def attributes
144
+ # We have to return a hash with string keys for backward compatibity reasons
145
+ @attributes.stringify_keys
140
146
  end
141
147
 
142
148
  def id
@@ -144,7 +150,7 @@ module FrozenRecord
144
150
  end
145
151
 
146
152
  def [](attr)
147
- @attributes[attr.to_s]
153
+ @attributes[attr.to_sym]
148
154
  end
149
155
  alias_method :attribute, :[]
150
156
 
@@ -163,7 +169,8 @@ module FrozenRecord
163
169
  private
164
170
 
165
171
  def attribute?(attribute_name)
166
- FALSY_VALUES.exclude?(self[attribute_name]) && self[attribute_name].present?
172
+ value = self[attribute_name]
173
+ FALSY_VALUES.exclude?(value) && value.present?
167
174
  end
168
175
 
169
176
  end
@@ -1,3 +1,3 @@
1
1
  module FrozenRecord
2
- VERSION = '0.12.1'
2
+ VERSION = '0.13.0'
3
3
  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.1
4
+ version: 0.13.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: 2019-02-07 00:00:00.000000000 Z
11
+ date: 2019-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel