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:
- 11201 Bytes
1 | require File.dirname(__FILE__) + "/../spec_helper" |
2 | |
3 | describe ApplicationHelper do |
4 | dataset :users |
5 | |
6 | before :each do |
7 | Radiant::Initializer.run :initialize_default_admin_tabs |
8 | helper.stub!(:request).and_return(ActionController::TestRequest.new) |
9 | end |
10 | |
11 | it "should have the Radiant::Config" do |
12 | helper.config.should == Radiant::Config |
13 | end |
14 | |
15 | it "should use the default title if not configured" do |
16 | helper.title.should == "Radiant CMS" |
17 | end |
18 | |
19 | it "should use the stored title if configured" do |
20 | helper.config['admin.title'] = "My Title" |
21 | helper.title.should == "My Title" |
22 | end |
23 | |
24 | it "should use the default subtitle if not configured" do |
25 | helper.subtitle.should == "Publishing for Small Teams" |
26 | end |
27 | |
28 | it "should use the stored title if configured" do |
29 | helper.config['admin.subtitle'] = "My Subtitle" |
30 | helper.subtitle.should == "My Subtitle" |
31 | end |
32 | |
33 | it "should not be logged in before authentication" do |
34 | helper.should_receive(:current_user).and_return(nil) |
35 | helper.logged_in?.should be_false |
36 | end |
37 | |
38 | it "should be logged in when authenticated" do |
39 | helper.should_receive(:current_user).and_return(users(:existing)) |
40 | helper.logged_in?.should be_true |
41 | end |
42 | |
43 | it "should create a button for a new model" do |
44 | model = mock_model(Page) |
45 | model.should_receive(:new_record?).and_return(true) |
46 | helper.should_receive(:submit_tag).with("Create Page", :class => 'button', :accesskey=>"S") |
47 | helper.save_model_button(model) |
48 | end |
49 | |
50 | it "should create a button for an existing model" do |
51 | model = mock_model(Page) |
52 | model.should_receive(:new_record?).and_return(false) |
53 | helper.should_receive(:submit_tag).with("Save Changes", :class => 'button', :accesskey=>"S") |
54 | helper.save_model_button(model) |
55 | end |
56 | |
57 | it "should create a button with custom options" do |
58 | model = mock_model(Page) |
59 | model.should_receive(:new_record?).and_return(false) |
60 | helper.should_receive(:submit_tag).with("Save Changes", :class => 'custom', :accesskey=>"S") |
61 | helper.save_model_button(model, :class => 'custom') |
62 | end |
63 | |
64 | it "should create a button with a custom label" do |
65 | model = mock_model(Page) |
66 | helper.should_receive(:submit_tag).with("Create PAGE", :class => 'button', :accesskey=>"S") |
67 | helper.save_model_button(model, :label => "Create PAGE") |
68 | end |
69 | |
70 | it "should create a save and continue button" do |
71 | model = mock_model(Page) |
72 | helper.save_model_and_continue_editing_button(model).should =~ /name="continue"/ |
73 | helper.save_model_and_continue_editing_button(model).should =~ /class="button"/ |
74 | helper.save_model_and_continue_editing_button(model).should =~ /^<input/ |
75 | end |
76 | |
77 | it "should redefine pluralize without the count" do |
78 | helper.pluralize(1, "page").should == "page" |
79 | helper.pluralize(2, "page").should == "pages" |
80 | helper.pluralize(0, "page").should == "pages" |
81 | helper.pluralize(2, "ox", "oxen").should == "oxen" |
82 | end |
83 | |
84 | it "should determine whether a given url matches the current url" do |
85 | request = mock("request") |
86 | helper.stub!(:request).and_return(request) |
87 | request.stub!(:request_uri).and_return("/foo/bar") |
88 | helper.current_url?("/foo/bar/").should_not be_false |
89 | helper.current_url?("/foo//bar").should_not be_false |
90 | helper.current_url?("/baz/bam").should_not be_true |
91 | helper.current_url?(:controller => "admin/pages", :action => "index").should_not be_true |
92 | end |
93 | |
94 | it "should clean a url" do |
95 | helper.clean("/foo/////bar").should == "/foo/bar" |
96 | helper.clean("/blah/").should == "/blah" |
97 | end |
98 | |
99 | it "should render an admin navigation link" do |
100 | request = mock("request") |
101 | helper.stub!(:request).and_return(request) |
102 | request.stub!(:request_uri).and_return("/admin/pages") |
103 | helper.nav_link_to("Pages", "/admin/pages").should =~ /<strong>/ |
104 | helper.nav_link_to("Snippets", "/admin/snippets").should_not =~ /<strong>/ |
105 | end |
106 | |
107 | it "should render an admin link without translation" do |
108 | helper.nav_link_to("Foo", "/admin/foo").should == '<a href="/admin/foo">Foo</a>' |
109 | end |
110 | |
111 | it "should render an admin section link with translation" do |
112 | helper.translate_with_default('Pages').should == 'Pages' |
113 | end |
114 | |
115 | it "should render an admin section link without translation" do |
116 | helper.translate_with_default('Foo').should == 'Foo' |
117 | end |
118 | |
119 | it "should determine whether the current user is an admin" do |
120 | helper.should_receive(:current_user).at_least(1).times.and_return(users(:admin)) |
121 | helper.admin?.should be_true |
122 | end |
123 | |
124 | it "should determine whether the current user is a designer" do |
125 | helper.should_receive(:current_user).at_least(1).times.and_return(users(:designer)) |
126 | helper.designer?.should be_true |
127 | end |
128 | |
129 | it "should render a Javascript snippet that focuses a given field" do |
130 | helper.focus('joe').should =~ Regexp.new(Regexp.quote("activate('joe')")) |
131 | end |
132 | |
133 | it "should render an updated timestamp for a model" do |
134 | model = mock_model(Page) |
135 | model.should_receive(:new_record?).and_return(false) |
136 | model.should_receive(:updated_by).and_return(users(:admin)) |
137 | model.should_receive(:updated_at).and_return(Time.local(2008, 3, 30, 10, 30)) |
138 | helper.updated_stamp(model).should == %{<p class="updated_line">Last Updated by <strong>Admin</strong> at 10:30 am on March 30, 2008</p>} |
139 | end |
140 | |
141 | it "should render a timezone-adjusted timestamp" do |
142 | helper.timestamp(Time.local(2008, 3, 30, 10, 30)).should == "10:30 am on March 30, 2008" |
143 | end |
144 | |
145 | it "should determine whether a meta area item should be visible" do |
146 | helper.meta_visible(:meta_more).should be_empty |
147 | helper.meta_visible(:meta_less).should == {:style => "display: none"} |
148 | helper.meta_visible(:meta).should == {:style => "display: none"} |
149 | end |
150 | |
151 | it "should not have meta errors" do |
152 | helper.meta_errors?.should be_false |
153 | end |
154 | |
155 | it "should provide a meta_label of 'Less' when meta_errors? is true" do |
156 | helper.stub!(:meta_errors?).and_return(true) |
157 | helper.meta_label.should == 'Less' |
158 | end |
159 | |
160 | it "should provide a meta_label of 'More' when meta_errors? is false" do |
161 | helper.stub!(:meta_errors?).and_return(false) |
162 | helper.meta_label.should == 'More' |
163 | end |
164 | |
165 | it "should render a Javascript snippet to toggle the meta area" do |
166 | helper.toggle_javascript_for("joe").should == "Element.toggle('joe'); Element.toggle('more-joe'); Element.toggle('less-joe'); return false;" |
167 | end |
168 | |
169 | it "should render an image tag with a default file extension" do |
170 | helper.should_receive(:image_tag).with("admin/plus.png", {}) |
171 | helper.image("plus") |
172 | end |
173 | |
174 | it "should render an image submit tag with a default file extension" do |
175 | helper.should_receive(:image_submit_tag).with("admin/plus.png", {}) |
176 | helper.image_submit("plus") |
177 | end |
178 | |
179 | it "should provide the admin object" do |
180 | helper.admin.should == Radiant::AdminUI.instance |
181 | end |
182 | |
183 | it "should include the regions helper" do |
184 | ApplicationHelper.included_modules.should include(Admin::RegionsHelper) |
185 | end |
186 | |
187 | describe 'stylesheet_and_javascript_overrides' do |
188 | before do |
189 | @override_css_path = "#{Rails.root}/public/stylesheets/admin/overrides.css" |
190 | @override_sass_path = "#{Rails.root}/public/stylesheets/sass/admin/overrides.sass" |
191 | @override_js_path = "#{Rails.root}/public/javascripts/admin/overrides.js" |
192 | File.stub!(:exist?) |
193 | end |
194 | it "should render a link to the overrides.css file when it exists" do |
195 | File.should_receive(:exist?).with(@override_css_path).and_return(true) |
196 | helper.stylesheet_and_javascript_overrides.should have_tag('link[href*=?][media=?][rel=?][type=?]','/stylesheets/admin/overrides.css','screen','stylesheet','text/css') |
197 | end |
198 | it "should render a link to the overrides.css file when the overrides.sass file exists" do |
199 | File.should_receive(:exist?).with(@override_sass_path).and_return(true) |
200 | helper.stylesheet_and_javascript_overrides.should have_tag('link[href*=?][media=?][rel=?][type=?]','/stylesheets/admin/overrides.css','screen','stylesheet','text/css') |
201 | end |
202 | it "should not render a link to the overrides.css file when it does not exist" do |
203 | File.should_receive(:exist?).at_least(:once).with(@override_css_path).and_return(false) |
204 | helper.stylesheet_and_javascript_overrides.should_not have_tag('link[href*=?][media=?][rel=?][type=?]','/stylesheets/admin/overrides.css','screen','stylesheet','text/css') |
205 | end |
206 | it "should not render a link to the overrides.css file when the overrides.css and overrides.sass file does not exist" do |
207 | File.should_receive(:exist?).at_least(:once).with(@override_css_path).and_return(false) |
208 | File.should_receive(:exist?).at_least(:once).with(@override_sass_path).and_return(false) |
209 | helper.stylesheet_and_javascript_overrides.should_not have_tag('link[href*=?][media=?][rel=?][type=?]','/stylesheets/admin/overrides.css','screen','stylesheet','text/css') |
210 | end |
211 | it "should render a link to the overrides.js file when it exists" do |
212 | File.should_receive(:exist?).at_least(:once).with(@override_js_path).and_return(true) |
213 | helper.stylesheet_and_javascript_overrides.should have_tag('script[src*=?][type=?]','/javascripts/admin/overrides.js', 'text/javascript') |
214 | end |
215 | it "should not render a link to the overrides.js file when it does not exist" do |
216 | File.should_receive(:exist?).at_least(:once).with(@override_js_path).and_return(false) |
217 | helper.stylesheet_and_javascript_overrides.should_not have_tag('script[src*=?][type=?]','/javascripts/admin/overrides.js', 'text/javascript') |
218 | end |
219 | end |
220 | |
221 | # describe "pagination" do |
222 | # before do |
223 | # @collection = WillPaginate::Collection.new(1, 10, 100) |
224 | # request = mock("request") |
225 | # helper.stub!(:request).and_return(request) |
226 | # helper.stub!(:will_paginate_options).and_return({}) |
227 | # helper.stub!(:will_paginate).and_return("pagination of some kind") |
228 | # helper.stub!(:link_to).and_return("link") |
229 | # end |
230 | # |
231 | # it "should render pagination controls for a supplied list" do |
232 | # helper.pagination_for(@collection).should have_tag('div.pagination').with_tag('span.current', :text => '1') |
233 | # end |
234 | # |
235 | # it "should include a depagination link by default" do |
236 | # helper.pagination_for(@collection).should have_tag('div.depaginate') |
237 | # end |
238 | # |
239 | # it "should omit the depagination link when :depaginate is false" do |
240 | # helper.pagination_for(@collection, :depaginate => false).should_not have_tag('div.depaginate') |
241 | # end |
242 | # |
243 | # it "should omit the depagination link when the :max_list_length is exceeded" do |
244 | # helper.pagination_for(@collection, :depaginate => true, :max_list_length => 5).should_not have_tag('div.depaginate') |
245 | # end |
246 | # |
247 | # it "should use the max_list_length config item when no other value is specified" do |
248 | # Radiant::Config['pagination.max_list_length'] = 50 |
249 | # helper.pagination_for(@collection).should_not have_tag('div.depaginate') |
250 | # end |
251 | # |
252 | # it "should disregard list length when max_list_length is false" do |
253 | # Radiant::Config['pagination.max_list_length'] = 50 |
254 | # helper.pagination_for(@collection, :max_list_length => false).should_not have_tag('div.depaginate') |
255 | # end |
256 | # |
257 | # end |
258 | end |