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 !
properly sweep cache after deleting a comment

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@1556 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Mon Aug 07 23:28:13 -0700 2006
commit  35c813774a09af6470b9a2a0aeb6688ecf2e6ff5
tree    30c3803561bc22461971adcb4698af160ad6fd57
parent  1a584599ab9c9be14a4ef28e19e184a363738cd4
...
11
12
13
14
15
 
16
 
 
 
 
 
 
 
 
 
 
 
 
17
18
...
11
12
13
 
 
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
0
@@ -11,7 +11,18 @@ class CommentSweeper < ActionController::Caching::Sweeper
0
   def after_save(record)
0
     return if controller.nil? || (@new && !record.approved?)
0
     expire_overview_feed!
0
- pages = CachedPage.find_by_reference(record.article)
0
- expire_cached_pages "Expired pages referenced by #{record.class} ##{record.id}", *pages
0
+ expire_cache_for record
0
   end
0
+
0
+ def after_destroy(record)
0
+ return if controller.nil?
0
+ expire_overview_feed!
0
+ expire_cache_for record if record.approved?
0
+ end
0
+
0
+ protected
0
+ def expire_cache_for(comment)
0
+ pages = CachedPage.find_by_reference(comment.article)
0
+ expire_cached_pages "Expired pages referenced by #{comment.class} ##{comment.id}", *pages
0
+ end
0
 end
0
\ No newline at end of file
...
78
79
80
81
 
82
83
84
85
 
86
87
88
...
137
138
139
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
141
142
...
78
79
80
 
81
82
83
84
 
85
86
87
88
...
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
173
174
175
176
177
178
179
0
@@ -78,11 +78,11 @@ class CachingTest < ActionController::IntegrationTest
0
     rss = visit
0
     writer = login_as :quentin
0
 
0
- assert_caches_page overview_url(:only_path => true, :skip_relative_url_root => true) do
0
+ assert_caches_page overview_path do
0
       rss.get_with_basic 'admin/overview.xml', :login => :quentin
0
     end
0
 
0
- assert_expires_page overview_url(:only_path => true, :skip_relative_url_root => true) do
0
+ assert_expires_page overview_path do
0
       writer.revise contents(:welcome), 'new welcome description'
0
     end
0
   end
0
@@ -137,6 +137,43 @@ class CachingTest < ActionController::IntegrationTest
0
     assert_not_cached contents(:welcome).full_permalink
0
   end
0
 
0
+ def test_should_expire_cache_when_approved_comment_is_deleted
0
+ visitor = visit
0
+ rss = visit
0
+ writer = login_as :quentin
0
+ assert_caches_page contents(:welcome).full_permalink do
0
+ visitor.read contents(:welcome)
0
+ end
0
+
0
+ assert_caches_page overview_path do
0
+ rss.get_with_basic 'admin/overview.xml', :login => :quentin
0
+ end
0
+
0
+ assert_expires_pages overview_path, contents(:welcome).full_permalink do
0
+ writer.post "admin/articles/destroy_comment/#{contents(:welcome).id}", :comment => contents(:welcome_comment).id
0
+ end
0
+ end
0
+
0
+ def test_should_only_expire_overview_when_unapproved_comment_is_deleted
0
+ visitor = visit
0
+ rss = visit
0
+ writer = login_as :quentin
0
+ assert_caches_page contents(:welcome).full_permalink do
0
+ visitor.read contents(:welcome)
0
+ end
0
+
0
+ assert_caches_page overview_path do
0
+ rss.get_with_basic 'admin/overview.xml', :login => :quentin
0
+ end
0
+
0
+ assert_expires_pages overview_path do
0
+ contents(:welcome_comment).update_attribute :approved, false
0
+ writer.post "admin/articles/destroy_comment/#{contents(:welcome).id}", :comment => contents(:welcome_comment).id
0
+ end
0
+
0
+ assert_cached contents(:welcome).full_permalink
0
+ end
0
+
0
   def test_should_not_cache_bad_urls
0
     visitor = visit
0
     pages = ['/about/blah', '/foo/bar', '2006/1/2/fasd']

Comments

    No one has commented yet.