test/functional/test_front.rb in spontaneous-0.2.0.alpha7 vs test/functional/test_front.rb in spontaneous-0.2.0.beta1

- old
+ new

@@ -17,19 +17,24 @@ FileUtils.cp_r(File.expand_path("../../fixtures/public/templates", __FILE__), @site_root) Spontaneous::Output.write_compiled_scripts = true end def self.shutdown - teardown_site + teardown_site(true) Spontaneous::Output.write_compiled_scripts = false end def setup @site = setup_site(self.class.site_root) - Site.publishing_method = :immediate + Site.background_mode = :immediate + ::Content.delete end + def teardown + teardown_site(false) + end + def app Spontaneous::Rack::Front.application end def root @@ -66,15 +71,14 @@ context "Public pages" do setup do - Site.publishing_method = :immediate - State.delete - Content.delete + S::Site.background_mode = :immediate + S::State.delete - class ::SitePage < Spontaneous::Page + class ::SitePage < ::Page layout :default layout :dynamic box :pages attr_accessor :status @@ -92,34 +96,36 @@ # Spontaneous.revision_root = @revision_root # @site.stubs(:template_root).returns(File.expand_path("../../fixtures/public/templates", __FILE__)) # self.template_root = File.expand_path("../../fixtures/public/templates", __FILE__) - @root = ::SitePage.create - @about = ::SitePage.create(:slug => "about", :uid => "about") - @sub = ::SubPage.create(:slug => "now", :uid => "now") - @news = ::SitePage.create(:slug => "news", :uid => "news") - @dynamic = ::SitePage.create(:slug => "dynamic", :uid => "dynamic") - @dynamic.layout = :dynamic - @root.pages << @about - @root.pages << @news - @root.pages << @dynamic - @about.pages << @sub - @root.save + ::Content.scope do + @root = ::SitePage.create + @about = ::SitePage.create(:slug => "about", :uid => "about") + @sub = ::SubPage.create(:slug => "now", :uid => "now") + @news = ::SitePage.create(:slug => "news", :uid => "news") + @dynamic = ::SitePage.create(:slug => "dynamic", :uid => "dynamic") + @dynamic.layout = :dynamic + @root.pages << @about + @root.pages << @news + @root.pages << @dynamic + @about.pages << @sub + @root.save + end Content.delete_revision(1) rescue nil Spontaneous.logger.silent! { - Site.publish_all + S::Site.publish_all } end teardown do Object.send(:remove_const, :SitePage) rescue nil Object.send(:remove_const, :SubPage) rescue nil Content.delete - State.delete + S::State.delete Content.delete_revision(1) end should "return a 404 if asked for a non-existant page" do get '/not-bloody-likely' @@ -182,12 +188,12 @@ assert last_response.status == 404 end context "Dynamic pages" do setup do - Spontaneous::Page.stubs(:path).with("/about").returns(about) - Spontaneous::Page.stubs(:path).with("/news").returns(news) + Content::Page.stubs(:path).with("/about").returns(about) + Content::Page.stubs(:path).with("/news").returns(news) end should "default to static behaviour" do SitePage.dynamic?.should be_false page = SitePage.new @@ -380,44 +386,33 @@ assert last_response.status == 307 end end - context "Templates" do + context "Templates xxx" do setup do - # Page.stubs(:path).with("/about").returns(about) - # about.style = :dynamic - # about.save + Spontaneous::Output.cache_templates = true + @cache_file = "#{Spontaneous.revision_dir(1)}/dynamic/dynamic.html.rb" + FileUtils.rm(@cache_file) if File.exist?(@cache_file) + Spontaneous::Output.write_compiled_scripts = true end teardown do - # about.style = :default - # about.save + Spontaneous::Output.cache_templates = true end should "have access to the params, request & session object" do get '/dynamic', {'wendy' => 'peter'}, 'rack.session' => { 'user_id' => 42 } assert last_response.ok? last_response.body.should == "42/peter/example.org\n" end context "caching" do - setup do - Spontaneous::Output.cache_templates = true - @cache_file = "#{Spontaneous.revision_dir(1)}/dynamic/dynamic.html.rb" - Spontaneous::Output.write_compiled_scripts = true - end - - teardown do - Spontaneous::Output.cache_templates = true - end - - should "use pre-rendered versions of the templates" do + should "use pre-rendered versions of the templates xxx" do dummy_content = 'cached-version/#{session[\'user_id\']}' dummy_template = File.join(@site.revision_root, "current/dynamic/dynamic.html.cut") File.open(dummy_template, 'w') { |f| f.write(dummy_content) } - # Spontaneous::Render.stubs(:output_path).returns(dummy_template) get '/dynamic', {'wendy' => 'peter'}, 'rack.session' => { 'user_id' => 42 } last_response.body.should == "cached-version/42" end should "cache templates as ruby files" do @@ -433,26 +428,24 @@ File.open(@cache_file, 'w') { |f| f.write('@__buf << %Q`@cache_filed-version/#{params[\'wendy\']}`;')} # Force compiled file to have a later timestamp File.utime(Time.now, Time.now + 1, @cache_file) get '/dynamic', {'wendy' => 'peter'}, 'rack.session' => { 'user_id' => 42 } last_response.body.should == "@cache_filed-version/peter" - FileUtils.rm(@cache_file) end should "not cache templates if caching turned off" do Spontaneous::Output.cache_templates = false - FileUtils.rm(@cache_file) if File.exists?(@cache_file) File.exists?(@cache_file).should be_false get '/dynamic', {'wendy' => 'peter'}, 'rack.session' => { 'user_id' => 42 } File.exists?(@cache_file).should be_false end end end context "Model controllers" do setup do - class ::TestController < Spontaneous::PageController + class ::TestController < Spontaneous::Rack::PageController get '/' do "Magic" end end SitePage.controller :comments do @@ -486,13 +479,13 @@ get "/block" do "Block" end end - Page.stubs(:path).with("/").returns(root) - Page.stubs(:path).with("/about").returns(about) - Page.stubs(:path).with("/about/now").returns(subpage) + Content.stubs(:path).with("/").returns(root) + Content.stubs(:path).with("/about").returns(about) + Content.stubs(:path).with("/about/now").returns(subpage) end teardown do SitePage.send(:remove_const, :StatusController) rescue nil SitePage.send(:remove_const, :TestController) rescue nil @@ -595,10 +588,10 @@ last_response.body.should == "Block" end context "overriding base controller class" do setup do - class ::PageController < S::PageController + class ::PageController < S::Rack::PageController get '/nothing' do 'Something' end end \ No newline at end of file