Skip to content
This repository
Browse code

Fix bad merge from e21ed3e

  • Loading branch information...
commit e7df4ce001fc5a7612c6b784ba2524f9b31cbc39 1 parent 184ae2c
Jeremy Kemper jeremy authored
78 actionpack/lib/action_controller/assertions/selector_assertions.rb
@@ -398,54 +398,31 @@ def count_description(min, max) #:nodoc:
398 398 # # The same, but shorter.
399 399 # assert_select "ol>li", 4
400 400 def assert_select_rjs(*args, &block)
401   - rjs_type = nil
402   - arg = args.shift
  401 + rjs_type = args.first.is_a?(Symbol) ? args.shift : nil
  402 + id = args.first.is_a?(String) ? args.shift : nil
403 403
404 404 # If the first argument is a symbol, it's the type of RJS statement we're looking
405 405 # for (update, replace, insertion, etc). Otherwise, we're looking for just about
406 406 # any RJS statement.
407   - if arg.is_a?(Symbol)
408   - rjs_type = arg
409   -
  407 + if rjs_type
410 408 if rjs_type == :insert
411   - arg = args.shift
412   - position = arg
413   - insertion = "insert_#{arg}".to_sym
414   - raise ArgumentError, "Unknown RJS insertion type #{arg}" unless RJS_STATEMENTS[insertion]
  409 + position = args.shift
  410 + insertion = "insert_#{position}".to_sym
  411 + raise ArgumentError, "Unknown RJS insertion type #{position}" unless RJS_STATEMENTS[insertion]
415 412 statement = "(#{RJS_STATEMENTS[insertion]})"
416 413 else
417 414 raise ArgumentError, "Unknown RJS statement type #{rjs_type}" unless RJS_STATEMENTS[rjs_type]
418 415 statement = "(#{RJS_STATEMENTS[rjs_type]})"
419 416 end
420   - arg = args.shift
421 417 else
422 418 statement = "#{RJS_STATEMENTS[:any]}"
423 419 end
424   - position ||= Regexp.new(RJS_INSERTIONS.join('|'))
425 420
426 421 # Next argument we're looking for is the element identifier. If missing, we pick
427   - # any element.
428   - if arg.is_a?(String)
429   - id = Regexp.quote(arg)
430   - arg = args.shift
431   - else
432   - id = "[^\"]*"
433   - end
434   -
435   - pattern =
436   - case rjs_type
437   - when :chained_replace, :chained_replace_html
438   - Regexp.new("\\$\\(\"#{id}\"\\)#{statement}\\(#{RJS_PATTERN_HTML}\\)", Regexp::MULTILINE)
439   - when :remove, :show, :hide, :toggle
440   - Regexp.new("#{statement}\\(\"#{id}\"\\)")
441   - when :replace, :replace_html
442   - Regexp.new("#{statement}\\(\"#{id}\", #{RJS_PATTERN_HTML}\\)")
443   - when :insert, :insert_html
444   - Regexp.new("Element.insert\\(\\\"#{id}\\\", \\{ #{position}: #{RJS_PATTERN_HTML} \\}\\);")
445   - else
446   - Regexp.union(Regexp.new("#{statement}\\(\"#{id}\", #{RJS_PATTERN_HTML}\\)"),
447   - Regexp.new("Element.insert\\(\\\"#{id}\\\", \\{ #{position}: #{RJS_PATTERN_HTML} \\}\\);"))
448   - end
  422 + # any element, otherwise we replace it in the statement.
  423 + pattern = Regexp.new(
  424 + id ? statement.gsub(RJS_ANY_ID, "\"#{id}\"") : statement
  425 + )
