Permalink
Browse files

port existing test suite to check for new output, and fix all breakin…

…g tests
  • Loading branch information...
1 parent 7bf5aef commit 37ad57596b7afdf38be443f06130b736539dd2af @stevestmartin stevestmartin committed with stefanpenner Jan 24, 2010
Showing with 268 additions and 162 deletions.
  1. +45 −41 actionpack/lib/action_view/helpers/ajax_helper.rb
  2. +223 −121 actionpack/test/template/ajax_helper_test.rb
@@ -105,13 +105,15 @@ def remote_form_for(record_or_name_or_array, *args, &proc)
# <% end -%>
def form_remote_tag(options = {}, &block)
+ html_options = options.delete(:callbacks)
+
attributes = {}
attributes.merge!(extract_remote_attributes!(options))
+ attributes.merge!(html_options) if html_options
attributes.merge!(options)
-
- url = attributes.delete("data-url")
attributes.delete(:builder)
- form_tag(attributes.delete(:action) || url, attributes, &block)
+
+ form_tag(attributes.delete(:action) || attributes.delete("data-url"), attributes, &block)
end
# Returns a link to a remote action defined by <tt>options[:url]</tt>
@@ -287,13 +289,12 @@ def form_remote_tag(options = {}, &block)
# link_to_remote "Delete this post",
# { :update => "posts", :url => { :action => "destroy", :id => post.id } },
# :href => url_for(:action => "destroy", :id => post.id)
- def link_to_remote(name, url, options = {})
+ def link_to_remote(name, options, html_options = {})
attributes = {}
attributes.merge!(extract_remote_attributes!(options))
- attributes.merge!(options)
+ attributes.merge!(html_options)
- url = url_for(url) if url.is_a?(Hash)
- content_tag(:a, name, attributes.merge(:href => url))
+ content_tag(:a, name, attributes.merge(:href => "#"))
end
# Creates a button with an onclick event which calls a remote action
@@ -303,7 +304,6 @@ def link_to_remote(name, url, options = {})
def button_to_remote(name, options = {}, html_options = {})
attributes = html_options.merge!(:type => "button", :value => name)
attributes.merge!(extract_remote_attributes!(options))
- attributes.merge!(extract_request_attributes!(options))
tag(:input, attributes)
end
@@ -341,10 +341,12 @@ def button_to_remote(name, options = {}, html_options = {})
# <tt>options</tt> argument is the same as in form_remote_tag.
def submit_to_remote(name, value, options = {})
html_options = options.delete(:html) || {}
- html_options.merge!(:name => name, :value => value, :type => "submit")
+ html_options.merge!(:name => name, :value => value, :type => "button")
attributes = extract_remote_attributes!(options)
attributes.merge!(html_options)
+ attributes["data-submit"] = true
+ attributes.delete("data-remote")
tag(:input, attributes)
end
@@ -376,7 +378,7 @@ def submit_to_remote(name, value, options = {})
#
def periodically_call_remote(options = {})
attributes = extract_observer_attributes!(options)
- attributes["data-js-type"] = "periodical_executer"
+ attributes["data-periodical"] = true
script_decorator(attributes)
end
@@ -493,9 +495,11 @@ def extract_remote_attributes!(options)
def extract_request_attributes!(options)
attributes = {}
attributes["data-method"] = options.delete(:method)
+ attributes["data-remote-type"] = options.delete(:type)
- url = options.delete(:url)
- attributes["data-url"] = url.is_a?(Hash) ? url_for(url) : url
+ url_options = options.delete(:url)
+ url_options = url_options.merge(:escape => false) if url_options.is_a?(Hash)
+ attributes["data-url"] = escape_javascript(url_for(url_options))
#TODO: Remove all references to prototype - BR
if options.delete(:form)
@@ -528,18 +532,16 @@ def extract_update_attributes!(options)
end
def extract_observer_attributes!(options)
+ callback = options.delete(:function)
+ frequency = options.delete(:frequency)
+
+
attributes = extract_remote_attributes!(options)
attributes["data-observe"] = true
attributes["data-observed"] = options.delete(:observed)
-
- callback = options.delete(:function)
- frequency = options.delete(:frequency)
- if callback
- attributes["data-observer-code"] = create_js_function(callback, "element", "value")
- end
- if frequency && frequency != 0
- attributes["data-frequency"] = frequency.to_i
- end
+ attributes["data-onobserve"] = create_js_function(callback, "element", "value") if callback
+ attributes["data-frequency"] = frequency.to_i if frequency && frequency != 0
+ attributes.delete("data-remote")
purge_unused_attributes!(attributes)
end
@@ -558,33 +560,35 @@ def create_js_function(statements, *arguments)
module AjaxHelperCompat
include AjaxHelper
- def set_callbacks(options, html)
- [:complete, :failure, :success, :interactive, :loaded, :loading].each do |type|
- html["data-#{type}-code"] = options.delete(type.to_sym)
- end
-
- options.each do |option, value|
- if option.is_a?(Integer)
- html["data-#{option}-code"] = options.delete(option)
- end
- end
- end
-
- def link_to_remote(name, url, options = nil)
- if !options && url.is_a?(Hash) && url.key?(:url)
- url, options = url.delete(:url), url
- end
- options = {} if options.nil?
-
- set_callbacks(options, options[:html] ||= {})
-
+ def link_to_remote(name, options, html_options = {})
+ set_callbacks(options, html_options)
super
end
def button_to_remote(name, options = {}, html_options = {})
set_callbacks(options, html_options)
super
end
+
+ def form_remote_tag(options, &block)
+ html = {}
+ set_callbacks(options, html)
+ options.merge!(:callbacks => html)
+ super
+ end
+
+ private
+ def set_callbacks(options, html)
+ [:uninitialized, :complete, :failure, :success, :interactive, :loaded, :loading].each do |type|
+ html["data-on#{type}"] = options.delete(type.to_sym)
+ end
+
+ options.each do |option, value|
+ if option.is_a?(Integer)
+ html["data-on#{option}"] = options.delete(option)
+ end
+ end
+ end
end
end
end
Oops, something went wrong.

0 comments on commit 37ad575

Please sign in to comment.