Permalink
Browse files

Add support for assert_select_rjs with :show and :hide. #7780 [dcheli…

…msky]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6861 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
Marcel Molina
Marcel Molina committed May 26, 2007
1 parent dc4d23f commit 42ebf559cc6ed80fa3bf55ecc1dea7c9e593f45e
View
@@ -1,5 +1,7 @@
*SVN*
+* Add support for assert_select_rjs with :show and :hide. #7780 [dchelimsky]
+
* Make assert_select's failure messages clearer about what failed. #7779 [dchelimsky]
* Introduce a default respond_to block for custom types. #8174 [Josh Peek]
@@ -325,8 +325,8 @@ def count_description(min, max) #:nodoc:
# that update or insert an element with that identifier.
#
# Use the first argument to narrow down assertions to only statements
- # of that type. Possible values are +:replace+, +:replace_html+, +:remove+ and
- # +:insert_html+.
+ # of that type. Possible values are +:replace+, +:replace_html+, +:show+,
+ # +:hide+, +:toggle+, +:remove+ and +:insert_html+.
#
# Use the argument +:insert+ followed by an insertion position to narrow
# down the assertion to only statements that insert elements in that
@@ -414,7 +414,7 @@ def assert_select_rjs(*args, &block)
case rjs_type
when :chained_replace, :chained_replace_html
Regexp.new("\\$\\(\"#{id}\"\\)#{statement}\\(#{RJS_PATTERN_HTML}\\)", Regexp::MULTILINE)
- when :remove
+ when :remove, :show, :hide, :toggle
Regexp.new("#{statement}\\(\"#{id}\"\\)")
else
Regexp.new("#{statement}\\(\"#{id}\", #{RJS_PATTERN_HTML}\\)", Regexp::MULTILINE)
@@ -423,7 +423,7 @@ def assert_select_rjs(*args, &block)
# Duplicate the body since the next step involves destroying it.
matches = nil
case rjs_type
- when :remove
+ when :remove, :show, :hide, :toggle
matches = @response.body.match(pattern)
else
@response.body.gsub(pattern) do |match|
@@ -434,7 +434,7 @@ def assert_select_rjs(*args, &block)
end
end
if matches
- if block_given? && rjs_type != :remove
+ if block_given? && !([:remove, :show, :hide, :toggle].include? rjs_type)
begin
in_scope, @selected = @selected, matches
yield matches
@@ -541,6 +541,9 @@ def assert_select_email(&block)
:chained_replace => /\.replace/,
:chained_replace_html => /\.update/,
:remove => /Element\.remove/,
+ :show => /Element\.show/,
+ :hide => /Element\.hide/,
+ :toggle => /Element\.toggle/
}
RJS_INSERTIONS = [:top, :bottom, :before, :after]
RJS_INSERTIONS.each do |insertion|
@@ -452,6 +452,69 @@ def test_assert_select_rjs_for_remove_ignores_block
end
end
+ # Simple show
+ def test_assert_select_rjs_for_show
+ render_rjs do |page|
+ page.show "test1"
+ end
+
+ assert_select_rjs :show, "test1"
+ end
+
+ def test_assert_select_rjs_for_show_ignores_block
+ render_rjs do |page|
+ page.show "test1"
+ end
+
+ assert_nothing_raised do
+ assert_select_rjs :show, "test1" do
+ assert_select "p"
+ end
+ end
+ end
+
+ # Simple hide
+ def test_assert_select_rjs_for_hide
+ render_rjs do |page|
+ page.hide "test1"
+ end
+
+ assert_select_rjs :hide, "test1"
+ end
+
+ def test_assert_select_rjs_for_hide_ignores_block
+ render_rjs do |page|
+ page.hide "test1"
+ end
+
+ assert_nothing_raised do
+ assert_select_rjs :hide, "test1" do
+ assert_select "p"
+ end
+ end
+ end
+
+ # Simple toggle
+ def test_assert_select_rjs_for_toggle
+ render_rjs do |page|
+ page.toggle "test1"
+ end
+
+ assert_select_rjs :toggle, "test1"
+ end
+
+ def test_assert_select_rjs_for_toggle_ignores_block
+ render_rjs do |page|
+ page.toggle "test1"
+ end
+
+ assert_nothing_raised do
+ assert_select_rjs :toggle, "test1" do
+ assert_select "p"
+ end
+ end
+ end
+
# Non-positioned insert.
def test_assert_select_rjs_for_nonpositioned_insert
render_rjs do |page|
@@ -498,8 +561,7 @@ def test_assert_select_rjs_for_positioned_insert
assert_select "div", 4
end
end
-
-
+
# Simple selection from a single result.
def test_nested_assert_select_rjs_with_single_result
render_rjs do |page|

0 comments on commit 42ebf55

Please sign in to comment.