Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #7780: assert_select_rjs_show_and_hide.patch

File assert_select_rjs_show_and_hide.patch, 3.1 kB (added by dchelimsky, 2 years ago)
  • actionpack/test/controller/assert_select_test.rb

    old new  
    429429    end 
    430430  end 
    431431 
     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   
    432474  # Non-positioned insert. 
    433475  def test_assert_select_rjs_for_nonpositioned_insert 
    434476    render_rjs do |page| 
     
    475517      assert_select "div", 4 
    476518    end 
    477519  end 
    478  
    479  
     520   
    480521  # Simple selection from a single result. 
    481522  def test_nested_assert_select_rjs_with_single_result 
    482523    render_rjs do |page| 
  • actionpack/lib/action_controller/assertions/selector_assertions.rb

    old new  
    406406          case rjs_type 
    407407            when :chained_replace, :chained_replace_html 
    408408              Regexp.new("\\$\\(\"#{id}\"\\)#{statement}\\(#{RJS_PATTERN_HTML}\\)", Regexp::MULTILINE) 
    409             when :remove 
     409            when :remove, :show, :hide 
    410410              Regexp.new("#{statement}\\(\"#{id}\"\\)") 
    411411            else 
    412412              Regexp.new("#{statement}\\(\"#{id}\", #{RJS_PATTERN_HTML}\\)", Regexp::MULTILINE) 
     
    415415        # Duplicate the body since the next step involves destroying it. 
    416416        matches = nil 
    417417        case rjs_type 
    418           when :remove 
     418          when :remove, :show, :hide 
    419419            matches = @response.body.match(pattern) 
    420420          else 
    421421            @response.body.gsub(pattern) do |match| 
     
    426426            end 
    427427        end 
    428428        if matches 
    429           if block_given? && rjs_type != :remove 
     429          if block_given? && !([:remove, :show, :hide].include? rjs_type) 
    430430            begin 
    431431              in_scope, @selected = @selected, matches 
    432432              yield matches 
     
    533533            :chained_replace      => /\.replace/, 
    534534            :chained_replace_html => /\.update/, 
    535535            :remove               => /Element\.remove/, 
     536            :show                 => /Element\.show/, 
     537            :hide                 => /Element\.hide/ 
    536538          } 
    537539          RJS_INSERTIONS = [:top, :bottom, :before, :after] 
    538540          RJS_INSERTIONS.each do |insertion|