breezy 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/lib/assets/javascript/breezy.js +6067 -0
  3. data/lib/breezy.rb +0 -7
  4. data/lib/breezy/configuration.rb +9 -3
  5. data/lib/breezy/helpers.rb +1 -1
  6. data/lib/breezy/render.rb +1 -1
  7. data/lib/breezy/version.rb +1 -1
  8. data/lib/generators/breezy/view/templates/view.js +17 -0
  9. data/lib/generators/breezy/view/templates/view.js.breezy +2 -0
  10. data/lib/generators/breezy/view/templates/view.jsx +21 -0
  11. data/lib/generators/breezy/view/view_generator.rb +40 -7
  12. data/lib/install/mobile.rb +54 -0
  13. data/lib/install/templates/mobile/app.js +84 -0
  14. data/lib/install/templates/mobile/app.json +6 -0
  15. data/lib/install/templates/mobile/package.json +32 -0
  16. data/lib/install/templates/mobile/rn-cli.config.js +4 -0
  17. data/lib/install/templates/web/application.js +62 -0
  18. data/lib/install/web.rb +72 -0
  19. data/lib/tasks/install.rake +46 -0
  20. data/test/render_test.rb +2 -2
  21. data/test/test_helper.rb +2 -0
  22. metadata +37 -48
  23. data/README.md +0 -338
  24. data/lib/assets/javascripts/breezy.coffee +0 -4
  25. data/lib/assets/javascripts/breezy/component_url.coffee +0 -61
  26. data/lib/assets/javascripts/breezy/controller.coffee +0 -197
  27. data/lib/assets/javascripts/breezy/csrf_token.coffee +0 -9
  28. data/lib/assets/javascripts/breezy/doubly_linked_list.coffee +0 -57
  29. data/lib/assets/javascripts/breezy/parallel_queue.coffee +0 -35
  30. data/lib/assets/javascripts/breezy/progress_bar.coffee +0 -139
  31. data/lib/assets/javascripts/breezy/remote.coffee +0 -136
  32. data/lib/assets/javascripts/breezy/snapshot.coffee +0 -100
  33. data/lib/assets/javascripts/breezy/start.coffee +0 -60
  34. data/lib/assets/javascripts/breezy/utils.coffee +0 -174
  35. data/lib/breezy/active_support.rb +0 -21
  36. data/lib/breezy_template.rb +0 -320
  37. data/lib/breezy_template/deferment_extension.rb +0 -48
  38. data/lib/breezy_template/dependency_tracker.rb +0 -47
  39. data/lib/breezy_template/digestor.rb +0 -30
  40. data/lib/breezy_template/handler.rb +0 -43
  41. data/lib/breezy_template/partial_extension.rb +0 -87
  42. data/lib/breezy_template/search_extension.rb +0 -108
  43. data/lib/generators/breezy/install/install_generator.rb +0 -61
  44. data/lib/generators/breezy/install/templates/Default.js.jsx +0 -7
  45. data/lib/generators/breezy/install/templates/View.js.jsx +0 -7
  46. data/lib/generators/breezy/install/templates/boot.js +0 -5
  47. data/lib/generators/breezy/view/templates/view.js.jsx +0 -8
  48. data/test/blade_helper.rb +0 -22
  49. data/test/breezy_template_test.rb +0 -1095
  50. data/test/dependency_tracker_test.rb +0 -66
