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

Changeset 5525

Show
Ignore:
Timestamp:
11/15/06 12:45:52 (2 years ago)
Author:
bitsweat
Message:

assert_select_rjs :remove

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r5512 r5525  
    11*SVN* 
     2 
     3* assert_select_rjs :remove.  [Dylan Egan] 
    24 
    35* Always clear model associations from session.  #4795 [sd@notso.net, andylien@gmail.com] 
  • trunk/actionpack/lib/action_controller/assertions/selector_assertions.rb

    r5278 r5525  
    318318      # 
    319319      # Use the first argument to narrow down assertions to only statements 
    320       # of that type. Possible values are +:replace+, +:replace_html+ and 
     320      # of that type. Possible values are +:replace+, +:replace_html+, +:remove+ and 
    321321      # +:insert_html+. 
    322322      # 
     
    324324      # down the assertion to only statements that insert elements in that 
    325325      # position. Possible values are +:top+, +:bottom+, +:before+ and +:after+. 
     326      # 
     327      # Using the +:remove+ statement, you will be able to pass a block, but it will 
     328      # be ignored as there is no HTML passed for this statement. 
    326329      # 
    327330      # === Using blocks 
     
    352355      #   # Inserting into the element bar, top position. 
    353356      #   assert_select_rjs :insert, :top, "bar" 
     357      # 
     358      #   # Remove the element bar 
     359      #   assert_select_rjs :remove, "bar" 
    354360      # 
    355361      #   # Changing the element foo, with an image. 
     
    401407            when :chained_replace, :chained_replace_html 
    402408              Regexp.new("\\$\\(\"#{id}\"\\)#{statement}\\(#{RJS_PATTERN_HTML}\\)", Regexp::MULTILINE) 
     409            when :remove 
     410              Regexp.new("#{statement}\\(\"#{id}\"\\)") 
    403411            else 
    404412              Regexp.new("#{statement}\\(\"#{id}\", #{RJS_PATTERN_HTML}\\)", Regexp::MULTILINE) 
     
    407415        # Duplicate the body since the next step involves destroying it. 
    408416        matches = nil 
    409         @response.body.gsub(pattern) do |match| 
    410           html = unescape_rjs($2) 
    411           matches ||= [] 
    412           matches.concat HTML::Document.new(html).root.children.select { |n| n.tag? } 
    413           "" 
     417        case rjs_type 
     418          when :remove 
     419            matches = @response.body.match(pattern) 
     420          else 
     421            @response.body.gsub(pattern) do |match| 
     422              html = unescape_rjs($2) 
     423              matches ||= [] 
     424              matches.concat HTML::Document.new(html).root.children.select { |n| n.tag? } 
     425              "" 
     426            end 
    414427        end 
    415428        if matches 
    416           if block_given? 
     429          if block_given? && rjs_type != :remove 
    417430            begin 
    418431              in_scope, @selected = @selected, matches 
     
    520533            :chained_replace      => /\.replace/, 
    521534            :chained_replace_html => /\.update/, 
     535            :remove               => /Element\.remove/, 
    522536          } 
    523537          RJS_INSERTIONS = [:top, :bottom, :before, :after] 
  • trunk/actionpack/test/controller/assert_select_test.rb

    r5251 r5525  
    407407    end 
    408408    assert_raises(AssertionFailedError) { assert_select_rjs :replace_html, "test1" } 
     409  end 
     410 
     411  # Simple remove 
     412  def test_assert_select_rjs_for_remove 
     413    render_rjs do |page| 
     414      page.remove "test1" 
     415    end 
     416 
     417    assert_select_rjs :remove, "test1" 
     418  end 
     419 
     420  def test_assert_select_rjs_for_remove_ignores_block 
     421    render_rjs do |page| 
     422      page.remove "test1" 
     423    end 
     424 
     425    assert_nothing_raised do 
     426      assert_select_rjs :remove, "test1" do 
     427        assert_select "p" 
     428      end 
     429    end 
    409430  end 
    410431