提交 67b73ff2 编写于 作者: B Bob Remeika 提交者: Stefan Penner

Removed duplication

上级 d9765c3a
......@@ -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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册