dry-view 0.5.1 → 0.5.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: 3b7142689536853b1e216512d00558c4edbaafe44ee3abc2d1e51eb1ad498bc1
4
- data.tar.gz: 6373160c6fa073a52c9fa106b6f1c8ac0b58c088bbce26e29b4b65ff587dad27
3
+ metadata.gz: d739724ab980eb210e9f651c78b3cbdf59e28c597e149b05d936f49a89f9d74f
4
+ data.tar.gz: 23604cb777111c1711b09fd1da0b98f18840872d6c03f6867257eb42b3b3d755
5
5
  SHA512:
6
- metadata.gz: 0eaccf27fc9d7f29a8b3be6e9b695341738e67d98b132630d8ec6bc462683bdcfa4613ed59c00a8d3791f93789f4a5c437ee6dd2b66c5c893d52e537a3a93f51
7
- data.tar.gz: a6b0bb154f5056de7b1bf6ca21d78e7ad9e1453dcc64d438d7f435e6285f236e0627d55838ba020bdf68749a4a1da577b6dc1e2cacc9e8b8993ba553d99a797d
6
+ metadata.gz: 5e66915108ff44c6e164459e30d3bcff67324b50dbd52bd853e1802bcbbefe824b440fc5e6e018033778f5d80717b8b61da1eaaf50071cad6ec9f3da154b15f8
7
+ data.tar.gz: c587910c53a1d229533740204875a99b480e232b8a8fb397775dc234d33cdda60b42095800ba7c16d3c4d181a64d9f7bab909e202684f7d8e192222a7d9cb650
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # 0.5.2 / 2018-06-13
2
+
3
+ ### Changed
4
+
5
+ - Only truthy view part attributes are decorated (timriley)
6
+
7
+ [Compare v0.5.0...v0.5.1](https://github.com/dry-rb/dry-view/compare/v0.5.1...v0.5.2)
8
+
1
9
  # 0.5.1 / 2018-02-20
2
10
 
3
11
  ### Added
data/lib/dry/view/part.rb CHANGED
@@ -90,13 +90,18 @@ module Dry
90
90
 
91
91
  def _resolve_decorated_attribute(name)
92
92
  _decorated_attributes.fetch(name) {
93
- _decorated_attributes[name] = _decorator.(
94
- name,
95
- _value.__send__(name),
96
- renderer: _renderer,
97
- context: _context,
98
- **self.class.decorated_attributes[name],
99
- )
93
+ attribute = _value.__send__(name)
94
+
95
+ _decorated_attributes[name] =
96
+ if attribute # Decorate truthy attributes only
97
+ _decorator.(
98
+ name,
99
+ attribute,
100
+ renderer: _renderer,
101
+ context: _context,
102
+ **self.class.decorated_attributes[name],
103
+ )
104
+ end
100
105
  }
101
106
  end
102
107
  end
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  module View
3
- VERSION = '0.5.1'.freeze
3
+ VERSION = '0.5.2'.freeze
4
4
  end
5
5
  end
@@ -32,10 +32,14 @@ RSpec.describe 'Part / Decorated attributes' do
32
32
  end
33
33
  }
34
34
 
35
+ let (:author) {
36
+ author_class.new(name: 'Jane Doe')
37
+ }
38
+
35
39
  let(:article) {
36
40
  article_class.new(
37
41
  title: 'Hello world',
38
- author: author_class.new(name: 'Jane Doe'),
42
+ author: author,
39
43
  comments: [
40
44
  comment_class.new(author: author_class.new(name: 'Sue Smith'), body: 'Great article')
41
45
  ]
@@ -59,10 +63,18 @@ RSpec.describe 'Part / Decorated attributes' do
59
63
  end
60
64
  }
61
65
 
62
- it 'decorates exposures with the standard Dry::View::Part class' do
66
+ it 'decorates attributes with the standard Dry::View::Part class' do
63
67
  expect(article_part.author).to be_a Dry::View::Part
64
68
  expect(article_part.comments[0]).to be_a Dry::View::Part
65
69
  end
70
+
71
+ context 'falsey values' do
72
+ let(:author) { nil }
73
+
74
+ it 'does not decorate the attributes' do
75
+ expect(article_part.author).to be_nil
76
+ end
77
+ end
66
78
  end
67
79
 
68
80
  describe 'single declaration' do
@@ -72,10 +84,18 @@ RSpec.describe 'Part / Decorated attributes' do
72
84
  end
73
85
  }
74
86
 
75
- it 'decorates exposures with the standard Dry::View::Part class' do
87
+ it 'decorates attributes with the standard Dry::View::Part class' do
76
88
  expect(article_part.author).to be_a Dry::View::Part
77
89
  expect(article_part.comments[0]).to be_a Dry::View::Part
78
90
  end
91
+
92
+ context 'falsey values' do
93
+ let(:author) { nil }
94
+
95
+ it 'does not decorate the attributes' do
96
+ expect(article_part.author).to be_nil
97
+ end
98
+ end
79
99
  end
80
100
  end
81
101
 
@@ -97,10 +117,18 @@ RSpec.describe 'Part / Decorated attributes' do
97
117
  end
98
118
  }
99
119
 
100
- it 'deorates exposures with the specified part class' do
120
+ it 'deorates attributes with the specified part class' do
101
121
  expect(article_part.author).to be_a Test::AuthorPart
102
122
  expect(article_part.comments[0]).to be_a Test::CommentPart
103
123
  end
124
+
125
+ context 'falsey values' do
126
+ let(:author) { nil }
127
+
128
+ it 'does not decorate the attributes' do
129
+ expect(article_part.author).to be_nil
130
+ end
131
+ end
104
132
  end
105
133
  end
106
134
 
@@ -148,10 +176,18 @@ RSpec.describe 'Part / Decorated attributes' do
148
176
  end
149
177
  end
150
178
 
151
- it 'deorates exposures using the custom decorator' do
179
+ it 'deorates attributes using the custom decorator' do
152
180
  expect(article_part.author).to be_a Test::AuthorPart
153
181
  expect(article_part.comments[0]).to be_a Test::CommentPart
154
182
  expect(article_part.comments[0].author).to be_a Test::AuthorPart
155
183
  end
184
+
185
+ context 'falsey values' do
186
+ let(:author) { nil }
187
+
188
+ it 'does not decorate the attributes' do
189
+ expect(article_part.author).to be_nil
190
+ end
191
+ end
156
192
  end
157
193
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-view
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-02-19 00:00:00.000000000 Z
12
+ date: 2018-06-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: tilt