public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
add tests that caches are cleared when updating sections/templates

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@1489 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Sun Aug 06 01:23:02 -0700 2006
commit  422f20385f2895f274e4d30a52cef1e71aa97531
tree    dd23888304c4283e174c90030ee415c8a3590838
parent  24286c7fbde127292ef457e2eded2baa5172a25a
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
...
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
...
1
2
3
 
 
 
 
 
 
 
 
 
4
 
5
6
7
...
16
17
18
 
 
 
 
 
 
 
 
 
 
19
20
21
0
@@ -1,17 +1,7 @@
0
 class AccountController < ApplicationController
0
   include AuthenticatedSystem
0
   layout 'simple'
0
- # Be sure to include AuthenticationSystem in Application Controller instead
0
- # To require logins, use:
0
- #
0
- # before_filter :login_required # restrict all actions
0
- # before_filter :login_required, :only => [:edit, :update] # only restrict these actions
0
- #
0
- # To skip this in a subclassed controller:
0
- #
0
- # skip_before_filter :login_required
0
 
0
- # say something nice, you goof! something sweet.
0
   def index
0
     render :action => 'login'
0
   end
0
@@ -26,16 +16,6 @@ class AccountController < ApplicationController
0
       flash[:error] = "Could not log you in. Are you sure your Login name and Password are correct?"
0
     end
0
   end
0
-
0
- # Sample method for activating the current user
0
- #def activate
0
- # @user = User.find_by_activation_code(params[:id])
0
- # if @user and @user.activate
0
- # self.current_user = @user
0
- # redirect_back_or_default(:controller => '/account', :action => 'index')
0
- # flash[:notice] = "Your account has been activated."
0
- # end
0
- #end
0
 
0
   def logout
0
     self.current_user = nil
...
9
10
11
12
 
13
14
15
...
9
10
11
 
12
13
14
15
0
@@ -9,7 +9,7 @@ class Admin::OverviewController < Admin::BaseController
0
     @users = User.find(:all, :order => 'updated_at desc')
0
     @events, @todays_events, @yesterdays_events = [], [], []
0
     today, yesterday = Time.now.to_date, 1.day.ago.to_date
0
- @articles = Comment.count :all, :conditions => ['site_id = ? and (approved = ? or approved is null)', @site.id, false], :group => :article, :order => '1 desc'
0
+ @articles = @site.comments.count :all, :conditions => ['approved = ? or approved is null', false], :group => :article, :order => '1 desc'
0
     @site.events.find(:all, :order => 'events.created_at DESC', :include => [:article, :user], :limit => 50).each do |event|
0
       case event.created_at.to_date
0
         when today then @todays_events
...
10
11
12
 
13
14
15
...
10
11
12
13
14
15
16
0
@@ -10,6 +10,7 @@ class FeedController < ApplicationController
0
     
0
     @section = site.sections.find_by_path(sections.blank? ? 'home' : sections.join('/'))
0
     @articles = @section.articles.find_by_date(:limit => 15)
0
+ cached_references << @section
0
     self.cached_references += @articles
0
   end
0
 end
...
78
79
80
81
 
 
 
 
 
82
83
84
85
 
86
87
88
...
78
79
80
 
81
82
83
84
85
86
87
88
 
89
90
91
92
0
@@ -78,11 +78,15 @@ class Section < ActiveRecord::Base
0
   end
0
 
0
   def to_url
0
- ((path.blank? || home?) ? '' : path).split('/')
0
+ path.blank? || home? ? [] : path.split('/')
0
+ end
0
+
0
+ def to_page_url(page_name)
0
+ to_url << (page_name.respond_to?(:permalink) ? page_name.permalink : page_name)
0
   end
0
 
0
   def to_feed_url
0
- to_url << 'atom.xml'
0
+ to_page_url 'atom.xml'
0
   end
0
   
0
   protected
...
5
6
7
8
 
9
10
11
...
5
6
7
 
8
9
10
11
0
@@ -5,7 +5,7 @@
0
       <p class="hint"><%= hint %></p>
0
     </dt>
0
     <dd><%= f.text_area :attachment_data, :class => 'fat' %></dd>
0
- <% if form.new_record? or form.is_a?(Resource) -%>
0
+ <% if form.new_record? || form.is_a?(Resource) -%>
0
     <dt><%= f.label_for :filename, :text => labels[:filename] %></dt>
0
     <dd><%= f.text_field :filename %></dd>
0
     <% end -%>
...
8
9
10
11
 
 
 
 
 
 
 
12
13
14
15
16
 
 
 
17
18
19
...
28
29
30
 
 
 
 
 
 
 
 
 
 
31
32
33
...
8
9
10
 
11
12
13
14
15
16
17
18
19
20
 
 
21
22
23
24
25
26
...
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
0
@@ -8,12 +8,19 @@ module Mephisto
0
           else record.to_s
