Permalink
Browse files

added site update of status, and spec test

  • Loading branch information...
1 parent 8658c50 commit 29ef21f54c4efba7747e61e382f06da7eeee4756 @banane banane committed Feb 2, 2010
Showing with 67 additions and 16 deletions.
  1. +1 −0 CHANGELOG
  2. +1 −0 CONTRIBUTORS
  3. +17 −3 app/controllers/site_controller.rb
  4. +19 −11 app/models/page.rb
  5. +29 −2 spec/controllers/site_controller_spec.rb
View
@@ -12,6 +12,7 @@
* Prevent admin from removing her own admin privilege [Jim Gay]
* Move to Rails 2.3.5 [Jim Gay]
* Simplify admin tab API [Jim Gay, John Long, Sean Cribbs]
+* Add future publishing feature [Anna Billstrom]
=== 0.9.0 RC1 (October 9, 2009)
View
@@ -19,6 +19,7 @@ core:
* Daniel Beach
* Chris Parrish
* John Long
+* Anna billstrom
=== 0.8.2 Lustery
@@ -1,10 +1,8 @@
class SiteController < ApplicationController
skip_before_filter :verify_authenticity_token
no_login_required
-
cattr_writer :cache_timeout
-
def self.cache_timeout
@@cache_timeout ||= 5.minutes
end
@@ -16,8 +14,10 @@ def show_page
else
url = url.to_s
end
+
if @page = find_page(url)
+ batch_page_status_refresh if (url == "/" || url == "")
process_page(@page)
set_cache_control
@performed_render ||= true
@@ -29,6 +29,20 @@ def show_page
end
private
+ def batch_page_status_refresh
+ @changed_pages = []
+ @pages = Page.find(:all, :conditions => {:status_id => 90})
+ @pages.each do |page|
+ if page.published_at <= Time.now
+ page.status_id = 100
+ page.save
+ @changed_pages << page.id
+ end
+ end
+
+ expires_in nil, :private=>true, "no-cache" => true if @changed_pages.length > 0
+ end
+
def set_cache_control
if (request.head? || request.get?) && @page.cache? && live?
expires_in self.class.cache_timeout, :public => true, :private => false
@@ -37,7 +51,7 @@ def set_cache_control
headers['ETag'] = ''
end
end
-
+
def find_page(url)
found = Page.find_by_url(url, live?)
found if found and (found.published? or dev?)
View
@@ -37,6 +37,7 @@ def initialize(message = 'Database missing root page'); super end
set_inheritance_column :class_name
+
def layout_with_inheritance
unless layout_without_inheritance
parent.layout if parent?
@@ -90,9 +91,14 @@ def inherits_part?(name)
def published?
status == Status[:published]
end
+
def status
- Status.find(self.status_id)
+ status = Status.find(self.status_id)
+ if status == 90
+ puts "HELLO IN HERE"
+ end
+ status
end
def status=(value)
@@ -167,6 +173,18 @@ def find_by_url(url, live = true, clean = true)
end
end
+ def update_status
+ self[:published_at] = Time.now if self[:status_id] == 100 && self[:published_at] == nil
+
+ if self[:published_at] != nil
+ self[:status_id] = 90 if self[:published_at] > Time.now
+ self[:status_id] = 100 if self[:published_at] <= Time.now
+ end
+
+ true
+ end
+
+
def to_xml(options={}, &block)
super(options.reverse_merge(:include => :parts), &block)
end
@@ -254,16 +272,6 @@ def attributes_protected_by_default
super - [self.class.inheritance_column]
end
- def update_status
- self[:published_at] = Time.now if self[:status_id] == 100 && self[:published_at] == nil
-
- if self[:published_at] != nil
- self[:status_id] = 90 if self[:published_at] > Time.now
- self[:status_id] = 100 if self[:published_at] <= Time.now
- end
-
- true
- end
def update_virtual
unless self.class == Page.descendant_class(class_name)
@@ -72,14 +72,41 @@
response.should be_missing
end
end
-
+
it "should not require login" do
lambda { get :show_page, :url => '/' }.should_not require_login
end
+ describe "scheduling" do
+ before do
+ @sched_page = Page.find(103)
+ end
+ it "should not display scheduled pages on live site" do
+ @sched_page.published_at = Time.now + 5000
+ @sched_page.save
+ request.host = 'mysite.com'
+ get :show_page, :url => @sched_page.slug
+ response.response_code.should == 404
+ response.should render_template('site/not_found')
+ end
+
+ it "should update status of scheduled pages on home page" do
+ @sched_page.published_at = Time.now - 50000
+ @sched_page.status_id = 90
+
+ get :show_page, :url => '/'
+ response.body.should == 'Hello world!'
+
+ @sched_page2 = Page.find(103)
+ @sched_page2.status_id.should == 100
+ end
+
+ end
+
+
describe "caching" do
it "should add a default Cache-Control header with public and max-age of 5 minutes" do
- get :show_page, :url => '/'
+ get :show_page, :url => ''
response.headers['Cache-Control'].should =~ /public/
response.headers['Cache-Control'].should =~ /max-age=300/
end

0 comments on commit 29ef21f

Please sign in to comment.