activerecord-typedstore 0.4.1 → 0.4.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
  SHA1:
3
- metadata.gz: 497e66e991da7941c1769d7152e95ba2947e0a10
4
- data.tar.gz: 91085d4d5f1563bd97f7becc775468ef2a70f706
3
+ metadata.gz: 4576d86d981102fb975b790007a6c030d1023e80
4
+ data.tar.gz: 04265638898e9a80318d931fcfbe4291026f63ee
5
5
  SHA512:
6
- metadata.gz: 764da6e7280e7f0f4a48fbd3ee5de62c82a643db98ae6609259340a4a7a8b46092178d6660e95f0679e9d0c1e0e9178ef6213658ee66fe377e267f6d7339391a
7
- data.tar.gz: 12b13ab9453e9c43220614b597e54befe9db493a517accf1e39a13e94630a7f3859ab3055be43f1204ee1b116b6eaadb81c8e2dcb6b21bff827be15d914f6a05
6
+ metadata.gz: eb80e3bfe74bf53c36a4e9c12c2aea8cc5bf612af892dccc2b9c9d52ff3863b9f797ae86634937fb5a99504e1a439520f25dc8a97bf8f1e46619eee6a368fc12
7
+ data.tar.gz: 5bc7ab0513420edd67af9821ce47947f70b31873b8e74f539fd0eefc5aacb2b327a4c92834e54e183e17a590c2fdd67837e2eaee031506eb9493b4aa57966ee8
@@ -17,6 +17,8 @@ module ActiveRecord::TypedStore
17
17
 
18
18
  end
19
19
 
20
+ delegate :as_indifferent_hash, to: 'self.class'
21
+
20
22
  end
21
23
 
22
24
  end
@@ -102,6 +102,16 @@ module ActiveRecord::TypedStore
102
102
 
103
103
  private
104
104
 
105
+ def write_attribute(attr_name, value)
106
+ if coder = self.class.serialized_attributes[attr_name]
107
+ if coder.is_a?(ActiveRecord::TypedStore::Coder)
108
+ return super(attr_name, coder.as_indifferent_hash(value))
109
+ end
110
+ end
111
+
112
+ super
113
+ end
114
+
105
115
  def store_column(store_attribute, key)
106
116
  store = store_columns(store_attribute)
107
117
  store && store[key]
@@ -47,7 +47,7 @@ module ActiveRecord::TypedStore
47
47
  def cast_value(key, value)
48
48
  key = convert_key(key)
49
49
  column = columns[key]
50
- return value unless columns
50
+ return value unless column
51
51
 
52
52
  casted_value = column.cast(value)
53
53
 
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module TypedStore
3
- VERSION = '0.4.1'
3
+ VERSION = '0.4.2'
4
4
  end
5
5
  end
@@ -196,9 +196,16 @@ describe ActiveRecord::TypedStore::TypedHash do
196
196
  hash.merge!(source: '')
197
197
  expect(hash[:source]).to be == 'web'
198
198
  end
199
-
200
199
  end
201
-
202
200
  end
203
201
 
202
+ context 'unknown columns' do
203
+ let(:column) { ['age', :integer] }
204
+
205
+ it 'can be assigned' do
206
+ hash = hash_class.new
207
+ hash[:unknown_key] = 42
208
+ expect(hash[:unknown_key]).to be == 42
209
+ end
210
+ end
204
211
  end
@@ -452,6 +452,22 @@ shared_examples 'a store' do |retain_type=true|
452
452
 
453
453
  let(:model) { described_class.new }
454
454
 
455
+ describe 'assigning the store' do
456
+
457
+ it 'coerce it to the proper typed hash' do
458
+ expect {
459
+ model.settings = {}
460
+ }.to_not change { model.settings.class }
461
+ end
462
+
463
+ it 'still handle default values' do
464
+ expect {
465
+ model.settings = {}
466
+ }.to_not change { model.settings['nickname'] }
467
+ end
468
+
469
+ end
470
+
455
471
  describe 'attributes' do
456
472
 
457
473
  it 'retrieve default if assigned nil and null not allowed' do
@@ -459,9 +475,18 @@ shared_examples 'a store' do |retain_type=true|
459
475
  expect(model.age).to be == 12
460
476
  end
461
477
 
462
- it 'retreive default if assigned a blank value and column cannot be blank' do
463
- model.update_attributes(nickname: '')
464
- expect(model.reload.nickname).to be == 'Please enter your nickname'
478
+ context 'when column cannot be blank' do
479
+
480
+ it 'retreive default if not persisted yet, and nothing was assigned' do
481
+ expect(model.nickname).to be == 'Please enter your nickname'
482
+ end
483
+
484
+ it 'retreive default if assigned a blank value' do
485
+ model.update_attributes(nickname: '')
486
+ expect(model.nickname).to be == 'Please enter your nickname'
487
+ expect(model.reload.nickname).to be == 'Please enter your nickname'
488
+ end
489
+
465
490
  end
466
491
 
467
492
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-typedstore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.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: 2014-02-13 00:00:00.000000000 Z
11
+ date: 2014-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord