From 631537a25d8158085657b10357072873646e0cb5 Mon Sep 17 00:00:00 2001 From: Bob Remeika Date: Wed, 30 Sep 2009 13:36:52 -0700 Subject: remote_form_for tests pass --- actionpack/test/javascript/ajax_test.rb | 103 ++++++++++++++++++++++++++++---- 1 file changed, 93 insertions(+), 10 deletions(-) (limited to 'actionpack') diff --git a/actionpack/test/javascript/ajax_test.rb b/actionpack/test/javascript/ajax_test.rb index 49942f6681..3004cac97f 100644 --- a/actionpack/test/javascript/ajax_test.rb +++ b/actionpack/test/javascript/ajax_test.rb @@ -1,21 +1,18 @@ require "abstract_unit" -class AjaxTestCase < ActiveSupport::TestCase - include ActionView::Helpers::AjaxHelper +#TODO: Switch to assert_dom_equal where appropriate. assert_html is not robust enough for all tests - BR - # TODO: Ask Katz: Should these be included by the AjaxHelper? - BR - include ActionView::Helpers::TagHelper - include ActionView::Helpers::FormTagHelper +class AjaxTestCase < ActionView::TestCase + include ActionView::Helpers::AjaxHelper - # TODO: Replace with the real url_for method - BR - def url_for(url) - case url + def url_for(options) + case options when Hash "/url/hash" when String - url + options else - raise TypeError.new("Unsupported url type (#{url.class}) for this test helper") + raise TypeError.new("Unsupported url type (#{options.class}) for this test helper") end end @@ -218,7 +215,93 @@ class FormRemoteTagTest < AjaxTestCase expected_form_attributes + expected_inner_html end +class Author + extend ActiveModel::Naming + include ActiveModel::Conversion + + 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 + extend ActiveModel::Naming + include ActiveModel::Conversion + 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 RemoteFormForTest < AjaxTestCase + + def setup + super + @record = @author = Author.new + @article = Article.new + end + + test "remote_form_for with record identification with new record" do + remote_form_for(@record, {:html => { :id => 'create-author' }}) {} + + expected = %(
) + assert_dom_equal expected, output_buffer + end + + test "remote_form_for with record identification without html options" do + remote_form_for(@record) {} + + expected = %(
) + assert_dom_equal expected, output_buffer + end + + test "remote_form_for with record identification with existing record" do + @record.save + remote_form_for(@record) {} + + expected = %(
) + assert_dom_equal expected, output_buffer + end + + test "remote_form_for with new object in list" do + remote_form_for([@author, @article]) {} + expected = %(
) + assert_dom_equal expected, output_buffer + end + + test "remote_form_for with existing object in list" do + @author.save + @article.save + remote_form_for([@author, @article]) {} + + expected = %(
) + assert_dom_equal expected, output_buffer + end + + protected + def author_path(record) + "/authors/#{record.id}" + end + + def authors_path + "/authors" + end + + def author_articles_path(author) + "/authors/#{author.id}/articles" + end + + def author_article_path(author, article) + "/authors/#{author.id}/articles/#{article.id}" + end end class ButtonToRemoteTest < AjaxTestCase -- cgit v1.2.3