提交 c9e0002d 编写于 作者: J Jeremy Kemper

assert_select_rjs :remove

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5525 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 079d684a
*SVN* *SVN*
* assert_select_rjs :remove. [Dylan Egan]
* Always clear model associations from session. #4795 [sd@notso.net, andylien@gmail.com] * Always clear model associations from session. #4795 [sd@notso.net, andylien@gmail.com]
* Update to Prototype 1.5.0_rc2. [Sam Stephenson] * Update to Prototype 1.5.0_rc2. [Sam Stephenson]
......
...@@ -317,13 +317,16 @@ def assert_select(*args, &block) ...@@ -317,13 +317,16 @@ def assert_select(*args, &block)
# that update or insert an element with that identifier. # that update or insert an element with that identifier.
# #
# Use the first argument to narrow down assertions to only statements # 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+. # +:insert_html+.
# #
# Use the argument +:insert+ followed by an insertion position to narrow # Use the argument +:insert+ followed by an insertion position to narrow
# down the assertion to only statements that insert elements in that # down the assertion to only statements that insert elements in that
# position. Possible values are +:top+, +:bottom+, +:before+ and +:after+. # 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 # === Using blocks
# #
# Without a block, #assert_select_rjs merely asserts that the response # Without a block, #assert_select_rjs merely asserts that the response
...@@ -352,6 +355,9 @@ def assert_select(*args, &block) ...@@ -352,6 +355,9 @@ def assert_select(*args, &block)
# # Inserting into the element bar, top position. # # Inserting into the element bar, top position.
# assert_select_rjs :insert, :top, "bar" # assert_select_rjs :insert, :top, "bar"
# #
# # Remove the element bar
# assert_select_rjs :remove, "bar"
#
# # Changing the element foo, with an image. # # Changing the element foo, with an image.
# assert_select_rjs "foo" do # assert_select_rjs "foo" do
# assert_select "img[src=/images/logo.gif"" # assert_select "img[src=/images/logo.gif""
...@@ -400,20 +406,27 @@ def assert_select_rjs(*args, &block) ...@@ -400,20 +406,27 @@ def assert_select_rjs(*args, &block)
case rjs_type case rjs_type
when :chained_replace, :chained_replace_html when :chained_replace, :chained_replace_html
Regexp.new("\\$\\(\"#{id}\"\\)#{statement}\\(#{RJS_PATTERN_HTML}\\)", Regexp::MULTILINE) Regexp.new("\\$\\(\"#{id}\"\\)#{statement}\\(#{RJS_PATTERN_HTML}\\)", Regexp::MULTILINE)
when :remove
Regexp.new("#{statement}\\(\"#{id}\"\\)")
else else
Regexp.new("#{statement}\\(\"#{id}\", #{RJS_PATTERN_HTML}\\)", Regexp::MULTILINE) Regexp.new("#{statement}\\(\"#{id}\", #{RJS_PATTERN_HTML}\\)", Regexp::MULTILINE)
end end
# Duplicate the body since the next step involves destroying it. # Duplicate the body since the next step involves destroying it.
matches = nil matches = nil
@response.body.gsub(pattern) do |match| case rjs_type
html = unescape_rjs($2) when :remove
matches ||= [] matches = @response.body.match(pattern)
matches.concat HTML::Document.new(html).root.children.select { |n| n.tag? } 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 end
if matches if matches
if block_given? if block_given? && rjs_type != :remove
begin begin
in_scope, @selected = @selected, matches in_scope, @selected = @selected, matches
yield matches yield matches
...@@ -519,6 +532,7 @@ def assert_select_email(&block) ...@@ -519,6 +532,7 @@ def assert_select_email(&block)
:replace_html => /Element\.update/, :replace_html => /Element\.update/,
:chained_replace => /\.replace/, :chained_replace => /\.replace/,
:chained_replace_html => /\.update/, :chained_replace_html => /\.update/,
:remove => /Element\.remove/,
} }
RJS_INSERTIONS = [:top, :bottom, :before, :after] RJS_INSERTIONS = [:top, :bottom, :before, :after]
RJS_INSERTIONS.each do |insertion| RJS_INSERTIONS.each do |insertion|
......
...@@ -408,6 +408,27 @@ def test_assert_select_rjs_for_chained_replace ...@@ -408,6 +408,27 @@ def test_assert_select_rjs_for_chained_replace
assert_raises(AssertionFailedError) { assert_select_rjs :replace_html, "test1" } assert_raises(AssertionFailedError) { assert_select_rjs :replace_html, "test1" }
end end
# Simple remove
def test_assert_select_rjs_for_remove
render_rjs do |page|
page.remove "test1"
end
assert_select_rjs :remove, "test1"
end
def test_assert_select_rjs_for_remove_ignores_block
render_rjs do |page|
page.remove "test1"
end
assert_nothing_raised do
assert_select_rjs :remove, "test1" do
assert_select "p"
end
end
end
# Non-positioned insert. # Non-positioned insert.
def test_assert_select_rjs_for_nonpositioned_insert def test_assert_select_rjs_for_nonpositioned_insert
render_rjs do |page| render_rjs do |page|
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册