0
         end
0
         get url
0
- assert_equal 200, status
0
+ assert_equal 200, status, url
0
+ end
0
+
0
+ def read_page(section, article)
0
+ url = section.to_page_url(article) * '/'
0
+ get url
0
+ assert_equal 200, status, url
0
       end
0
 
0
       def syndicate(section)
0
- get "/feed/#{section.to_feed_url * '/'}"
0
- assert_equal 200, status
0
+ url = "/feed/#{section.to_feed_url * '/'}"
0
+ get url
0
+ assert_equal 200, status, url
0
       end
0
 
0
       def comment_on(article, comment)
0
@@ -28,6 +35,16 @@ module Mephisto
0
         manage_comment :unapprove, comment
0
       end
0
 
0
+ def update_section(section, options = {})
0
+ post "/admin/sections/update/#{section.id}", :section => options
0
+ assert_equal 200, status, "Updating section #{section.id}"
0
+ end
0
+
0
+ def update_template(template, options = {})
0
+ post "/admin/templates/update/#{template.filename}", :template => (options.is_a?(Hash) ? options : { :attachment_data => options })
0
+ assert_equal 200, status, "Updating template #{template.filename}"
0
+ end
0
+
0
       def revise(article, contents)
0
         post "/admin/articles/update/#{article.id}", to_article_params(article, contents.is_a?(Hash) ? contents : {:body => contents})
0
         assert_redirected_to "/admin/articles"
...
1
2
3
 
4
5
6
...
137
138
139
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
141
142
...
1
2
 
3
4
5
6
...
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
0
@@ -1,6 +1,6 @@
0
 require File.dirname(__FILE__) + '/../test_helper'
0
 class CachingTest < ActionController::IntegrationTest
0
- fixtures :contents, :users, :sections, :assigned_sections, :sites
0
+ fixtures :contents, :users, :sections, :assigned_sections, :sites, :attachments
0
 
0
   def setup
0
     prepare_for_caching!
0
@@ -137,6 +137,36 @@ class CachingTest < ActionController::IntegrationTest
0
     end
0
   end
0
 
0
+ def test_should_expire_section_cache_when_updating_section
0
+ visitor = visit
0
+ assert_caches_page section_url_for(:about) do
0
+ visitor.read sections(:about)
0
+ end
0
+
0
+ assert_caches_page feed_url_for(:about) do
0
+ visitor.syndicate sections(:about)
0
+ end
0
+
0
+ assert_caches_page section_url_for(:about, :site_map) do
0
+ visitor.read_page sections(:about), contents(:site_map)
0
+ end
0
+
0
+ assert_expires_pages section_url_for(:about), feed_url_for(:about), section_url_for(:about, :site_map) do
0
+ login_as :quentin do |writer|
0
+ writer.update_section sections(:about), :name => 'ABOUT'
0
+ end
0
+ end
0
+ end
0
+
0
+ def test_should_expire_cache_when_updating_template
0
+ visit_sections_and_feeds_with visit
0
+ assert_expires_pages section_url_for(:home), section_url_for(:about), feed_url_for(:home), feed_url_for(:about) do
0
+ login_as :quentin do |writer|
0
+ writer.update_template attachments(:error), '<p>error!</p>'
0
+ end
0
+ end
0
+ end
0
+
0
   protected
0
     def visit_sections_and_feeds_with(visitor)
0
       assert_difference CachedPage, :count, 4 do
...
97
98
99
100
101
 
 
102
103
104
...
97
98
99
 
 
100
101
102
103
104
0
@@ -97,8 +97,8 @@ class ActionController::IntegrationTest
0
     end
0
   end
0
 
0
- def section_url_for(section)
0
- sections(section).to_url * '/'
0
+ def section_url_for(section, article = nil)
0
+ (article ? sections(section).to_page_url(contents(article)) : sections(section).to_url) * '/'
0
   end
0
 
0
   def feed_url_for(section)
...
29
30
31
 
 
 
 
 
 
32
33
34
...
29
30
31
32
33
34
35
36
37
38
39
40
0
@@ -29,6 +29,12 @@ class SectionTest < Test::Unit::TestCase
0
     assert_equal ['about'], sections(:about).to_url
0
   end
0
 
0
+ def test_should_return_correct_page_url_paths
0
+ assert_equal ['foo'], sections(:home).to_page_url('foo')
0
+ assert_equal ['about', 'foo'], sections(:about).to_page_url('foo')
0
+ assert_equal ['about', 'the-site-map'], sections(:about).to_page_url(contents(:site_map))
0
+ end
0
+
0
   def test_should_return_correct_feed_url_paths
0
     assert_equal ['atom.xml'], sections(:home).to_feed_url
0
     assert_equal ['about', 'atom.xml'], sections(:about).to_feed_url

Comments

    No one has commented yet.