aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/assertions/selector_assertions.rb
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2006-09-14 17:50:46 +0000
committerRick Olson <technoweenie@gmail.com>2006-09-14 17:50:46 +0000
commit6dbac689a8d7f285ccdb2e3fa2b2967d731475ab (patch)
tree021f656f0cea1e4b13f9a8e47e02adb7eac2dde8 /actionpack/lib/action_controller/assertions/selector_assertions.rb
parent3ab1cb6a6a1ea0bde8ef35d02370248396753c7a (diff)
downloadrails-6dbac689a8d7f285ccdb2e3fa2b2967d731475ab.tar.gz
rails-6dbac689a8d7f285ccdb2e3fa2b2967d731475ab.tar.bz2
rails-6dbac689a8d7f285ccdb2e3fa2b2967d731475ab.zip
Add chained replace/update support for assert_select_rjs [Rick Olson]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5110 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_controller/assertions/selector_assertions.rb')
-rw-r--r--actionpack/lib/action_controller/assertions/selector_assertions.rb35
1 files changed, 25 insertions, 10 deletions
diff --git a/actionpack/lib/action_controller/assertions/selector_assertions.rb b/actionpack/lib/action_controller/assertions/selector_assertions.rb
index 7984e14c67..a6cba9d805 100644
--- a/actionpack/lib/action_controller/assertions/selector_assertions.rb
+++ b/actionpack/lib/action_controller/assertions/selector_assertions.rb
@@ -343,11 +343,16 @@ EOT
#
# === Examples
#
- # # Updating the element foo.
- # assert_select_rjs :update, "foo"
+ # # Replacing the element foo.
+ # # page.replace 'foo', ...
+ # assert_select_rjs :replace, "foo"
+ #
+ # # Replacing with the chained RJS proxy.
+ # # page[:foo].replace ...
+ # assert_select_rjs :chained_replace, 'foo'
#
# # Inserting into the element bar, top position.
- # assert_select rjs, :insert, :top, "bar"
+ # assert_select_rjs :insert, :top, "bar"
#
# # Changing the element foo, with an image.
# assert_select_rjs "foo" do
@@ -362,20 +367,22 @@ EOT
# # The same, but shorter.
# assert_select "ol>li", 4
def assert_select_rjs(*args, &block)
- arg = args.shift
+ rjs_type = nil
+ arg = args.shift
# If the first argument is a symbol, it's the type of RJS statement we're looking
# for (update, replace, insertion, etc). Otherwise, we're looking for just about
# any RJS statement.
if arg.is_a?(Symbol)
- if arg == :insert
+ rjs_type = arg
+ if rjs_type == :insert
arg = args.shift
insertion = "insert_#{arg}".to_sym
raise ArgumentError, "Unknown RJS insertion type #{arg}" unless RJS_STATEMENTS[insertion]
statement = "(#{RJS_STATEMENTS[insertion]})"
else
- raise ArgumentError, "Unknown RJS statement type #{arg}" unless RJS_STATEMENTS[arg]
- statement = "(#{RJS_STATEMENTS[arg]})"
+ raise ArgumentError, "Unknown RJS statement type #{rjs_type}" unless RJS_STATEMENTS[rjs_type]
+ statement = "(#{RJS_STATEMENTS[rjs_type]})"
end
arg = args.shift
else
@@ -391,7 +398,13 @@ EOT
id = "[^\"]*"
end
- pattern = Regexp.new("#{statement}\\(\"#{id}\", #{RJS_PATTERN_HTML}\\)", Regexp::MULTILINE)
+ pattern =
+ case rjs_type
+ when :chained_replace, :chained_replace_html
+ Regexp.new("\\$\\(\"#{id}\"\\)#{statement}\\(#{RJS_PATTERN_HTML}\\)", Regexp::MULTILINE)
+ else
+ Regexp.new("#{statement}\\(\"#{id}\", #{RJS_PATTERN_HTML}\\)", Regexp::MULTILINE)
+ end
# Duplicate the body since the next step involves destroying it.
matches = nil
@@ -507,8 +520,10 @@ EOT
protected
unless const_defined?(:RJS_STATEMENTS)
RJS_STATEMENTS = {
- :replace => /Element\.replace/,
- :replace_html => /Element\.update/
+ :replace => /Element\.replace/,
+ :replace_html => /Element\.update/,
+ :chained_replace => /\.replace/,
+ :chained_replace_html => /\.update/,
}
RJS_INSERTIONS = [:top, :bottom, :before, :after]
RJS_INSERTIONS.each do |insertion|