From 39ec7ce6a93945bc97f599d8cb503711a66f3952 Mon Sep 17 00:00:00 2001 From: Bob Remeika Date: Wed, 4 Nov 2009 02:35:16 -0800 Subject: Removed duplication --- actionpack/lib/action_view/helpers/ajax_helper.rb | 16 ++++++++-------- actionpack/test/javascript/ajax_test.rb | 12 ++++++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) (limited to 'actionpack') 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 -- cgit v1.2.3