2010-05-30 23:57:33 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe 'Locomotive rendering system' do
|
|
|
|
|
|
|
|
before(:each) do
|
|
|
|
@controller = Locomotive::TestController.new
|
|
|
|
Site.any_instance.stubs(:create_default_pages!).returns(true)
|
|
|
|
@site = Factory.build(:site)
|
|
|
|
Site.stubs(:find).returns(@site)
|
|
|
|
@controller.current_site = @site
|
2010-07-09 10:38:50 +00:00
|
|
|
@page = Factory.build(:page, :site => nil, :published => true)
|
2010-05-30 23:57:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'setting the response' do
|
|
|
|
|
|
|
|
before(:each) do
|
2010-07-09 10:38:50 +00:00
|
|
|
@controller.instance_variable_set(:@page, @page)
|
2010-05-30 23:57:33 +00:00
|
|
|
@controller.send(:prepare_and_set_response, 'Hello world !')
|
|
|
|
end
|
|
|
|
|
2010-06-16 14:43:29 +00:00
|
|
|
it 'sets the content type to html' do
|
|
|
|
@controller.response.headers['Content-Type'].should == 'text/html; charset=utf-8'
|
2010-05-30 23:57:33 +00:00
|
|
|
end
|
|
|
|
|
2010-06-16 14:43:29 +00:00
|
|
|
it 'displays the output' do
|
2010-05-30 23:57:33 +00:00
|
|
|
@controller.output.should == 'Hello world !'
|
|
|
|
end
|
2010-06-16 14:43:29 +00:00
|
|
|
|
|
|
|
it 'does not set the cache' do
|
|
|
|
@controller.response.headers['Cache-Control'].should be_nil
|
|
|
|
end
|
2010-07-09 10:38:50 +00:00
|
|
|
|
|
|
|
it 'sets the cache by simply using etag' do
|
|
|
|
@page.cache_strategy = 'simple'
|
|
|
|
@page.stubs(:updated_at).returns(Time.now)
|
|
|
|
@controller.send(:prepare_and_set_response, 'Hello world !')
|
|
|
|
@controller.response.to_a # force to build headers
|
|
|
|
@controller.response.headers['Cache-Control'].should == 'public'
|
|
|
|
end
|
2010-06-16 14:43:29 +00:00
|
|
|
|
2010-07-09 10:38:50 +00:00
|
|
|
it 'sets the cache for Varnish' do
|
|
|
|
@page.cache_strategy = '3600'
|
|
|
|
@page.stubs(:updated_at).returns(Time.now)
|
|
|
|
@controller.send(:prepare_and_set_response, 'Hello world !')
|
|
|
|
@controller.response.to_a # force to build headers
|
|
|
|
@controller.response.headers['Cache-Control'].should == 'max-age=3600, public'
|
2010-06-16 14:43:29 +00:00
|
|
|
end
|
2010-05-30 23:57:33 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when retrieving page' do
|
|
|
|
|
|
|
|
it 'should retrieve the index page /' do
|
|
|
|
@controller.request.fullpath = '/'
|
2010-07-16 20:36:07 +00:00
|
|
|
@controller.current_site.pages.expects(:any_in).with({ :fullpath => %w{index} }).returns([@page])
|
2010-06-01 00:06:46 +00:00
|
|
|
@controller.send(:locomotive_page).should_not be_nil
|
2010-05-30 23:57:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should also retrieve the index page (index.html)' do
|
|
|
|
@controller.request.fullpath = '/index.html'
|
2010-07-16 20:36:07 +00:00
|
|
|
@controller.current_site.pages.expects(:any_in).with({ :fullpath => %w{index} }).returns([@page])
|
2010-06-01 00:06:46 +00:00
|
|
|
@controller.send(:locomotive_page).should_not be_nil
|
2010-05-30 23:57:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should retrieve it based on the full path' do
|
|
|
|
@controller.request.fullpath = '/about_us/team.html'
|
2010-07-16 20:36:07 +00:00
|
|
|
@controller.current_site.pages.expects(:any_in).with({ :fullpath => %w{about_us/team about_us/content_type_template} }).returns([@page])
|
2010-06-01 00:06:46 +00:00
|
|
|
@controller.send(:locomotive_page).should_not be_nil
|
2010-05-30 23:57:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return the 404 page if the page does not exist' do
|
|
|
|
@controller.request.fullpath = '/contact'
|
|
|
|
@controller.current_site.pages.expects(:not_found).returns([true])
|
|
|
|
@controller.send(:locomotive_page).should be_true
|
|
|
|
end
|
|
|
|
|
2010-07-16 20:36:07 +00:00
|
|
|
context 'templatized page' do
|
|
|
|
|
|
|
|
before(:each) do
|
|
|
|
@content_type = Factory.build(:content_type, :site => nil)
|
|
|
|
@page.templatized = true
|
|
|
|
@page.content_type = @content_type
|
|
|
|
@controller.request.fullpath = '/projects/edeneo.html'
|
|
|
|
@controller.current_site.pages.expects(:any_in).with({ :fullpath => %w{projects/edeneo projects/content_type_template} }).returns([@page])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets the content_instance variable' do
|
|
|
|
@content_type.contents.stubs(:where).returns([42])
|
|
|
|
@controller.send(:locomotive_page).should_not be_nil
|
|
|
|
@controller.instance_variable_get(:@content_instance).should == 42
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the 404 page if the instance does not exist' do
|
|
|
|
@content_type.contents.stubs(:where).returns([])
|
|
|
|
@controller.current_site.pages.expects(:not_found).returns([true])
|
|
|
|
@controller.send(:locomotive_page).should be_true
|
|
|
|
@controller.instance_variable_get(:@content_instance).should be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2010-06-01 00:06:46 +00:00
|
|
|
context 'non published page' do
|
|
|
|
|
|
|
|
before(:each) do
|
|
|
|
@page.published = false
|
2010-06-10 22:07:59 +00:00
|
|
|
@controller.current_admin = nil
|
2010-06-01 00:06:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return the 404 page if the page has not been published yet' do
|
|
|
|
@controller.request.fullpath = '/contact'
|
2010-07-16 20:36:07 +00:00
|
|
|
@controller.current_site.pages.expects(:any_in).with({ :fullpath => %w{contact content_type_template} }).returns([@page])
|
2010-06-01 00:06:46 +00:00
|
|
|
@controller.current_site.pages.expects(:not_found).returns([true])
|
|
|
|
@controller.send(:locomotive_page).should be_true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not return the 404 page if the page has not been published yet and admin is logged in' do
|
2010-06-10 22:07:59 +00:00
|
|
|
@controller.current_admin = true
|
2010-06-01 00:06:46 +00:00
|
|
|
@controller.request.fullpath = '/contact'
|
2010-07-16 20:36:07 +00:00
|
|
|
@controller.current_site.pages.expects(:any_in).with({ :fullpath => %w{contact content_type_template} }).returns([@page])
|
2010-06-01 00:06:46 +00:00
|
|
|
@controller.send(:locomotive_page).should == @page
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|