Skip to content
Browse files

Add examples in the documentation for various assertions. Closes #9938

…[zapnap]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8284 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent da5fef4 commit 096f3f64680c9f19c78999a6b2ffdaca9606403c Marcel Molina committed Dec 5, 2007
View
2 actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Add examples in the documentation for various assertions. Closes #9938 [zapnap]
+
* When a NonInferrableControllerError is raised, make the proposed fix clearer in the error message. Closes #10199 [danger]
* Update Prototype to 1.6.0.1. [sam]
View
14 actionpack/lib/action_controller/assertions/dom_assertions.rb
@@ -2,6 +2,12 @@ module ActionController
module Assertions
module DomAssertions
# Test two HTML strings for equivalency (e.g., identical up to reordering of attributes)
+ #
+ # ==== Examples
+ #
+ # # assert that the referenced method generates the appropriate HTML string
+ # assert_dom_equal '<a href="http://www.example.com">Apples</a>', link_to("Apples", "http://www.example.com")
+ #
def assert_dom_equal(expected, actual, message = "")
clean_backtrace do
expected_dom = HTML::Document.new(expected).root
@@ -13,6 +19,12 @@ def assert_dom_equal(expected, actual, message = "")
end
# The negated form of +assert_dom_equivalent+.
+ #
+ # ==== Examples
+ #
+ # # assert that the referenced method does not generate the specified HTML string
+ # assert_dom_not_equal '<a href="http://www.example.com">Apples</a>', link_to("Oranges", "http://www.example.com")
+ #
def assert_dom_not_equal(expected, actual, message = "")
clean_backtrace do
expected_dom = HTML::Document.new(expected).root
@@ -24,4 +36,4 @@ def assert_dom_not_equal(expected, actual, message = "")
end
end
end
-end
+end
View
9 actionpack/lib/action_controller/assertions/model_assertions.rb
@@ -2,11 +2,18 @@ module ActionController
module Assertions
module ModelAssertions
# Ensures that the passed record is valid by ActiveRecord standards and returns any error messages if it is not.
+ #
+ # ==== Examples
+ #
+ # # assert that a newly created record is valid
+ # model = Model.new
+ # assert_valid(model)
+ #
def assert_valid(record)
clean_backtrace do
assert record.valid?, record.errors.full_messages.join("\n")
end
end
end
end
-end
+end
View
30 actionpack/lib/action_controller/assertions/response_assertions.rb
@@ -14,6 +14,15 @@ module ResponseAssertions
# You can also pass an explicit status number like assert_response(501)
# or its symbolic equivalent assert_response(:not_implemented).
# See ActionController::StatusCodes for a full list.
+ #
+ # ==== Examples
+ #
+ # # assert that the response was a redirection
+ # assert_response :redirect
+ #
+ # # assert that the response code was status code 401 (unauthorized)
+ # assert_response 401
+ #
def assert_response(type, message = nil)
clean_backtrace do
if [ :success, :missing, :redirect, :error ].include?(type) && @response.send("#{type}?")
@@ -28,9 +37,18 @@ def assert_response(type, message = nil)
end
end
- # Assert that the redirection options passed in match those of the redirect called in the latest action. This match can be partial,
- # such that assert_redirected_to(:controller => "weblog") will also match the redirection of
- # redirect_to(:controller => "weblog", :action => "show") and so on.
+ # Assert that the redirection options passed in match those of the redirect called in the latest action.
+ # This match can be partial, such that assert_redirected_to(:controller => "weblog") will also
+ # match the redirection of redirect_to(:controller => "weblog", :action => "show") and so on.
+ #
+ # ==== Examples
+ #
+ # # assert that the redirection was to the "index" action on the WeblogController
+ # assert_redirected_to :controller => "weblog", :action => "index"
+ #
+ # # assert that the redirection was to the named route login_url
+ # assert_redirected_to login_url
+ #
def assert_redirected_to(options = {}, message=nil)
clean_backtrace do
assert_response(:redirect, message)
@@ -104,6 +122,12 @@ def assert_redirected_to(options = {}, message=nil)
end
# Asserts that the request was rendered with the appropriate template file.
+ #
+ # ==== Examples
+ #
+ # # assert that the "new" view template was rendered
+ # assert_template "new"
+ #
def assert_template(expected = nil, message=nil)
clean_backtrace do
rendered = expected ? @response.rendered_file(!expected.include?('/')) : @response.rendered_file

0 comments on commit 096f3f6

Please sign in to comment.
Something went wrong with that request. Please try again.