aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/assertions
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-11-15 12:45:52 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-11-15 12:45:52 +0000
commitc9e0002d36429a382ab4f96059a3b6eb51605d88 (patch)
tree50745d3993e57f09f22aac8470fcdfb1013b33dd /actionpack/lib/action_controller/assertions
parent079d684a37a1d5e7c61661bdf6221ded90c06159 (diff)
downloadrails-c9e0002d36429a382ab4f96059a3b6eb51605d88.tar.gz
rails-c9e0002d36429a382ab4f96059a3b6eb51605d88.tar.bz2
rails-c9e0002d36429a382ab4f96059a3b6eb51605d88.zip
assert_select_rjs :remove
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5525 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_controller/assertions')
-rw-r--r--actionpack/lib/action_controller/assertions/selector_assertions.rb28
1 files changed, 21 insertions, 7 deletions
diff --git a/actionpack/lib/action_controller/assertions/selector_assertions.rb b/actionpack/lib/action_controller/assertions/selector_assertions.rb
index a5267e20e8..f9d67fb5bd 100644
--- a/actionpack/lib/action_controller/assertions/selector_assertions.rb
+++ b/actionpack/lib/action_controller/assertions/selector_assertions.rb
@@ -317,13 +317,16 @@ module ActionController
# 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+ and
+ # of that type. Possible values are +:replace+, +:replace_html+, +: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
# position. Possible values are +:top+, +:bottom+, +:before+ and +:after+.
#
+ # Using the +:remove+ statement, you will be able to pass a block, but it will
+ # be ignored as there is no HTML passed for this statement.
+ #
# === Using blocks
#
# Without a block, #assert_select_rjs merely asserts that the response
@@ -352,6 +355,9 @@ module ActionController
# # Inserting into the element bar, top position.
# assert_select_rjs :insert, :top, "bar"
#
+ # # Remove the element bar
+ # assert_select_rjs :remove, "bar"
+ #
# # Changing the element foo, with an image.
# assert_select_rjs "foo" do
# assert_select "img[src=/images/logo.gif""
@@ -400,20 +406,27 @@ module ActionController
case rjs_type
when :chained_replace, :chained_replace_html
Regexp.new("\\$\\(\"#{id}\"\\)#{statement}\\(#{RJS_PATTERN_HTML}\\)", Regexp::MULTILINE)
+ when :remove
+ Regexp.new("#{statement}\\(\"#{id}\"\\)")
else
Regexp.new("#{statement}\\(\"#{id}\", #{RJS_PATTERN_HTML}\\)", Regexp::MULTILINE)
end
# Duplicate the body since the next step involves destroying it.
matches = nil
- @response.body.gsub(pattern) do |match|
- html = unescape_rjs($2)
- matches ||= []
- matches.concat HTML::Document.new(html).root.children.select { |n| n.tag? }
- ""
+ case rjs_type
+ when :remove
+ matches = @response.body.match(pattern)
+ else
+ @response.body.gsub(pattern) do |match|
+ html = unescape_rjs($2)
+ matches ||= []
+ matches.concat HTML::Document.new(html).root.children.select { |n| n.tag? }
+ ""
+ end
end
if matches
- if block_given?
+ if block_given? && rjs_type != :remove
begin
in_scope, @selected = @selected, matches
yield matches
@@ -519,6 +532,7 @@ module ActionController
:replace_html => /Element\.update/,
:chained_replace => /\.replace/,
:chained_replace_html => /\.update/,
+ :remove => /Element\.remove/,
}
RJS_INSERTIONS = [:top, :bottom, :before, :after]
RJS_INSERTIONS.each do |insertion|