breezy_template 0.10.1 → 0.11.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/cache_extension.rb +1 -1
- data/lib/breezy_template/deferment_extension.rb +1 -1
- data/lib/breezy_template/errors.rb +7 -0
- data/lib/breezy_template/partial_extension.rb +5 -7
- data/lib/breezy_template/search_extension.rb +5 -3
- data/test/cache_extension_test.rb +334 -0
- data/test/deferement_test.rb +322 -0
- data/test/extensions_test.rb +3 -1351
- data/test/partial_extension_test.rb +273 -0
- data/test/search_extension_test.rb +334 -0
- data/test/test_helper.rb +162 -1
- metadata +10 -2
@@ -0,0 +1,273 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class PartialExtensionTest < BreezyTemplateTestCase
|
4
|
+
test "renders partial via the option through set!" do
|
5
|
+
@post = BLOG_POST_COLLECTION.first
|
6
|
+
Rails.cache.clear
|
7
|
+
|
8
|
+
result = jbuild(<<-JBUILDER)
|
9
|
+
json.post @post, partial: ["blog_post", as: :blog_post, fragment_name: :header]
|
10
|
+
JBUILDER
|
11
|
+
|
12
|
+
expected = strip_format(<<-JS)
|
13
|
+
(function(){
|
14
|
+
var fragments={};
|
15
|
+
var lastFragmentName;
|
16
|
+
var lastFragmentPath;
|
17
|
+
var cache={};
|
18
|
+
var defers=[];
|
19
|
+
fragments['header'] = fragments['header'] || []; fragments['header'].push('post'); lastFragmentName='header'; lastFragmentPath='post';
|
20
|
+
return ({"data":{"post":{
|
21
|
+
"id":1,
|
22
|
+
"body":"post body 1",
|
23
|
+
"author":{"firstName":"David","lastName":"Heinemeier Hansson"}
|
24
|
+
}},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
|
25
|
+
})()
|
26
|
+
JS
|
27
|
+
|
28
|
+
assert_equal expected, result
|
29
|
+
end
|
30
|
+
|
31
|
+
test "renders a partial with explicit fragment" do
|
32
|
+
result = jbuild(<<-JBUILDER)
|
33
|
+
json.footer nil, partial: ["footer", fragment_name: 'hello']
|
34
|
+
JBUILDER
|
35
|
+
|
36
|
+
expected = strip_format(<<-JS)
|
37
|
+
(function(){
|
38
|
+
var fragments={};
|
39
|
+
var lastFragmentName;
|
40
|
+
var lastFragmentPath;
|
41
|
+
var cache={};
|
42
|
+
var defers=[];
|
43
|
+
fragments['hello'] = fragments['hello'] || []; fragments['hello'].push('footer'); lastFragmentName='hello'; lastFragmentPath='footer';
|
44
|
+
return ({"data":{"footer":{"terms":"You agree"}},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
|
45
|
+
})()
|
46
|
+
JS
|
47
|
+
assert_equal expected, result
|
48
|
+
end
|
49
|
+
|
50
|
+
test "render array of partials with unique fragments" do
|
51
|
+
result = jbuild(<<-JBUILDER)
|
52
|
+
json.array! [1,2], partial: ["footer", fragment_name: ->(x){"somefoo"+x.to_s}]
|
53
|
+
JBUILDER
|
54
|
+
|
55
|
+
expected = strip_format(<<-JS)
|
56
|
+
(function(){
|
57
|
+
var fragments={};
|
58
|
+
var lastFragmentName;
|
59
|
+
var lastFragmentPath;
|
60
|
+
var cache={};
|
61
|
+
var defers=[];
|
62
|
+
fragments['somefoo1'] = fragments['somefoo1'] || []; fragments['somefoo1'].push('0'); lastFragmentName='somefoo1'; lastFragmentPath='0';fragments['somefoo2'] = fragments['somefoo2'] || []; fragments['somefoo2'].push('1'); lastFragmentName='somefoo2'; lastFragmentPath='1';
|
63
|
+
return ({"data":[{"terms":"You agree"},{"terms":"You agree"}],"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
|
64
|
+
})()
|
65
|
+
JS
|
66
|
+
|
67
|
+
assert_equal expected, result
|
68
|
+
end
|
69
|
+
|
70
|
+
test "renders a partial with no locals" do
|
71
|
+
result = jbuild(<<-JBUILDER)
|
72
|
+
json.footer nil, partial: "footer"
|
73
|
+
JBUILDER
|
74
|
+
|
75
|
+
expected = strip_format(<<-JS)
|
76
|
+
(function(){
|
77
|
+
var fragments={};
|
78
|
+
var lastFragmentName;
|
79
|
+
var lastFragmentPath;
|
80
|
+
var cache={};
|
81
|
+
var defers=[];
|
82
|
+
return ({"data":{"footer":{"terms":"You agree"}},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
|
83
|
+
})()
|
84
|
+
JS
|
85
|
+
assert_equal expected, result
|
86
|
+
end
|
87
|
+
|
88
|
+
test "renders a partial with locals" do
|
89
|
+
result = jbuild(<<-JBUILDER)
|
90
|
+
json.profile nil, partial: ["profile", locals: {email: "test@test.com"}]
|
91
|
+
JBUILDER
|
92
|
+
|
93
|
+
expected = strip_format(<<-JS)
|
94
|
+
(function(){
|
95
|
+
var fragments={};
|
96
|
+
var lastFragmentName;
|
97
|
+
var lastFragmentPath;
|
98
|
+
var cache={};
|
99
|
+
var defers=[];
|
100
|
+
return ({"data":{"profile":{"email":"test@test.com"}},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
|
101
|
+
})()
|
102
|
+
JS
|
103
|
+
assert_equal expected, result
|
104
|
+
end
|
105
|
+
|
106
|
+
test "renders a partial with locals and caches" do
|
107
|
+
result = jbuild(<<-JBUILDER)
|
108
|
+
opts = {
|
109
|
+
cache: 'cachekey',
|
110
|
+
partial: ["profile", locals: {email: "test@test.com"}]
|
111
|
+
}
|
112
|
+
json.profile 32, opts
|
113
|
+
JBUILDER
|
114
|
+
|
115
|
+
expected = strip_format(<<-JS)
|
116
|
+
(function(){
|
117
|
+
var fragments={};
|
118
|
+
var lastFragmentName;
|
119
|
+
var lastFragmentPath;
|
120
|
+
var cache={};
|
121
|
+
var defers=[];
|
122
|
+
cache["#{cache_keys[0]}"]={"email":"test@test.com"};
|
123
|
+
return ({"data":{"profile":cache["#{cache_keys[0]}"]},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
|
124
|
+
})()
|
125
|
+
JS
|
126
|
+
|
127
|
+
assert_equal expected, result
|
128
|
+
end
|
129
|
+
|
130
|
+
test "renders a partial even without a :as to the value, this usage is rare" do
|
131
|
+
result = jbuild(<<-JBUILDER)
|
132
|
+
json.profile 32, partial: ["profile", locals: {email: "test@test.com"}]
|
133
|
+
JBUILDER
|
134
|
+
|
135
|
+
expected = strip_format(<<-JS)
|
136
|
+
(function(){
|
137
|
+
var fragments={};
|
138
|
+
var lastFragmentName;
|
139
|
+
var lastFragmentPath;
|
140
|
+
var cache={};
|
141
|
+
var defers=[];
|
142
|
+
return ({"data":{"profile":{"email":"test@test.com"}},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
|
143
|
+
})()
|
144
|
+
JS
|
145
|
+
|
146
|
+
assert_equal expected, result
|
147
|
+
end
|
148
|
+
|
149
|
+
test "render array of partials without an :as to a member, this usage is very rare" do
|
150
|
+
result = jbuild(<<-JBUILDER)
|
151
|
+
json.array! [1,2], partial: "footer"
|
152
|
+
JBUILDER
|
153
|
+
|
154
|
+
expected = strip_format(<<-JS)
|
155
|
+
(function(){
|
156
|
+
var fragments={};
|
157
|
+
var lastFragmentName;
|
158
|
+
var lastFragmentPath;
|
159
|
+
var cache={};
|
160
|
+
var defers=[];
|
161
|
+
return ({"data":[{"terms":"You agree"},{"terms":"You agree"}],"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
|
162
|
+
})()
|
163
|
+
JS
|
164
|
+
|
165
|
+
assert_equal expected, result
|
166
|
+
end
|
167
|
+
|
168
|
+
test "render array of partials without an :as to a member and cache" do
|
169
|
+
result = jbuild(<<-JBUILDER)
|
170
|
+
json.array! [1,2], partial: "footer", cache: ->(i){ ['a', i] }
|
171
|
+
JBUILDER
|
172
|
+
|
173
|
+
expected = strip_format(<<-JS)
|
174
|
+
(function(){
|
175
|
+
var fragments={};
|
176
|
+
var lastFragmentName;
|
177
|
+
var lastFragmentPath;
|
178
|
+
var cache={};
|
179
|
+
var defers=[];
|
180
|
+
cache["#{cache_keys[0]}"]={"terms":"You agree"};
|
181
|
+
cache["#{cache_keys[1]}"]={"terms":"You agree"};
|
182
|
+
return ({"data":[cache["#{cache_keys[0]}"],cache["#{cache_keys[1]}"]],"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
|
183
|
+
})()
|
184
|
+
JS
|
185
|
+
|
186
|
+
assert_equal expected, result
|
187
|
+
end
|
188
|
+
|
189
|
+
test "render array of partials" do
|
190
|
+
result = jbuild(<<-JBUILDER)
|
191
|
+
json.array! BLOG_POST_COLLECTION, partial: ["blog_post", as: :blog_post]
|
192
|
+
JBUILDER
|
193
|
+
|
194
|
+
expected = strip_format(<<-JS)
|
195
|
+
(function(){
|
196
|
+
var fragments={};
|
197
|
+
var lastFragmentName;
|
198
|
+
var lastFragmentPath;
|
199
|
+
var cache={};
|
200
|
+
var defers=[];
|
201
|
+
return ({"data":[
|
202
|
+
{"id":1,"body":"post body 1","author":{"firstName":"David","lastName":"Heinemeier Hansson"}},
|
203
|
+
{"id":2,"body":"post body 2","author":{"firstName":"Pavel","lastName":"Pravosud"}},
|
204
|
+
{"id":3,"body":"post body 3","author":{"firstName":"David","lastName":"Heinemeier Hansson"}},
|
205
|
+
{"id":4,"body":"post body 4","author":{"firstName":"Pavel","lastName":"Pravosud"}},
|
206
|
+
{"id":5,"body":"post body 5","author":{"firstName":"David","lastName":"Heinemeier Hansson"}},
|
207
|
+
{"id":6,"body":"post body 6","author":{"firstName":"Pavel","lastName":"Pravosud"}},
|
208
|
+
{"id":7,"body":"post body 7","author":{"firstName":"David","lastName":"Heinemeier Hansson"}},
|
209
|
+
{"id":8,"body":"post body 8","author":{"firstName":"Pavel","lastName":"Pravosud"}},
|
210
|
+
{"id":9,"body":"post body 9","author":{"firstName":"David","lastName":"Heinemeier Hansson"}},
|
211
|
+
{"id":10,"body":"post body 10","author":{"firstName":"Pavel","lastName":"Pravosud"}}
|
212
|
+
],"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
|
213
|
+
})()
|
214
|
+
JS
|
215
|
+
|
216
|
+
assert_equal expected, result
|
217
|
+
end
|
218
|
+
|
219
|
+
test "renders array of partials as empty array with an empty collection" do
|
220
|
+
result = jbuild(<<-JBUILDER)
|
221
|
+
json.array! [], partial: ["blog_post", as: :blog_post]
|
222
|
+
JBUILDER
|
223
|
+
|
224
|
+
expected = strip_format(<<-JS)
|
225
|
+
(function(){
|
226
|
+
var fragments={};
|
227
|
+
var lastFragmentName;
|
228
|
+
var lastFragmentPath;
|
229
|
+
var cache={};
|
230
|
+
var defers=[];
|
231
|
+
return ({"data":[],"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
|
232
|
+
})()
|
233
|
+
JS
|
234
|
+
|
235
|
+
assert_equal expected, result
|
236
|
+
end
|
237
|
+
|
238
|
+
test "renders the partial and ignores the value" do
|
239
|
+
result = jbuild <<-JBUILDER
|
240
|
+
json.posts nil, partial: "footer"
|
241
|
+
JBUILDER
|
242
|
+
|
243
|
+
expected = strip_format(<<-JS)
|
244
|
+
(function(){
|
245
|
+
var fragments={};
|
246
|
+
var lastFragmentName;
|
247
|
+
var lastFragmentPath;
|
248
|
+
var cache={};
|
249
|
+
var defers=[];
|
250
|
+
return ({"data":{"posts":{"terms":"You agree"}},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
|
251
|
+
})()
|
252
|
+
JS
|
253
|
+
assert_equal expected, result
|
254
|
+
end
|
255
|
+
|
256
|
+
test "renders the partial as an array and ignores the value" do
|
257
|
+
result = jbuild <<-JBUILDER
|
258
|
+
json.posts nil, partial: "flattened"
|
259
|
+
JBUILDER
|
260
|
+
|
261
|
+
expected = strip_format(<<-JS)
|
262
|
+
(function(){
|
263
|
+
var fragments={};
|
264
|
+
var lastFragmentName;
|
265
|
+
var lastFragmentPath;
|
266
|
+
var cache={};
|
267
|
+
var defers=[];
|
268
|
+
return ({"data":{"posts":[1,2]},"screen":"test","fragments":fragments,"privateOpts":{"lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
|
269
|
+
})()
|
270
|
+
JS
|
271
|
+
assert_equal expected, result
|
272
|
+
end
|
273
|
+
end
|
@@ -0,0 +1,334 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class SearchExtensionTest < BreezyTemplateTestCase
|
4
|
+
test "filtering for a node in the tree" do
|
5
|
+
result = jbuild(<<-JBUILDER, breezy_filter: 'hit.hit2')
|
6
|
+
json.hit do
|
7
|
+
json.hit2 do
|
8
|
+
json.greeting 'hello world'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
json.miss do
|
13
|
+
json.miss2 do
|
14
|
+
raise 'this should not be called'
|
15
|
+
json.greeting 'missed call'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
JBUILDER
|
19
|
+
Rails.cache.clear
|
20
|
+
|
21
|
+
expected = strip_format(<<-JS)
|
22
|
+
(function(){
|
23
|
+
var fragments={};
|
24
|
+
var lastFragmentName;
|
25
|
+
var lastFragmentPath;
|
26
|
+
var cache={};
|
27
|
+
var defers=[];
|
28
|
+
return (
|
29
|
+
{"data":{"greeting":"hello world"},"screen":"test","fragments":fragments,"privateOpts":{"action":"graft","path":"hit.hit2","lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}}
|
30
|
+
);
|
31
|
+
})()
|
32
|
+
JS
|
33
|
+
|
34
|
+
assert_equal expected, result
|
35
|
+
end
|
36
|
+
|
37
|
+
test "filtering for a node in the tree with camelized keys" do
|
38
|
+
result = jbuild(<<-JBUILDER, breezy_filter: 'hit_one.hit_two')
|
39
|
+
json.hit_one do
|
40
|
+
json.hit_two do
|
41
|
+
json.greeting 'hello world'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
JBUILDER
|
45
|
+
Rails.cache.clear
|
46
|
+
|
47
|
+
expected = strip_format(<<-JS)
|
48
|
+
(function(){
|
49
|
+
var fragments={};
|
50
|
+
var lastFragmentName;
|
51
|
+
var lastFragmentPath;
|
52
|
+
var cache={};
|
53
|
+
var defers=[];
|
54
|
+
return (
|
55
|
+
{"data":{"greeting":"hello world"},"screen":"test","fragments":fragments,"privateOpts":{"action":"graft","path":"hitOne.hitTwo","lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}}
|
56
|
+
);
|
57
|
+
})()
|
58
|
+
JS
|
59
|
+
|
60
|
+
assert_equal expected, result
|
61
|
+
end
|
62
|
+
|
63
|
+
test "filtering for a nonexistant node in the tree" do
|
64
|
+
begin
|
65
|
+
jbuild(<<-JBUILDER)
|
66
|
+
json._set_search_path_once('miss.miss.miss.miss')
|
67
|
+
json.hit do
|
68
|
+
json.hit2 do
|
69
|
+
json.greeting 'hello world'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
JBUILDER
|
73
|
+
rescue => e
|
74
|
+
assert_equal e.cause.class, BreezyTemplate::NotFoundError
|
75
|
+
assert_equal e.message, 'Could not find node at ["miss", "miss", "miss", "miss"]'
|
76
|
+
end
|
77
|
+
|
78
|
+
Rails.cache.clear
|
79
|
+
end
|
80
|
+
|
81
|
+
test "filtering for a node but forgetting to use nil as the first param" do
|
82
|
+
undef_context_methods :fragment_name_with_digest, :cache_fragment_name
|
83
|
+
|
84
|
+
begin
|
85
|
+
result = jbuild(<<-JBUILDER, breezy_filter: 'hit.hit2.terms')
|
86
|
+
json.hit do
|
87
|
+
json.hit2 cache: 'a', partial: 'footer'
|
88
|
+
end
|
89
|
+
JBUILDER
|
90
|
+
rescue => e
|
91
|
+
assert_equal e.cause.class, BreezyTemplate::LeafTraversalError
|
92
|
+
assert_equal e.message, "Attempted to traverse into node named hit2 but got a value. This may happen if you forgot to use nil as a first value if you're using a partial, e.g, json.foo nil, partial: 'footer'. Key: hit2 Value: {:cache=>\"a\", :partial=>\"footer\"} Options: {} Remaining search path: [\"terms\"]."
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
test "filtering for a raw value is also possble" do
|
97
|
+
result = jbuild(<<-JBUILDER, breezy_filter: 'hit.hit2')
|
98
|
+
json.hit do
|
99
|
+
json.hit2 23
|
100
|
+
end
|
101
|
+
|
102
|
+
json.miss do
|
103
|
+
json.miss2 do
|
104
|
+
raise 'this should not be called'
|
105
|
+
json.greeting 'missed call'
|
106
|
+
end
|
107
|
+
end
|
108
|
+
JBUILDER
|
109
|
+
Rails.cache.clear
|
110
|
+
|
111
|
+
expected = strip_format(<<-JS)
|
112
|
+
(function(){
|
113
|
+
var fragments={};
|
114
|
+
var lastFragmentName;
|
115
|
+
var lastFragmentPath;
|
116
|
+
var cache={};
|
117
|
+
var defers=[];
|
118
|
+
return (
|
119
|
+
{"data":23,"screen":"test","fragments":fragments,"privateOpts":{"action":"graft","path":"hit.hit2","lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}}
|
120
|
+
);
|
121
|
+
})()
|
122
|
+
JS
|
123
|
+
|
124
|
+
assert_equal expected, result
|
125
|
+
end
|
126
|
+
|
127
|
+
test "filter with partials" do
|
128
|
+
result = jbuild(<<-JBUILDER, breezy_filter: 'hit.hit2.nested.terms')
|
129
|
+
json.hit do
|
130
|
+
json.hit2 nil, partial: "nested"
|
131
|
+
end
|
132
|
+
JBUILDER
|
133
|
+
|
134
|
+
expected = strip_format(<<-JS)
|
135
|
+
(function(){
|
136
|
+
var fragments={};
|
137
|
+
var lastFragmentName;
|
138
|
+
var lastFragmentPath;
|
139
|
+
var cache={};
|
140
|
+
var defers=[];
|
141
|
+
return (
|
142
|
+
{"data":"You agree","screen":"test","fragments":fragments,"privateOpts":{"action":"graft","path":"hit.hit2.nested.terms","lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}}
|
143
|
+
);
|
144
|
+
})()
|
145
|
+
JS
|
146
|
+
assert_equal expected, result
|
147
|
+
end
|
148
|
+
|
149
|
+
test "filtering for a node in the tree via breezy_filter helper" do
|
150
|
+
result = jbuild(<<-JBUILDER, breezy_filter: 'hit.hit2')
|
151
|
+
json.hit do
|
152
|
+
json.hit2 do
|
153
|
+
json.greeting 'hello world'
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
json.miss do
|
158
|
+
json.miss2 do
|
159
|
+
raise 'this should not be called'
|
160
|
+
json.greeting 'missed call'
|
161
|
+
end
|
162
|
+
end
|
163
|
+
JBUILDER
|
164
|
+
Rails.cache.clear
|
165
|
+
|
166
|
+
expected = strip_format(<<-JS)
|
167
|
+
(function(){
|
168
|
+
var fragments={};
|
169
|
+
var lastFragmentName;
|
170
|
+
var lastFragmentPath;
|
171
|
+
var cache={};
|
172
|
+
var defers=[];
|
173
|
+
return (
|
174
|
+
{"data":{"greeting":"hello world"},"screen":"test","fragments":fragments,"privateOpts":{"action":"graft","path":"hit.hit2","lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}}
|
175
|
+
);
|
176
|
+
})()
|
177
|
+
JS
|
178
|
+
|
179
|
+
assert_equal expected, result
|
180
|
+
end
|
181
|
+
|
182
|
+
test "filtering a cached node returns just that" do
|
183
|
+
undef_context_methods :fragment_name_with_digest, :cache_fragment_name
|
184
|
+
result = jbuild(<<-JBUILDER, breezy_filter: 'hit.hit2')
|
185
|
+
json.hit do
|
186
|
+
json.hit2 cache: 'a' do
|
187
|
+
json.greeting 'hello world'
|
188
|
+
end
|
189
|
+
end
|
190
|
+
JBUILDER
|
191
|
+
Rails.cache.clear
|
192
|
+
|
193
|
+
expected = strip_format(<<-JS)
|
194
|
+
(function(){
|
195
|
+
var fragments={};
|
196
|
+
var lastFragmentName;
|
197
|
+
var lastFragmentPath;
|
198
|
+
var cache={};
|
199
|
+
var defers=[];
|
200
|
+
cache["#{cache_keys[0]}"]={"greeting":"hello world"};
|
201
|
+
return ({"data":cache["#{cache_keys[0]}"],"screen":"test","fragments":fragments,"privateOpts":{"action":"graft","path":"hit.hit2","lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
|
202
|
+
})()
|
203
|
+
JS
|
204
|
+
|
205
|
+
assert_equal expected, result
|
206
|
+
end
|
207
|
+
|
208
|
+
test "filtering disables all ancestor cache of target node" do
|
209
|
+
undef_context_methods :fragment_name_with_digest, :cache_fragment_name
|
210
|
+
jbuild(<<-JBUILDER, breezy_filter: 'hit.hit2')
|
211
|
+
json.hit do
|
212
|
+
json.hit2 cache: 'a' do
|
213
|
+
json.greeting 'stale'
|
214
|
+
end
|
215
|
+
end
|
216
|
+
JBUILDER
|
217
|
+
|
218
|
+
result = jbuild(<<-JBUILDER, breezy_filter: 'hit.hit2.greeting')
|
219
|
+
json.hit do
|
220
|
+
json.hit2 cache: 'a' do
|
221
|
+
json.greeting 'fresh hit'
|
222
|
+
end
|
223
|
+
end
|
224
|
+
JBUILDER
|
225
|
+
Rails.cache.clear
|
226
|
+
|
227
|
+
expected = strip_format(<<-JS)
|
228
|
+
(function(){
|
229
|
+
var fragments={};
|
230
|
+
var lastFragmentName;
|
231
|
+
var lastFragmentPath;
|
232
|
+
var cache={};
|
233
|
+
var defers=[];
|
234
|
+
return ({"data":"fresh hit","screen":"test","fragments":fragments,"privateOpts":{"action":"graft","path":"hit.hit2.greeting","lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
|
235
|
+
})()
|
236
|
+
JS
|
237
|
+
|
238
|
+
assert_equal expected, result
|
239
|
+
end
|
240
|
+
|
241
|
+
test "filtering disables all ancestor cache of target node with partial options" do
|
242
|
+
undef_context_methods :fragment_name_with_digest, :cache_fragment_name
|
243
|
+
jbuild(<<-JBUILDER, breezy_filter: 'hit.hit2')
|
244
|
+
json.hit do
|
245
|
+
json.hit2 cache: 'a' do
|
246
|
+
json.greeting 'stale'
|
247
|
+
end
|
248
|
+
end
|
249
|
+
JBUILDER
|
250
|
+
|
251
|
+
result = jbuild(<<-JBUILDER, breezy_filter: 'hit.hit2.terms')
|
252
|
+
json.hit do
|
253
|
+
json.hit2 nil, cache: 'a', partial: 'footer'
|
254
|
+
end
|
255
|
+
JBUILDER
|
256
|
+
Rails.cache.clear
|
257
|
+
|
258
|
+
expected = strip_format(<<-JS)
|
259
|
+
(function(){
|
260
|
+
var fragments={};
|
261
|
+
var lastFragmentName;
|
262
|
+
var lastFragmentPath;
|
263
|
+
var cache={};
|
264
|
+
var defers=[];
|
265
|
+
return ({"data":"You agree","screen":"test","fragments":fragments,"privateOpts":{"action":"graft","path":"hit.hit2.terms","lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}});
|
266
|
+
})()
|
267
|
+
JS
|
268
|
+
|
269
|
+
assert_equal expected, result
|
270
|
+
end
|
271
|
+
|
272
|
+
test "filtering for a node in an array of a tree by id" do
|
273
|
+
result = jbuild(<<-JBUILDER, breezy_filter: 'hit.hit2.id=1')
|
274
|
+
json.hit do
|
275
|
+
json.hit2 do
|
276
|
+
data = ObjectCollection.new([{id: 1, name: 'hit' }, {id:2, name: 'miss'}])
|
277
|
+
json.array! data do |x|
|
278
|
+
raise 'this should be be called' if x[:name] == 'miss'
|
279
|
+
json.name x[:name]
|
280
|
+
end
|
281
|
+
end
|
282
|
+
end
|
283
|
+
JBUILDER
|
284
|
+
Rails.cache.clear
|
285
|
+
|
286
|
+
expected = strip_format(<<-JS)
|
287
|
+
(function(){
|
288
|
+
var fragments={};
|
289
|
+
var lastFragmentName;
|
290
|
+
var lastFragmentPath;
|
291
|
+
var cache={};
|
292
|
+
var defers=[];
|
293
|
+
return (
|
294
|
+
{"data":{"name":"hit"},"screen":"test","fragments":fragments,"privateOpts":{"action":"graft","path":"hit.hit2.id=1","lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}}
|
295
|
+
);
|
296
|
+
})()
|
297
|
+
JS
|
298
|
+
|
299
|
+
assert_equal expected, result
|
300
|
+
end
|
301
|
+
|
302
|
+
test "filtering for a node in an array of a tree by index" do
|
303
|
+
result = jbuild(<<-JBUILDER, breezy_filter: 'hit.hit2.0')
|
304
|
+
data = [{id: 1, name: 'hit' }, {id:2, name: 'miss'}]
|
305
|
+
json.hit do
|
306
|
+
json.hit2 do
|
307
|
+
json.array! data do |x|
|
308
|
+
raise 'this should be be called' if x[:name] == 'miss'
|
309
|
+
json.name x[:name]
|
310
|
+
end
|
311
|
+
end
|
312
|
+
end
|
313
|
+
JBUILDER
|
314
|
+
Rails.cache.clear
|
315
|
+
|
316
|
+
expected = strip_format(<<-JS)
|
317
|
+
(function(){
|
318
|
+
var fragments={};
|
319
|
+
var lastFragmentName;
|
320
|
+
var lastFragmentPath;
|
321
|
+
var cache={};
|
322
|
+
var defers=[];
|
323
|
+
return (
|
324
|
+
{"data":{"name":"hit"},"screen":"test","fragments":fragments,"privateOpts":{"action":"graft","path":"hit.hit2.0","lastFragmentName":lastFragmentName,"lastFragmentPath":lastFragmentPath,"defers":defers}}
|
325
|
+
);
|
326
|
+
})()
|
327
|
+
JS
|
328
|
+
|
329
|
+
assert_equal expected, result
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
|
334
|
+
|