Renamed helpers to correspond to renamed Controller classes.
[merb_radiant.git] / radiant_specs / test / unit / radiant / .svn / text-base / taggable_test.rb.svn-base
blob3f741fcd2efde96b64fd7acdd08ed2f9b1ff479f
1 require File.dirname(__FILE__) + '/../../test_helper'
2 require 'ostruct'
3 require 'radiant/taggable'
4 class Radiant::TaggableTest < Test::Unit::TestCase
5   
6   class TestObject
7     include Radiant::Taggable
8     
9     desc %{This tag renders the text "just a test".}
10     tag "test" do
11       "just a test"
12     end
14     desc %{This tag implements "Hello, world!".}    
15     tag "hello" do |tag|
16       "Hello, #{ tag.attr['name'] || 'world' }!"
17     end
18   end
19   
20   module AdditionalTags
21     include Radiant::Taggable
22     
23     desc %{This tag renders the text "another tag".}
24     tag "another" do
25       "another tag"
26     end
27     
28   end
29   
30   class AnotherObject < TestObject
31     include AdditionalTags
32   end
33   
34   def setup
35     @object = TestObject.new
36   end
37   
38   def test_tag_class_method
39     assert_equal "just a test", @object.send("tag:test")
40   end
41   
42   def test_tags_class_method
43     assert_equal ["hello", "test"], TestObject.tags
44   end
45   
46   def test_tags
47     @object.extend AdditionalTags
48     assert_equal ["another", "hello", "test"], @object.tags
49   end
50   
51   def test_render_tag
52     binding = OpenStruct.new( :attr => { 'name' => 'John' } )
53     assert_equal "Hello, John!", @object.render_tag(:hello, binding)
54   end
55   
56   def test_descriptions
57     assert @object.respond_to?(:tag_descriptions)
58     assert_equal "<p>This tag renders the text &#8220;just a test&#8221;.</p>", @object.tag_descriptions["test"]
59     assert_equal "<p>This tag implements &#8220;Hello, world!&#8221;.</p>", @object.tag_descriptions["hello"]    
60   end
61   
62   def test_description_inclusion_and_inheritance
63     @object = AnotherObject.new
64     assert_not_nil @object.tag_descriptions["another"] 
65     assert_equal "<p>This tag renders the text &#8220;another tag&#8221;.</p>", @object.tag_descriptions["another"]
66     assert_equal "<p>This tag renders the text &#8220;just a test&#8221;.</p>", @object.tag_descriptions["test"]
67     assert_equal "<p>This tag implements &#8220;Hello, world!&#8221;.</p>", @object.tag_descriptions["hello"]
68   end
70   def test_strip_leading_whitespace
71     markup = %{  
72   
73   I'm a really small paragraph that
74   happens to span two lines.
75   
76   * I'm just
77   * a simple
78   * list
80   Let's try a small code example:
81   
82     puts "Hello world!"
83   
84   Nice job! It really, really, really
85   works.
88 result = %{
90 I'm a really small paragraph that
91 happens to span two lines.
93 * I'm just
94 * a simple
95 * list
97 Let's try a small code example:
99   puts "Hello world!"
101 Nice job! It really, really, really
102 works.}
103      assert_equal result, Radiant::Taggable::Util.strip_leading_whitespace(markup)
104    end