449 426
450 427 # Duplicate the body since the next step involves destroying it.
451 428 matches = nil
@@ -584,26 +561,23 @@ def assert_select_email(&block)
584 561
585 562 protected
586 563 unless const_defined?(:RJS_STATEMENTS)
587   - RJS_STATEMENTS = {
588   - :replace => /Element\.replace/,
589   - :replace_html => /Element\.update/,
590   - :chained_replace => /\.replace/,
591   - :chained_replace_html => /\.update/,
592   - :remove => /Element\.remove/,
593   - :show => /Element\.show/,
594   - :hide => /Element\.hide/,
595   - :toggle => /Element\.toggle/
  564 + RJS_PATTERN_HTML = "\"((\\\\\"|[^\"])*)\""
  565 + RJS_ANY_ID = "\"([^\"])*\""
  566 + RJS_STATEMENTS = {
  567 + :chained_replace => "\\$\\(#{RJS_ANY_ID}\\)\\.replace\\(#{RJS_PATTERN_HTML}\\)",
  568 + :chained_replace_html => "\\$\\(#{RJS_ANY_ID}\\)\\.update\\(#{RJS_PATTERN_HTML}\\)",
  569 + :replace_html => "Element\\.update\\(#{RJS_ANY_ID}, #{RJS_PATTERN_HTML}\\)",
  570 + :replace => "Element\\.replace\\(#{RJS_ANY_ID}, #{RJS_PATTERN_HTML}\\)"
596 571 }
597   - RJS_STATEMENTS[:any] = Regexp.new("(#{RJS_STATEMENTS.values.join('|')})")
598   - RJS_PATTERN_HTML = /"((\\"|[^"])*)"/
599   - RJS_INSERTIONS = [:top, :bottom, :before, :after]
  572 + [:remove, :show, :hide, :toggle].each do |action|
  573 + RJS_STATEMENTS[action] = "Element\\.#{action}\\(#{RJS_ANY_ID}\\)"
  574 + end
  575 + RJS_INSERTIONS = ["top", "bottom", "before", "after"]
600 576 RJS_INSERTIONS.each do |insertion|
601   - RJS_STATEMENTS["insert_#{insertion}".to_sym] = /Element.insert\(\"([^\"]*)\", \{ #{insertion.to_s.downcase}: #{RJS_PATTERN_HTML} \}\);/
  577 + RJS_STATEMENTS["insert_#{insertion}".to_sym] = "Element.insert\\(#{RJS_ANY_ID}, \\{ #{insertion}: #{RJS_PATTERN_HTML} \\}\\)"
602 578 end
603   - RJS_STATEMENTS[:insert_html] = Regexp.new(RJS_INSERTIONS.collect do |insertion|
604   - /Element.insert\(\"([^\"]*)\", \{ #{insertion.to_s.downcase}: #{RJS_PATTERN_HTML} \}\);/
605   - end.join('|'))
606   - RJS_PATTERN_EVERYTHING = Regexp.new("#{RJS_STATEMENTS[:any]}\\(\"([^\"]*)\", #{RJS_PATTERN_HTML}\\)", Regexp::MULTILINE)
  579 + RJS_STATEMENTS[:insert_html] = "Element.insert\\(#{RJS_ANY_ID}, \\{ (#{RJS_INSERTIONS.join('|')}): #{RJS_PATTERN_HTML} \\}\\)"
  580 + RJS_STATEMENTS[:any] = Regexp.new("(#{RJS_STATEMENTS.values.join('|')})")
607 581 RJS_PATTERN_UNICODE_ESCAPED_CHAR = /\\u([0-9a-zA-Z]{4})/
608 582 end
609 583
@@ -617,8 +591,8 @@ def response_from_page_or_rjs()
617 591 root = HTML::Node.new(nil)
618 592
619 593 while true
620   - next if body.sub!(RJS_PATTERN_EVERYTHING) do |match|
621   - html = unescape_rjs($3)
  594 + next if body.sub!(RJS_STATEMENTS[:any]) do |match|
  595 + html = unescape_rjs(match)
622 596 matches = HTML::Document.new(html).root.children.select { |n| n.tag? }
623 597 root.children.concat matches
624 598 ""
7 actionpack/test/controller/assert_select_test.rb
@@ -568,7 +568,12 @@ def test_assert_select_rjs_for_positioned_insert
568 568 assert_select "div", 4
569 569 end
570 570 end
571   -
  571 +
  572 + def test_assert_select_rjs_raise_errors
  573 + assert_raises(ArgumentError) { assert_select_rjs(:destroy) }
  574 + assert_raises(ArgumentError) { assert_select_rjs(:insert, :left) }
  575 + end
  576 +
572 577 # Simple selection from a single result.
573 578 def test_nested_assert_select_rjs_with_single_result
574 579 render_rjs do |page|
2  actionpack/test/controller/request_test.rb
@@ -13,7 +13,7 @@ def test_remote_ip
13 13 assert_equal '1.2.3.4', @request.remote_ip
14 14
15 15 @request.remote_addr = '1.2.3.4,3.4.5.6'
16   - assert_equal '1.2.3.4', @request.remote_ip(true)
  16 + assert_equal '1.2.3.4', @request.remote_ip
17 17
18 18 @request.env['HTTP_CLIENT_IP'] = '2.3.4.5'
19 19 assert_equal '1.2.3.4', @request.remote_ip

0 comments on commit e7df4ce

Please sign in to comment.
Something went wrong with that request. Please try again.