prototype-rails 4.0.0 → 4.0.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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +20 -0
  3. data/{README → README.md} +12 -0
  4. data/Rakefile +2 -0
  5. data/lib/prototype-rails/on_load_action_view.rb +5 -3
  6. metadata +15 -46
  7. data/test/assert_select_test.rb +0 -457
  8. data/test/controller/caching_test.rb +0 -43
  9. data/test/controller/content_type_test.rb +0 -16
  10. data/test/controller/mime_responds_test.rb +0 -213
  11. data/test/controller/new_base/content_type_test.rb +0 -19
  12. data/test/controller/new_base/render_rjs_test.rb +0 -71
  13. data/test/controller/render_js_test.rb +0 -22
  14. data/test/fixtures/functional_caching/_partial.erb +0 -3
  15. data/test/fixtures/functional_caching/formatted_fragment_cached.js.rjs +0 -6
  16. data/test/fixtures/functional_caching/js_fragment_cached_with_partial.js.rjs +0 -1
  17. data/test/fixtures/old_content_type/render_default_for_rjs.rjs +0 -1
  18. data/test/fixtures/respond_to/all_types_with_layout.js.rjs +0 -1
  19. data/test/fixtures/respond_to/layouts/standard.html.erb +0 -1
  20. data/test/fixtures/respond_to/using_defaults.js.rjs +0 -1
  21. data/test/fixtures/respond_to/using_defaults_with_type_list.js.rjs +0 -1
  22. data/test/fixtures/respond_with/using_resource.js.rjs +0 -1
  23. data/test/fixtures/test/_one.html.erb +0 -1
  24. data/test/fixtures/test/_partial.html.erb +0 -1
  25. data/test/fixtures/test/_partial.js.erb +0 -1
  26. data/test/fixtures/test/_two.html.erb +0 -1
  27. data/test/fixtures/test/delete_with_js.rjs +0 -2
  28. data/test/fixtures/test/enum_rjs_test.rjs +0 -6
  29. data/test/fixtures/test/greeting.js.rjs +0 -1
  30. data/test/fixtures/test/render_explicit_html_template.js.rjs +0 -1
  31. data/test/fixtures/test/render_implicit_html_template.js.rjs +0 -1
  32. data/test/javascript_helper_test.rb +0 -61
  33. data/test/lib/abstract_unit.rb +0 -225
  34. data/test/lib/controller/fake_models.rb +0 -29
  35. data/test/render_other_test.rb +0 -256
  36. data/test/template/prototype_helper_test.rb +0 -476
  37. data/test/template/render_test.rb +0 -24
  38. data/test/template/scriptaculous_helper_test.rb +0 -86
