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:
- 6010 Bytes
1 | require File.dirname(__FILE__) + '/../spec_helper' |
2 | |
3 | describe SiteController do |
4 | dataset :pages |
5 | |
6 | it "should find and render home page" do |
7 | get :show_page, :url => '' |
8 | response.should be_success |
9 | response.body.should == 'Hello world!' |
10 | end |
11 | |
12 | it "should find a page one level deep" do |
13 | get :show_page, :url => 'first/' |
14 | response.should be_success |
15 | response.body.should == 'First body.' |
16 | end |
17 | |
18 | it "should find a page two levels deep" do |
19 | get :show_page, :url => 'parent/child/' |
20 | response.should be_success |
21 | response.body.should == 'Child body.' |
22 | end |
23 | |
24 | it "should show page not found" do |
25 | get :show_page, :url => 'a/non-existant/page' |
26 | response.response_code.should == 404 |
27 | response.should render_template('site/not_found') |
28 | end |
29 | |
30 | it "should redirect to admin if missing root" do |
31 | Page.should_receive(:find_by_url).and_raise(Page::MissingRootPageError) |
32 | get :show_page, :url => '/' |
33 | response.should redirect_to(welcome_url) |
34 | end |
35 | |
36 | it "should pass pagination parameters to the page" do |
37 | page = pages(:first) |
38 | param_name = WillPaginate::ViewHelpers.pagination_options[:param_name] || :p |
39 | pagination_parameters = {param_name => 3, :per_page => 100} |
40 | controller.stub!(:pagination_parameters).and_return(pagination_parameters) |
41 | controller.stub!(:find_page).and_return(page) |
42 | |
43 | get :show_page, :url => 'first/' |
44 | |
45 | page.pagination_parameters.should == pagination_parameters |
46 | end |
47 | |
48 | it "should parse pages with Radius" do |
49 | get :show_page, :url => 'radius' |
50 | response.should be_success |
51 | response.body.should == 'Radius body.' |
52 | end |
53 | |
54 | it "should render 404 if page is not published status" do |
55 | ['draft', 'hidden'].each do |url| |
56 | get :show_page, :url => url |
57 | response.should be_missing |
58 | response.should render_template('site/not_found') |
59 | end |
60 | end |
61 | |
62 | it "should display draft and hidden pages on default dev site" do |
63 | request.host = "dev.site.com" |
64 | ['draft', 'hidden'].each do |url| |
65 | get :show_page, :url => url |
66 | response.should be_success |
67 | end |
68 | end |
69 | |
70 | it "should display draft and hidden pages on dev site in config" do |
71 | controller.config = { 'dev.host' => 'mysite.com' } |
72 | request.host = 'mysite.com' |
73 | ['draft', 'hidden'].each do |url| |
74 | get :show_page, :url => url |
75 | response.should be_success |
76 | end |
77 | end |
78 | |
79 | it "should not display draft and hidden pages on default dev site when dev.host specified" do |
80 | controller.config = { 'dev.host' => 'mysite.com' } |
81 | request.host = 'dev.mysite.com' |
82 | ['draft', 'hidden'].each do |url| |
83 | get :show_page, :url => url |
84 | response.should be_missing |
85 | end |
86 | end |
87 | |
88 | it "should not require login" do |
89 | lambda { get :show_page, :url => '/' }.should_not require_login |
90 | end |
91 | |
92 | describe "scheduling" do |
93 | before do |
94 | @sched_page = Page.find(103) |
95 | end |
96 | it "should not display scheduled pages on live site" do |
97 | @sched_page.published_at = Time.now + 5000 |
98 | @sched_page.save |
99 | request.host = 'mysite.com' |
100 | get :show_page, :url => @sched_page.slug |
101 | response.response_code.should == 404 |
102 | response.should render_template('site/not_found') |
103 | end |
104 | |
105 | it "should update status of scheduled pages on home page" do |
106 | @sched_page.published_at = Time.now - 50000 |
107 | @sched_page.status_id = 90 |
108 | |
109 | get :show_page, :url => '/' |
110 | response.body.should == 'Hello world!' |
111 | |
112 | @sched_page2 = Page.find(103) |
113 | @sched_page2.status_id.should == 100 |
114 | end |
115 | |
116 | end |
117 | |
118 | describe "caching" do |
119 | it "should add a default Cache-Control header with public and max-age of 5 minutes" do |
120 | get :show_page, :url => '/' |
121 | response.headers['Cache-Control'].should =~ /public/ |
122 | response.headers['Cache-Control'].should =~ /max-age=300/ |
123 | end |
124 | |
125 | it "should pass along the etag set by the page" do |
126 | get :show_page, :url => '/' |
127 | response.headers['ETag'].should be |
128 | end |
129 | |
130 | %w{put post delete}.each do |method| |
131 | it "should prevent upstream caching on #{method.upcase} requests" do |
132 | send(method, :show_page, :url => '/') |
133 | response.headers['Cache-Control'].should =~ /private/ |
134 | response.headers['Cache-Control'].should =~ /no-cache/ |
135 | response.headers['ETag'].should be_blank |
136 | end |
137 | end |
138 | |
139 | it "should return a not-modified response when the sent etag matches" do |
140 | response.stub!(:etag).and_return("foobar") |
141 | request.if_none_match = 'foobar' |
142 | get :show_page, :url => '/' |
143 | response.response_code.should == 304 |
144 | response.body.should be_blank |
145 | end |
146 | |
147 | it "should prevent upstream caching when the page should not be cached" do |
148 | @page = pages(:home) |
149 | Page.should_receive(:find_by_url).and_return(@page) |
150 | @page.should_receive(:cache?).and_return(false) |
151 | get :show_page, :url => '/' |
152 | response.headers['Cache-Control'].should =~ /private/ |
153 | response.headers['Cache-Control'].should =~ /no-cache/ |
154 | response.headers['ETag'].should be_blank |
155 | end |
156 | |
157 | it "should prevent upstream caching in dev mode" do |
158 | request.host = "dev.site.com" |
159 | |
160 | get :show_page, :url => '/' |
161 | response.headers['Cache-Control'].should =~ /private/ |
162 | response.headers['Cache-Control'].should =~ /no-cache/ |
163 | response.headers['ETag'].should be_blank |
164 | end |
165 | |
166 | it "should set the default cache timeout (max-age) to a value assigned by the user" do |
167 | SiteController.cache_timeout = 10.minutes |
168 | get :show_page, :url => '/' |
169 | response.headers['Cache-Control'].should =~ /public/ |
170 | response.headers['Cache-Control'].should =~ /max-age=600/ |
171 | end |
172 | end |
173 | |
174 | describe "pagination" do |
175 | it "should pass through pagination parameters to the page" do |
176 | @page = pages(:home) |
177 | Page.stub!(:find_by_url).and_return(@page) |
178 | @page.should_receive(:pagination_parameters=).with({:page => '3', :per_page => '12'}) |
179 | get :show_page, :url => '/', :page => '3', :per_page => '12' |
180 | end |
181 | end |
182 | end |