virtus_model 0.2.8 → 0.2.9
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 +4 -4
- data/lib/virtus_model/base.rb +1 -1
- data/lib/virtus_model/version.rb +1 -1
- data/spec/virtus_model/base_spec.rb +13 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0cb3157871c8866d19ac88f068076329ee5d9c5
|
4
|
+
data.tar.gz: 68f6a26a49f767e902e335b30ef43a4cf5ef01e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d74acfb486d3792660e01ee32423c95c7c10837c775d35e41183325c47b64a637ed712502771cad02c56ba7e6d9c48ec12c49a1d2705071d7d139ef32654cd39
|
7
|
+
data.tar.gz: 3ec66545f02ad0aba4a926d6748880a8a3e2ae9221ea0d5c466369574c58e332f89768578ce72ef25c932cd9838a5e67c75c3f3077999d7a0a6c1f25b3938be3
|
data/lib/virtus_model/base.rb
CHANGED
@@ -108,7 +108,7 @@ module VirtusModel
|
|
108
108
|
self.class.attributes.reduce({}) do |result, name|
|
109
109
|
if model.respond_to?(name)
|
110
110
|
result[name] = model.public_send(name)
|
111
|
-
elsif model.respond_to?(:[])
|
111
|
+
elsif model.respond_to?(:[]) && model.respond_to?(:key?) && model.key?(name)
|
112
112
|
result[name] = model[name]
|
113
113
|
end
|
114
114
|
result
|
data/lib/virtus_model/version.rb
CHANGED
@@ -143,8 +143,14 @@ describe VirtusModel::Base do
|
|
143
143
|
|
144
144
|
context 'hash' do
|
145
145
|
let(:attributes) { { name: 'test', other: 'test' } }
|
146
|
+
|
146
147
|
it { expect(subject.attributes).to include(name: 'test') }
|
147
148
|
it { expect(subject.attributes).not_to include(other: 'test') }
|
149
|
+
|
150
|
+
it 'does not overwrite omitted fields' do
|
151
|
+
expect(subject.assign_attributes({})).to be_a(SimpleModel)
|
152
|
+
expect(subject.attributes[:name]).to eq('test')
|
153
|
+
end
|
148
154
|
end
|
149
155
|
|
150
156
|
context 'object' do
|
@@ -159,9 +165,16 @@ describe VirtusModel::Base do
|
|
159
165
|
context 'hash' do
|
160
166
|
let(:attributes) { { model: model, models: [model], other: 'test' } }
|
161
167
|
let(:model) { { name: 'test', other: 'test' } }
|
168
|
+
|
162
169
|
it { expect(subject.attributes[:model]).to eq(SimpleModel.new(model)) }
|
163
170
|
it { expect(subject.attributes[:models]).to eq([SimpleModel.new(model)]) }
|
164
171
|
it { expect(subject.attributes).not_to include(other: 'test') }
|
172
|
+
|
173
|
+
it 'does not overwrite omitted fields' do
|
174
|
+
expect(subject.assign_attributes(model: nil)).to be_a(ComplexModel)
|
175
|
+
expect(subject.attributes[:model]).to be(nil)
|
176
|
+
expect(subject.attributes[:models]).to eq([SimpleModel.new(model)])
|
177
|
+
end
|
165
178
|
end
|
166
179
|
|
167
180
|
context 'object' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: virtus_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derek Schaefer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: virtus
|
@@ -169,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
169
|
version: '0'
|
170
170
|
requirements: []
|
171
171
|
rubyforge_project:
|
172
|
-
rubygems_version: 2.
|
172
|
+
rubygems_version: 2.6.13
|
173
173
|
signing_key:
|
174
174
|
specification_version: 4
|
175
175
|
summary: VirtusModel = Virtus + ActiveModel
|