inertia_builder 0.2.0 → 0.2.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 +4 -4
- data/lib/inertia_builder/version.rb +1 -1
- data/lib/inertia_builder.rb +7 -3
- data/test/inertia_builder_test.rb +50 -14
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2db7cf7bc04f52285ccfb06231fcb67cca0038b80140b84ec314f2cf9f1196b
|
4
|
+
data.tar.gz: '02989fb26e14f25cbfe80ca52559813137c7cbf67c9983afed7f0cb23ad59451'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: faf2b72091c7fecc1c74f51b91e3a1e2237e8878d61777b8b6f5ed9505185c8a81c5cca058b0fcc470f42d98014783cd6b28a5494125a76df4525cbaac82b537
|
7
|
+
data.tar.gz: 359cfcca048b25bde18ac719f9a2a3dbccb02d1081d5c3886b424afcab8ef202d3d4997323640490ab3b63d1c48fa0806da861fa13dda60c7195442c3aa05d85
|
data/lib/inertia_builder.rb
CHANGED
@@ -66,15 +66,19 @@ module InertiaBuilder
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def _scope
|
69
|
+
has_parent_scope = @in_scope
|
69
70
|
@in_scope = true
|
70
71
|
super
|
71
72
|
ensure
|
72
|
-
@in_scope = false
|
73
|
+
@in_scope = false unless has_parent_scope
|
73
74
|
end
|
74
75
|
|
75
76
|
def _merge_values(current_value, updates)
|
76
|
-
# Always override lazy evaluation procs.
|
77
|
-
if current_value.is_a?(::Proc)
|
77
|
+
# Always override lazy evaluation procs. For the other special prop types, InertiaRails already handles merging.
|
78
|
+
if current_value.is_a?(::Proc) ||
|
79
|
+
current_value.is_a?(::InertiaRails::OptionalProp) ||
|
80
|
+
current_value.is_a?(::InertiaRails::AlwaysProp) ||
|
81
|
+
current_value.is_a?(::InertiaRails::DeferProp)
|
78
82
|
updates
|
79
83
|
else
|
80
84
|
super
|
@@ -8,6 +8,11 @@ class User < Struct.new(:id, :first_name, :last_name, :email)
|
|
8
8
|
include ActiveModel::Conversion
|
9
9
|
end
|
10
10
|
|
11
|
+
class Item < Struct.new(:id, :title)
|
12
|
+
extend ActiveModel::Naming
|
13
|
+
include ActiveModel::Conversion
|
14
|
+
end
|
15
|
+
|
11
16
|
class InertiaBuilderTest < Minitest::Test
|
12
17
|
USER_PARTIAL = <<~INERTIA
|
13
18
|
prop.id user.id
|
@@ -16,8 +21,14 @@ class InertiaBuilderTest < Minitest::Test
|
|
16
21
|
prop.email user.email
|
17
22
|
INERTIA
|
18
23
|
|
24
|
+
ITEM_PARTIAL = <<~INERTIA
|
25
|
+
prop.id item.id
|
26
|
+
prop.title item.title
|
27
|
+
INERTIA
|
28
|
+
|
19
29
|
PARTIALS = {
|
20
|
-
'users/_user.html.inertia' => USER_PARTIAL
|
30
|
+
'users/_user.html.inertia' => USER_PARTIAL,
|
31
|
+
'items/_item.html.inertia' => ITEM_PARTIAL
|
21
32
|
}
|
22
33
|
|
23
34
|
def test_basic_html_rendering
|
@@ -119,12 +130,23 @@ class InertiaBuilderTest < Minitest::Test
|
|
119
130
|
User.new({ id: 43, first_name: 'Jane', last_name: 'Smith', email: 'jane@email.com' })
|
120
131
|
]
|
121
132
|
|
122
|
-
|
133
|
+
items = [
|
134
|
+
Item.new({ id: 1, title: 'Item 1' }),
|
135
|
+
Item.new({ id: 2, title: 'Item 2' })
|
136
|
+
]
|
123
137
|
|
124
|
-
|
138
|
+
template = <<~INERTIA
|
139
|
+
prop.data do
|
140
|
+
prop.users @users, partial: 'users/user', as: :user
|
141
|
+
prop.items @items, partial: 'items/item', as: :item
|
142
|
+
end
|
143
|
+
INERTIA
|
125
144
|
|
126
|
-
|
127
|
-
|
145
|
+
expected_props = { data: { users: users, items: items } }
|
146
|
+
|
147
|
+
assert_equal inertia_json_with_props(expected_props),
|
148
|
+
render_view(template, assigns: { users: users, items: items }, json: true)
|
149
|
+
assert_equal inertia_html_with_props(expected_props), render_view(template, assigns: { users: users, items: items })
|
128
150
|
end
|
129
151
|
|
130
152
|
def test_nil_prop_block
|
@@ -144,7 +166,10 @@ class InertiaBuilderTest < Minitest::Test
|
|
144
166
|
template = <<~INERTIA
|
145
167
|
prop.id 1
|
146
168
|
prop.optional! do
|
147
|
-
prop.user
|
169
|
+
prop.user do
|
170
|
+
prop.id 1
|
171
|
+
prop.email 'user@email.com'
|
172
|
+
end
|
148
173
|
prop.calculation 'Calculation'
|
149
174
|
end
|
150
175
|
INERTIA
|
@@ -154,7 +179,7 @@ class InertiaBuilderTest < Minitest::Test
|
|
154
179
|
'X-Inertia-Partial-Component' => '/'
|
155
180
|
}
|
156
181
|
assert_equal inertia_json_with_props({ id: 1 }), render_view(template, json: true)
|
157
|
-
assert_equal inertia_json_with_props({ user: '
|
182
|
+
assert_equal inertia_json_with_props({ user: { id: 1, email: 'user@email.com' }, calculation: 'Calculation' }),
|
158
183
|
render_view(template, json: true, headers: partial_headers)
|
159
184
|
end
|
160
185
|
|
@@ -162,7 +187,10 @@ class InertiaBuilderTest < Minitest::Test
|
|
162
187
|
template = <<~INERTIA
|
163
188
|
prop.id 1
|
164
189
|
prop.always! do
|
165
|
-
prop.user
|
190
|
+
prop.user do
|
191
|
+
prop.id 1
|
192
|
+
prop.email 'user@email.com'
|
193
|
+
end
|
166
194
|
end
|
167
195
|
prop.optional! do
|
168
196
|
prop.calculation 'Calculation'
|
@@ -173,8 +201,9 @@ class InertiaBuilderTest < Minitest::Test
|
|
173
201
|
'X-Inertia-Partial-Data' => 'calculation',
|
174
202
|
'X-Inertia-Partial-Component' => '/'
|
175
203
|
}
|
176
|
-
assert_equal inertia_json_with_props({ id: 1, user:
|
177
|
-
|
204
|
+
assert_equal inertia_json_with_props({ id: 1, user: { id: 1, email: 'user@email.com' } }),
|
205
|
+
render_view(template, json: true)
|
206
|
+
assert_equal inertia_json_with_props({ user: { id: 1, email: 'user@email.com' }, calculation: 'Calculation' }),
|
178
207
|
render_view(template, json: true, headers: partial_headers)
|
179
208
|
end
|
180
209
|
|
@@ -182,7 +211,10 @@ class InertiaBuilderTest < Minitest::Test
|
|
182
211
|
template = <<~INERTIA
|
183
212
|
prop.id 1
|
184
213
|
prop.defer! do
|
185
|
-
prop.user
|
214
|
+
prop.user do
|
215
|
+
prop.id 1
|
216
|
+
prop.email 'user@email.com'
|
217
|
+
end
|
186
218
|
prop.calculation 'Calculation'
|
187
219
|
end
|
188
220
|
INERTIA
|
@@ -207,10 +239,14 @@ class InertiaBuilderTest < Minitest::Test
|
|
207
239
|
end
|
208
240
|
|
209
241
|
def test_defer_block_fetching
|
242
|
+
user = User.new({ id: 1, email: 'user@email.com' })
|
243
|
+
|
210
244
|
template = <<~INERTIA
|
211
245
|
prop.id 1
|
212
246
|
prop.defer! do
|
213
|
-
prop.user
|
247
|
+
prop.user do
|
248
|
+
prop.partial! @user
|
249
|
+
end
|
214
250
|
prop.calculation 'Calculation'
|
215
251
|
end
|
216
252
|
INERTIA
|
@@ -220,8 +256,8 @@ class InertiaBuilderTest < Minitest::Test
|
|
220
256
|
'X-Inertia-Partial-Component' => '/'
|
221
257
|
}
|
222
258
|
|
223
|
-
assert_equal inertia_json_with_props({ user:
|
224
|
-
render_view(template, json: true, headers: partial_headers)
|
259
|
+
assert_equal inertia_json_with_props({ user: user, calculation: 'Calculation' }),
|
260
|
+
render_view(template, assigns: { user: user }, json: true, headers: partial_headers)
|
225
261
|
end
|
226
262
|
|
227
263
|
private
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inertia_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Lima
|
@@ -70,8 +70,8 @@ licenses:
|
|
70
70
|
- MIT
|
71
71
|
metadata:
|
72
72
|
bug_tracker_uri: https://github.com/rodrigotavio91/inertia-builder/issues
|
73
|
-
changelog_uri: https://github.com/rodrigotavio91/inertia-builder/releases/tag/v0.2.
|
74
|
-
source_code_uri: https://github.com/rodrigotavio91/inertia-builder/tree/v0.2.
|
73
|
+
changelog_uri: https://github.com/rodrigotavio91/inertia-builder/releases/tag/v0.2.1
|
74
|
+
source_code_uri: https://github.com/rodrigotavio91/inertia-builder/tree/v0.2.1
|
75
75
|
rubygems_mfa_required: 'true'
|
76
76
|
rdoc_options: []
|
77
77
|
require_paths:
|