Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 373
- Log:
Initial import of Radiant 0.9.1, which is now packaged as a gem. This is an
import of the tagged 0.9.1 source checked out from GitHub, which isn't quite
the same as the gem distribution - but it doesn't seem to be available in an
archived form and the installed gem already has modifications, so this is
the closest I can get.
- Author:
- rool
- Date:
- Mon Mar 21 13:40:05 +0000 2011
- Size:
- 4639 Bytes
1 | require File.dirname(__FILE__) + "/../../spec_helper" |
2 | require 'ostruct' |
3 | |
4 | describe Radiant::Taggable, "when included in a class or module" do |
5 | |
6 | class TaggedClass |
7 | include Radiant::Taggable |
8 | end |
9 | |
10 | module TaggedModule |
11 | include Radiant::Taggable |
12 | end |
13 | |
14 | it "should add tag definition methods to the class" do |
15 | [TaggedClass, TaggedModule].each do |c| |
16 | c.should respond_to(:tag) |
17 | c.should respond_to(:desc) |
18 | end |
19 | end |
20 | |
21 | it "should turn tag definitions into methods" do |
22 | [TaggedClass, TaggedModule].each do |c| |
23 | c.tag 'hello' do |
24 | "hello world" |
25 | end |
26 | c.instance_methods.should include("tag:hello") |
27 | end |
28 | TaggedClass.new.send("tag:hello").should == "hello world" |
29 | end |
30 | |
31 | it "should store tag descriptions filtered without Textile, so that translations can be applied" do |
32 | [TaggedClass, TaggedModule].each do |c| |
33 | c.desc "A simple tag." |
34 | Radiant::Taggable.last_description.should == "A simple tag." |
35 | end |
36 | end |
37 | |
38 | it "should associate a tag description with the tag definition that follows it" do |
39 | [TaggedClass, TaggedModule].each do |c| |
40 | c.desc "Bonjour!" |
41 | c.tag "hello" do |
42 | "hello world" |
43 | end |
44 | c.tag_descriptions['hello'].should =~ /Bonjour!/ |
45 | Radiant::Taggable.last_description.should be_nil |
46 | end |
47 | end |
48 | |
49 | # This has been moved to the admin/references_helper |
50 | # |
51 | # it "should normalize leading whitespace in a tag description" do |
52 | # Radiant::Taggable::Util.should_receive(:strip_leading_whitespace).twice.with(" Blah blah\n blah blah").and_return("blah") |
53 | # [TaggedClass, TaggedModule].each do |c| |
54 | # c.desc " Blah blah\n blah blah" |
55 | # end |
56 | # end |
57 | end |
58 | |
59 | describe Radiant::Taggable, "when included in a module with defined tags" do |
60 | |
61 | module MyTags |
62 | include Radiant::Taggable |
63 | |
64 | desc %{This tag renders the text "just a test".} |
65 | tag "test" do |
66 | "just a test" |
67 | end |
68 | |
69 | desc %{This tag implements "Hello, world!".} |
70 | tag "hello" do |tag| |
71 | "Hello, #{ tag.attr['name'] || 'world' }!" |
72 | end |
73 | |
74 | tag "page_index_path" do |tag| |
75 | admin_pages_path |
76 | end |
77 | end |
78 | |
79 | class TestObject |
80 | include Radiant::Taggable |
81 | |
82 | desc %{Yet another test} |
83 | tag "test" do |
84 | "My new test" |
85 | end |
86 | |
87 | include MyTags |
88 | end |
89 | |
90 | before :each do |
91 | @object = TestObject.new |
92 | @tag_binding = OpenStruct.new('attr' => {"name" => "John"}) |
93 | end |
94 | |
95 | it "should have a collection of defined tags" do |
96 | MyTags.should respond_to(:tags) |
97 | MyTags.tags.should == ['hello', 'page_index_path', 'test'] |
98 | end |
99 | |
100 | it "should add tags to an included class" do |
101 | TestObject.should respond_to(:tags) |
102 | TestObject.tags.should == ['hello', 'page_index_path', 'test'] |
103 | end |
104 | |
105 | it "should merge tag descriptions with an included class" do |
106 | TestObject.tag_descriptions["test"].should == MyTags.tag_descriptions["test"] |
107 | end |
108 | |
109 | it "should render a defined tag on an instance of an included class" do |
110 | @object.should respond_to(:render_tag) |
111 | @object.render_tag(:test, {}).should == "My new test" |
112 | end |
113 | |
114 | it "should render a defined tag on an instance of an included class with a given tag binding" do |
115 | @object.render_tag(:hello, @tag_binding).should == "Hello, John!" |
116 | end |
117 | |
118 | it "should render a url helper called in a tag definition" do |
119 | @object.render_tag(:page_index_path, {}).should == "/admin/pages" |
120 | end |
121 | |
122 | end |
123 | |
124 | describe Radiant::Taggable, "when included in a module with defined tags which is included in the Page model" do |
125 | dataset :users_and_pages, :file_not_found, :snippets |
126 | |
127 | module CustomTags |
128 | include Radiant::Taggable |
129 | |
130 | tag "param_value" do |tag| |
131 | params[:sample_param] |
132 | end |
133 | end |
134 | |
135 | Page.send :include, CustomTags |
136 | |
137 | it 'should render a param value used in a tag' do |
138 | page(:home) |
139 | page.should render('<r:param_value />').as('data') |
140 | end |
141 | |
142 | private |
143 | def page(symbol = nil) |
144 | if symbol.nil? |
145 | @page ||= pages(:assorted) |
146 | else |
147 | @page = pages(symbol) |
148 | end |
149 | end |
150 | end |
151 | |
152 | describe Radiant::Taggable::Util do |
153 | it "should normalize leading whitespace" do |
154 | markup = %{ |
155 | |
156 | I'm a really small paragraph that |
157 | happens to span two lines. |
158 | |
159 | * I'm just |
160 | * a simple |
161 | * list |
162 | |
163 | Let's try a small code example: |
164 | |
165 | puts "Hello world!" |
166 | |
167 | Nice job! It really, really, really |
168 | works. |
169 | |
170 | } |
171 | result = %{ |
172 | |
173 | I'm a really small paragraph that |
174 | happens to span two lines. |
175 | |
176 | * I'm just |
177 | * a simple |
178 | * list |
179 | |
180 | Let's try a small code example: |
181 | |
182 | puts "Hello world!" |
183 | |
184 | Nice job! It really, really, really |
185 | works.} |
186 | Radiant::Taggable::Util.strip_leading_whitespace(markup).should == result |
187 | end |
188 | end |