@@ -1,476 +0,0 @@
1
- require 'abstract_unit'
2
- require 'active_model'
3
-
4
- class Bunny < Struct.new(:Bunny, :id)
5
- extend ActiveModel::Naming
6
- include ActiveModel::Conversion
7
- def to_key() id ? [id] : nil end
8
- end
9
-
10
- class Author
11
- extend ActiveModel::Naming
12
- include ActiveModel::Conversion
13
-
14
- attr_reader :id
15
- def to_key() id ? [id] : nil end
16
- def save; @id = 1 end
17
- def new_record?; @id.nil? end
18
- def name
19
- @id.nil? ? 'new author' : "author ##{@id}"
20
- end
21
- end
22
-
23
- class Article
24
- extend ActiveModel::Naming
25
- include ActiveModel::Conversion
26
- attr_reader :id
27
- attr_reader :author_id
28
- def to_key() id ? [id] : nil end
29
- def save; @id = 1; @author_id = 1 end
30
- def new_record?; @id.nil? end
31
- def name
32
- @id.nil? ? 'new article' : "article ##{@id}"
33
- end
34
- end
35
-
36
- class Author::Nested < Author; end
37
-
38
-
39
- class PrototypeHelperBaseTest < ActionView::TestCase
40
- attr_accessor :formats, :output_buffer
41
-
42
- def update_details(details)
43
- @details = details
44
- yield if block_given?
45
- end
46
-
47
- def setup
48
- super
49
- @template = self
50
- end
51
-
52
- def url_for(options)
53
- if options.is_a?(String)
54
- options
55
- else
56
- url = "http://www.example.com/"
57
- url << options[:action].to_s if options and options[:action]
58
- url << "?a=#{options[:a]}" if options && options[:a]
59
- url << "&b=#{options[:b]}" if options && options[:a] && options[:b]
60
- url
61
- end
62
- end
63
-
64
- protected
65
- def request_forgery_protection_token
66
- nil
67
- end
68
-
69
- def protect_against_forgery?
70
- false
71
- end
72
-
73
- def create_generator
74
- block = Proc.new { |*args| yield(*args) if block_given? }
75
- JavaScriptGenerator.new self, &block
76
- end
77
- end
78
-
79
- class PrototypeHelperTest < PrototypeHelperBaseTest
80
- def _evaluate_assigns_and_ivars() end
81
-
82
- def setup
83
- @record = @author = Author.new
84
- @article = Article.new
85
- super
86
- end
87
-
88
- def test_update_page
89
- old_output_buffer = output_buffer
90
-
91
- block = Proc.new { |page| page.replace_html('foo', 'bar') }
92
- assert_equal create_generator(&block).to_s, update_page(&block)
93
-
94
- assert_equal old_output_buffer, output_buffer
95
- end
96
-
97
- def test_update_page_tag
98
- block = Proc.new { |page| page.replace_html('foo', 'bar') }
99
- assert_equal javascript_tag(create_generator(&block).to_s), update_page_tag(&block)
100
- end
101
-
102
- def test_update_page_tag_with_html_options
103
- block = Proc.new { |page| page.replace_html('foo', 'bar') }
104
- assert_equal javascript_tag(create_generator(&block).to_s, {:defer => 'true'}), update_page_tag({:defer => 'true'}, &block)
105
- end
106
-
107
- def test_remote_function
108
- res = remote_function(:url => authors_path, :with => "'author[name]='+$F('author_name')+'&author[dob]='+$F('author_dob')")
109
- assert_equal "new Ajax.Request('/authors', {asynchronous:true, evalScripts:true, parameters:'author[name]='+$F('author_name')+'&author[dob]='+$F('author_dob')})", res
110
- assert res.html_safe?
111
- end
112
-
113
- protected
114
- def author_path(record)
115
- "/authors/#{record.id}"
116
- end
117
-
118
- def authors_path
119
- "/authors"
120
- end
121
-
122
- def author_articles_path(author)
123
- "/authors/#{author.id}/articles"
124
- end
125
-
126
- def author_article_path(author, article)
127
- "/authors/#{author.id}/articles/#{article.id}"
128
- end
129
- end
130
-
131
- class JavaScriptGeneratorTest < PrototypeHelperBaseTest
132
- def setup
133
- super
134
- @generator = create_generator
135
- ActiveSupport.escape_html_entities_in_json = true
136
- end
137
-
138
- def teardown
139
- ActiveSupport.escape_html_entities_in_json = false
140
- end
141
-
142
- def _evaluate_assigns_and_ivars() end
143
-
144
- def test_insert_html_with_string
145
- assert_equal 'Element.insert("element", { top: "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E" });',
146
- @generator.insert_html(:top, 'element', '<p>This is a test</p>')
147
- assert_equal 'Element.insert("element", { bottom: "\\u003Cp\u003EThis is a test\\u003C/p\u003E" });',
148
- @generator.insert_html(:bottom, 'element', '<p>This is a test</p>')
149
- assert_equal 'Element.insert("element", { before: "\\u003Cp\u003EThis is a test\\u003C/p\u003E" });',
150
- @generator.insert_html(:before, 'element', '<p>This is a test</p>')
151
- assert_equal 'Element.insert("element", { after: "\\u003Cp\u003EThis is a test\\u003C/p\u003E" });',
152
- @generator.insert_html(:after, 'element', '<p>This is a test</p>')
153
- end
154
-
155
- def test_replace_html_with_string
156
- assert_equal 'Element.update("element", "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");',
157
- @generator.replace_html('element', '<p>This is a test</p>')
158
- end
159
-
160
- def test_replace_element_with_string
161
- assert_equal 'Element.replace("element", "\\u003Cdiv id=\"element\"\\u003E\\u003Cp\\u003EThis is a test\\u003C/p\\u003E\\u003C/div\\u003E");',
162
- @generator.replace('element', '<div id="element"><p>This is a test</p></div>')
163
- end
164
-
165
- def test_remove
166
- assert_equal 'Element.remove("foo");',
167
- @generator.remove('foo')
168
- assert_equal '["foo","bar","baz"].each(Element.remove);',
169
- @generator.remove('foo', 'bar', 'baz')
170
- end
171
-
172
- def test_show
173
- assert_equal 'Element.show("foo");',
174
- @generator.show('foo')
175
- assert_equal '["foo","bar","baz"].each(Element.show);',
176
- @generator.show('foo', 'bar', 'baz')
177
- end
178
-
179
- def test_hide
180
- assert_equal 'Element.hide("foo");',
181
- @generator.hide('foo')
182
- assert_equal '["foo","bar","baz"].each(Element.hide);',
183
- @generator.hide('foo', 'bar', 'baz')
184
- end
185
-
186
- def test_toggle
187
- assert_equal 'Element.toggle("foo");',
188
- @generator.toggle('foo')
189
- assert_equal '["foo","bar","baz"].each(Element.toggle);',
190
- @generator.toggle('foo', 'bar', 'baz')
191
- end
192
-
193
- def test_alert
194
- assert_equal 'alert("hello");', @generator.alert('hello')
195
- end
196
-
197
- def test_redirect_to
198
- assert_equal 'window.location.href = "http://www.example.com/welcome";',
199
- @generator.redirect_to(:action => 'welcome')
200
- assert_equal 'window.location.href = "http://www.example.com/welcome?a=b&c=d";',
201
- @generator.redirect_to("http://www.example.com/welcome?a=b&c=d")
202
- end
203
-
204
- def test_reload
205
- assert_equal 'window.location.reload();',
206
- @generator.reload
207
- end
208
-
209
- def test_delay
210
- @generator.delay(20) do
211
- @generator.hide('foo')
212
- end
213
-
214
- assert_equal "setTimeout(function() {\n;\nElement.hide(\"foo\");\n}, 20000);", @generator.to_s
215
- end
216
-
217
- def test_to_s
218
- @generator.insert_html(:top, 'element', '<p>This is a test</p>')
219
- @generator.insert_html(:bottom, 'element', '<p>This is a test</p>')
220
- @generator.remove('foo', 'bar')
221
- @generator.replace_html('baz', '<p>This is a test</p>')
222
-
223
- assert_equal <<-EOS.chomp, @generator.to_s
224
- Element.insert("element", { top: "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E" });
225
- Element.insert("element", { bottom: "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E" });
226
- ["foo","bar"].each(Element.remove);
227
- Element.update("baz", "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");
228
- EOS
229
- end
230
-
231
- def test_element_access
232
- assert_equal %($("hello");), @generator['hello']
233
- end
234
-
235
- def test_element_access_on_records
236
- assert_equal %($("bunny_5");), @generator[Bunny.new(:id => 5)]
237
- assert_equal %($("new_bunny");), @generator[Bunny.new]
238
- end
239
-
240
- def test_element_proxy_one_deep
241
- @generator['hello'].hide
242
- assert_equal %($("hello").hide();), @generator.to_s
243
- end
244
-
245
- def test_element_proxy_variable_access
246
- @generator['hello']['style']
247
- assert_equal %($("hello").style;), @generator.to_s
248
- end
249
-
250
- def test_element_proxy_variable_access_with_assignment
251
- @generator['hello']['style']['color'] = 'red'
252
- assert_equal %($("hello").style.color = "red";), @generator.to_s
253
- end
254
-
255
- def test_element_proxy_assignment
256
- @generator['hello'].width = 400
257
- assert_equal %($("hello").width = 400;), @generator.to_s
258
- end
259
-
260
- def test_element_proxy_two_deep
261
- @generator['hello'].hide("first").clean_whitespace
262
- assert_equal %($("hello").hide("first").cleanWhitespace();), @generator.to_s
263
- end
264
-
265
- def test_select_access
266
- assert_equal %($$("div.hello");), @generator.select('div.hello')
267
- end
268
-
269
- def test_select_proxy_one_deep
270
- @generator.select('p.welcome b').first.hide
271
- assert_equal %($$("p.welcome b").first().hide();), @generator.to_s
272
- end
273
-
274
- def test_visual_effect
275
- assert_equal %(new Effect.Puff("blah",{});),
276
- @generator.visual_effect(:puff,'blah')
277
- end
278
-
279
- def test_visual_effect_toggle
280
- assert_equal %(Effect.toggle("blah",'appear',{});),
281
- @generator.visual_effect(:toggle_appear,'blah')
282
- end
283
-
284
- def test_sortable
285
- assert_equal %(Sortable.create("blah", {onUpdate:function(){new Ajax.Request('http://www.example.com/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize("blah")})}});),
286
- @generator.sortable('blah', :url => { :action => "order" })
287
- assert_equal %(Sortable.create("blah", {onUpdate:function(){new Ajax.Request('http://www.example.com/order', {asynchronous:false, evalScripts:true, parameters:Sortable.serialize("blah")})}});),
288
- @generator.sortable('blah', :url => { :action => "order" }, :type => :synchronous)
289
- end
290
-
291
- def test_draggable
292
- assert_equal %(new Draggable("blah", {});),
293
- @generator.draggable('blah')
294
- end
295
-
296
- def test_drop_receiving
297
- assert_equal %(Droppables.add("blah", {onDrop:function(element){new Ajax.Request('http://www.example.com/order', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}});),
298
- @generator.drop_receiving('blah', :url => { :action => "order" })
299
- assert_equal %(Droppables.add("blah", {onDrop:function(element){new Ajax.Request('http://www.example.com/order', {asynchronous:false, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}});),
300
- @generator.drop_receiving('blah', :url => { :action => "order" }, :type => :synchronous)
301
- end
302
-
303
- def test_collection_first_and_last
304
- @generator.select('p.welcome b').first.hide()
305
- @generator.select('p.welcome b').last.show()
306
- assert_equal <<-EOS.strip, @generator.to_s
307
- $$("p.welcome b").first().hide();
308
- $$("p.welcome b").last().show();
309
- EOS
310
- end
311
-
312
- def test_collection_proxy_with_each
313
- @generator.select('p.welcome b').each do |value|
314
- value.remove_class_name 'selected'
315
- end
316
- @generator.select('p.welcome b').each do |value, index|
317
- @generator.visual_effect :highlight, value
318
- end
319
- assert_equal <<-EOS.strip, @generator.to_s
320
- $$("p.welcome b").each(function(value, index) {
321
- value.removeClassName("selected");
322
- });
323
- $$("p.welcome b").each(function(value, index) {
324
- new Effect.Highlight(value,{});
325
- });
326
- EOS
327
- end
328
-
329
- def test_collection_proxy_on_collect
330
- @generator.select('p').collect('a') { |para| para.show }
331
- @generator.select('p').collect { |para| para.hide }
332
- assert_equal <<-EOS.strip, @generator.to_s
333
- var a = $$("p").collect(function(value, index) {
334
- return value.show();
335
- });
336
- $$("p").collect(function(value, index) {
337
- return value.hide();
338
- });
339
- EOS
340
- @generator = create_generator
341
- end
342
-
343
- def test_collection_proxy_with_grep
344
- @generator.select('p').grep 'a', /^a/ do |value|
345
- @generator << '(value.className == "welcome")'
346
- end
347
- @generator.select('p').grep 'b', /b$/ do |value, index|
348
- @generator.call 'alert', value
349
- @generator << '(value.className == "welcome")'
350
- end
351
-
352
- assert_equal <<-EOS.strip, @generator.to_s
353
- var a = $$("p").grep(/^a/, function(value, index) {
354
- return (value.className == "welcome");
355
- });
356
- var b = $$("p").grep(/b$/, function(value, index) {
357
- alert(value);
358
- return (value.className == "welcome");
359
- });
360
- EOS
361
- end
362
-
363
- def test_collection_proxy_with_inject
364
- @generator.select('p').inject 'a', [] do |memo, value|
365
- @generator << '(value.className == "welcome")'
366
- end
367
- @generator.select('p').inject 'b', nil do |memo, value, index|
368
- @generator.call 'alert', memo
369
- @generator << '(value.className == "welcome")'
370
- end
371
-
372
- assert_equal <<-EOS.strip, @generator.to_s
373
- var a = $$("p").inject([], function(memo, value, index) {
374
- return (value.className == "welcome");
375
- });
376
- var b = $$("p").inject(null, function(memo, value, index) {
377
- alert(memo);
378
- return (value.className == "welcome");
379
- });
380
- EOS
381
- end
382
-
383
- def test_collection_proxy_with_pluck
384
- @generator.select('p').pluck('a', 'className')
385
- assert_equal %(var a = $$("p").pluck("className");), @generator.to_s
386
- end
387
-
388
- def test_collection_proxy_with_zip
389
- ActionView::Helpers::JavaScriptCollectionProxy.new(@generator, '[1, 2, 3]').zip('a', [4, 5, 6], [7, 8, 9])
390
- ActionView::Helpers::JavaScriptCollectionProxy.new(@generator, '[1, 2, 3]').zip('b', [4, 5, 6], [7, 8, 9]) do |array|
391
- @generator.call 'array.reverse'
392
- end
393
-
394
- assert_equal <<-EOS.strip, @generator.to_s
395
- var a = [1, 2, 3].zip([4,5,6], [7,8,9]);
396
- var b = [1, 2, 3].zip([4,5,6], [7,8,9], function(array) {
397
- return array.reverse();
398
- });
399
- EOS
400
- end
401
-
402
- def test_collection_proxy_with_find_all
403
- @generator.select('p').find_all 'a' do |value, index|
404
- @generator << '(value.className == "welcome")'
405
- end
406
-
407
- assert_equal <<-EOS.strip, @generator.to_s
408
- var a = $$("p").findAll(function(value, index) {
409
- return (value.className == "welcome");
410
- });
411
- EOS
412
- end
413
-
414
- def test_collection_proxy_with_in_groups_of
415
- @generator.select('p').in_groups_of('a', 3)
416
- @generator.select('p').in_groups_of('a', 3, 'x')
417
- assert_equal <<-EOS.strip, @generator.to_s
418
- var a = $$("p").inGroupsOf(3);
419
- var a = $$("p").inGroupsOf(3, "x");
420
- EOS
421
- end
422
-
423
- def test_collection_proxy_with_each_slice
424
- @generator.select('p').each_slice('a', 3)
425
- @generator.select('p').each_slice('a', 3) do |group, index|
426
- group.reverse
427
- end
428
-
429
- assert_equal <<-EOS.strip, @generator.to_s
430
- var a = $$("p").eachSlice(3);
431
- var a = $$("p").eachSlice(3, function(value, index) {
432
- return value.reverse();
433
- });
434
- EOS
435
- end
436
-
437
- def test_debug_rjs
438
- ActionView::Base.debug_rjs = true
439
- @generator['welcome'].replace_html 'Welcome'
440
- assert_equal "try {\n$(\"welcome\").update(\"Welcome\");\n} catch (e) { alert('RJS error:\\n\\n' + e.toString()); alert('$(\\\"welcome\\\").update(\\\"Welcome\\\");'); throw e }", @generator.to_s
441
- ensure
442
- ActionView::Base.debug_rjs = false
443
- end
444
-
445
- def test_literal
446
- literal = @generator.literal("function() {}")
447
- assert_equal "function() {}", ActiveSupport::JSON.encode(literal)
448
- assert_equal "", @generator.to_s
449
- end
450
-
451
- def test_class_proxy
452
- @generator.form.focus('my_field')
453
- assert_equal "Form.focus(\"my_field\");", @generator.to_s
454
- end
455
-
456
- def test_call_with_block
457
- @generator.call(:before)
458
- @generator.call(:my_method) do |p|
459
- p[:one].show
460
- p[:two].hide
461
- end
462
- @generator.call(:in_between)
463
- @generator.call(:my_method_with_arguments, true, "hello") do |p|
464
- p[:three].visual_effect(:highlight)
465
- end
466
- assert_equal "before();\nmy_method(function() { $(\"one\").show();\n$(\"two\").hide(); });\nin_between();\nmy_method_with_arguments(true, \"hello\", function() { $(\"three\").visualEffect(\"highlight\"); });", @generator.to_s
467
- end
468
-
469
- def test_class_proxy_call_with_block
470
- @generator.my_object.my_method do |p|
471
- p[:one].show
472
- p[:two].hide
473
- end
474
- assert_equal "MyObject.myMethod(function() { $(\"one\").show();\n$(\"two\").hide(); });", @generator.to_s
475
- end
476
- end