diff --git a/app/controllers/static_controller.rb b/app/controllers/static_controller.rb index 6e5e81cf3..f6816a35f 100644 --- a/app/controllers/static_controller.rb +++ b/app/controllers/static_controller.rb @@ -5,6 +5,8 @@ class StaticController < ApplicationController def show + return redirect_to('/') if current_user && params[:id] == 'login' + map = { "faq" => "faq_url", "tos" => "tos_url", diff --git a/spec/controllers/static_controller_spec.rb b/spec/controllers/static_controller_spec.rb index cad411e07..79c1e7512 100644 --- a/spec/controllers/static_controller_spec.rb +++ b/spec/controllers/static_controller_spec.rb @@ -2,56 +2,65 @@ require 'spec_helper' describe StaticController do - context "with a static file that's present" do + context 'show' do + context "with a static file that's present" do - before do - xhr :get, :show, id: 'faq' - end + before do + xhr :get, :show, id: 'faq' + end - it 'renders the static file if present' do - response.should be_success - end + it 'renders the static file if present' do + response.should be_success + end - it "renders the file" do - if rails4? - response.should render_template('static/faq.en') - else - response.should render_template('faq') + it "renders the file" do + if rails4? + response.should render_template('static/faq.en') + else + response.should render_template('faq') + end end end - end - [ ['tos', :tos_url], ['privacy', :privacy_policy_url] ].each do |id, setting_name| - context "#{id}" do - subject { xhr :get, :show, id: id } + [ ['tos', :tos_url], ['privacy', :privacy_policy_url] ].each do |id, setting_name| + context "#{id}" do + subject { xhr :get, :show, id: id } - context "when #{setting_name} site setting is NOT set" do - it "renders the #{id} page" do - if rails4? - expect(subject).to render_template("static/#{id}.en") - else - expect(subject).to render_template(id) + context "when #{setting_name} site setting is NOT set" do + it "renders the #{id} page" do + if rails4? + expect(subject).to render_template("static/#{id}.en") + else + expect(subject).to render_template(id) + end + end + end + + context "when #{setting_name} site setting is set" do + before { SiteSetting.stubs(setting_name).returns('http://example.com/page') } + + it "redirects to the #{setting_name}" do + expect(subject).to redirect_to('http://example.com/page') end end end + end - context "when #{setting_name} site setting is set" do - before { SiteSetting.stubs(setting_name).returns('http://example.com/page') } - - it "redirects to the #{setting_name}" do - expect(subject).to redirect_to('http://example.com/page') - end + 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 - end - context "with a missing file" do - it "should respond 404" do - xhr :get, :show, id: 'does-not-exist' - response.response_code.should == 404 + it 'should redirect to / when logged in and path is /login' do + log_in + xhr :get, :show, id: 'login' + response.should redirect_to '/' end end + describe '#enter' do context 'without a redirect path' do it 'redirects to the root url' do