Skip to content
This repository
Browse code

Made JavaScriptHelper tests pass regardless of hash order #1656 [Sam …

…Stephenson]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1794 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 383b6afd1c943096951ea845b3fc726f4d2193a6 1 parent c697be5
David Heinemeier Hansson authored July 10, 2005
2  actionpack/lib/action_view/helpers/javascript_helper.rb
@@ -504,7 +504,7 @@ def javascript_tag(content)
504 504
 
505 505
     private
506 506
       def options_for_javascript(options)
507  
-        '{' + options.map {|k, v| "#{k}:#{v}"}.join(', ') + '}'
  507
+        '{' + options.map {|k, v| "#{k}:#{v}"}.sort.join(', ') + '}'
508 508
       end
509 509
       
510 510
       def options_for_ajax(options)
36  actionpack/test/template/javascript_helper_test.rb
@@ -35,40 +35,40 @@ def test_link_to_function
35 35
   end
36 36
   
37 37
   def test_link_to_remote
38  
-    assert_equal %(<a class=\"fine\" href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {evalScripts:true, asynchronous:true}); return false;\">Remote outpost</a>),
  38
+    assert_equal %(<a class=\"fine\" href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true}); return false;\">Remote outpost</a>),
39 39
       link_to_remote("Remote outpost", { :url => { :action => "whatnot"  }}, { :class => "fine"  })
40  
-    assert_equal %(<a href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {onComplete:function(request){alert(request.reponseText)}, evalScripts:true, asynchronous:true}); return false;\">Remote outpost</a>),
  40
+    assert_equal %(<a href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true, onComplete:function(request){alert(request.reponseText)}}); return false;\">Remote outpost</a>),
41 41
       link_to_remote("Remote outpost", :complete => "alert(request.reponseText)", :url => { :action => "whatnot"  })
42 42
   end
43 43
   
44 44
   def test_periodically_call_remote
45  
-    assert_equal %(<script>new PeriodicalExecuter(function() {new Ajax.Updater('schremser_bier', 'http://www.example.com/mehr_bier', {evalScripts:true, asynchronous:true})}, 10)</script>),
  45
+    assert_equal %(<script>new PeriodicalExecuter(function() {new Ajax.Updater('schremser_bier', 'http://www.example.com/mehr_bier', {asynchronous:true, evalScripts:true})}, 10)</script>),
46 46
       periodically_call_remote(:update => "schremser_bier", :url => { :action => "mehr_bier" })
47 47
   end
48 48
   
49 49
   def test_form_remote_tag
50  
-    assert_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {parameters:Form.serialize(this), evalScripts:true, asynchronous:true}); return false;\">),
  50
+    assert_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\">),
51 51
       form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast  })
52  
-    assert_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater({success:'glass_of_beer'}, 'http://www.example.com/fast', {parameters:Form.serialize(this), evalScripts:true, asynchronous:true}); return false;\">),
  52
