aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorBob Remeika <bob.remeika@gmail.com>2009-11-04 02:35:16 -0800
committerStefan Penner <stefan.penner@gmail.com>2010-01-27 12:44:31 -0600
commit39ec7ce6a93945bc97f599d8cb503711a66f3952 (patch)
treede3b1b94b559cf0556a3413072fdfe813a9d1dea /actionpack
parent8e172f13d7f43b999b7028153ac6327ff592c72a (diff)
downloadrails-39ec7ce6a93945bc97f599d8cb503711a66f3952.tar.gz
rails-39ec7ce6a93945bc97f599d8cb503711a66f3952.tar.bz2
rails-39ec7ce6a93945bc97f599d8cb503711a66f3952.zip
Removed duplication
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_view/helpers/ajax_helper.rb16
-rw-r--r--actionpack/test/javascript/ajax_test.rb12
2 files changed, 20 insertions, 8 deletions
diff --git a/actionpack/lib/action_view/helpers/ajax_helper.rb b/actionpack/lib/action_view/helpers/ajax_helper.rb
index 807c943d2c..9f1ca138eb 100644
--- a/actionpack/lib/action_view/helpers/ajax_helper.rb
+++ b/actionpack/lib/action_view/helpers/ajax_helper.rb
@@ -49,16 +49,16 @@ module ActionView
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 @@ module ActionView
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 @@ module ActionView
attributes["data-frequency"] = frequency.to_i
end
- attributes
+ purge_unused_attributes!(attributes)
end
def purge_unused_attributes!(attributes)
diff --git a/actionpack/test/javascript/ajax_test.rb b/actionpack/test/javascript/ajax_test.rb
index 0cc4460870..f1207e938d 100644
--- a/actionpack/test/javascript/ajax_test.rb
+++ b/actionpack/test/javascript/ajax_test.rb
@@ -423,3 +423,15 @@ class ObserveFieldTest < AjaxTestCase
%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