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

Ticket #11223: tests_for_record_tag_helpers.diff

File tests_for_record_tag_helpers.diff, 2.7 kB (added by thechrisoshow, 9 months ago)

Tests for RecordTagHelper methods

  • actionpack/test/template/record_tag_helper_test.rb

    old new  
     1require 'abstract_unit' 
     2 
     3class Post 
     4  def id 
     5     45  
     6  end 
     7  def body 
     8    "What a wonderful world!" 
     9  end 
     10end 
     11 
     12class RecordTagHelperTest < Test::Unit::TestCase 
     13  include ActionView::Helpers::RecordTagHelper 
     14  include ActionView::Helpers::CaptureHelper 
     15  include ActionView::Helpers::RecordIdentificationHelper   
     16  include ActionView::Helpers::TagHelper 
     17  include ActionView::Helpers::TextHelper   
     18  include ActionView::Helpers::UrlHelper   
     19     
     20  def setup 
     21    @post = Post.new 
     22  end 
     23   
     24  def test_content_tag_for 
     25    _erbout = '' 
     26    expected = %(<li class="post bar" id="post_45"></li>) 
     27    actual = content_tag_for(:li, @post, :class => 'bar') { } 
     28    assert_dom_equal expected, actual 
     29  end 
     30   
     31  def test_content_tag_for_prefix 
     32    _erbout = '' 
     33    expected = %(<ul class="post" id="archived_post_45"></ul>) 
     34    actual = content_tag_for(:ul, @post, :archived) { } 
     35    assert_dom_equal expected, actual     
     36  end 
     37   
     38  def test_content_tag_for_with_extra_html_tags 
     39    _erbout = '' 
     40    expected = %(<tr class="post bar" id="post_45" style='background-color: #f0f0f0'></tr>) 
     41    actual = content_tag_for(:tr, @post, {:class => "bar", :style => "background-color: #f0f0f0"}) { } 
     42    assert_dom_equal expected, actual         
     43  end 
     44   
     45  def test_block_works_with_content_tag_for 
     46    _erbout = '' 
     47    expected = %(<tr class="post" id="post_45">#{@post.body}</tr>) 
     48    actual = content_tag_for(:tr, @post) { _erbout.concat @post.body } 
     49    assert_dom_equal expected, actual             
     50  end 
     51   
     52  def test_div_for     
     53    _erbout = ''     
     54    expected = %(<div class="post bar" id="post_45">#{@post.body}</div>) 
     55    actual = div_for(@post, :class => "bar") { _erbout.concat @post.body } 
     56    assert_dom_equal expected, actual 
     57  end   
     58   
     59end 
  • actionpack/lib/action_view/helpers/record_tag_helper.rb

    old new  
    2424      #      <td><%=h @person.last_name %></td> 
    2525      #    <% end %> 
    2626      # 
    27       # would produce hthe following HTML (assuming @person is an instance of 
     27      # would produce the following HTML (assuming @person is an instance of 
    2828      # a Person object, with an id value of 123): 
    2929      # 
    3030      #    <tr id="person_123" class="person">....</tr>