Skip to content

Commit

Permalink
Improve UrlRewriter tests. Improve helper test coverage. Closes #7207,
Browse files Browse the repository at this point in the history
…#7208, #7212.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7013 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jeremy committed Jun 13, 2007
1 parent 71b77a3 commit 17927cb
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
4 changes: 3 additions & 1 deletion actionpack/CHANGELOG
Expand Up @@ -8,7 +8,9 @@

* Improve Text Helper test coverage. #7274 [Rob Sanheim, Josh Peek]

* Improve helper test coverage. #7215, #7233, #7234, #7235, #7236, #7237, #7238, #7241, #7243, #7244 [Rich Collins, Josh Peek]
* Improve helper test coverage. #7208, #7212, #7215, #7233, #7234, #7235, #7236, #7237, #7238, #7241, #7243, #7244 [Rich Collins, Josh Peek]

* Improve UrlRewriter tests. #7207 [Rich Collins]

* Resources: url_for([parent, child]) generates /parents/1/children/2 for the nested resource. Likewise with the other simply helpful methods like form_for and link_to. #6432 [mhw, Jonathan Vaught, lotswholetime]

Expand Down
10 changes: 10 additions & 0 deletions actionpack/test/controller/url_rewriter_test.rb
@@ -1,5 +1,7 @@
require File.dirname(__FILE__) + '/../abstract_unit'

ActionController::UrlRewriter

class UrlRewriterTests < Test::Unit::TestCase
def setup
@request = ActionController::TestRequest.new
Expand Down Expand Up @@ -63,6 +65,14 @@ def test_overwrite_removes_original
u = @rewriter.rewrite(:only_path => false, :overwrite_params => {:list_page => 2})
assert_equal 'http://test.host/search/list?list_page=2', u
end

def test_to_str
@params[:controller] = 'hi'
@params[:action] = 'bye'
@request.parameters[:id] = '2'

assert_equal 'http://, test.host, /, hi, bye, {"id"=>"2"}', @rewriter.to_str
end
end

class UrlWriterTests < Test::Unit::TestCase
Expand Down
38 changes: 27 additions & 11 deletions actionpack/test/template/active_record_helper_test.rb
Expand Up @@ -28,7 +28,16 @@ def setup_post
@post = Post.new
def @post.errors
Class.new {
def on(field) field == "author_name" || field == "body" end
def on(field)
case field.to_s
when "author_name"
"can't be empty"
when "body"
true
else
false
end
end
def empty?() false end
def count() 1 end
def full_messages() [ "Author name can't be empty" ] end
Expand All @@ -52,7 +61,7 @@ def Post.content_columns() [ Column.new(:string, "title", "Title"), Column.new(:
@post.secret = 1
@post.written_on = Date.new(2004, 6, 15)
end

def setup_user
@user = User.new
def @user.errors
Expand Down Expand Up @@ -95,7 +104,7 @@ def test_generic_input_tag
%(<input id="post_title" name="post[title]" size="30" type="text" value="Hello World" />), input("post", "title")
)
end

def test_text_area_with_errors
assert_dom_equal(
%(<div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div>),
Expand All @@ -109,7 +118,7 @@ def test_text_field_with_errors
text_field("post", "author_name")
)
end

def test_form_with_string
assert_dom_equal(
%(<form action="create" method="post"><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>),
Expand All @@ -129,7 +138,7 @@ def id() 1 end
form("post")
)
end

def test_form_with_date
silence_warnings do
def Post.content_columns() [ Column.new(:date, "written_on", "Written on") ] end
Expand All @@ -152,26 +161,30 @@ def Post.content_columns() [ Column.new(:datetime, "written_on", "Written on") ]
form("post")
)
end

def test_error_for_block
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post")
assert_equal %(<div class="errorDeathByClass" id="errorDeathById"><h1>1 error prohibited this post from being saved</h1><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :class => "errorDeathByClass", :id => "errorDeathById", :header_tag => "h1")
assert_equal %(<div id="errorDeathById"><h1>1 error prohibited this post from being saved</h1><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :class => nil, :id => "errorDeathById", :header_tag => "h1")
assert_equal %(<div class="errorDeathByClass"><h1>1 error prohibited this post from being saved</h1><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :class => "errorDeathByClass", :id => nil, :header_tag => "h1")
end

def test_error_messages_for_handles_nil
assert_equal "", error_messages_for("notthere")
end

def test_error_message_on_handles_nil
assert_equal "", error_message_on("notthere", "notthere")
end

def test_error_message_on
assert error_message_on(:post, :author_name)
assert_dom_equal "<div class=\"formError\">can't be empty</div>", error_message_on(:post, :author_name)
end

def test_error_message_on_should_use_options
assert_dom_equal "<div class=\"differentError\">beforecan't be emptyafter</div>", error_message_on(:post, :author_name, "before", "after", "differentError")
end

def test_error_messages_for_many_objects
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li><li>User email can't be empty</li></ul></div>), error_messages_for("post", "user")

Expand All @@ -186,6 +199,9 @@ def test_error_messages_for_many_objects

# any default works too
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this monkey from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for(:user, :post, :object_name => "monkey")

# should space object name
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this chunky bacon from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for(:user, :post, :object_name => "chunky_bacon")
end

def test_form_with_string_multipart
Expand Down

0 comments on commit 17927cb

Please sign in to comment.