+    assert_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater({success:'glass_of_beer'}, 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\">),
53 53
       form_remote_tag(:update => { :success => "glass_of_beer" }, :url => { :action => :fast  })
54  
-    assert_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater({failure:'glass_of_water'}, 'http://www.example.com/fast', {parameters:Form.serialize(this), evalScripts:true, asynchronous:true}); return false;\">),
  54
+    assert_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater({failure:'glass_of_water'}, 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\">),
55 55
       form_remote_tag(:update => { :failure => "glass_of_water" }, :url => { :action => :fast  })
56  
-    assert_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater({success:'glass_of_beer',failure:'glass_of_water'}, 'http://www.example.com/fast', {parameters:Form.serialize(this), evalScripts:true, asynchronous:true}); return false;\">),
  56
+    assert_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater({success:'glass_of_beer',failure:'glass_of_water'}, 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\">),
57 57
       form_remote_tag(:update => { :success => 'glass_of_beer', :failure => "glass_of_water" }, :url => { :action => :fast  })
58 58
   end
59 59
   
60 60
   def test_submit_to_remote
61  
-    assert_equal %(<input name=\"More beer!\" onclick=\"new Ajax.Updater('empty_bottle', 'http://www.example.com/', {parameters:Form.serialize(this.form), evalScripts:true, asynchronous:true}); return false;\" type=\"button\" value=\"1000000\" />),
  61
+    assert_equal %(<input name=\"More beer!\" onclick=\"new Ajax.Updater('empty_bottle', 'http://www.example.com/', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this.form)}); return false;\" type=\"button\" value=\"1000000\" />),
62 62
       submit_to_remote("More beer!", 1_000_000, :update => "empty_bottle")
63 63
   end
64 64
   
65 65
   def test_observe_field
66  
-    assert_equal %(<script type=\"text/javascript\">new Form.Element.Observer('glass', 300, function(element, value) {new Ajax.Request('http://www.example.com/reorder_if_empty', {evalScripts:true, asynchronous:true})})</script>),
  66
+    assert_equal %(<script type=\"text/javascript\">new Form.Element.Observer('glass', 300, function(element, value) {new Ajax.Request('http://www.example.com/reorder_if_empty', {asynchronous:true, evalScripts:true})})</script>),
67 67
       observe_field("glass", :frequency => 5.minutes, :url => { :action => "reorder_if_empty" })
68 68
   end
69 69
   
70 70
   def test_observe_form
71  
-    assert_equal %(<script type=\"text/javascript\">new Form.Observer('cart', 2, function(element, value) {new Ajax.Request('http://www.example.com/cart_changed', {evalScripts:true, asynchronous:true})})</script>),
  71
+    assert_equal %(<script type=\"text/javascript\">new Form.Observer('cart', 2, function(element, value) {new Ajax.Request('http://www.example.com/cart_changed', {asynchronous:true, evalScripts:true})})</script>),
72 72
       observe_form("cart", :frequency => 2, :url => { :action => "cart_changed" })
73 73
   end
74 74
   
@@ -101,13 +101,13 @@ def test_effect
101 101
   end
102 102
   
103 103
   def test_sortable_element
104  
-    assert_equal %(<script type=\"text/javascript\">Sortable.create('mylist', {onUpdate:function(){new Ajax.Request('http://www.example.com/order', {parameters:Sortable.serialize('mylist'), evalScripts:true, asynchronous:true})}})</script>), 
  104
+    assert_equal %(<script type=\"text/javascript\">Sortable.create('mylist', {onUpdate:function(){new Ajax.Request('http://www.example.com/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize('mylist')})}})</script>), 
105 105
       sortable_element("mylist", :url => { :action => "order" })
106  
-    assert_equal %(<script type=\"text/javascript\">Sortable.create('mylist', {tag:'div', constraint:'horizontal', onUpdate:function(){new Ajax.Request('http://www.example.com/order', {parameters:Sortable.serialize('mylist'), evalScripts:true, asynchronous:true})}})</script>), 
  106
+    assert_equal %(<script type=\"text/javascript\">Sortable.create('mylist', {constraint:'horizontal', onUpdate:function(){new Ajax.Request('http://www.example.com/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize('mylist')})}, tag:'div'})</script>), 
107 107
       sortable_element("mylist", :tag => "div", :constraint => "horizontal", :url => { :action => "order" })
108  
-    assert_equal %|<script type=\"text/javascript\">Sortable.create('mylist', {constraint:'horizontal', onUpdate:function(){new Ajax.Request('http://www.example.com/order', {parameters:Sortable.serialize('mylist'), evalScripts:true, asynchronous:true})}, containment:['list1','list2']})</script>|, 
  108
+    assert_equal %|<script type=\"text/javascript\">Sortable.create('mylist', {constraint:'horizontal', containment:['list1','list2'], onUpdate:function(){new Ajax.Request('http://www.example.com/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize('mylist')})}})</script>|, 
109 109
       sortable_element("mylist", :containment => ['list1','list2'], :constraint => "horizontal", :url => { :action => "order" })
110  
-    assert_equal %(<script type=\"text/javascript\">Sortable.create('mylist', {constraint:'horizontal', onUpdate:function(){new Ajax.Request('http://www.example.com/order', {parameters:Sortable.serialize('mylist'), evalScripts:true, asynchronous:true})}, containment:'list1'})</script>), 
  110
+    assert_equal %(<script type=\"text/javascript\">Sortable.create('mylist', {constraint:'horizontal', containment:'list1', onUpdate:function(){new Ajax.Request('http://www.example.com/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize('mylist')})}})</script>), 
111 111
       sortable_element("mylist", :containment => 'list1', :constraint => "horizontal", :url => { :action => "order" })
112 112
   end
113 113
   
@@ -119,13 +119,13 @@ def test_draggable_element
119 119
   end
120 120
   
121 121
   def test_drop_receiving_element
122  
-    assert_equal %(<script type=\"text/javascript\">Droppables.add('droptarget1', {onDrop:function(element){new Ajax.Request('http://www.example.com/', {parameters:'id=' + encodeURIComponent(element.id), evalScripts:true, asynchronous:true})}})</script>),
  122
+    assert_equal %(<script type=\"text/javascript\">Droppables.add('droptarget1', {onDrop:function(element){new Ajax.Request('http://www.example.com/', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}})</script>),
123 123
       drop_receiving_element('droptarget1')
124  
-    assert_equal %(<script type=\"text/javascript\">Droppables.add('droptarget1', {accept:'products', onDrop:function(element){new Ajax.Request('http://www.example.com/', {parameters:'id=' + encodeURIComponent(element.id), evalScripts:true, asynchronous:true})}})</script>),
  124
+    assert_equal %(<script type=\"text/javascript\">Droppables.add('droptarget1', {accept:'products', onDrop:function(element){new Ajax.Request('http://www.example.com/', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}})</script>),
125 125
       drop_receiving_element('droptarget1', :accept => 'products')
126  
-    assert_equal %(<script type=\"text/javascript\">Droppables.add('droptarget1', {accept:'products', onDrop:function(element){new Ajax.Updater('infobox', 'http://www.example.com/', {parameters:'id=' + encodeURIComponent(element.id), evalScripts:true, asynchronous:true})}})</script>),
  126
+    assert_equal %(<script type=\"text/javascript\">Droppables.add('droptarget1', {accept:'products', onDrop:function(element){new Ajax.Updater('infobox', 'http://www.example.com/', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}})</script>),
127 127
       drop_receiving_element('droptarget1', :accept => 'products', :update => 'infobox')
128  
-    assert_equal %(<script type=\"text/javascript\">Droppables.add('droptarget1', {accept:['tshirts','mugs'], onDrop:function(element){new Ajax.Updater('infobox', 'http://www.example.com/', {parameters:'id=' + encodeURIComponent(element.id), evalScripts:true, asynchronous:true})}})</script>),
  128
+    assert_equal %(<script type=\"text/javascript\">Droppables.add('droptarget1', {accept:['tshirts','mugs'], onDrop:function(element){new Ajax.Updater('infobox', 'http://www.example.com/', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}})</script>),
129 129
       drop_receiving_element('droptarget1', :accept => ['tshirts','mugs'], :update => 'infobox')
130 130
   end
131 131
   

0 notes on commit 383b6af

Please sign in to comment.
Something went wrong with that request. Please try again.