breezy_template 0.11.0 → 0.12.0
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/breezy_template.rb +5 -30
- data/lib/breezy_template/digestor.rb +4 -22
- data/lib/breezy_template/handler.rb +2 -1
- data/test/cache_extension_test.rb +51 -64
- data/test/deferement_test.rb +29 -38
- data/test/dependency_tracker_test.rb +7 -7
- data/test/extensions_test.rb +14 -14
- data/test/partial_extension_test.rb +27 -27
- data/test/search_extension_test.rb +42 -30
- data/test/test_helper.rb +43 -61
- metadata +14 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '098563fc3e08c7eaa01b1dc73cb551ebf4ff8cf7'
|
4
|
+
data.tar.gz: cecb85dfa8df05ba1b4696023382842d55fc767a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86749c4dcba84969e0c6171250eb37df44a9b8840e09bbf2d15af538bdc473cf824935f7eaae52b80163552bec2166b61300c615598af39092834b6d9ecfc4b1
|
7
|
+
data.tar.gz: 7b5ab237cba0e99707fe76fd6a5ad069dd1ee186cc85101a3557e67577c9f57acdaf613627356abfac2421864971518c335f12b5c79fa21e8ca2b1887eeb7fcc
|
data/lib/breezy_template.rb
CHANGED
@@ -17,7 +17,7 @@ require 'breezy_template/search_extension'
|
|
17
17
|
require 'digest/md5'
|
18
18
|
require 'action_view'
|
19
19
|
require 'active_support'
|
20
|
-
require '
|
20
|
+
require 'json'
|
21
21
|
require 'ostruct'
|
22
22
|
|
23
23
|
class BreezyTemplate
|
@@ -49,7 +49,7 @@ class BreezyTemplate
|
|
49
49
|
yield self if ::Kernel.block_given?
|
50
50
|
end
|
51
51
|
|
52
|
-
|
52
|
+
# Yields a builder and automatically turns the result into a JSON string
|
53
53
|
def self.encode(*args, &block)
|
54
54
|
new(*args, &block).target!
|
55
55
|
end
|
@@ -63,13 +63,8 @@ class BreezyTemplate
|
|
63
63
|
else
|
64
64
|
if _is_collection?(value) && !args.last.is_a?(::Hash)
|
65
65
|
_scope{ array! value, *args }
|
66
|
-
# elsif args.empty?
|
67
|
-
# _result(value, *args)
|
68
|
-
# elsif !args.last.is_a? ::Hash
|
69
|
-
# _merge_block(key){ extract! value, *args }
|
70
66
|
else
|
71
67
|
_result(value, *args)
|
72
|
-
# value
|
73
68
|
end
|
74
69
|
end
|
75
70
|
|
@@ -144,7 +139,7 @@ class BreezyTemplate
|
|
144
139
|
collection.to_a
|
145
140
|
end
|
146
141
|
|
147
|
-
merge! array
|
142
|
+
merge! array
|
148
143
|
end
|
149
144
|
|
150
145
|
def extract!(object, *attributes)
|
@@ -155,14 +150,6 @@ class BreezyTemplate
|
|
155
150
|
end
|
156
151
|
end
|
157
152
|
|
158
|
-
# def call(object, *attributes)
|
159
|
-
# if ::Kernel.block_given?
|
160
|
-
# array! object, &::Proc.new
|
161
|
-
# else
|
162
|
-
# extract! object, *attributes
|
163
|
-
# end
|
164
|
-
# end
|
165
|
-
|
166
153
|
# Returns the nil JSON.
|
167
154
|
def nil!
|
168
155
|
@attributes = nil
|
@@ -276,10 +263,8 @@ class BreezyTemplate
|
|
276
263
|
end
|
277
264
|
|
278
265
|
def _args_for_set_with_block(*args)
|
279
|
-
# return args
|
280
266
|
key = args[0]
|
281
|
-
|
282
|
-
# #
|
267
|
+
|
283
268
|
if ::Hash === args[1] && _extended_options?(args[1])
|
284
269
|
options = args[1]
|
285
270
|
[key, BLANK, options]
|
@@ -290,16 +275,6 @@ class BreezyTemplate
|
|
290
275
|
|
291
276
|
def _args_for_set(*args)
|
292
277
|
return args
|
293
|
-
# if args.length >= 3
|
294
|
-
# return args
|
295
|
-
# # key, value, options = args
|
296
|
-
# #
|
297
|
-
# # [key, value, options]
|
298
|
-
# else
|
299
|
-
# key, value = args
|
300
|
-
#
|
301
|
-
# [key, value]
|
302
|
-
# end
|
303
278
|
end
|
304
279
|
|
305
280
|
def _extended_options?(value)
|
@@ -311,7 +286,7 @@ class BreezyTemplate
|
|
311
286
|
end
|
312
287
|
|
313
288
|
def _dump(value)
|
314
|
-
::
|
289
|
+
::JSON.dump(value)
|
315
290
|
end
|
316
291
|
|
317
292
|
def _logger
|
@@ -4,28 +4,10 @@ require 'action_view/digestor'
|
|
4
4
|
|
5
5
|
class BreezyTemplate
|
6
6
|
module PartialDigestor
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
::ActionView::Digestor.digest(name: name, finder: finder)
|
12
|
-
end
|
13
|
-
elsif ::Rails.version >= '4.1'
|
14
|
-
def _partial_digestor(options)
|
15
|
-
name = options[:name]
|
16
|
-
finder = options[:finder]
|
17
|
-
::ActionView::PartialDigestor.new(name: name, finder: finder).digest
|
18
|
-
end
|
19
|
-
elsif ::Rails.version >= '4.0'
|
20
|
-
def _partial_digestor(options={})
|
21
|
-
name = options[:name]
|
22
|
-
finder = options[:finder]
|
23
|
-
::ActionView::PartialDigestor.new(name, finder.formats.last, finder).digest
|
24
|
-
end
|
25
|
-
else
|
26
|
-
def _partial_digestor(options)
|
27
|
-
options[:name]
|
28
|
-
end
|
7
|
+
def _partial_digestor(options)
|
8
|
+
name = options[:name]
|
9
|
+
finder = options[:finder]
|
10
|
+
::ActionView::Digestor.digest(name: name, finder: finder)
|
29
11
|
end
|
30
12
|
end
|
31
13
|
end
|
@@ -9,7 +9,8 @@ class BreezyTemplate
|
|
9
9
|
template.identifier.sub("#{Rails.root}/app/views/", "").split('.')[0]
|
10
10
|
end
|
11
11
|
|
12
|
-
def self.call(template)
|
12
|
+
def self.call(template, source = nil)
|
13
|
+
|
13
14
|
# this juggling is required to keep line numbers right in the error
|
14
15
|
%{__already_defined = defined?(json);json||=::BreezyTemplate.new(self);json._set_search_path_once(breezy_filter) if defined?(breezy_filter); json._set_request_url_once(request.fullpath);#{template.source}
|
15
16
|
if !(__already_defined && __already_defined != "method")
|
@@ -3,16 +3,14 @@ require "test_helper"
|
|
3
3
|
|
4
4
|
class CacheExtensionTest < BreezyTemplateTestCase
|
5
5
|
test "caching a value at a node" do
|
6
|
-
|
7
|
-
|
8
|
-
result = jbuild(<<-JBUILDER)
|
6
|
+
result = jbuild(<<~JBUILDER)
|
9
7
|
opts = {
|
10
8
|
cache: [['b', 'c']]
|
11
9
|
}
|
12
10
|
json.hello 32, opts
|
13
11
|
JBUILDER
|
14
12
|
|
15
|
-
expected = strip_format(
|
13
|
+
expected = strip_format(<<~JS)
|
16
14
|
(function(){
|
17
15
|
var fragments={};
|
18
16
|
var lastFragmentName;
|
@@ -28,9 +26,7 @@ class CacheExtensionTest < BreezyTemplateTestCase
|
|
28
26
|
end
|
29
27
|
|
30
28
|
test "caching elements in a list" do
|
31
|
-
|
32
|
-
|
33
|
-
result = jbuild(<<-JBUILDER)
|
29
|
+
result = jbuild(<<~JBUILDER)
|
34
30
|
json.hello do
|
35
31
|
opts = {
|
36
32
|
cache: ->(i){ ['a', i] }
|
@@ -41,7 +37,7 @@ class CacheExtensionTest < BreezyTemplateTestCase
|
|
41
37
|
end
|
42
38
|
JBUILDER
|
43
39
|
|
44
|
-
expected = strip_format(
|
40
|
+
expected = strip_format(<<~JS)
|
45
41
|
(function(){
|
46
42
|
var fragments={};
|
47
43
|
var lastFragmentName;
|
@@ -58,9 +54,7 @@ class CacheExtensionTest < BreezyTemplateTestCase
|
|
58
54
|
end
|
59
55
|
|
60
56
|
test "nested caching generates a depth-first list of cache nodes" do
|
61
|
-
|
62
|
-
|
63
|
-
result = jbuild(<<-JBUILDER)
|
57
|
+
result = jbuild(<<~JBUILDER)
|
64
58
|
json.hello cache: [['a', 'b']] do
|
65
59
|
json.content cache: [['d', 'z']] do
|
66
60
|
json.subcontent 'inner'
|
@@ -71,7 +65,7 @@ class CacheExtensionTest < BreezyTemplateTestCase
|
|
71
65
|
end
|
72
66
|
JBUILDER
|
73
67
|
|
74
|
-
expected = strip_format(
|
68
|
+
expected = strip_format(<<~JS)
|
75
69
|
(function(){
|
76
70
|
var fragments={};
|
77
71
|
var lastFragmentName;
|
@@ -89,20 +83,18 @@ class CacheExtensionTest < BreezyTemplateTestCase
|
|
89
83
|
end
|
90
84
|
|
91
85
|
test "caching an empty block generates no cache and no errors" do
|
92
|
-
undef_context_methods :fragment_name_with_digest, :cache_fragment_name
|
93
|
-
|
94
86
|
result = nil
|
95
87
|
|
96
88
|
assert_nothing_raised do
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
end
|
89
|
+
result = jbuild(<<~JBUILDER)
|
90
|
+
json.hello do
|
91
|
+
json.array! [4,5], cache: ->(i){['a', i]} do |x|
|
101
92
|
end
|
102
|
-
|
93
|
+
end
|
94
|
+
JBUILDER
|
103
95
|
end
|
104
96
|
|
105
|
-
expected = strip_format(
|
97
|
+
expected = strip_format(<<~JS)
|
106
98
|
(function(){
|
107
99
|
var fragments={};
|
108
100
|
var lastFragmentName;
|
@@ -117,23 +109,21 @@ class CacheExtensionTest < BreezyTemplateTestCase
|
|
117
109
|
end
|
118
110
|
|
119
111
|
test "fragment caching" do
|
120
|
-
|
121
|
-
|
122
|
-
jbuild(<<-JBUILDER)
|
112
|
+
jbuild(<<~JBUILDER)
|
123
113
|
opts = {cache: ['cachekey']}
|
124
114
|
json.post opts do
|
125
115
|
json.name "Cache"
|
126
116
|
end
|
127
117
|
JBUILDER
|
128
118
|
|
129
|
-
result = jbuild(
|
119
|
+
result = jbuild(<<~JBUILDER)
|
130
120
|
opts = {cache: ['cachekey']}
|
131
121
|
json.post opts do
|
132
122
|
json.name "Miss"
|
133
123
|
end
|
134
124
|
JBUILDER
|
135
125
|
|
136
|
-
expected = strip_format(
|
126
|
+
expected = strip_format(<<~JS)
|
137
127
|
(function(){
|
138
128
|
var fragments={};
|
139
129
|
var lastFragmentName;
|
@@ -149,15 +139,13 @@ class CacheExtensionTest < BreezyTemplateTestCase
|
|
149
139
|
end
|
150
140
|
|
151
141
|
test "fragment caching deserializes an array" do
|
152
|
-
|
153
|
-
|
154
|
-
result = jbuild <<-JBUILDER
|
142
|
+
result = jbuild <<~JBUILDER
|
155
143
|
json.content cache: "cachekey" do
|
156
144
|
json.array! %w[a b c]
|
157
145
|
end
|
158
146
|
JBUILDER
|
159
147
|
|
160
|
-
expected = strip_format(
|
148
|
+
expected = strip_format(<<~JS)
|
161
149
|
(function(){
|
162
150
|
var fragments={};
|
163
151
|
var lastFragmentName;
|
@@ -173,47 +161,47 @@ class CacheExtensionTest < BreezyTemplateTestCase
|
|
173
161
|
end
|
174
162
|
|
175
163
|
test "fragment caching works with previous version of cache digests" do
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
def fragment_name_with_digest
|
181
|
-
end
|
182
|
-
end
|
164
|
+
method_was_called = false
|
165
|
+
@view.define_singleton_method(:fragment_name_with_digest) do |key|
|
166
|
+
method_was_called = true
|
167
|
+
key
|
183
168
|
end
|
184
169
|
|
185
|
-
|
186
|
-
|
187
|
-
jbuild <<-JBUILDER
|
170
|
+
jbuild <<~JBUILDER
|
188
171
|
json.content cache: 'cachekey' do
|
189
172
|
json.name "Cache"
|
190
173
|
end
|
191
174
|
JBUILDER
|
175
|
+
|
176
|
+
assert_equal method_was_called, true
|
192
177
|
end
|
193
178
|
|
194
179
|
test "fragment caching works with current cache digests" do
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
180
|
+
method_was_called = false
|
181
|
+
@view.define_singleton_method(:cache_fragment_name) do |key, options|
|
182
|
+
method_was_called = true
|
183
|
+
key
|
184
|
+
end
|
199
185
|
|
200
|
-
jbuild
|
186
|
+
jbuild <<~JBUILDER
|
201
187
|
json.content cache: 'cachekey' do
|
202
188
|
json.name "Cache"
|
203
189
|
end
|
204
190
|
JBUILDER
|
191
|
+
|
192
|
+
assert_equal method_was_called, true
|
205
193
|
end
|
206
194
|
|
207
195
|
test "does not perform caching when controller.perform_caching is false" do
|
208
|
-
controller.perform_caching = false
|
196
|
+
@controller.perform_caching = false
|
209
197
|
|
210
|
-
result = jbuild
|
198
|
+
result = jbuild(<<~JBUILDER, disable_caching: true)
|
211
199
|
json.content cache: 'cachekey' do
|
212
200
|
json.name "Cache"
|
213
201
|
end
|
214
202
|
JBUILDER
|
215
203
|
|
216
|
-
expected = strip_format(
|
204
|
+
expected = strip_format(<<~JS)
|
217
205
|
(function(){
|
218
206
|
var fragments={};
|
219
207
|
var lastFragmentName;
|
@@ -228,20 +216,22 @@ class CacheExtensionTest < BreezyTemplateTestCase
|
|
228
216
|
end
|
229
217
|
|
230
218
|
test "caches and runs a partial exactly once" do
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
219
|
+
assert_nothing_raised do
|
220
|
+
jbuild(<<~JBUILDER)
|
221
|
+
json.hit nil, partial: ["raise_if_used", locals: {used: false}], cache: 'once'
|
222
|
+
json.miss nil, partial: ["raise_if_used", locals: {used: true}], cache: 'once'
|
223
|
+
JBUILDER
|
224
|
+
end
|
235
225
|
end
|
236
226
|
|
237
227
|
test "invokes templates via params via set! and caches" do
|
238
|
-
|
228
|
+
post = BLOG_POST_COLLECTION.first
|
239
229
|
|
240
|
-
result = jbuild(
|
230
|
+
result = jbuild(<<~JBUILDER, assigns: {post: post})
|
241
231
|
json.post @post, partial: ["blog_post", as: :blog_post], cache: [['a', 'b']]
|
242
232
|
JBUILDER
|
243
233
|
|
244
|
-
expected = strip_format(
|
234
|
+
expected = strip_format(<<~JS)
|
245
235
|
(function(){
|
246
236
|
var fragments={};
|
247
237
|
var lastFragmentName;
|
@@ -257,12 +247,10 @@ class CacheExtensionTest < BreezyTemplateTestCase
|
|
257
247
|
end
|
258
248
|
|
259
249
|
test "shares partial caches (via the partial's digest) across multiple templates" do
|
260
|
-
|
250
|
+
hit = BlogPost.new(1, "hit", "John Smith")
|
251
|
+
miss = BlogPost.new(2, "miss", "John Smith")
|
261
252
|
|
262
|
-
|
263
|
-
@miss = BlogPost.new(2, "miss", "John Smith")
|
264
|
-
|
265
|
-
cat = jbuild(<<-JBUILDER)
|
253
|
+
cat = jbuild(<<~JBUILDER, assigns: {hit: hit})
|
266
254
|
opts = {
|
267
255
|
cache: [['a', 'b']],
|
268
256
|
partial: ["blog_post", as: :blog_post]
|
@@ -271,7 +259,7 @@ class CacheExtensionTest < BreezyTemplateTestCase
|
|
271
259
|
json.post @hit, opts
|
272
260
|
JBUILDER
|
273
261
|
|
274
|
-
result = jbuild(
|
262
|
+
result = jbuild(<<~JBUILDER, assigns: {miss: miss})
|
275
263
|
opts = {
|
276
264
|
cache: [['a', 'b']],
|
277
265
|
partial: ["blog_post", as: :blog_post]
|
@@ -280,7 +268,7 @@ class CacheExtensionTest < BreezyTemplateTestCase
|
|
280
268
|
json.post @miss, opts
|
281
269
|
JBUILDER
|
282
270
|
|
283
|
-
expected = strip_format(
|
271
|
+
expected = strip_format(<<~JS)
|
284
272
|
(function(){
|
285
273
|
var fragments={};
|
286
274
|
var lastFragmentName;
|
@@ -295,9 +283,8 @@ class CacheExtensionTest < BreezyTemplateTestCase
|
|
295
283
|
assert_equal expected, result
|
296
284
|
end
|
297
285
|
|
298
|
-
|
299
286
|
test "render array of partials and caches" do
|
300
|
-
result = jbuild(
|
287
|
+
result = jbuild(<<~JBUILDER)
|
301
288
|
opts = {
|
302
289
|
cache: (->(d){ ['a', d.id] }),
|
303
290
|
partial: ["blog_post", as: :blog_post]
|
@@ -306,7 +293,7 @@ class CacheExtensionTest < BreezyTemplateTestCase
|
|
306
293
|
JBUILDER
|
307
294
|
Rails.cache.clear
|
308
295
|
|
309
|
-
expected = strip_format(
|
296
|
+
expected = strip_format(<<~JS)
|
310
297
|
(function(){
|
311
298
|
var fragments={};
|
312
299
|
var lastFragmentName;
|
data/test/deferement_test.rb
CHANGED
@@ -2,10 +2,9 @@ require "test_helper"
|
|
2
2
|
|
3
3
|
class DefermentExtensionTest < BreezyTemplateTestCase
|
4
4
|
test "rendering with node deferement" do
|
5
|
-
|
6
|
-
req.path = '/some_url'
|
5
|
+
@controller.request.path = '/some_url'
|
7
6
|
|
8
|
-
result = jbuild(
|
7
|
+
result = jbuild(<<~JBUILDER)
|
9
8
|
json.hit do
|
10
9
|
json.hit2(defer: :auto)do
|
11
10
|
json.hit3 do
|
@@ -16,7 +15,7 @@ class DefermentExtensionTest < BreezyTemplateTestCase
|
|
16
15
|
JBUILDER
|
17
16
|
Rails.cache.clear
|
18
17
|
|
19
|
-
expected = strip_format(
|
18
|
+
expected = strip_format(<<~JS)
|
20
19
|
(function(){
|
21
20
|
var fragments={};
|
22
21
|
var lastFragmentName;
|
@@ -34,10 +33,9 @@ class DefermentExtensionTest < BreezyTemplateTestCase
|
|
34
33
|
end
|
35
34
|
|
36
35
|
test "rendering with manual node deferement" do
|
37
|
-
|
38
|
-
req.path = '/some_url'
|
36
|
+
@controller.request.path = '/some_url'
|
39
37
|
|
40
|
-
result = jbuild(
|
38
|
+
result = jbuild(<<~JBUILDER)
|
41
39
|
json.hit do
|
42
40
|
json.hit2 defer: :manual do
|
43
41
|
json.hit3 do
|
@@ -48,7 +46,7 @@ class DefermentExtensionTest < BreezyTemplateTestCase
|
|
48
46
|
JBUILDER
|
49
47
|
Rails.cache.clear
|
50
48
|
|
51
|
-
expected = strip_format(
|
49
|
+
expected = strip_format(<<~JS)
|
52
50
|
(function(){
|
53
51
|
var fragments={};
|
54
52
|
var lastFragmentName;
|
@@ -65,10 +63,9 @@ class DefermentExtensionTest < BreezyTemplateTestCase
|
|
65
63
|
end
|
66
64
|
|
67
65
|
test "rendering with selective array node deferment" do
|
68
|
-
|
69
|
-
req.path = '/some_url'
|
66
|
+
@controller.request.path = '/some_url'
|
70
67
|
|
71
|
-
result = jbuild(
|
68
|
+
result = jbuild(<<~JBUILDER)
|
72
69
|
keep_first = lambda do |item|
|
73
70
|
if item[:id] == 1
|
74
71
|
false
|
@@ -88,7 +85,7 @@ class DefermentExtensionTest < BreezyTemplateTestCase
|
|
88
85
|
JBUILDER
|
89
86
|
Rails.cache.clear
|
90
87
|
|
91
|
-
expected = strip_format(
|
88
|
+
expected = strip_format(<<~JS)
|
92
89
|
(function(){
|
93
90
|
var fragments={};
|
94
91
|
var lastFragmentName;
|
@@ -106,10 +103,9 @@ class DefermentExtensionTest < BreezyTemplateTestCase
|
|
106
103
|
end
|
107
104
|
|
108
105
|
test "rendering with node array partial deferment" do
|
109
|
-
|
110
|
-
req.path = '/some_url'
|
106
|
+
@controller.request.path = '/some_url'
|
111
107
|
|
112
|
-
result = jbuild(
|
108
|
+
result = jbuild(<<~JBUILDER)
|
113
109
|
keep_first = lambda do |item|
|
114
110
|
if item[:id] == 1
|
115
111
|
false
|
@@ -127,7 +123,7 @@ class DefermentExtensionTest < BreezyTemplateTestCase
|
|
127
123
|
JBUILDER
|
128
124
|
Rails.cache.clear
|
129
125
|
|
130
|
-
expected = strip_format(
|
126
|
+
expected = strip_format(<<~JS)
|
131
127
|
(function(){
|
132
128
|
var fragments={};
|
133
129
|
var lastFragmentName;
|
@@ -145,10 +141,9 @@ class DefermentExtensionTest < BreezyTemplateTestCase
|
|
145
141
|
end
|
146
142
|
|
147
143
|
test "rendering with node array deferment" do
|
148
|
-
|
149
|
-
req.path = '/some_url'
|
144
|
+
@controller.request.path = '/some_url'
|
150
145
|
|
151
|
-
result = jbuild(
|
146
|
+
result = jbuild(<<~JBUILDER)
|
152
147
|
json.hit do
|
153
148
|
json.hit2 do
|
154
149
|
data = [{id: 1, name: 'foo'}, {id: 2, name: 'bar'}]
|
@@ -160,7 +155,7 @@ class DefermentExtensionTest < BreezyTemplateTestCase
|
|
160
155
|
JBUILDER
|
161
156
|
Rails.cache.clear
|
162
157
|
|
163
|
-
expected = strip_format(
|
158
|
+
expected = strip_format(<<~JS)
|
164
159
|
(function(){
|
165
160
|
var fragments={};
|
166
161
|
var lastFragmentName;
|
@@ -179,10 +174,9 @@ class DefermentExtensionTest < BreezyTemplateTestCase
|
|
179
174
|
end
|
180
175
|
|
181
176
|
test "rendering with node array deferment using index" do
|
182
|
-
|
183
|
-
req.path = '/some_url'
|
177
|
+
@controller.request.path = '/some_url'
|
184
178
|
|
185
|
-
result = jbuild(
|
179
|
+
result = jbuild(<<~JBUILDER)
|
186
180
|
json.hit do
|
187
181
|
json.hit2 do
|
188
182
|
data = [{id: 1, name: 'foo'}, {id: 2, name: 'bar'}]
|
@@ -194,7 +188,7 @@ class DefermentExtensionTest < BreezyTemplateTestCase
|
|
194
188
|
JBUILDER
|
195
189
|
Rails.cache.clear
|
196
190
|
|
197
|
-
expected = strip_format(
|
191
|
+
expected = strip_format(<<~JS)
|
198
192
|
(function(){
|
199
193
|
var fragments={};
|
200
194
|
var lastFragmentName;
|
@@ -213,10 +207,9 @@ class DefermentExtensionTest < BreezyTemplateTestCase
|
|
213
207
|
end
|
214
208
|
|
215
209
|
test "rendering with node array deferment on nested node" do
|
216
|
-
|
217
|
-
req.path = '/some_url'
|
210
|
+
@controller.request.path = '/some_url'
|
218
211
|
|
219
|
-
result = jbuild(
|
212
|
+
result = jbuild(<<~JBUILDER)
|
220
213
|
json.hit do
|
221
214
|
json.hit2 do
|
222
215
|
data = [{id: 1, name: 'foo'}, {id: 2, name: 'bar'}]
|
@@ -230,7 +223,7 @@ class DefermentExtensionTest < BreezyTemplateTestCase
|
|
230
223
|
JBUILDER
|
231
224
|
Rails.cache.clear
|
232
225
|
|
233
|
-
expected = strip_format(
|
226
|
+
expected = strip_format(<<~JS)
|
234
227
|
(function(){
|
235
228
|
var fragments={};
|
236
229
|
var lastFragmentName;
|
@@ -249,13 +242,11 @@ class DefermentExtensionTest < BreezyTemplateTestCase
|
|
249
242
|
end
|
250
243
|
|
251
244
|
test 'deferment does not work on values' do
|
252
|
-
|
253
|
-
|
254
|
-
result = jbuild(<<-JBUILDER)
|
245
|
+
result = jbuild(<<~JBUILDER)
|
255
246
|
json.hello(32, defer: :auto)
|
256
247
|
JBUILDER
|
257
248
|
|
258
|
-
expected = strip_format(
|
249
|
+
expected = strip_format(<<~JS)
|
259
250
|
(function(){
|
260
251
|
var fragments={};
|
261
252
|
var lastFragmentName;
|
@@ -270,14 +261,14 @@ class DefermentExtensionTest < BreezyTemplateTestCase
|
|
270
261
|
end
|
271
262
|
|
272
263
|
test 'deferment is disabled when filtering by keypath' do
|
273
|
-
|
274
|
-
result = jbuild(
|
264
|
+
@view.stubs(:breezy_filter).returns('hello.world')
|
265
|
+
result = jbuild(<<~JBUILDER)
|
275
266
|
json.hello defer: :auto do
|
276
267
|
json.world 32
|
277
268
|
end
|
278
269
|
JBUILDER
|
279
270
|
|
280
|
-
expected = strip_format(
|
271
|
+
expected = strip_format(<<~JS)
|
281
272
|
(function(){
|
282
273
|
var fragments={};
|
283
274
|
var lastFragmentName;
|
@@ -293,8 +284,8 @@ class DefermentExtensionTest < BreezyTemplateTestCase
|
|
293
284
|
end
|
294
285
|
|
295
286
|
test 'deferment is enabled at the end of a keypath when filtering' do
|
296
|
-
|
297
|
-
result = jbuild(
|
287
|
+
@view.stubs(:breezy_filter).returns('hello')
|
288
|
+
result = jbuild(<<~JBUILDER)
|
298
289
|
json.hello do
|
299
290
|
json.content defer: :auto do
|
300
291
|
json.world 32
|
@@ -302,7 +293,7 @@ class DefermentExtensionTest < BreezyTemplateTestCase
|
|
302
293
|
end
|
303
294
|
JBUILDER
|
304
295
|
|
305
|
-
expected = strip_format(
|
296
|
+
expected = strip_format(<<~JS)
|
306
297
|
(function(){
|
307
298
|
var fragments={};
|
308
299
|
var lastFragmentName;
|