aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/template/record_tag_helper_test.rb
blob: bb5440be20912cfb62e00eda6c5c7e379142bdf5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require 'abstract_unit'

class Post
  def id
     45 
  end
  def body
    "What a wonderful world!"
  end
end

class RecordTagHelperTest < Test::Unit::TestCase
  include ActionView::Helpers::RecordTagHelper
  include ActionView::Helpers::CaptureHelper
  include ActionView::Helpers::RecordIdentificationHelper  
  include ActionView::Helpers::TagHelper
  include ActionView::Helpers::TextHelper  
  include ActionView::Helpers::UrlHelper  
    
  def setup
    @post = Post.new
  end
  
  def test_content_tag_for
    _erbout = ''
    expected = %(<li class="post bar" id="post_45"></li>)
    actual = content_tag_for(:li, @post, :class => 'bar') { }
    assert_dom_equal expected, actual
  end
  
  def test_content_tag_for_prefix
    _erbout = ''
    expected = %(<ul class="post" id="archived_post_45"></ul>)
    actual = content_tag_for(:ul, @post, :archived) { }
    assert_dom_equal expected, actual    
  end
  
  def test_content_tag_for_with_extra_html_tags
    _erbout = ''
    expected = %(<tr class="post bar" id="post_45" style='background-color: #f0f0f0'></tr>)
    actual = content_tag_for(:tr, @post, {:class => "bar", :style => "background-color: #f0f0f0"}) { }
    assert_dom_equal expected, actual        
  end
  
  def test_block_works_with_content_tag_for
    _erbout = ''
    expected = %(<tr class="post" id="post_45">#{@post.body}</tr>)
    actual = content_tag_for(:tr, @post) { _erbout.concat @post.body }
    assert_dom_equal expected, actual            
  end
  
  def test_div_for    
    _erbout = ''    
    expected = %(<div class="post bar" id="post_45">#{@post.body}</div>)
    actual = div_for(@post, :class => "bar") { _erbout.concat @post.body }
    assert_dom_equal expected, actual
  end  
  
end