Ticket #7780: assert_select_rjs_show_hide_and_toggle.patch
| File assert_select_rjs_show_hide_and_toggle.patch, 4.2 kB (added by dchelimsky, 2 years ago) |
|---|
-
actionpack/test/controller/assert_select_test.rb
old new 429 429 end 430 430 end 431 431 432 # Simple show 433 def test_assert_select_rjs_for_show 434 render_rjs do |page| 435 page.show "test1" 436 end 437 438 assert_select_rjs :show, "test1" 439 end 440 441 def test_assert_select_rjs_for_show_ignores_block 442 render_rjs do |page| 443 page.show "test1" 444 end 445 446 assert_nothing_raised do 447 assert_select_rjs :show, "test1" do 448 assert_select "p" 449 end 450 end 451 end 452 453 # Simple hide 454 def test_assert_select_rjs_for_hide 455 render_rjs do |page| 456 page.hide "test1" 457 end 458 459 assert_select_rjs :hide, "test1" 460 end 461 462 def test_assert_select_rjs_for_hide_ignores_block 463 render_rjs do |page| 464 page.hide "test1" 465 end 466 467 assert_nothing_raised do 468 assert_select_rjs :hide, "test1" do 469 assert_select "p" 470 end 471 end 472 end 473 474 # Simple toggle 475 def test_assert_select_rjs_for_toggle 476 render_rjs do |page| 477 page.toggle "test1" 478 end 479 480 assert_select_rjs :toggle, "test1" 481 end 482 483 def test_assert_select_rjs_for_toggle_ignores_block 484 render_rjs do |page| 485 page.toggle "test1" 486 end 487 488 assert_nothing_raised do 489 assert_select_rjs :toggle, "test1" do 490 assert_select "p" 491 end 492 end 493 end 494 432 495 # Non-positioned insert. 433 496 def test_assert_select_rjs_for_nonpositioned_insert 434 497 render_rjs do |page| … … 475 538 assert_select "div", 4 476 539 end 477 540 end 478 479 541 480 542 # Simple selection from a single result. 481 543 def test_nested_assert_select_rjs_with_single_result 482 544 render_rjs do |page| -
actionpack/lib/action_controller/assertions/selector_assertions.rb
old new 317 317 # that update or insert an element with that identifier. 318 318 # 319 319 # Use the first argument to narrow down assertions to only statements 320 # of that type. Possible values are +:replace+, +:replace_html+, +: remove+ and321 # +: insert_html+.320 # of that type. Possible values are +:replace+, +:replace_html+, +:show+, 321 # +:hide+, +:toggle+, +:remove+ and +:insert_html+. 322 322 # 323 323 # Use the argument +:insert+ followed by an insertion position to narrow 324 324 # down the assertion to only statements that insert elements in that … … 406 406 case rjs_type 407 407 when :chained_replace, :chained_replace_html 408 408 Regexp.new("\\$\\(\"#{id}\"\\)#{statement}\\(#{RJS_PATTERN_HTML}\\)", Regexp::MULTILINE) 409 when :remove 409 when :remove, :show, :hide, :toggle 410 410 Regexp.new("#{statement}\\(\"#{id}\"\\)") 411 411 else 412 412 Regexp.new("#{statement}\\(\"#{id}\", #{RJS_PATTERN_HTML}\\)", Regexp::MULTILINE) … … 415 415 # Duplicate the body since the next step involves destroying it. 416 416 matches = nil 417 417 case rjs_type 418 when :remove 418 when :remove, :show, :hide, :toggle 419 419 matches = @response.body.match(pattern) 420 420 else 421 421 @response.body.gsub(pattern) do |match| … … 426 426 end 427 427 end 428 428 if matches 429 if block_given? && rjs_type != :remove429 if block_given? && !([:remove, :show, :hide, :toggle].include? rjs_type) 430 430 begin 431 431 in_scope, @selected = @selected, matches 432 432 yield matches … … 533 533 :chained_replace => /\.replace/, 534 534 :chained_replace_html => /\.update/, 535 535 :remove => /Element\.remove/, 536 :show => /Element\.show/, 537 :hide => /Element\.hide/, 538 :toggle => /Element\.toggle/ 536 539 } 537 540 RJS_INSERTIONS = [:top, :bottom, :before, :after] 538 541 RJS_INSERTIONS.each do |insertion|