aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorBob Remeika <bob.remeika@gmail.com>2009-09-30 13:36:52 -0700
committerStefan Penner <stefan.penner@gmail.com>2010-01-27 12:44:30 -0600
commit631537a25d8158085657b10357072873646e0cb5 (patch)
treec38da4984c7f9fa1c6468e6b2344595e85c7d485 /actionpack
parent5316e77db1c34dca15f83dd6a10e78e847c356c3 (diff)
downloadrails-631537a25d8158085657b10357072873646e0cb5.tar.gz
rails-631537a25d8158085657b10357072873646e0cb5.tar.bz2
rails-631537a25d8158085657b10357072873646e0cb5.zip
remote_form_for tests pass
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/test/javascript/ajax_test.rb103
1 files changed, 93 insertions, 10 deletions
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 = %(<form action="/authors" data-remote="true" class="new_author" id="create-author" method="post"></form>)
+ assert_dom_equal expected, output_buffer
+ end
+
+ test "remote_form_for with record identification without html options" do
+ remote_form_for(@record) {}
+
+ expected = %(<form action="/authors" data-remote="true" class="new_author" id="new_author" method="post"></form>)
+ 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 = %(<form action="/authors/1" data-remote="true" class="edit_author" id="edit_author_1" method="post"><div style="margin:0;padding:0;display:inline"><input name="_method" type="hidden" value="put" /></div></form>)
+ assert_dom_equal expected, output_buffer
+ end
+
+ test "remote_form_for with new object in list" do
+ remote_form_for([@author, @article]) {}
+ expected = %(<form action="#{author_articles_path(@author)}" class="new_article" method="post" id="new_article" data-remote="true"></form>)
+ 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 = %(<form action='#{author_article_path(@author, @article)}' id='edit_article_1' method='post' class='edit_article' data-remote="true"><div style='margin:0;padding:0;display:inline'><input name='_method' type='hidden' value='put' /></div></form>)
+ 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