Permalink
Browse files

Removed duplication

  • Loading branch information...
1 parent 8e172f1 commit 39ec7ce6a93945bc97f599d8cb503711a66f3952 @foobarfighter foobarfighter committed with stefanpenner Nov 4, 2009
Showing with 20 additions and 8 deletions.
  1. +8 −8 actionpack/lib/action_view/helpers/ajax_helper.rb
  2. +12 −0 actionpack/test/javascript/ajax_test.rb
@@ -49,16 +49,16 @@ def button_to_remote(name, options = {}, html_options = {})
end
def periodically_call_remote(options = {})
-# frequency = options[:frequency] || 10 # every ten seconds by default
-# code = "new PeriodicalExecuter(function() {#{remote_function(options)}}, #{frequency})"
-# javascript_tag(code)
+ attributes = extract_observer_attributes!(options)
+ attributes["data-js-type"] = "periodical_executer"
+
+ script_decorator(attributes)
end
+ #TODO: Should name change to a css query? - BR
def observe_field(name, options = {})
options[:observed] = name
-
- attributes = extract_remote_attributes!(options)
- attributes.merge!(extract_observer_attributes!(options))
+ attributes = extract_observer_attributes!(options)
attributes["data-js-type"] = "field_observer"
script_decorator(attributes)
@@ -139,7 +139,7 @@ def extract_update_attributes!(options)
end
def extract_observer_attributes!(options)
- attributes = {}
+ attributes = extract_remote_attributes!(options)
attributes["data-observed"] = options.delete(:observed)
callback = options.delete(:function)
@@ -151,7 +151,7 @@ def extract_observer_attributes!(options)
attributes["data-frequency"] = frequency.to_i
end
- attributes
+ purge_unused_attributes!(attributes)
end
def purge_unused_attributes!(attributes)
@@ -423,3 +423,15 @@ def field(options = {})
%w(script data-observer-code="function(element, value) {alert('Element changed')}")
end
end
+
+class PeriodicallyCallRemoteTest < AjaxTestCase
+ test "basic" do
+ assert_html periodically_call_remote(:update => "#schremser_bier", :url => { :action => "mehr_bier" }),
+ %w(script data-url="/url/hash" data-update-success="#schremser_bier")
+ end
+
+ test "periodically call remote with :frequency" do
+ assert_html periodically_call_remote(:frequency => 2, :url => "/url/string"),
+ %w(script data-url="/url/string" data-frequency="2")
+ end
+end

0 comments on commit 39ec7ce

Please sign in to comment.