@@ -1,43 +0,0 @@
1
- module BreezyTemplate
2
- class Handler
3
- cattr_accessor :default_format
4
- self.default_format = Mime[:js]
5
-
6
- def self.call(template)
7
- # this juggling is required to keep line numbers right in the error
8
- %{__already_defined = defined?(json); json||=::BreezyTemplate::Template.new(self);json._filter_by_path(breezy_filter) if defined?(breezy_filter); json._set_request_url(request.path);#{template.source}
9
- if !(__already_defined && __already_defined != "method")
10
- json.merge!({data: json.found! || json.empty! })
11
- if defined?(breezy) && breezy
12
- breezy.each do |k, v|
13
- json.set! k, v
14
- end
15
- end
16
-
17
- if protect_against_forgery?
18
- json.csrf_token form_authenticity_token
19
- end
20
-
21
- if ::Breezy.configuration.track_assets.any?
22
- json.assets do
23
- json.array! (::Breezy.configuration.track_assets || []).map{|assets|
24
- asset_path(assets)
25
- }
26
- end
27
- end
28
-
29
- if defined?(breezy_filter) && !!breezy_filter
30
- json.action 'graft'
31
- json.path breezy_filter
32
- end
33
-
34
- if defined?(session) && session
35
- session.delete(:breezy_filter)
36
- end
37
-
38
- json.target!
39
- end
40
- }
41
- end
42
- end
43
- end
@@ -1,87 +0,0 @@
1
- module BreezyTemplate
2
- module PartialExtension
3
- def set!(key, value = BLANK, *args)
4
- options = args.first || {}
5
- options = _normalize_options(options)
6
- if args.one? && _partial_options?(options)
7
- _set_inline_partial key, value, options
8
- else
9
- super
10
- end
11
- end
12
-
13
- def _fragment_name_with_digest(key, options)
14
- if options[:partial] && !options[:skip_digest]
15
- [key, _partial_digest(options[:partial])]
16
- else
17
- super
18
- end
19
- end
20
-
21
- def array!(collection = [], *attributes)
22
- options = attributes.first || {}
23
- options = _normalize_options(options)
24
-
25
- if attributes.one? && _partial_options?(options)
26
- _render_partial_with_options(options.merge(collection: collection))
27
- else
28
- super
29
- end
30
- end
31
-
32
- def _partial_options?(options)
33
- ::Hash === options && options.key?(:partial)
34
- end
35
-
36
- def _partial_digest(partial)
37
- lookup_context = @context.lookup_context
38
- name = lookup_context.find(partial, lookup_context.prefixes, true).virtual_path
39
- _partial_digestor({name: name, finder: lookup_context})
40
- end
41
-
42
- def _set_inline_partial(name, object, options)
43
- value = if object.nil?
44
- []
45
- elsif _is_collection?(object)
46
- _scope{ _render_partial_with_options options.merge(collection: object) }
47
- else
48
- locals = {}
49
- locals[options[:as]] = object if !_blank?(object) && options.key?(:as)
50
- locals.merge!(options[:locals]) if options.key? :locals
51
-
52
- _cache(*options[:cache]) {
53
- _scope{ _render_partial options.merge(locals: locals) }
54
- }
55
- end
56
-
57
- set! name, value
58
- end
59
-
60
- def _render_partial(options)
61
- options[:locals].merge! json: self
62
- @context.render options
63
- end
64
-
65
- def _render_partial_with_options(options)
66
- ary_opts = options.dup
67
- options.reverse_merge! locals: {}
68
- options.reverse_merge! ::BreezyTemplate::Template.template_lookup_options
69
- as = options[:as]
70
-
71
- if options.key?(:collection)
72
- collection = options.delete(:collection)
73
- locals = options.delete(:locals)
74
-
75
- ary_opts.delete(:partial)
76
- array! collection, ary_opts do |member|
77
- member_locals = locals.clone
78
- member_locals.merge! collection: collection
79
- member_locals.merge! as.to_sym => member if as
80
- _render_partial options.merge(locals: member_locals)
81
- end
82
- else
83
- _render_partial options
84
- end
85
- end
86
- end
87
- end
@@ -1,108 +0,0 @@
1
- module BreezyTemplate
2
- module SearchExtension
3
- def found!
4
- found = @found
5
- @found = nil
6
- @search_path = []
7
- found
8
- end
9
-
10
- def _filter_by_path(search_path)
11
- if search_path.is_a? ::String
12
- return _filter_by_path(search_path.split('.'))
13
- end
14
- @search_path = search_path
15
- end
16
-
17
- def _mapping_element(element, options)
18
- if @search_path && !@search_path.empty?
19
- original_search_path = @search_path
20
- @search_path = original_search_path[1..-1]
21
- if @search_path.size == 0
22
- @found = super
23
- else
24
- yield element
25
- end
26
-
27
- @search_path = original_search_path
28
- else
29
- super
30
- end
31
- end
32
-
33
- def _prepare_collection_for_map(collection)
34
- if @search_path && !@search_path.empty?
35
- id_name, id_val = @search_path.first.split('=')
36
-
37
-
38
- if (defined? ::ActiveRecord) && collection.is_a?(::ActiveRecord::Relation)
39
- if id_val
40
- id_val = id_val.to_i
41
- collection = collection.where(::Hash[id_name, id_val])
42
- else
43
- index = id_name.to_i
44
- collection = collection.offset(index).limit(1)
45
- end
46
- else
47
- if id_val
48
- id_val = id_val.to_i
49
- found = collection.find do |ele|
50
- ele[id_name] == id_val || ele[id_name.to_sym] == id_val
51
- end
52
- else
53
- index = id_name.to_i
54
- found = collection[index]
55
- end
56
-
57
- if found
58
- collection = [found]
59
- else
60
- collection = []
61
- end
62
- end
63
- else
64
- super
65
- end
66
- end
67
-
68
- def set!(key, value = BLANK, *args)
69
- return if @found
70
- options = args.first || {}
71
- options = _normalize_options(options)
72
-
73
- if @search_path && !@search_path.empty?
74
- if key.to_s == @search_path.first
75
- original_search_path = @search_path
76
- @search_path = original_search_path[1..-1]
77
- if @search_path.size == 0
78
- if ::Kernel.block_given?
79
- @found = if _cache_options?(options)
80
- _cache(*options[:cache]) { _scope { yield self } }
81
- else
82
- _scope { yield self }
83
- end
84
- elsif _partial_options?(options)
85
- super
86
- else
87
- @found = value
88
- end
89
- else
90
- if ::Kernel.block_given?
91
- yield self
92
- elsif _partial_options?(options)
93
- super
94
- else
95
- ::Kernel.raise 'can not'
96
- end
97
- end
98
-
99
- @search_path = original_search_path
100
- end
101
-
102
- return _blank
103
- else
104
- super
105
- end
106
- end
107
- end
108
- end
@@ -1,61 +0,0 @@
1
- module Breezy
2
- module Generators
3
- class InstallGenerator < ::Rails::Generators::Base
4
- desc <<-DESC
5
- Description:
6
- Copy breezy files to your application.
7
- DESC
8
- def self.source_root
9
- @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
10
- end
11
-
12
- def create_views_and_layouts
13
- empty_directory 'app/assets/javascripts/views'
14
- empty_directory 'app/assets/javascripts/layouts'
15
- empty_directory 'app/assets/javascripts/components'
16
- end
17
-
18
- def copy_view_component
19
- copy_file 'View.js.jsx', 'app/assets/javascripts/components/View.js.jsx'
20
- copy_file 'boot.js', 'app/assets/javascripts/boot.js'
21
- copy_file 'Default.js.jsx', 'app/assets/javascripts/layouts/default.js.jsx'
22
- end
23
-
24
- def append_js_requires
25
- app_js = "app/assets/javascripts/application.js"
26
-
27
- if File.readlines("#{Rails.root}/#{app_js}").grep(/require_tree/).any?
28
- inject_into_file app_js, before: '//= require_tree .' do
29
- "//= require breezy\n//= require boot\n//= require_tree ./layouts\n//= require_tree ./views\n//= require_tree ./components\n"
30
- end
31
- end
32
- end
33
-
34
- def append_entry_point
35
- app_html = 'app/views/layouts/application.html.erb'
36
- js_tag = <<-JS_TAG
37
- <script type="text/javascript">
38
- document.addEventListener('breezy:load', function(event){
39
- var props = {
40
- view: event.data.view,
41
- data: event.data.data
42
- }
43
- ReactDOM.render(React.createElement(window.App.Components.View, props), document.getElementById('app'));
44
- });
45
-
46
- $(function(){ <%= breezy_snippet %> });
47
-
48
- </script>
49
- JS_TAG
50
-
51
- inject_into_file app_html, before: '</head>' do
52
- js_tag
53
- end
54
-
55
- inject_into_file app_html, after: '</head>' do
56
- "\n<div id='app'></div>"
57
- end
58
- end
59
- end
60
- end
61
- end
@@ -1,7 +0,0 @@
1
- App.Layouts.Default = function(view) {
2
- return (
3
- <div className='container'>
4
- {view}
5
- </div>
6
- );
7
- }
@@ -1,7 +0,0 @@
1
- App.Components.View = React.createClass({
2
- render: function() {
3
- var view = App.Views[this.props.view].call(this, this.props.data);
4
- var layout = App.Layouts[this.props.layout || 'Default'];
5
- return layout(view);
6
- }
7
- });
@@ -1,5 +0,0 @@
1
- window.App = {
2
- Views: {},
3
- Layouts: {},
4
- Components:{}
5
- }
@@ -1,8 +0,0 @@
1
- App.Views.<%= @js_filename %> = function(json) {
2
-
3
- return (
4
- <div>
5
- </div>
6
- );
7
- };
8
-
@@ -1,22 +0,0 @@
1
- require_relative "dummy/application"
2
- Dummy::Application.initialize!
3
-
4
- module Blade
5
- module Server
6
- private
7
-
8
- def app
9
- Rack::Builder.app do
10
- use Rack::ShowExceptions
11
-
12
- map '/app' do
13
- run Dummy::Application
14
- end
15
-
16
- map '/' do
17
- run Blade::RackAdapter.new
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,1095 +0,0 @@
1
- require "test_helper"
2
- require "mocha/setup"
3
- require "action_view"
4
- require "action_view/testing/resolvers"
5
- require "breezy_template"
6
- require 'byebug'
7
-
8
- BLOG_POST_PARTIAL = <<-JBUILDER
9
- json.extract! blog_post, :id, :body
10
- json.author do
11
- first_name, last_name = blog_post.author_name.split(nil, 2)
12
- json.first_name first_name
13
- json.last_name last_name
14
- end
15
- JBUILDER
16
-
17
- COLLECTION_PARTIAL = <<-JBUILDER
18
- json.extract! collection, :id, :name
19
- JBUILDER
20
-
21
- PROFILE_PARTIAL = <<-JBUILDER
22
- json.email email
23
- JBUILDER
24
-
25
- FOOTER_PARTIAL = <<-JBUILDER
26
- json.terms "You agree"
27
- JBUILDER
28
-
29
- BlogPost = Struct.new(:id, :body, :author_name)
30
- Collection = Struct.new(:id, :name)
31
- blog_authors = [ "David Heinemeier Hansson", "Pavel Pravosud" ].cycle
32
- BLOG_POST_COLLECTION = Array.new(10){ |i| BlogPost.new(i+1, "post body #{i+1}", blog_authors.next) }
33
- COLLECTION_COLLECTION = Array.new(5){ |i| Collection.new(i+1, "collection #{i+1}") }
34
-
35
- ActionView::Template.register_template_handler :breezy, BreezyTemplate::Handler
36
-
37
- PARTIALS = {
38
- "_partial.js.breezy" => "foo ||= 'hello'; json.content foo",
39
- "_blog_post.js.breezy" => BLOG_POST_PARTIAL,
40
- "_profile.js.breezy" => PROFILE_PARTIAL,
41
- "_footer.js.breezy" => FOOTER_PARTIAL,
42
- "_collection.js.breezy" => COLLECTION_PARTIAL
43
- }
44
-
45
- def strip_format(str)
46
- str.strip_heredoc.gsub(/\n\s*/, "")
47
- end
48
-
49
- class BreezyTemplateTest < ActionView::TestCase
50
- setup do
51
- self.request_forgery = false
52
- Breezy.configuration.track_assets = []
53
-
54
- # this is a stub. Normally this would be set by the
55
- # controller locals
56
- self.breezy = {}
57
-
58
- @context = self
59
- Rails.cache.clear
60
- end
61
-
62
- cattr_accessor :request_forgery, :breezy
63
- self.request_forgery = false
64
-
65
- def breezy_filter
66
- @breezy_filter
67
- end
68
-
69
- def request
70
- @request
71
- end
72
-
73
- def jbuild(source, opts={})
74
- @breezy_filter = opts[:breezy_filter]
75
- @request = opts[:request] || action_controller_test_request
76
- @rendered = []
77
- partials = PARTIALS.clone
78
- partials["test.js.breezy"] = source
79
- resolver = ActionView::FixtureResolver.new(partials)
80
- lookup_context.view_paths = [resolver]
81
- lookup_context.formats = [:js]
82
- template = ActionView::Template.new(source, "test", BreezyTemplate::Handler, virtual_path: "test")
83
- template.render(self, {}).strip
84
- end
85
-
86
- def action_controller_test_request
87
- if ::Rails.version.start_with?('5')
88
- ::ActionController::TestRequest.create
89
- else
90
- ::ActionController::TestRequest.new
91
- end
92
- end
93
-
94
- def cache_keys
95
- major_v = Rails::VERSION::MAJOR
96
- minor_v = Rails::VERSION::MINOR
97
- rails_v = "rails#{major_v}#{minor_v}"
98
- path = File.expand_path("../fixtures/cache_keys.yaml", __FILE__)
99
- keys = YAML.load_file(path)
100
- keys[method_name][rails_v]
101
- end
102
-
103
- def undef_context_methods(*names)
104
- self.class_eval do
105
- names.each do |name|
106
- undef_method name.to_sym if method_defined?(name.to_sym)
107
- end
108
- end
109
- end
110
-
111
- def protect_against_forgery?
112
- self.request_forgery
113
- end
114
-
115
- def form_authenticity_token
116
- "secret"
117
- end
118
-
119
- test "rendering" do
120
- result = jbuild(<<-JBUILDER)
121
- json.content "hello"
122
- JBUILDER
123
-
124
- expected = strip_format(<<-JS)
125
- (function(){
126
- return ({"data":{"content":"hello"}});
127
- })()
128
- JS
129
-
130
- assert_equal expected, result
131
- end
132
-
133
- test "when rendering with duplicate keys, the last one wins" do
134
- result = jbuild(<<-JBUILDER)
135
- json.content do
136
- json.miss 123
137
- end
138
-
139
- json.content do
140
- json.hit 123
141
- end
142
- JBUILDER
143
-
144
-
145
- expected = strip_format(<<-JS)
146
- (function(){
147
- return ({"data":{"content":{"hit":123}}});
148
- })()
149
- JS
150
-
151
- assert_equal expected, result
152
- end
153
-
154
- test "when rendering with duplicate array values, the last one wins" do
155
- result = jbuild(<<-JBUILDER)
156
- json.content do
157
- json.array! [1,2]
158
- json.array! [3,4]
159
- end
160
- JBUILDER
161
-
162
- expected = strip_format(<<-JS)
163
- (function(){
164
- return ({\"data\":{\"content\":[3,4]}});
165
- })()
166
- JS
167
-
168
- assert_equal expected, result
169
- end
170
-
171
- test "render with asset tracking" do
172
- Breezy.configuration.track_assets = ['test.js', 'test.css']
173
-
174
- result = jbuild(<<-TEMPLATE)
175
- json.content "hello"
176
- TEMPLATE
177
-
178
- expected = strip_format(<<-JS)
179
- (function(){
180
- return ({"data":{"content":"hello"},"assets":["/test.js","/test.css"]});
181
- })()
182
- JS
183
-
184
- assert_equal expected, result
185
- end
186
-
187
-
188
- test "render with csrf token when request forgery is on" do
189
- self.request_forgery = true
190
- # csrf_meta_tags also delegate authenticity tokens to the controller
191
- # here we provide a simple mock to the context
192
-
193
- result = jbuild(<<-TEMPLATE)
194
- json.content "hello"
195
- TEMPLATE
196
-
197
- expected = strip_format(<<-JS)
198
- (function(){
199
- return ({"data":{"content":"hello"},"csrf_token":"secret"});
200
- })()
201
- JS
202
-
203
- assert_equal expected, result
204
- end
205
-
206
- test "wrapping jbuilder contents inside Breezy with additional options" do
207
- Breezy.configuration.track_assets = ['test.js', 'test.css']
208
- self.breezy = { title: 'this is fun' }
209
-
210
- result = jbuild(<<-TEMPLATE)
211
- json.content "hello"
212
- TEMPLATE
213
-
214
- expected = strip_format(<<-JS)
215
- (function(){
216
- return ({"data":{"content":"hello"},"title":"this is fun","assets":["/test.js","/test.css"]});
217
- })()
218
- JS
219
-
220
- assert_equal expected, result
221
- end
222
-
223
- test "key_format! with parameter" do
224
- result = jbuild(<<-JBUILDER)
225
- json.key_format! camelize: [:lower]
226
- json.camel_style "for JS"
227
- JBUILDER
228
-
229
- expected = strip_format(<<-JS)
230
- (function(){
231
- return ({"data":{"camelStyle":"for JS"}});
232
- })()
233
- JS
234
-
235
- assert_equal expected, result
236
- end
237
-
238
- test "key_format! propagates to child elements" do
239
- result = jbuild(<<-JBUILDER)
240
- json.key_format! :upcase
241
- json.level1 "one"
242
- json.level2 do
243
- json.value "two"
244
- end
245
- JBUILDER
246
-
247
- expected = strip_format(<<-JS)
248
- (function(){
249
- return ({"data":{
250
- "LEVEL1":"one",
251
- "LEVEL2":{"VALUE":"two"}
252
- }});
253
- })()
254
- JS
255
-
256
- assert_equal expected, result
257
- end
258
-
259
- test "renders partial via the option through set!" do
260
- @post = BLOG_POST_COLLECTION.first
261
- Rails.cache.clear
262
-
263
- result = jbuild(<<-JBUILDER)
264
- json.post @post, partial: "blog_post", as: :blog_post
265
- JBUILDER
266
-
267
- expected = strip_format(<<-JS)
268
- (function(){
269
- return ({"data":{"post":{
270
- "id":1,
271
- "body":"post body 1",
272
- "author":{"first_name":"David","last_name":"Heinemeier Hansson"}
273
- }}});
274
- })()
275
- JS
276
-
277
- assert_equal expected, result
278
- end
279
-
280
- test "renders a partial with no locals" do
281
- result = jbuild(<<-JBUILDER)
282
- json.footer partial: "footer"
283
- JBUILDER
284
-
285
- expected = strip_format(<<-JS)
286
- (function(){
287
- return ({"data":{"footer":{"terms":"You agree"}}});
288
- })()
289
- JS
290
- assert_equal expected, result
291
- end
292
-
293
- test "renders a partial with locals" do
294
- result = jbuild(<<-JBUILDER)
295
- json.profile partial: "profile", locals: {email: "test@test.com"}
296
- JBUILDER
297
-
298
- expected = strip_format(<<-JS)
299
- (function(){
300
- return ({"data":{"profile":{"email":"test@test.com"}}});
301
- })()
302
- JS
303
- assert_equal expected, result
304
- end
305
-
306
- test "renders a partial with locals and caches" do
307
- result = jbuild(<<-JBUILDER)
308
- json.profile 32, cache: "cachekey", partial: "profile", locals: {email: "test@test.com"}
309
- JBUILDER
310
-
311
- expected = strip_format(<<-JS)
312
- (function(){
313
- Breezy.cache("#{cache_keys[0]}", {"email":"test@test.com"});
314
- return ({"data":{"profile":Breezy.cache("#{cache_keys[0]}")}});
315
- })()
316
- JS
317
-
318
- assert_equal expected, result
319
- end
320
-
321
- test "renders a partial even without a :as to the value, this usage is rare" do
322
- result = jbuild(<<-JBUILDER)
323
- json.profile 32, partial: "profile", locals: {email: "test@test.com"}
324
- JBUILDER
325
-
326
- expected = strip_format(<<-JS)
327
- (function(){
328
- return ({"data":{"profile":{"email":"test@test.com"}}});
329
- })()
330
- JS
331
-
332
- assert_equal expected, result
333
- end
334
-
335
- test "render array of partials without an :as to a member, this usage is very rare" do
336
- result = jbuild(<<-JBUILDER)
337
- json.array! [1,2], partial: "footer"
338
- JBUILDER
339
-
340
- expected = strip_format(<<-JS)
341
- (function(){
342
- return ({"data":[{"terms":"You agree"},{"terms":"You agree"}]});
343
- })()
344
- JS
345
-
346
- assert_equal expected, result
347
- end
348
-
349
- test "render array of partials without an :as to a member and cache" do
350
- result = jbuild(<<-JBUILDER)
351
- json.array! [1,2], partial: "footer", cache: ->(i){ ['a', i] }
352
- JBUILDER
353
-
354
- expected = strip_format(<<-JS)
355
- (function(){
356
- Breezy.cache("#{cache_keys[0]}", {"terms":"You agree"});
357
- Breezy.cache("#{cache_keys[1]}", {"terms":"You agree"});
358
- return ({"data":[Breezy.cache("#{cache_keys[0]}"),Breezy.cache("#{cache_keys[1]}")]});
359
- })()
360
- JS
361
-
362
- assert_equal expected, result
363
- end
364
-
365
- test "render array of partials" do
366
- result = jbuild(<<-JBUILDER)
367
- json.array! BLOG_POST_COLLECTION, partial: "blog_post", as: :blog_post
368
- JBUILDER
369
-
370
- expected = strip_format(<<-JS)
371
- (function(){
372
- return ({"data":[
373
- {"id":1,"body":"post body 1","author":{"first_name":"David","last_name":"Heinemeier Hansson"}},
374
- {"id":2,"body":"post body 2","author":{"first_name":"Pavel","last_name":"Pravosud"}},
375
- {"id":3,"body":"post body 3","author":{"first_name":"David","last_name":"Heinemeier Hansson"}},
376
- {"id":4,"body":"post body 4","author":{"first_name":"Pavel","last_name":"Pravosud"}},
377
- {"id":5,"body":"post body 5","author":{"first_name":"David","last_name":"Heinemeier Hansson"}},
378
- {"id":6,"body":"post body 6","author":{"first_name":"Pavel","last_name":"Pravosud"}},
379
- {"id":7,"body":"post body 7","author":{"first_name":"David","last_name":"Heinemeier Hansson"}},
380
- {"id":8,"body":"post body 8","author":{"first_name":"Pavel","last_name":"Pravosud"}},
381
- {"id":9,"body":"post body 9","author":{"first_name":"David","last_name":"Heinemeier Hansson"}},
382
- {"id":10,"body":"post body 10","author":{"first_name":"Pavel","last_name":"Pravosud"}}
383
- ]});
384
- })()
385
- JS
386
-
387
- assert_equal expected, result
388
- end
389
-
390
- test "renders array of partials as empty array with nil-collection" do
391
- result = jbuild(<<-JBUILDER)
392
- json.array! nil, partial: "blog_post", as: :blog_post
393
- JBUILDER
394
-
395
- expected = strip_format(<<-JS)
396
- (function(){
397
- return ({"data":[]});
398
- })()
399
- JS
400
-
401
- assert_equal expected, result
402
- end
403
-
404
- test "renders array of partials via set!" do
405
- result = jbuild(<<-JBUILDER)
406
- json.posts BLOG_POST_COLLECTION, partial: "blog_post", as: :blog_post
407
- JBUILDER
408
-
409
- expected = strip_format(<<-JS)
410
- (function(){
411
- return ({"data":{"posts":[
412
- {"id":1,"body":"post body 1","author":{"first_name":"David","last_name":"Heinemeier Hansson"}},
413
- {"id":2,"body":"post body 2","author":{"first_name":"Pavel","last_name":"Pravosud"}},
414
- {"id":3,"body":"post body 3","author":{"first_name":"David","last_name":"Heinemeier Hansson"}},
415
- {"id":4,"body":"post body 4","author":{"first_name":"Pavel","last_name":"Pravosud"}},
416
- {"id":5,"body":"post body 5","author":{"first_name":"David","last_name":"Heinemeier Hansson"}},
417
- {"id":6,"body":"post body 6","author":{"first_name":"Pavel","last_name":"Pravosud"}},
418
- {"id":7,"body":"post body 7","author":{"first_name":"David","last_name":"Heinemeier Hansson"}},
419
- {"id":8,"body":"post body 8","author":{"first_name":"Pavel","last_name":"Pravosud"}},
420
- {"id":9,"body":"post body 9","author":{"first_name":"David","last_name":"Heinemeier Hansson"}},
421
- {"id":10,"body":"post body 10","author":{"first_name":"Pavel","last_name":"Pravosud"}}
422
- ]}});
423
- })()
424
- JS
425
-
426
- assert_equal expected, result
427
- end
428
-
429
- test "render as empty array if partials as a nil value" do
430
- result = jbuild <<-JBUILDER
431
- json.posts nil, partial: "blog_post", as: :blog_post
432
- JBUILDER
433
-
434
- expected = strip_format(<<-JS)
435
- (function(){
436
- return ({"data":{"posts":[]}});
437
- })()
438
- JS
439
- assert_equal expected, result
440
- end
441
-
442
- test "caching a value at a node" do
443
- undef_context_methods :fragment_name_with_digest, :cache_fragment_name
444
-
445
- result = jbuild(<<-JBUILDER)
446
- json.hello(32, cache: ['b', 'c'])
447
- JBUILDER
448
-
449
- expected = strip_format(<<-JS)
450
- (function(){
451
- Breezy.cache("#{cache_keys[0]}", 32);
452
- return ({"data":{"hello":Breezy.cache("#{cache_keys[0]}")}});
453
- })()
454
- JS
455
-
456
- assert_equal expected, result
457
- end
458
-
459
- test "caching elements in a list" do
460
- undef_context_methods :fragment_name_with_digest, :cache_fragment_name
461
-
462
- result = jbuild(<<-JBUILDER)
463
- json.hello do
464
- json.array! [4,5], cache: ->(i){ ['a', i] } do |x|
465
- json.top "hello" + x.to_s
466
- end
467
- end
468
- JBUILDER
469
-
470
- expected = strip_format(<<-JS)
471
- (function(){
472
- Breezy.cache("#{cache_keys[0]}", {"top":"hello4"});
473
- Breezy.cache("#{cache_keys[1]}", {"top":"hello5"});
474
- return ({"data":{"hello":[Breezy.cache("#{cache_keys[0]}"),Breezy.cache("#{cache_keys[1]}")]}});
475
- })()
476
- JS
477
-
478
- assert_equal expected, result
479
- end
480
-
481
- test "nested caching generates a depth-first list of cache nodes" do
482
- undef_context_methods :fragment_name_with_digest, :cache_fragment_name
483
-
484
- result = jbuild(<<-JBUILDER)
485
- json.hello(cache: ['a', 'b']) do
486
- json.content(cache: ['d', 'z']) do
487
- json.subcontent 'inner'
488
- end
489
- json.other(cache: ['e', 'z']) do
490
- json.subcontent 'other'
491
- end
492
- end
493
- JBUILDER
494
-
495
- expected = strip_format(<<-JS)
496
- (function(){
497
- Breezy.cache("#{cache_keys[0]}", {"subcontent":"inner"});
498
- Breezy.cache("#{cache_keys[1]}", {"subcontent":"other"});
499
- Breezy.cache("#{cache_keys[2]}", {"content":Breezy.cache("#{cache_keys[0]}"),"other":Breezy.cache("#{cache_keys[1]}")});
500
- return ({"data":{"hello":Breezy.cache("#{cache_keys[2]}")}});
501
- })()
502
- JS
503
-
504
- assert_equal expected, result
505
- end
506
-
507
- test "caching an empty block generates no cache and no errors" do
508
- undef_context_methods :fragment_name_with_digest, :cache_fragment_name
509
-
510
- result = nil
511
-
512
- assert_nothing_raised do
513
- result = jbuild(<<-JBUILDER)
514
- json.hello do
515
- json.array! [4,5], cache: ->(i){['a', i]} do |x|
516
- end
517
- end
518
- JBUILDER
519
- end
520
-
521
- expected = strip_format(<<-JS)
522
- (function(){
523
- return ({\"data\":{\"hello\":[]}});
524
- })()
525
- JS
526
-
527
- assert_equal expected, result
528
- end
529
-
530
- test "child! accepts cache options" do
531
- undef_context_methods :fragment_name_with_digest, :cache_fragment_name
532
-
533
- result = jbuild(<<-JBUILDER)
534
- json.comments do
535
- json.child!(cache: ['e', 'z']) { json.content "hello" }
536
- json.child! { json.content "world" }
537
- end
538
- JBUILDER
539
-
540
- expected = strip_format(<<-JS)
541
- (function(){
542
- Breezy.cache("#{cache_keys[0]}", {"content":"hello"});
543
- return ({"data":{"comments":[Breezy.cache("#{cache_keys[0]}"),{"content":"world"}]}});
544
- })()
545
- JS
546
-
547
- assert_equal expected, result
548
- end
549
-
550
- test "fragment caching" do
551
- undef_context_methods :fragment_name_with_digest, :cache_fragment_name
552
-
553
- jbuild(<<-JBUILDER)
554
- json.post(cache: 'cachekey') do
555
- json.name "Cache"
556
- end
557
- JBUILDER
558
-
559
- result = jbuild(<<-JBUILDER)
560
- json.post(cache: 'cachekey') do
561
- json.name "Miss"
562
- end
563
- JBUILDER
564
-
565
- expected = strip_format(<<-JS)
566
- (function(){
567
- Breezy.cache("#{cache_keys[0]}", {"name":"Cache"});
568
- return ({"data":{"post":Breezy.cache("#{cache_keys[0]}")}});
569
- })()
570
- JS
571
-
572
- assert_equal expected, result
573
- end
574
-
575
- test "fragment caching deserializes an array" do
576
- undef_context_methods :fragment_name_with_digest, :cache_fragment_name
577
-
578
- result = jbuild <<-JBUILDER
579
- json.content(cache: "cachekey") do
580
- json.array! %w[a b c]
581
- end
582
- JBUILDER
583
-
584
- expected = strip_format(<<-JS)
585
- (function(){
586
- Breezy.cache("#{cache_keys[0]}", ["a","b","c"]);
587
- return ({"data":{"content":Breezy.cache("#{cache_keys[0]}")}});
588
- })()
589
- JS
590
-
591
- assert_equal expected, result
592
- end
593
-
594
- test "fragment caching works with previous version of cache digests" do
595
- undef_context_methods :cache_fragment_name
596
-
597
- if !@context.class.method_defined? :fragment_name_with_digest
598
- @context.class_eval do
599
- def fragment_name_with_digest
600
- end
601
- end
602
- end
603
-
604
- @context.expects :fragment_name_with_digest
605
-
606
- jbuild <<-JBUILDER
607
- json.content(cache: "cachekey") do
608
- json.name "Cache"
609
- end
610
- JBUILDER
611
- end
612
-
613
- test "fragment caching works with current cache digests" do
614
- undef_context_methods :fragment_name_with_digest
615
-
616
- @context.expects :cache_fragment_name
617
- ActiveSupport::Cache.expects :expand_cache_key
618
-
619
- jbuild <<-JBUILDER
620
- json.content(cache: "cachekey") do
621
- json.name "Cache"
622
- end
623
- JBUILDER
624
- end
625
-
626
- test "current cache digest option accepts options through the last element hash" do
627
- undef_context_methods :fragment_name_with_digest
628
-
629
- @context.expects(:cache_fragment_name)
630
- .with("cachekey", skip_digest: true)
631
- .returns("cachekey")
632
-
633
- ActiveSupport::Cache.expects :expand_cache_key
634
-
635
- jbuild <<-JBUILDER
636
- json.content(cache: ["cachekey", skip_digest: true]) do
637
- json.name "Cache"
638
- end
639
- JBUILDER
640
- end
641
-
642
- test "does not perform caching when controller.perform_caching is false" do
643
- controller.perform_caching = false
644
-
645
- result = jbuild <<-JBUILDER
646
- json.content(cache: "cachekey") do
647
- json.name "Cache"
648
- end
649
- JBUILDER
650
-
651
- expected = strip_format(<<-JS)
652
- (function(){
653
- return ({"data":{"content":{"name":"Cache"}}});
654
- })()
655
- JS
656
-
657
- assert_equal expected, result
658
- end
659
-
660
- test "invokes templates via params via set! and caches" do
661
- @post = BLOG_POST_COLLECTION.first
662
-
663
- result = jbuild(<<-JBUILDER)
664
- json.post @post, partial: "blog_post", as: :blog_post, cache: ['a', 'b']
665
- JBUILDER
666
-
667
- expected = strip_format(<<-JS)
668
- (function(){
669
- Breezy.cache("#{cache_keys[0]}", {"id":1,"body":"post body 1","author":{"first_name":"David","last_name":"Heinemeier Hansson"}});
670
- return ({"data":{"post":Breezy.cache("#{cache_keys[0]}")}});
671
- })()
672
- JS
673
-
674
- assert_equal expected, result
675
- end
676
-
677
- test "shares partial caches (via the partial's digest) across multiple templates" do
678
- @hit = BlogPost.new(1, "hit", "John Smith")
679
- @miss = BlogPost.new(2, "miss", "John Smith")
680
-
681
- jbuild(<<-JBUILDER)
682
- json.post @hit, partial: "blog_post", as: :blog_post, cache: ['a', 'b']
683
- JBUILDER
684
-
685
- result = jbuild(<<-JBUILDER)
686
- json.post @miss, partial: "blog_post", as: :blog_post, cache: ['a', 'b']
687
- JBUILDER
688
-
689
- expected = strip_format(<<-JS)
690
- (function(){
691
- Breezy.cache("#{cache_keys[0]}", {"id":1,"body":"hit","author":{"first_name":"John","last_name":"Smith"}});
692
- return ({"data":{"post":Breezy.cache("#{cache_keys[0]}")}});
693
- })()
694
- JS
695
-
696
- assert_equal expected, result
697
- end
698
-
699
-
700
- test "render array of partials and caches" do
701
- result = jbuild(<<-JBUILDER)
702
- json.array! BLOG_POST_COLLECTION, partial: "blog_post", as: :blog_post, cache: ->(d){ ['a', d.id] }
703
- JBUILDER
704
- Rails.cache.clear
705
-
706
- expected = strip_format(<<-JS)
707
- (function(){
708
- Breezy.cache("#{cache_keys[0]}", {"id":1,"body":"post body 1","author":{"first_name":"David","last_name":"Heinemeier Hansson"}});
709
- Breezy.cache("#{cache_keys[1]}", {"id":2,"body":"post body 2","author":{"first_name":"Pavel","last_name":"Pravosud"}});
710
- Breezy.cache("#{cache_keys[2]}", {"id":3,"body":"post body 3","author":{"first_name":"David","last_name":"Heinemeier Hansson"}});
711
- Breezy.cache("#{cache_keys[3]}", {"id":4,"body":"post body 4","author":{"first_name":"Pavel","last_name":"Pravosud"}});
712
- Breezy.cache("#{cache_keys[4]}", {"id":5,"body":"post body 5","author":{"first_name":"David","last_name":"Heinemeier Hansson"}});
713
- Breezy.cache("#{cache_keys[5]}", {"id":6,"body":"post body 6","author":{"first_name":"Pavel","last_name":"Pravosud"}});
714
- Breezy.cache("#{cache_keys[6]}", {"id":7,"body":"post body 7","author":{"first_name":"David","last_name":"Heinemeier Hansson"}});
715
- Breezy.cache("#{cache_keys[7]}", {"id":8,"body":"post body 8","author":{"first_name":"Pavel","last_name":"Pravosud"}});
716
- Breezy.cache("#{cache_keys[8]}", {"id":9,"body":"post body 9","author":{"first_name":"David","last_name":"Heinemeier Hansson"}});
717
- Breezy.cache("#{cache_keys[9]}", {"id":10,"body":"post body 10","author":{"first_name":"Pavel","last_name":"Pravosud"}});
718
- return ({"data":[Breezy.cache("#{cache_keys[0]}"),Breezy.cache("#{cache_keys[1]}"),Breezy.cache("#{cache_keys[2]}"),Breezy.cache("#{cache_keys[3]}"),Breezy.cache("#{cache_keys[4]}"),Breezy.cache("#{cache_keys[5]}"),Breezy.cache("#{cache_keys[6]}"),Breezy.cache("#{cache_keys[7]}"),Breezy.cache("#{cache_keys[8]}"),Breezy.cache("#{cache_keys[9]}")]});
719
- })()
720
- JS
721
-
722
- assert_equal expected, result
723
- end
724
-
725
- test "filtering for a node in the tree" do
726
- result = jbuild(<<-JBUILDER)
727
- json._filter_by_path('hit.hit2')
728
- json.hit do
729
- json.hit2 do
730
- json.greeting 'hello world'
731
- end
732
- end
733
-
734
- json.miss do
735
- json.miss2 do
736
- raise 'this should not be called'
737
- json.greeting 'missed call'
738
- end
739
- end
740
- JBUILDER
741
- Rails.cache.clear
742
-
743
- expected = strip_format(<<-JS)
744
- (function(){
745
- return (
746
- {"data":{"greeting":"hello world"}}
747
- );
748
- })()
749
- JS
750
-
751
- assert_equal expected, result
752
- end
753
-
754
- test "filtering for a raw value is also possble" do
755
- result = jbuild(<<-JBUILDER, breezy_filter: 'hit.hit2')
756
- json.hit do
757
- json.hit2 23
758
- end
759
-
760
- json.miss do
761
- json.miss2 do
762
- raise 'this should not be called'
763
- json.greeting 'missed call'
764
- end
765
- end
766
- JBUILDER
767
- Rails.cache.clear
768
-
769
- expected = strip_format(<<-JS)
770
- (function(){
771
- return (
772
- {"data":23,"action":"graft","path":"hit.hit2"}
773
- );
774
- })()
775
- JS
776
-
777
- assert_equal expected, result
778
- end
779
-
780
- test "filter with partial" do
781
- result = jbuild(<<-JBUILDER, breezy_filter: 'hit.hit2.terms')
782
- json.hit do
783
- json.hit2 partial: "footer"
784
- end
785
- JBUILDER
786
-
787
- expected = strip_format(<<-JS)
788
- (function(){
789
- return (
790
- {"data":"You agree","action":"graft","path":"hit.hit2.terms"}
791
- );
792
- })()
793
- JS
794
- assert_equal expected, result
795
- end
796
-
797
- test "filtering for a node in the tree via breezy_filter helper" do
798
- result = jbuild(<<-JBUILDER, breezy_filter: 'hit.hit2')
799
- json.hit do
800
- json.hit2 do
801
- json.greeting 'hello world'
802
- end
803
- end
804
-
805
- json.miss do
806
- json.miss2 do
807
- raise 'this should not be called'
808
- json.greeting 'missed call'
809
- end
810
- end
811
- JBUILDER
812
- Rails.cache.clear
813
-
814
- expected = strip_format(<<-JS)
815
- (function(){
816
- return (
817
- {"data":{"greeting":"hello world"},"action":"graft","path":"hit.hit2"}
818
- );
819
- })()
820
- JS
821
-
822
- assert_equal expected, result
823
- end
824
-
825
- test "filtering a cached node returns just that" do
826
- undef_context_methods :fragment_name_with_digest, :cache_fragment_name
827
- result = jbuild(<<-JBUILDER, breezy_filter: 'hit.hit2')
828
- json.hit do
829
- json.hit2(cache: 'a') do
830
- json.greeting 'hello world'
831
- end
832
- end
833
- JBUILDER
834
- Rails.cache.clear
835
-
836
- expected = strip_format(<<-JS)
837
- (function(){
838
- Breezy.cache("#{cache_keys[0]}", {"greeting":"hello world"});
839
- return ({"data":Breezy.cache("219dfba9f552f91402a22cf67c633582"),"action":"graft","path":"hit.hit2"});
840
- })()
841
-
842
-
843
- JS
844
-
845
- assert_equal expected, result
846
- end
847
-
848
- test "filtering for a node of a AR relation in a tree by id via an appended where clause" do
849
- result = jbuild(<<-JBUILDER, breezy_filter: 'hit.hit2.id=1')
850
- post = Post.create
851
- post.comments.create title: 'first'
852
- post.comments.create title: 'second'
853
-
854
- post.comments.expects(:where).once().with('id'=>1).returns([{id: 1, title: 'first'}])
855
-
856
- json.hit do
857
- json.hit2 do
858
- json.array! post.comments do |x|
859
- raise 'this should be be called' if x[:title] == 'second'
860
- json.title x[:title]
861
- end
862
- end
863
- end
864
- JBUILDER
865
-
866
- Rails.cache.clear
867
-
868
- expected = strip_format(<<-JS)
869
- (function(){
870
- return (
871
- {"data":{"title":"first"},"action":"graft","path":"hit.hit2.id=1"}
872
- );
873
- })()
874
- JS
875
- assert_equal expected, result
876
- end
877
-
878
-
879
- test "filtering for a node of a AR relation in a tree by index via an appended where clause" do
880
- result = jbuild(<<-JBUILDER, breezy_filter: 'hit.hit2.0')
881
- post = Post.create
882
- post.comments.create title: 'first'
883
- post.comments.create title: 'second'
884
-
885
- offset = post.comments.offset(0)
886
- post.comments.expects(:offset).once().with(0).returns(offset)
887
-
888
- json.hit do
889
- json.hit2 do
890
- json.array! post.comments do |x|
891
- raise 'this should be be called' if x[:title] == 'second'
892
- json.title x[:title]
893
- end
894
- end
895
- end
896
- JBUILDER
897
-
898
- Rails.cache.clear
899
-
900
- expected = strip_format(<<-JS)
901
- (function(){
902
- return (
903
- {"data":{"title":"first"},"action":"graft","path":"hit.hit2.0"}
904
- );
905
- })()
906
- JS
907
- assert_equal expected, result
908
- end
909
-
910
- test "filtering for a node in an array of a tree by id" do
911
- result = jbuild(<<-JBUILDER, breezy_filter: 'hit.hit2.id=1')
912
- json.hit do
913
- json.hit2 do
914
- json.array! [{id: 1, name: 'hit' }, {id:2, name: 'miss'}] do |x|
915
- raise 'this should be be called' if x[:name] == 'miss'
916
- json.name x[:name]
917
- end
918
- end
919
- end
920
- JBUILDER
921
- Rails.cache.clear
922
-
923
- expected = strip_format(<<-JS)
924
- (function(){
925
- return (
926
- {"data":{"name":"hit"},"action":"graft","path":"hit.hit2.id=1"}
927
- );
928
- })()
929
- JS
930
-
931
- assert_equal expected, result
932
- end
933
-
934
- test "filtering for a node in an array of a tree by index" do
935
- result = jbuild(<<-JBUILDER, breezy_filter: 'hit.hit2.0')
936
- json.hit do
937
- json.hit2 do
938
- json.array! [{id: 1, name: 'hit' }, {id:2, name: 'miss'}] do |x|
939
- raise 'this should be be called' if x[:name] == 'miss'
940
- json.name x[:name]
941
- end
942
- end
943
- end
944
- JBUILDER
945
- Rails.cache.clear
946
-
947
- expected = strip_format(<<-JS)
948
- (function(){
949
- return (
950
- {"data":{"name":"hit"},"action":"graft","path":"hit.hit2.0"}
951
- );
952
- })()
953
- JS
954
-
955
- assert_equal expected, result
956
- end
957
-
958
- test "rendering with node deferement" do
959
- req = action_controller_test_request
960
- req.path = '/some_url'
961
-
962
- result = jbuild(<<-JBUILDER, request: req)
963
- json.hit do
964
- json.hit2 defer: :auto do
965
- json.hit3 do
966
- json.greeting 'hello world'
967
- end
968
- end
969
- end
970
- JBUILDER
971
- Rails.cache.clear
972
-
973
- expected = strip_format(<<-JS)
974
- (function(){
975
- Breezy.visit('/some_url?_breezy_filter=hit.hit2', {async: true, pushState: false});
976
- return (
977
- {"data":{"hit":{"hit2":null}}}
978
- );
979
- })()
980
- JS
981
-
982
- assert_equal expected, result
983
- end
984
-
985
- test "rendering with manual node deferement" do
986
- req = action_controller_test_request
987
- req.path = '/some_url'
988
-
989
- result = jbuild(<<-JBUILDER, request: req)
990
- json.hit do
991
- json.hit2 defer: :manual do
992
- json.hit3 do
993
- json.greeting 'hello world'
994
- end
995
- end
996
- end
997
- JBUILDER
998
- Rails.cache.clear
999
-
1000
- expected = strip_format(<<-JS)
1001
- (function(){
1002
- return (
1003
- {"data":{"hit":{"hit2":null}}}
1004
- );
1005
- })()
1006
- JS
1007
-
1008
- assert_equal expected, result
1009
- end
1010
-
1011
- test "rendering with node array deferment" do
1012
- req = action_controller_test_request
1013
- req.path = '/some_url'
1014
-
1015
- result = jbuild(<<-JBUILDER, request: req)
1016
- json.hit do
1017
- json.hit2 do
1018
- data = [{id: 1, name: 'foo'}, {id: 2, name: 'bar'}]
1019
- json.array! data, key: :id do
1020
- json.greeting defer: :auto do
1021
- json.gree 'hi'
1022
- end
1023
- end
1024
- end
1025
- end
1026
- JBUILDER
1027
- Rails.cache.clear
1028
-
1029
- expected = strip_format(<<-JS)
1030
- (function(){
1031
- Breezy.visit('/some_url?_breezy_filter=hit.hit2.id%3D1.greeting', {async: true, pushState: false});
1032
- Breezy.visit('/some_url?_breezy_filter=hit.hit2.id%3D2.greeting', {async: true, pushState: false});
1033
- return (
1034
- {"data":{"hit":{"hit2":[{"greeting":null},{"greeting":null}]}}}
1035
- );
1036
- })()
1037
- JS
1038
-
1039
- assert_equal expected, result
1040
- end
1041
-
1042
- test 'deferment does not work on values' do
1043
- undef_context_methods :fragment_name_with_digest, :cache_fragment_name
1044
-
1045
- result = jbuild(<<-JBUILDER)
1046
- json.hello(32, defer: :auto)
1047
- JBUILDER
1048
-
1049
- expected = strip_format(<<-JS)
1050
- (function(){
1051
- return ({"data":{"hello":32}});
1052
- })()
1053
- JS
1054
-
1055
- assert_equal expected, result
1056
- end
1057
-
1058
- test 'deferment is disabled when filtering by keypath' do
1059
- undef_context_methods :fragment_name_with_digest, :cache_fragment_name
1060
- result = jbuild(<<-JBUILDER, breezy_filter: 'hello.world')
1061
- json.hello defer: :auto do
1062
- json.world 32
1063
- end
1064
- JBUILDER
1065
-
1066
- expected = strip_format(<<-JS)
1067
- (function(){
1068
- return ({"data":32,"action":"graft","path":"hello.world"});
1069
- })()
1070
- JS
1071
-
1072
- assert_equal expected, result
1073
-
1074
- end
1075
-
1076
- test 'deferment is enabled at the end of a keypath when filtering' do
1077
- undef_context_methods :fragment_name_with_digest, :cache_fragment_name
1078
- result = jbuild(<<-JBUILDER, breezy_filter: 'hello')
1079
- json.hello defer: :auto do
1080
- json.content defer: :auto do
1081
- json.world 32
1082
- end
1083
- end
1084
- JBUILDER
1085
-
1086
- expected = strip_format(<<-JS)
1087
- (function(){
1088
- Breezy.visit('?_breezy_filter=hello.content', {async: true, pushState: false});
1089
- return ({"data":{"content":null},"action":"graft","path":"hello"});
1090
- })()
1091
- JS
1092
-
1093
- assert_equal expected, result
1094
- end
1095
- end