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

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  
    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   
     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   
    432495  # Non-positioned insert. 
    433496  def test_assert_select_rjs_for_nonpositioned_insert 
    434497    render_rjs do |page| 
     
    475538      assert_select "div", 4 
    476539    end 
    477540  end 
    478  
    479  
     541   
    480542  # Simple selection from a single result. 
    481543  def test_nested_assert_select_rjs_with_single_result 
    482544    render_rjs do |page| 
  • actionpack/lib/action_controller/assertions/selector_assertions.rb

    old new  
    317317      # that update or insert an element with that identifier. 
    318318      # 
    319319      # Use the first argument to narrow down assertions to only statements 
    320       # of that type. Possible values are +:replace+, +:replace_html+, +:remove+ and 
    321       # +:insert_html+. 
     320      # of that type. Possible values are +:replace+, +:replace_html+, +:show+, 
     321      # +:hide+, +:toggle+, +:remove+ and +:insert_html+. 
    322322      # 
    323323      # Use the argument +:insert+ followed by an insertion position to narrow 
    324324      # down the assertion to only statements that insert elements in that 
     
    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, :toggle 
    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, :toggle 
    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, :toggle].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/, 
     538            :toggle                 => /Element\.toggle/ 
    536539          } 
    537540          RJS_INSERTIONS = [:top, :bottom, :before, :after] 
    538541          RJS_INSERTIONS.each do |insertion|