require "#{File.dirname(__FILE__)}/../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 module BaseTest def self.included(base) base.send :attr_accessor, :template_format end include ActionView::Helpers::JavaScriptHelper include ActionView::Helpers::PrototypeHelper include ActionView::Helpers::ScriptaculousHelper include ActionView::Helpers::UrlHelper include ActionView::Helpers::TagHelper include ActionView::Helpers::TextHelper include ActionView::Helpers::FormTagHelper include ActionView::Helpers::FormHelper include ActionView::Helpers::CaptureHelper include ActionView::Helpers::RecordIdentificationHelper include ActionController::PolymorphicRoutes 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 create_generator block = Proc.new { |*args| yield *args if block_given? } JavaScriptGenerator.new self, &block end end class PrototypeHelperTest < Test::Unit::TestCase include BaseTest 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_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 %(