diff options
author | Joshua Peek <josh@joshpeek.com> | 2010-01-30 15:08:29 -0600 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2010-01-30 15:08:29 -0600 |
commit | 2de311a09363f0e7bb4e21cef8e77df7ee92d33f (patch) | |
tree | 05aa8fc829144a688dd3770a43f864a531ecc3dd | |
parent | 95f317b0204d63810b837eae48667d9ed311f7dd (diff) | |
download | rails-2de311a09363f0e7bb4e21cef8e77df7ee92d33f.tar.gz rails-2de311a09363f0e7bb4e21cef8e77df7ee92d33f.tar.bz2 rails-2de311a09363f0e7bb4e21cef8e77df7ee92d33f.zip |
Drop AjaxHelper
-rw-r--r-- | actionpack/lib/action_view/helpers.rb | 1 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/ajax_helper.rb | 68 | ||||
-rw-r--r-- | actionpack/test/template/ajax_test.rb | 114 |
3 files changed, 0 insertions, 183 deletions
diff --git a/actionpack/lib/action_view/helpers.rb b/actionpack/lib/action_view/helpers.rb index 3d088678fc..ceb0e18d80 100644 --- a/actionpack/lib/action_view/helpers.rb +++ b/actionpack/lib/action_view/helpers.rb @@ -3,7 +3,6 @@ require 'active_support/benchmarkable' module ActionView #:nodoc: module Helpers #:nodoc: autoload :ActiveModelHelper, 'action_view/helpers/active_model_helper' - autoload :AjaxHelper, 'action_view/helpers/ajax_helper' autoload :AssetTagHelper, 'action_view/helpers/asset_tag_helper' autoload :AtomFeedHelper, 'action_view/helpers/atom_feed_helper' autoload :CacheHelper, 'action_view/helpers/cache_helper' diff --git a/actionpack/lib/action_view/helpers/ajax_helper.rb b/actionpack/lib/action_view/helpers/ajax_helper.rb deleted file mode 100644 index 9cc2acc239..0000000000 --- a/actionpack/lib/action_view/helpers/ajax_helper.rb +++ /dev/null @@ -1,68 +0,0 @@ -module ActionView - module Helpers - module AjaxHelper - include UrlHelper - - def link_to_remote(name, url, options = {}) - html = options.delete(:html) || {} - - update = options.delete(:update) - if update.is_a?(Hash) - html["data-update-success"] = update[:success] - html["data-update-failure"] = update[:failure] - else - html["data-update-success"] = update - end - - html["data-update-position"] = options.delete(:position) - html["data-method"] = options.delete(:method) - html["data-remote"] = "true" - - html.merge!(options) - - url = url_for(url) if url.is_a?(Hash) - link_to(name, url, html) - end - - def button_to_remote(name, options = {}, html_options = {}) - url = options.delete(:url) - url = url_for(url) if url.is_a?(Hash) - - html_options.merge!(:type => "button", :value => name, - :"data-url" => url) - - tag(:input, html_options) - end - - module Rails2Compatibility - 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 - - set_callbacks(options, options[:html] ||= {}) - - super - end - - def button_to_remote(name, options = {}, html_options = {}) - set_callbacks(options, html_options) - super - end - end - - end - end -end
\ No newline at end of file diff --git a/actionpack/test/template/ajax_test.rb b/actionpack/test/template/ajax_test.rb deleted file mode 100644 index aeb7c09b09..0000000000 --- a/actionpack/test/template/ajax_test.rb +++ /dev/null @@ -1,114 +0,0 @@ -require "abstract_unit" - -class AjaxTestCase < ActiveSupport::TestCase - include ActionView::Helpers::AjaxHelper - include ActionView::Helpers::TagHelper - - def assert_html(html, matches) - matches.each do |match| - assert_match(Regexp.new(Regexp.escape(match)), html) - end - end - - def self.assert_callbacks_work(&blk) - define_method(:assert_callbacks_work, &blk) - - [:complete, :failure, :success, :interactive, :loaded, :loading, 404].each do |callback| - test "#{callback} callback" do - markup = assert_callbacks_work(callback) - assert_html markup, %W(data-#{callback}-code="undoRequestCompleted\(request\)") - end - end - end -end - -class LinkToRemoteTest < AjaxTestCase - def url_for(hash) - "/blog/destroy/4" - end - - def link(options = {}) - link_to_remote("Delete this post", "/blog/destroy/3", options) - end - - test "with no update" do - assert_html link, %w(href="/blog/destroy/4" Delete\ this\ post data-remote="true") - end - - test "basic" do - assert_html link(:update => "#posts"), - %w(data-update-success="#posts") - end - - test "using a url hash" do - link = link_to_remote("Delete this post", {:controller => :blog}, :update => "#posts") - assert_html link, %w(href="/blog/destroy/4" data-update-success="#posts") - end - - test "with :html options" do - expected = %{<a href="/blog/destroy/4" data-custom="me" data-remote="true" data-update-success="#posts">Delete this post</a>} - assert_equal expected, link(:update => "#posts", :html => {"data-custom" => "me"}) - end - - test "with a hash for :update" do - link = link(:update => {:success => "#posts", :failure => "#error"}) - assert_match(/data-update-success="#posts"/, link) - assert_match(/data-update-failure="#error"/, link) - end - - test "with positional parameters" do - link = link(:position => :top, :update => "#posts") - assert_match(/data\-update\-position="top"/, link) - end - - test "with an optional method" do - link = link(:method => "delete") - assert_match(/data-method="delete"/, link) - end - - class LegacyLinkToRemoteTest < AjaxTestCase - include ActionView::Helpers::AjaxHelper::Rails2Compatibility - - def link(options) - link_to_remote("Delete this post", "/blog/destroy/3", options) - end - - test "basic link_to_remote with :url =>" do - expected = %{<a href="/blog/destroy/3" data-remote="true" data-update-success="#posts">Delete this post</a>} - assert_equal expected, - link_to_remote("Delete this post", :url => "/blog/destroy/3", :update => "#posts") - end - - assert_callbacks_work do |callback| - link(callback => "undoRequestCompleted(request)") - end - end -end - -class ButtonToRemoteTest < AjaxTestCase - def button(options, html = {}) - button_to_remote("Remote outpost", options, html) - end - - def url_for(*) - "/whatnot" - end - - class StandardTest < ButtonToRemoteTest - test "basic" do - button = button({:url => {:action => "whatnot"}}, {:class => "fine"}) - [/input/, /class="fine"/, /type="button"/, /value="Remote outpost"/, - /data-url="\/whatnot"/].each do |match| - assert_match(match, button) - end - end - end - - class LegacyButtonToRemoteTest < ButtonToRemoteTest - include ActionView::Helpers::AjaxHelper::Rails2Compatibility - - assert_callbacks_work do |callback| - button(callback => "undoRequestCompleted(request)") - end - end -end |