require 'abstract_unit' Bunny = Struct.new(:Bunny, :id) class Author attr_reader :id def save; @id = 1 end def new_record?; @id.nil? end def name @id.nil? ? 'new author' : "author ##{@id}" end end class Article attr_reader :id attr_reader :author_id def save; @id = 1; @author_id = 1 end def new_record?; @id.nil? end def name @id.nil? ? 'new article' : "article ##{@id}" end end class Author::Nested < Author; end class PrototypeHelperBaseTest < ActionView::TestCase attr_accessor :template_format def setup @template = nil @controller = Class.new do def url_for(options) if options.is_a?(String) options else url = "http://www.example.com/" url << options[:action].to_s if options and options[:action] url << "?a=#{options[:a]}" if options && options[:a] url << "&b=#{options[:b]}" if options && options[:a] && options[:b] url end end end.new end protected def request_forgery_protection_token nil end def protect_against_forgery? false end def create_generator block = Proc.new { |*args| yield *args if block_given? } JavaScriptGenerator.new self, &block end end class PrototypeHelperTest < PrototypeHelperBaseTest def setup @record = @author = Author.new @article = Article.new super end def test_link_to_remote assert_dom_equal %(Remote outauthor), link_to_remote("Remote outauthor", { :url => { :action => "whatnot" }}, { :class => "fine" }) assert_dom_equal %(Remote outauthor), link_to_remote("Remote outauthor", :complete => "alert(request.responseText)", :url => { :action => "whatnot" }) assert_dom_equal %(Remote outauthor), link_to_remote("Remote outauthor", :success => "alert(request.responseText)", :url => { :action => "whatnot" }) assert_dom_equal %(Remote outauthor), link_to_remote("Remote outauthor", :failure => "alert(request.responseText)", :url => { :action => "whatnot" }) assert_dom_equal %(Remote outauthor), link_to_remote("Remote outauthor", :failure => "alert(request.responseText)", :url => { :action => "whatnot", :a => '10', :b => '20' }) end def test_link_to_remote_html_options assert_dom_equal %(Remote outauthor), link_to_remote("Remote outauthor", { :url => { :action => "whatnot" }, :html => { :class => "fine" } }) end def test_link_to_remote_url_quote_escaping assert_dom_equal %(Remote), link_to_remote("Remote", { :url => { :action => "whatnot's" } }) end def test_periodically_call_remote assert_dom_equal %(), periodically_call_remote(:update => "schremser_bier", :url => { :action => "mehr_bier" }) end def test_periodically_call_remote_with_frequency assert_dom_equal( "", periodically_call_remote(:frequency => 2) ) end def test_form_remote_tag assert_dom_equal %(
), _erbout end def test_remote_form_for_with_record_identification_with_new_record _erbout = '' remote_form_for(@record, {:html => { :id => 'create-author' }}) {} expected = %() assert_dom_equal expected, _erbout end def test_remote_form_for_with_record_identification_without_html_options _erbout = '' remote_form_for(@record) {} expected = %() assert_dom_equal expected, _erbout end def test_remote_form_for_with_record_identification_with_existing_record @record.save _erbout = '' remote_form_for(@record) {} expected = %() assert_dom_equal expected, _erbout end def test_remote_form_for_with_new_object_in_list _erbout = '' remote_form_for([@author, @article]) {} expected = %() assert_dom_equal expected, _erbout end def test_remote_form_for_with_existing_object_in_list @author.save @article.save _erbout = '' remote_form_for([@author, @article]) {} expected = %() assert_dom_equal expected, _erbout end def test_on_callbacks callbacks = [:uninitialized, :loading, :loaded, :interactive, :complete, :success, :failure] callbacks.each do |callback| assert_dom_equal %(