2013-02-05 14:16:51 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe StaticController do
|
|
|
|
|
2013-10-30 16:37:22 -04:00
|
|
|
context 'show' do
|
|
|
|
context "with a static file that's present" do
|
2013-02-05 14:16:51 -05:00
|
|
|
|
2013-10-30 16:37:22 -04:00
|
|
|
before do
|
|
|
|
xhr :get, :show, id: 'faq'
|
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
|
2013-10-30 16:37:22 -04:00
|
|
|
it 'renders the static file if present' do
|
|
|
|
response.should be_success
|
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
|
2013-10-30 16:37:22 -04:00
|
|
|
it "renders the file" do
|
2014-02-17 11:44:28 -05:00
|
|
|
response.should render_template('static/faq.en')
|
2013-07-23 14:42:52 -04:00
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
2013-10-30 16:37:22 -04:00
|
|
|
[ ['tos', :tos_url], ['privacy', :privacy_policy_url] ].each do |id, setting_name|
|
|
|
|
context "#{id}" do
|
|
|
|
subject { xhr :get, :show, id: id }
|
2013-06-18 10:52:04 -04:00
|
|
|
|
2013-10-30 16:37:22 -04:00
|
|
|
context "when #{setting_name} site setting is NOT set" do
|
|
|
|
it "renders the #{id} page" do
|
2014-02-17 11:44:28 -05:00
|
|
|
expect(subject).to render_template("static/#{id}.en")
|
2013-07-23 14:42:52 -04:00
|
|
|
end
|
2013-06-18 10:52:04 -04:00
|
|
|
end
|
|
|
|
|
2013-10-30 16:37:22 -04:00
|
|
|
context "when #{setting_name} site setting is set" do
|
|
|
|
before { SiteSetting.stubs(setting_name).returns('http://example.com/page') }
|
2013-06-18 10:52:04 -04:00
|
|
|
|
2013-10-30 16:37:22 -04:00
|
|
|
it "redirects to the #{setting_name}" do
|
|
|
|
expect(subject).to redirect_to('http://example.com/page')
|
|
|
|
end
|
2013-06-18 10:52:04 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-10-30 16:37:22 -04:00
|
|
|
context "with a missing file" do
|
|
|
|
it "should respond 404" do
|
|
|
|
xhr :get, :show, id: 'does-not-exist'
|
|
|
|
response.response_code.should == 404
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should redirect to / when logged in and path is /login' do
|
|
|
|
log_in
|
|
|
|
xhr :get, :show, id: 'login'
|
|
|
|
response.should redirect_to '/'
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-10-30 16:37:22 -04:00
|
|
|
|
2013-06-04 18:34:54 -04:00
|
|
|
describe '#enter' do
|
|
|
|
context 'without a redirect path' do
|
|
|
|
it 'redirects to the root url' do
|
|
|
|
xhr :post, :enter
|
2013-07-01 14:00:06 -04:00
|
|
|
expect(response).to redirect_to '/'
|
2013-06-04 18:34:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a redirect path' do
|
|
|
|
it 'redirects to the redirect path' do
|
|
|
|
xhr :post, :enter, redirect: '/foo'
|
|
|
|
expect(response).to redirect_to '/foo'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the redirect path is the login page' do
|
|
|
|
it 'redirects to the root url' do
|
|
|
|
xhr :post, :enter, redirect: login_path
|
2013-07-01 14:00:06 -04:00
|
|
|
expect(response).to redirect_to '/'
|
2013-06-04 18:34:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|