store_attribute 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 36243b5e350010855d95f5104c95dead8d0f6f8a
4
- data.tar.gz: d28d7d37b5db4a62a7ee363acdfb7b2d18e599c1
3
+ metadata.gz: 5b686f8993ef12feb2c0a1b36dcf90fbf0a7225b
4
+ data.tar.gz: 5498a60d8e4ac7ce66e4316b5fe2dfb50856c662
5
5
  SHA512:
6
- metadata.gz: 9cd64959ebac0572406300a1f3f350dc54232d8ed05639d03a9f941fdf8c0703d9ac2f23b40b589fca9b696da42e263f262231f84c613c04fd6a13c18ef68c17
7
- data.tar.gz: 61693d8113e5f3f419e558a3f40877cdbe6ae03e1b3a7a27d5f3097d51a08540f581cd0e7f5a89ad626169fb3d4d71c6c48796df346f56e94ba2a0d88f1406e8
6
+ metadata.gz: b41a03c88333430a322a2b0147b445284c4335063fcfaccaae53200b8438cad9a22996b1951df936da18fbbde23bd57d06847a49042971346896e181a9729e86
7
+ data.tar.gz: eb62f09e1f44a05d3d29540ac9b7f4751d226c0b4f37e6c92cc7b1c285c7cf993e16585e3f33edae18d2170f6544ac30f810590d8ac3a0fd23f1df124fed1ec6
data/.gitignore CHANGED
@@ -33,4 +33,5 @@ spec/dummy/log/*.log
33
33
  spec/dummy/tmp/
34
34
  spec/dummy/.sass-cache
35
35
  Gemfile.local
36
- Gemfile.lock
36
+ Gemfile.lock
37
+ tmp/
@@ -39,17 +39,25 @@ module ActiveRecord
39
39
 
40
40
  def type_cast_from_database(value)
41
41
  hash = super
42
- type_cast_from_user(hash)
42
+ if hash
43
+ accessor_types.each do |key, type|
44
+ hash[key] = type.type_cast_from_database(hash[key]) if hash.key?(key)
45
+ end
46
+ end
47
+ hash
43
48
  end
44
49
 
45
50
  def type_cast_for_database(value)
46
- if value
51
+ if value.is_a?(Hash)
52
+ typed_casted = {}
47
53
  accessor_types.each do |key, type|
48
54
  k = key_to_cast(value, key)
49
- value[k] = type.type_cast_for_database(value[k]) unless k.nil?
55
+ typed_casted[k] = type.type_cast_for_database(value[k]) unless k.nil?
50
56
  end
57
+ super(value.merge(typed_casted))
58
+ else
59
+ super(value)
51
60
  end
52
- super(value)
53
61
  end
54
62
 
55
63
  def type_cast_from_user(value)
@@ -1,3 +1,3 @@
1
1
  module StoreAttribute # :nodoc:
2
- VERSION = "0.4.0".freeze
2
+ VERSION = "0.4.1".freeze
3
3
  end
@@ -140,9 +140,32 @@ describe StoreAttribute do
140
140
 
141
141
  it "typecasts on reload" do
142
142
  jamie = User.create!(custom: { price: '$12' })
143
+ expect(jamie.reload.price).to eq 1200
144
+
143
145
  jamie = User.find(jamie.id)
144
146
 
145
147
  expect(jamie.price).to eq 1200
146
148
  end
147
149
  end
150
+
151
+ context "store subtype" do
152
+ it "typecasts on build" do
153
+ user = User.new(inner_json: { x: 1 })
154
+ expect(user.inner_json).to eq('x' => 1)
155
+ end
156
+
157
+ it "typecasts on update" do
158
+ user = User.new
159
+ user.update!(inner_json: { x: 1 })
160
+ expect(user.inner_json).to eq('x' => 1)
161
+
162
+ expect(user.reload.inner_json).to eq('x' => 1)
163
+ end
164
+
165
+ it "typecasts on reload" do
166
+ jamie = User.create!(inner_json: { x: 1 })
167
+ jamie = User.find(jamie.id)
168
+ expect(jamie.inner_json).to eq('x' => 1)
169
+ end
170
+ end
148
171
  end
data/spec/spec_helper.rb CHANGED
@@ -30,4 +30,13 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
30
30
 
31
31
  RSpec.configure do |config|
32
32
  config.mock_with :rspec
33
+
34
+ config.filter_run :focus
35
+ config.run_all_when_everything_filtered = true
36
+
37
+ config.example_status_persistence_file_path = "tmp/rspec_examples.txt"
38
+
39
+ if config.files_to_run.one?
40
+ config.default_formatter = 'doc'
41
+ end
33
42
  end
data/spec/support/user.rb CHANGED
@@ -6,6 +6,8 @@ class User < ActiveRecord::Base
6
6
  store_accessor :jparams, :version, active: :boolean, salary: :integer
7
7
  store_attribute :jparams, :birthday, :date
8
8
 
9
+ store_attribute :jparams, :inner_json, :json
10
+
9
11
  store :custom, accessors: [price: :money_type]
10
12
 
11
13
  store_accessor :hdata, visible: :boolean
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: store_attribute
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - palkan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-22 00:00:00.000000000 Z
11
+ date: 2016-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord