Skip to content

Commit

Permalink
Add :redirect to the testable RJS statements [#2612 state:resolved]
Browse files Browse the repository at this point in the history
Example :
  assert_select_rjs :redirect, root_path

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information
Jon Wood authored and lifo committed Aug 9, 2009
1 parent 89c8aff commit 271baf2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
13 changes: 10 additions & 3 deletions actionpack/lib/action_dispatch/testing/assertions/selector.rb
Expand Up @@ -345,14 +345,17 @@ def count_description(min, max) #:nodoc:
#
# Use the first argument to narrow down assertions to only statements
# of that type. Possible values are <tt>:replace</tt>, <tt>:replace_html</tt>,
# <tt>:show</tt>, <tt>:hide</tt>, <tt>:toggle</tt>, <tt>:remove</tt> and
# <tt>:insert_html</tt>.
# <tt>:show</tt>, <tt>:hide</tt>, <tt>:toggle</tt>, <tt>:remove</tta>,
# <tt>:insert_html</tt> and <tt>:redirect</tt>.
#
# Use the argument <tt>:insert</tt> followed by an insertion position to narrow
# down the assertion to only statements that insert elements in that
# position. Possible values are <tt>:top</tt>, <tt>:bottom</tt>, <tt>:before</tt>
# and <tt>:after</tt>.
#
# Use the argument <tt>:redirect</tt> follwed by a path to check that an statement
# which redirects to the specified path is generated.
#
# Using the <tt>:remove</tt> statement, you will be able to pass a block, but it will
# be ignored as there is no HTML passed for this statement.
#
Expand Down Expand Up @@ -399,6 +402,9 @@ def count_description(min, max) #:nodoc:
#
# # The same, but shorter.
# assert_select "ol>li", 4
#
# # Checking for a redirect.
# assert_select_rjs :redirect, root_path
def assert_select_rjs(*args, &block)
rjs_type = args.first.is_a?(Symbol) ? args.shift : nil
id = args.first.is_a?(String) ? args.shift : nil
Expand Down Expand Up @@ -576,7 +582,8 @@ def assert_select_email(&block)
:chained_replace => "\\$\\(#{RJS_ANY_ID}\\)\\.replace\\(#{RJS_PATTERN_HTML}\\)",
:chained_replace_html => "\\$\\(#{RJS_ANY_ID}\\)\\.update\\(#{RJS_PATTERN_HTML}\\)",
:replace_html => "Element\\.update\\(#{RJS_ANY_ID}, #{RJS_PATTERN_HTML}\\)",
:replace => "Element\\.replace\\(#{RJS_ANY_ID}, #{RJS_PATTERN_HTML}\\)"
:replace => "Element\\.replace\\(#{RJS_ANY_ID}, #{RJS_PATTERN_HTML}\\)",
:redirect => "window.location.href = #{RJS_ANY_ID}"
}
[:remove, :show, :hide, :toggle].each do |action|
RJS_STATEMENTS[action] = "Element\\.#{action}\\(#{RJS_ANY_ID}\\)"
Expand Down
7 changes: 7 additions & 0 deletions actionpack/test/controller/assert_select_test.rb
Expand Up @@ -257,6 +257,13 @@ def test_assert_select_rjs_for_positioned_insert_should_fail_when_mixing_argumen
end
assert_raise(Assertion) {assert_select_rjs :insert, :top, "test2"}
end

def test_assert_select_rjs_for_redirect_to
render_rjs do |page|
page.redirect_to '/'
end
assert_select_rjs :redirect, '/'
end

def test_elect_with_xml_namespace_attributes
render_html %Q{<link xlink:href="http://nowhere.com"></link>}
Expand Down

0 comments on commit 271baf2

Please sign in to comment.