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:
- 8768 Bytes
1 | require File.dirname(__FILE__) + '/../../spec_helper' |
2 | |
3 | describe Admin::PagesController do |
4 | dataset :users, :pages |
5 | |
6 | before :each do |
7 | login_as :existing |
8 | end |
9 | |
10 | it "should route children to the pages controller" do |
11 | route_for(:controller => "admin/pages", :page_id => '1', |
12 | :action => "index").should == '/admin/pages/1/children' |
13 | route_for(:controller => "admin/pages", :page_id => '1', |
14 | :action => 'new').should == '/admin/pages/1/children/new' |
15 | end |
16 | |
17 | describe "show" do |
18 | it "should redirect to the edit action" do |
19 | get :show, :id => 1 |
20 | response.should redirect_to(edit_admin_page_path(params[:id])) |
21 | end |
22 | |
23 | it "should show xml when format is xml" do |
24 | page = Page.first |
25 | get :show, :id => page.id, :format => "xml" |
26 | response.body.should == page.to_xml |
27 | end |
28 | end |
29 | |
30 | describe "with invalid page id" do |
31 | [:edit, :remove].each do |action| |
32 | before do |
33 | @parameters = {:id => 999} |
34 | end |
35 | it "should redirect the #{action} action to the index action" do |
36 | get action, @parameters |
37 | response.should redirect_to(admin_pages_path) |
38 | end |
39 | it "should say that the 'Page could not be found.' after the #{action} action" do |
40 | get action, @parameters |
41 | flash[:notice].should == 'Page could not be found.' |
42 | end |
43 | end |
44 | it 'should redirect the update action to the index action' do |
45 | put :update, @parameters |
46 | response.should redirect_to(admin_pages_path) |
47 | end |
48 | it "should say that the 'Page could not be found.' after the update action" do |
49 | put :update, @parameters |
50 | flash[:notice].should == 'Page could not be found.' |
51 | end |
52 | it 'should redirect the destroy action to the index action' do |
53 | delete :destroy, @parameters |
54 | response.should redirect_to(admin_pages_path) |
55 | end |
56 | it "should say that the 'Page could not be found.' after the destroy action" do |
57 | delete :destroy, @parameters |
58 | flash[:notice].should == 'Page could not be found.' |
59 | end |
60 | end |
61 | |
62 | describe "viewing the sitemap" do |
63 | integrate_views |
64 | |
65 | it "should render when the homepage is present" do |
66 | get :index |
67 | response.should be_success |
68 | assigns(:homepage).should be_kind_of(Page) |
69 | response.should render_template('index') |
70 | end |
71 | |
72 | it "should allow the index to render even with there are no pages" do |
73 | Page.delete_all; PagePart.delete_all |
74 | get :index |
75 | response.should be_success |
76 | assigns(:homepage).should be_nil |
77 | response.should render_template('index') |
78 | end |
79 | |
80 | it "should show the tree partially expanded by default" do |
81 | get :index |
82 | response.should be_success |
83 | assert_rendered_nodes_where { |page| [nil, page_id(:home)].include?(page.parent_id) } |
84 | end |
85 | |
86 | it "should show the tree partially expanded even when the expanded_rows cookie is empty" do |
87 | write_cookie('expanded_rows', '') |
88 | get :index |
89 | response.should be_success |
90 | cookies['expanded_rows'].should be_nil |
91 | assert_rendered_nodes_where { |page| [nil, page_id(:home)].include?(page.parent_id) } |
92 | end |
93 | |
94 | it "should show the tree partially expanded according to the expanded_rows cookie" do |
95 | cookie = "#{page_id(:home)},#{page_id(:parent)},#{page_id(:child)}" |
96 | write_cookie('expanded_rows', cookie) |
97 | get :index |
98 | response.should be_success |
99 | assert_rendered_nodes_where { |page| [nil, page_id(:home), page_id(:parent), page_id(:child)].include?(page.parent_id) } |
100 | end |
101 | |
102 | it "should show the tree with a mangled cookie" do |
103 | cookie = "#{page_id(:home)},#{page_id(:parent)},:#*)&},9a,,," |
104 | write_cookie('expanded_rows', cookie) |
105 | get :index |
106 | response.should be_success |
107 | assert_rendered_nodes_where { |page| [nil, page_id(:home), page_id(:parent)].include?(page.parent_id) } |
108 | assigns(:homepage).should_not be_nil |
109 | end |
110 | |
111 | it "should render the appropriate children when branch of the site map is expanded via AJAX" do |
112 | xml_http_request :get, :index, :page_id => page_id(:home), :level => '1' |
113 | response.should be_success |
114 | assigns(:level).should == 1 |
115 | response.body.should_not have_text('<head>') |
116 | response.content_type.should == 'text/html' |
117 | response.charset.should == 'utf-8' |
118 | end |
119 | end |
120 | |
121 | describe "permissions" do |
122 | |
123 | [:admin, :designer, :non_admin, :existing].each do |user| |
124 | { |
125 | :post => :create, |
126 | :put => :update, |
127 | :delete => :destroy |
128 | }.each do |method, action| |
129 | it "should require login to access the #{action} action" do |
130 | logout |
131 | send method, action, :id => Page.first.id |
132 | response.should redirect_to('/admin/login') |
133 | end |
134 | |
135 | it "should allow access to #{user.to_s.humanize}s for the #{action} action" do |
136 | login_as user |
137 | send method, action, :id => Page.first.id |
138 | response.should redirect_to('/admin/pages') |
139 | end |
140 | end |
141 | end |
142 | |
143 | [:index, :show, :new, :edit, :remove].each do |action| |
144 | before :each do |
145 | @parameters = lambda do |
146 | case action |
147 | when :index |
148 | {} |
149 | when :new |
150 | {:page_id => page_id(:home)} |
151 | else |
152 | {:id => Page.first.id} |
153 | end |
154 | end |
155 | end |
156 | |
157 | it "should require login to access the #{action} action" do |
158 | logout |
159 | lambda { send(:get, action, @parameters.call) }.should require_login |
160 | end |
161 | |
162 | if action == :show |
163 | it "should request authentication for API access on show" do |
164 | logout |
165 | get action, :id => page_id(:home), :format => "xml" |
166 | response.response_code.should == 401 |
167 | end |
168 | else |
169 | it "should allow access to admins for the #{action} action" do |
170 | lambda { |
171 | send(:get, action, @parameters.call) |
172 | }.should restrict_access(:allow => [users(:admin)], |
173 | :url => '/admin/pages') |
174 | end |
175 | |
176 | it "should allow access to designers for the #{action} action" do |
177 | lambda { |
178 | send(:get, action, @parameters.call) |
179 | }.should restrict_access(:allow => [users(:designer)], |
180 | :url => '/admin/pages') |
181 | end |
182 | |
183 | it "should allow non-designers and non-admins for the #{action} action" do |
184 | lambda { |
185 | send(:get, action, @parameters.call) |
186 | }.should restrict_access(:allow => [users(:non_admin), users(:existing)], |
187 | :url => '/admin/pages') |
188 | end |
189 | end |
190 | end |
191 | end |
192 | |
193 | |
194 | describe "prompting page removal" do |
195 | integrate_views |
196 | |
197 | # TODO: This should be in a view or integration spec |
198 | it "should render the expanded descendants of the page being removed" do |
199 | get :remove, :id => page_id(:parent), :format => 'html' # shouldn't need this! |
200 | rendered_pages = [:parent, :child, :grandchild, :great_grandchild, :child_2, :child_3].map {|p| pages(p) } |
201 | rendered_pages.each do |page| |
202 | response.should have_tag("tr#page_#{page.id}") |
203 | end |
204 | end |
205 | end |
206 | |
207 | it "should initialize meta and buttons_partials in new action" do |
208 | get :new, :page_id => page_id(:home) |
209 | response.should be_success |
210 | assigns(:meta).should be_kind_of(Array) |
211 | assigns(:buttons_partials).should be_kind_of(Array) |
212 | end |
213 | |
214 | it "should initialize meta and buttons_partials in edit action" do |
215 | get :edit, :id => page_id(:home) |
216 | response.should be_success |
217 | assigns(:meta).should be_kind_of(Array) |
218 | assigns(:buttons_partials).should be_kind_of(Array) |
219 | end |
220 | |
221 | it "should clear the page cache when saved" do |
222 | Radiant::Cache.should_receive(:clear) |
223 | put :update, :id => page_id(:home), :page => {:breadcrumb => 'Homepage'} |
224 | end |
225 | |
226 | describe "@body_classes" do |
227 | it "should return 'reversed' when the action_name is 'new'" do |
228 | get :new |
229 | assigns[:body_classes].should == ['reversed'] |
230 | end |
231 | it "should return 'reversed' when the action_name is 'edit'" do |
232 | get :edit, :id => 1 |
233 | assigns[:body_classes].should == ['reversed'] |
234 | end |
235 | it "should return 'reversed' when the action_name is 'create'" do |
236 | post :create |
237 | assigns[:body_classes].should == ['reversed'] |
238 | end |
239 | it "should return 'reversed' when the action_name is 'update'" do |
240 | put :update, :id => 1 |
241 | assigns[:body_classes].should == ['reversed'] |
242 | end |
243 | end |
244 | |
245 | protected |
246 | |
247 | def assert_rendered_nodes_where(&block) |
248 | wanted, unwanted = Page.find(:all).partition(&block) |
249 | wanted.each do |page| |
250 | response.should have_tag("tr[id=page_#{page.id}]") |
251 | end |
252 | unwanted.each do |page| |
253 | response.should_not have_tag("tr[id=page_#{page.id}]") |
254 | end |
255 | end |
256 | |
257 | def write_cookie(name, value) |
258 | request.cookies[name] = value |
259 | end |
260 | end |