remote_form_for tests pass
This commit is contained in:
parent
5316e77db1
commit
631537a25d
@ -1,21 +1,18 @@
|
||||
require "abstract_unit"
|
||||
|
||||
class AjaxTestCase < ActiveSupport::TestCase
|
||||
#TODO: Switch to assert_dom_equal where appropriate. assert_html is not robust enough for all tests - BR
|
||||
|
||||
class AjaxTestCase < ActionView::TestCase
|
||||
include ActionView::Helpers::AjaxHelper
|
||||
|
||||
# TODO: Ask Katz: Should these be included by the AjaxHelper? - BR
|
||||
include ActionView::Helpers::TagHelper
|
||||
include ActionView::Helpers::FormTagHelper
|
||||
|
||||
# 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 @@ def concat(str)
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user