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
Search Repo:
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
refactor so that admin/comments is more restful, allow inline comment 
editing in the admin.  [court3nay]
technoweenie (author)
Sat Feb 02 17:26:47 -0800 2008
commit  a1329bde8030def40ed0cc227e34c14a2b43058f
tree    02b889394f6738fe2ee4228d0b65b173ba28a71c
parent  f3ae6c08dd171d3346cc8a18be7eaba58b498d0e
...
3
4
5
6
7
8
9
...
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
 
98
99
100
...
3
4
5
 
6
7
8
...
68
69
70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
72
73
74
0
@@ -3,7 +3,6 @@
0
   with_options :only => [:create, :update, :destroy, :upload] do |c|
0
     c.before_filter :set_default_section_ids
0
     c.cache_sweeper :article_sweeper, :assigned_section_sweeper
0
- cache_sweeper :comment_sweeper, :only => [:approve, :unapprove, :destroy_comment]
0
   end
0
 
0
   before_filter :convert_times_to_utc, :only => [:create, :update, :upload]
0
@@ -69,32 +68,7 @@
0
   end
0
 
0
   def comments
0
- @comments =
0
- case params[:filter]
0
- when 'approved' then :comments
0
- when 'unapproved' then :unapproved_comments
0
- else :all_comments
0
- end
0
- @comments = @article.send @comments
0
- @articles = @site.unapproved_comments.count :all, :group => :article, :order => '1 desc'
0
- end
0
-
0
- # xhr baby
0
- # needs some restful lovin'
0
- def approve
0
- @comment = @article.unapproved_comments.approve(params[:comment])
0
- @comment.mark_as_ham(site, request)
0
- end
0
-
0
- def unapprove
0
- @comment = @article.comments.unapprove(params[:comment])
0
- @comment.mark_as_spam(site, request)
0
- render :action => 'approve'
0
- end
0
-
0
- def destroy_comment
0
- @comments = site.all_comments.find :all, :conditions => ['id in (?)', [params[:comment]].flatten] rescue []
0
- Comment.transaction { @comments.each(&:destroy) } if @comments.any?
0
+ redirect_to article_comments_path(@article)
0
   end
0
 
0
   def upload
...
1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
5
6
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
0
@@ -1,6 +1,70 @@
0
 class Admin::CommentsController < Admin::BaseController
0
+
0
+ member_actions.push(*%w(index unapproved create edit update approve unapprove destroy close ))
0
+
0
+private
0
+
0
+ before_filter :find_site_article, :except => [ :close ]
0
+ def find_site_article
0
+ @article = site.articles.find params[:article_id]
0
+ end
0
+
0
+ cache_sweeper :comment_sweeper, :only => [:approve, :unapprove, :destroy, :create]
0
+
0
+public
0
+
0
   def index
0
- @comments = site.unapproved_comments.find(:all, :include => :article)
0
+ @comments = if params[:article_id]
0
+ @comment = Comment.new
0
+ @articles = site.unapproved_comments.count :all, :group => :article, :order => '1 desc'
0
+ @article.send case params[:filter]
0
+ when 'approved' then :comments
0
+ when 'unapproved' then :unapproved_comments
0
+ else :all_comments
0
+ end
0
+ end
0
+ end
0
+
0
+ def unapproved
0
+ site.unapproved_comments.find(:all, :include => :article)
0
+ end
0
+
0
+ def create
0
+ @comment = @article.comments.build(params[:comment].merge(
0
+ :user_id => session[:user],
0
+ :author_ip => request.remote_ip,
0
+ :user_agent => request.env['HTTP_USER_AGENT'],
0
+ :referrer => request.env['HTTP_REFERER'])
0
+ )
0
+ @comment.approved = true
0
+ @comment.save
0
+ end
0
+
0
+ def edit
0
+ @comment = @article.all_comments.find params[:id]
0
+ end
0
+
0
+ def update
0
+ @comment = @article.all_comments.find params[:id]
0
+ @comment.update_attributes(params[:comment])
0
+ end
0
+
0
+ # xhr baby
0
+ # needs some restful lovin'
0
+ def approve
0
+ @comment = @article.unapproved_comments.approve(params[:comment] || params[:id])
0
+ @comment.mark_as_ham(site, request)
0
+ end
0
+
0
+ def unapprove
0
+ @comment = @article.comments.unapprove(params[:comment] || params[:id])
0
+ @comment.mark_as_spam(site, request)
0
+ render :action => 'approve'
0
+ end
0
+
0
+ def destroy
0
+ @comments = site.all_comments.find :all, :conditions => ['id in (?)', [ (params[:comment] || params[:id])].flatten] # rescue []
0
+ Comment.transaction { @comments.each(&:destroy) } if @comments.any?
0
   end
0
   
0
   # ajax action, called from _page_nav
...
5
6
7
8
 
9
10
11
...
5
6
7
 
8
9
10
11
0
@@ -5,7 +5,7 @@
0
     <% if article.comments.size == 0 %>
0
       none
0
     <% else %>
0
- <%= link_to article.comments.size.to_s.rjust(2, '0'), { : :action => 'comments', :id => article } %>
0
+ <%= link_to article.comments.size.to_s.rjust(2, '0'), { :controller => 'admin/comments', :action => 'comments', :id => article } %>
0
     <% end %>
0
   </td>
0
   <td><span class="date"><%= published_at_for article %></span></td>
...
22
23
24
25
 
26
27
28
...
22
23
24
 
25
26
27
28
0
@@ -22,7 +22,7 @@
0
       <div id="optgroup" style="display: none">
0
         <ul id="options">
0
         <% unless @article.new_record? -%>
0
- <li><%= link_to 'Edit this article', :', :action => 'edit', :id => @article, :version => nil %></li>
0
+ <li><%= link_to 'Edit this article', :controller => 'articles', :action => 'edit', :id => @article, :version => nil %></li>
0
         <% end -%>
0
         <% if @article.comments.any? && controller.action_name != 'comments' -%>
0
           <li><%= link_to "View comments", :controller => 'articles', :action => 'comments', :id => @article %></li>
...
1
...
 
0
@@ -1,2 +1 @@
0
-page["comment-#{@comment.id}"].add_class_name 'disabled'
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -1,58 +1 @@
0
-<%= render :partial => "page_nav" %>
0
-
0
-
0
-<h3 style="border-bottom:1px solid #ccc;padding:5px">Comments on <%= link_to @article.title, { :action => 'edit', :id => @article }, :style => 'border:none' %> <span class="right"><%= @article.published? ? link_to(image_tag('/images/mephisto/icons/24-zoom-in.png', :style => 'vertical-align: middle'), @site.permalink_for(@article), :style => 'border:none;') : '&nbsp;' %></span></h3>
0
-
0
-<ul class="pagelist commentlist">
0
- <% if @comments.any? %>
0
- <% @comments.reverse.each_with_index do |comment, i| -%>
0
- <li class="event-comment<%= " shade" if (i % 2 > 0) %>" id="comment-<%= comment.id %>">
0
- <% if false %>
0
- <input type="checkbox" title="" />
0
- <% end %>
0
- <a name="comment-<%= comment.id %>"></a>
0
- <% unless comment.body.blank? -%>
0
- <blockquote><p>"<%= strip_tags(comment.body) %>"</p></blockquote>
0
- <% end -%>
0
- <span class="meta">
0
- <cite>&mdash; <%= author_link_for comment %><%= %( (#{comment.author_email})) unless comment.author_email.blank? %> said <%= time_ago_in_words comment.created_at %> ago</cite>
0
-
0
- <% if comment.approved? -%>
0
- <%= link_to_remote 'Unapprove', :url => { :action => 'unapprove', :id => @article, :comment => comment } %> |
0
- <% else -%>
0
- <%= link_to_remote 'Approve', :url => { :action => 'approve', :id => @article, :comment => comment } %> |
0
- <% end -%>
0
- <%= link_to_remote 'Delete', :url => { :action => 'destroy_comment', :id => @article, :comment => comment } %>
0
- </span>
0
- </li>
0
- <% end -%>
0
- <% else %>
0
- <li class="event-none shade">This article has no <%= params[:filter].to_s.humanize.downcase %> comments.</li>
0
- <% end %>
0
-</ul>
0
-
0
-
0
-<% content_for :sidebar do %>
0
- <% if @articles.size > 1 -%>
0
- <div class="sgroup">
0
- <h3>Comments awaiting your approval</h3>
0
- <ul class="slist">
0
- <% @articles.each do |article, count| -%>
0
- <% if article.title != @article.title -%>
0
- <li><%= link_to "<strong>(#{count})</strong> #{h(article.title)}", :controller => 'articles', :action => 'comments', :id => article.id, :filter => :unapproved %></li>
0
- <% end -%>
0
- <% end -%>
0
- </ul>
0
- </div>
0
- <% end -%>
0
-<% end %>
0
-
0
-
0
-<script type="text/javascript" language="javascript" charset="utf-8">
0
-// <![CDATA[
0
- var comment = $(document.location.hash.substring(1));
0
- if(comment) Element.addClassName(comment, 'focused');
0
-
0
-// ]]>
0
-</script>
...
1
2
3
...
 
 
 
0
@@ -1,4 +1 @@
0
-@comments.each do |comment|
0
- page["comment-#{comment.id}"].add_class_name 'disabled'
0
-end
...
1
2
3
4
5
 
 
 
6
7
8
9
10
11
12
 
13
14
15
16
17
18
19
20
 
 
 
 
 
 
21
...
1
2
3
 
 
4
5
6
7
 
8
9
10
11
 
12
13
14
15
 
 
 
 
 
16
17
18
19
20
21
22
0
@@ -1,22 +1,23 @@
0
 <%= render :partial => "page_nav" %>
0
 
0
 <% fields_for :article, @version do |f| -%>
0
-<% content_for :sidebar do %>
0
- <%= render :partial => 'shared_options', :locals => { :form => f } %>
0
+ <% content_for :sidebar do %>
0
+ <%= render :partial => 'shared_options', :locals => { :form => f } %>
0
+ <% end %>
0
 <% end %>
0
-<% end %>
0
 
0
 <%= error_messages_for :article %>
0
 
0
 <% content_for :form do -%>
0
- <%= form_tag({:action => 'update', :id => @article}, {:id => 'article-form', :multipart => true}) %>
0
+ <%= form_tag({:action => 'update', :id => @article}, {:id => 'article-form', :multipart => true, :method => :put}) %>
0
 <% end -%>
0
 
0
 <% fields_for :article, @version do |f| -%>
0
-<%= render :partial => 'form', :object => f %>
0
-<p class="btns">
0
- <%= submit_tag 'Apply Changes' %>
0
- <%= submit_tag 'Save without Revision' %>
0
- <%= link_to "cancel", :controller => "articles" %></p>
0
+ <%= render :partial => 'form', :object => f %>
0
+ <p class="btns">
0
+ <%= submit_tag 'Apply Changes' %>
0
+ <%= submit_tag 'Save without Revision' %>
0
+ <%= link_to "cancel", :controller => "articles" %>
0
+ </p>
0
 <% end -%>
...
81
82
83
84
 
85
86
87
...
81
82
83
 
84
85
86
87
0
@@ -81,7 +81,7 @@
0
     <h3>Comments awaiting your approval</h3>
0
     <ul class="slist">
0
     <% @comments.each do |article, count| -%>
0
- <li><%= link_to "<strong>(#{count})</strong> #{h(article.title)}", :controller => 'articles', :action => 'comments', :id => article.id, :filter => :unapproved %></li>
0
+ <li><%= link_to "<strong>(#{count})</strong> #{h(article.title)}", article_comments_path(article), :filter => :unapproved %></li>
0
     <% end -%>
0
     </ul>
0
   </div>
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
0
@@ -1 +1,17 @@
0
+
0
+ <li class="event-comment<%= cycle(" shade", "") %>" id="comment-<%= comment.id %>">
0
+ <h3><a name="comment-<%= comment.id %>"></a> <%= link_to comment.article.title, :controller => 'articles', :action => 'edit', :id => comment.article %></h3>
0
+ <blockquote><p>"<%= truncate strip_tags(comment.body), 255 %>"</p></blockquote>
0
+ <span class="meta">
0
+ <cite>&mdash; <%= author_link_for comment %><%= %( (#{comment.author_email})) unless comment.author_email.blank? %></cite>
0
+
0
+ <%= link_to_remote 'Edit', :url => edit_article_comment_path(@article, comment), :method => :get %> |
0
+ <% if comment.approved? -%>
0
+ <%= link_to_remote 'Unapprove', :url => unapprove_article_comment_path(comment.article, comment) %> |
0
+ <% else -%>
0
+ <%= link_to_remote 'Approve', :url => approve_article_comment_path(comment.article, comment) %> |
0
+ <% end -%>
0
+ <%= link_to_remote 'Delete', :url => article_comment_path(comment.article, comment), :method => :delete %>
0
+ </span>
0
+ </li>
...
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
0
@@ -1 +1,10 @@
0
+<li id="edit-comment-<%= comment.id %>">
0
+ <%= error_messages_for :comment %>
0
+ <% remote_form_for :comment, :url => article_comment_path(@article, comment), :html => { :method => :put, :onsubmit => "$('comment-#{comment.id}-spinner').show()" } do |form| %>
0
+ <%= render :partial => 'form', :object => form %>
0
+ <%= submit_tag "Update" %>
0
+ <span style="display:none;" id="comment-<%= comment.id %>-spinner"><img src="/images/mephisto/spinner.gif" /> Saving..</span>
0
+ <%= link_to_function "Cancel", "$('comment-#{comment.id}').show(); $('edit-comment-#{comment.id}').remove()" %>
0
+ <% end # form %>
0
+</li>
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
0
@@ -1 +1,16 @@
0
+ <p>
0
+ <label for="author">Name (required)</label>
0
+ <%= form.text_field :author %>
0
+ </p>
0
+ <p>
0
+ <label for="email">Mail (will not be published</label>
0
+ <%= form.text_field :author_email %>
0
+ </p>
0
+ <p>
0
+ <label for="url">Website</label>
0
+ <%= form.text_field :author_url %>
0
+ </p>
0
+ <p>
0
+ <%= form.text_area :body, { :rows => '10' } %>
0
+ </p>
...
 
 
 
 
 
...
1
2
3
4
5
0
@@ -1 +1,6 @@
0
+ <%= error_messages_for :comment %>
0
+ <% remote_form_for :comment, :url => article_comments_path(@article) do |form| %>
0
+ <%= render :partial => 'form', :object => form %>
0
+ <%= submit_tag "Create" %> or <%= link_to_function "hide", "$('new-comment-form').toggle()" %>
0
+ <% end # form %>
...
 
...
1
0
@@ -1 +1,2 @@
0
+page["comment-#{@comment.id}"].add_class_name 'disabled'
...
 
 
 
 
 
 
...
1
2
3
4
5
6
0
@@ -1 +1,7 @@
0
+ if @comment.new_record?
0
+ page.replace_html 'new-comment-form', :partial => 'new_comment'
0
+ else
0
+ page['new-comment-form'].reset
0
+ page.insert_html :top, 'comment-list', :partial => 'comment', :object => @comment
0
+ end
...
 
 
 
...
1
2
3
0
@@ -1 +1,4 @@
0
+@comments.each do |comment|
0
+ page["comment-#{comment.id}"].add_class_name 'disabled'
0
+end
...
 
 
...
1
2
0
@@ -1 +1,3 @@
0
+ page.insert_html :after, "comment-#{@comment.id}", :partial => 'edit_comment', :locals => { :comment => @comment }
0
+ page.hide "comment-#{@comment.id}"
...
1
2
3
4
5
6
7
8
9
10
11
12
 
13
14
 
15
16
 
 
 
 
 
17
18
19
20
 
 
 
 
21
22
23
 
 
 
24
25
 
26
27
 
28
29
 
30
31
32
 
 
 
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
 
 
 
 
 
 
 
 
 
 
 
 
1
2
 
3
4
 
5
6
7
8
9
10
11
 
 
12
13
14
15
16
 
 
17
18
19
20
 
21
22
 
23
24
 
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
0
@@ -1,34 +1,58 @@
0
-<% content_for :action_nav do %>
0
-<!-- begin action nav -->
0
-<div id="page-nav">
0
- <ul id="act-nav" class="clear">
0
- <li><%= link_to_remote 'Delete these comments', :confirm => "Are you sure you wish to delete all of these comments?",
0
- :url => { :controller => 'articles', :action => 'destroy_comment' },
0
- :with => "ArticleForm.getAvailableComments().toQueryString('comment')"
0
- %></li>
0
- </ul>
0
-</div>
0
-<!-- /end action nav -->
0
-<% end %>
0
+<%= render :partial => "admin/articles/page_nav" %>
0
 
0
-<h3><%= pluralize(@comments.size, 'Unapproved Comment') %></h3>
0
+<h3 style="border-bottom:1px solid #ccc;padding:5px">Comments on <%= link_to @article.title, edit_article_path(@article), :style => 'border:none' %> <span class="right"><%= @article.published? ? link_to(image_tag('/images/mephisto/icons/24-zoom-in.png', :style => 'vertical-align: middle'), @site.permalink_for(@article), :style => 'border:none;') : '&nbsp;' %></span></h3>
0
 
0
-<ul class="pagelist commentlist">
0
+ <%= link_to_function "New comment", "$('new-comment-form').toggle()" %>
0
+ <div id="new-comment-form" style="display:none"><%= render :partial => "new_comment" %></div>
0
+
0
+<ul class="pagelist commentlist" id="comment-list">
0
+ <% if @comments.any? %>
0
   <% @comments.reverse.each_with_index do |comment, i| -%>
0
   <li class="event-comment<%= " shade" if (i % 2 > 0) %>" id="comment-<%= comment.id %>">
0
- <h3><a name="comment-<%= comment.id %>"></a> <%= link_to comment.article.title, :controller => 'articles', :action => 'edit', :id => comment.article %></h3>
0
- <blockquote><p>"<%= truncate strip_tags(comment.body), 255 %>"</p></blockquote>
0
+ <a name="comment-<%= comment.id %>"></a>
0
+ <% unless comment.body.blank? -%>
0
+ <blockquote><p>"<%= strip_tags(comment.body) %>"</p></blockquote>
0
+ <% end -%>
0
     <span class="meta">
0
- <cite>&mdash; <%= author_link_for comment %><%= %( (#{comment.author_email})) unless comment.author_email.blank? %></cite>
0
-
0
+ <cite>&mdash; <%= author_link_for comment %><%= %( (#{comment.author_email})) unless comment.author_email.blank? %> said <%= time_ago_in_words comment.created_at %> ago</cite>
0
+
0
+ <%= link_to_remote 'Edit', :url => edit_article_comment_path(@article, comment), :method => :get %> |
0
     <% if comment.approved? -%>
0
- <%= link_to_remote 'Unapprove', :url => { :action => 'unapprove', :controller => 'articles', :id => comment.article, :comment => comment } %> |
0
+ <%= link_to_remote 'Unapprove', :url => unapprove_article_comment_path(@article, comment) %> |
0
     <% else -%>
0
- <%= link_to_remote 'Approve', :url => { :action => 'approve', :controller => 'articles', :id => comment.article, :comment => comment } %> |
0
+ <%= link_to_remote 'Approve', :url => approve_article_comment_path(@article, comment) %> |
0
     <% end -%>
0
- <%= link_to_remote 'Delete', :url => { :action => 'destroy_comment', :controller => 'articles', :id => comment.article, :comment => comment } %>
0
+ <%= link_to_remote 'Delete', :url => article_comment_path(@article, comment), :method => :delete %>
0
     </span>
0
   </li>
0
   <% end -%>
0
+ <% else %>
0
+ <li class="event-none shade">This article has no <%= params[:filter].to_s.humanize.downcase %> comments.</li>
0
+ <% end %>
0
 </ul>
0
+
0
+
0
+<% content_for :sidebar do %>
0
+ <% if @articles.size > 1 -%>
0
+ <div class="sgroup">
0
+ <h3>Comments awaiting your approval</h3>
0
+ <ul class="slist">
0
+ <% @articles.each do |article, count| -%>
0
+ <% if article.title != @article.title -%>
0
+ <li><%= link_to "<strong>(#{count})</strong> #{h(article.title)}", :controller => 'articles', :action => 'comments', :id => article.id, :filter => :unapproved %></li>
0
+ <% end -%>
0
+ <% end -%>
0
+ </ul>
0
+ </div>
0
+ <% end -%>
0
+<% end %>
0
+
0
+
0
+<script type="text/javascript" language="javascript" charset="utf-8">
0
+// <![CDATA[
0
+ var comment = $(document.location.hash.substring(1));
0
+ if(comment) Element.addClassName(comment, 'focused');
0
+
0
+// ]]>
0
+</script>
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
0
@@ -1 +1,21 @@
0
+<% content_for :action_nav do %>
0
+<!-- begin action nav -->
0
+<div id="page-nav">
0
+ <ul id="act-nav" class="clear">
0
+ <li><%= link_to_remote 'Delete these comments', :confirm => "Are you sure you wish to delete all of these comments?",
0
+ :url => { :controller => 'articles', :action => 'destroy_comment' },
0
+ :with => "ArticleForm.getAvailableComments().toQueryString('comment')"
0
+ %></li>
0
+ </ul>
0
+</div>
0
+<!-- /end action nav -->
0
+<% end %>
0
+
0
+<h3><%= pluralize(@comments.size, 'Unapproved Comment') %></h3>
0
+
0
+<ul class="pagelist commentlist">
0
+ <% @comments.reverse.each_with_index do |comment, i| -%>
0
+ <%= render :partial => 'comment', :object => comment %>
0
+ <% end -%>
0
+</ul>
...
 
 
 
...
1
2
3
0
@@ -1 +1,4 @@
0
+
0
+ page.replace "comment-#{@comment.id}", :partial => 'comment', :object => @comment
0
+ page.remove "edit-comment-#{@comment.id}"
...
14
15
16
17
 
 
 
 
 
18
19
20
21
...
22
23
24
 
25
 
26
27
28
...
14
15
16
 
17
18
19
20
21
22
23
24
25
...
26
27
28
29
30
31
32
33
34
0
@@ -14,7 +14,11 @@
0
         m.js 'javascripts/:path.:ext', :dir => 'javascripts'
0
         m.images 'images/:path.:ext', :dir => 'images'
0
       end
0
-
0
+
0
+ map.resources :articles, :path_prefix => 'admin', :controller => 'admin/articles' do |r|
0
+ r.resources :comments, :controller => 'admin/comments', :member => { :unapprove => :post, :approve => :post, :edit => :get }
0
+ end
0
+
0
       map.overview 'admin/overview.xml', :controller => 'admin/overview', :action => 'feed'
0
       map.admin 'admin', :controller => 'admin/overview', :action => 'index'
0
       map.resources :assets, :path_prefix => '/admin', :controller => 'admin/assets', :member => { :add_bucket => :post },
0
0
@@ -22,7 +26,9 @@
0
       
0
       map.connect 'xmlrpc', :controller => 'backend', :action => 'xmlrpc'
0
       
0
+
0
       map.connect ':controller/:action/:id/:version', :version => nil, :controller => /routing_navigator|account|(admin\/\w+)/, :id => /[^\/]*/
0
+
0
 
0
       yield if block_given?
0
       Mephisto::Plugin.custom_routes.each do |path, options|
...
51
52
53
54
55
 
 
56
57
58
59
 
60
61
62
63
64
65
 
 
66
67
68
69
70
 
71
72
73
...
51
52
53
 
 
54
55
56
57
58
 
59
60
61
62
63
 
 
64
65
66
67
68
69
 
70
71
72
73
0
@@ -51,23 +51,23 @@
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/edit/#{assigns(:article).id}"
0
+ put "/admin/articles/#{article.id}", to_article_params(article, contents.is_a?(Hash) ? contents : {:body => contents})
0
+ assert_redirected_to "/admin/articles/#{assigns(:article).id}/edit"
0
       end
0
 
0
       def remove_article(article)
0
- post "/admin/articles/destroy/#{article.id}"
0
+ delete "/admin/articles/#{article.id}"
0
         assert_equal 200, status, "Removing article #{article.id}"
0
       end
0
 
0
       def create(params)
0
- post '/admin/articles/create', to_article_params(params)
0
- assert_redirected_to "/admin/articles/edit/#{assigns(:article).id}"
0
+ post '/admin/articles', to_article_params(params)
0
+ assert_redirected_to "/admin/articles/#{assigns(:article).id}/edit"
0
       end
0
 
0
       private
0
         def manage_comment(action, comment)
0
- post "/admin/articles/#{action}/#{comment.article_id}", :comment => comment.id
0
+ post "/admin/articles/#{comment.article_id}/comments/#{comment.id}/#{action}", :comment => comment.id
0
         end
0
 
0
         def to_article_params(*args)
...
125
126
127
128
 
129
130
131
...
182
183
184
185
 
 
 
186
187
188
...
125
126
127
 
128
129
130
131
...
182
183
184
 
185
186
187
188
189
190
0
@@ -125,7 +125,7 @@
0
   def test_should_show_default_checked_sections
0
     get :new
0
     assert_response :success
0
- assert_tag 'form', :attributes => { :action => '/admin/articles/create' }
0
+ assert_tag 'form', :attributes => { :action => '/admin/articles', :method => 'post' }
0
     assert_tag 'input', :attributes => { :id => "article_section_ids_#{sections(:home).id.to_s}" }
0
     assert_no_tag 'input', :attributes => { :id => "article_section_ids_#{sections(:about).id.to_s}", :checked => 'checked' }
0
   end
0
@@ -182,7 +182,9 @@
0
   def test_edit_form_should_have_correct_post_action
0
     get :edit, :id => contents(:welcome).id
0
     assert_response :success
0
- assert_tag :tag => 'form', :attributes => { :action => "/admin/articles/update/#{contents(:welcome).id}" }
0
+ assert_tag :tag => 'form', :attributes => { :action => "/admin/articles/#{contents(:welcome).id}" } do
0
+ assert_tag :tag => 'input', :attributes => { :name => "_method", :value => "put" }
0
+ end
0
   end
0
 
0
   def test_should_update_article_with_correct_time
...
10
11
12
13
 
14
15
16
...
18
19
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
...
10
11
12
 
13
14
15
16
...
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
0
@@ -10,7 +10,7 @@
0
     @controller = Admin::CommentsController.new
0
     @request = ActionController::TestRequest.new
0
     @response = ActionController::TestResponse.new
0
- login_as :ben
0
+ login_as :quentin
0
   end
0
 
0
   def test_should_disable_comments_on_article
0
@@ -18,5 +18,61 @@
0
     assert_equal -1, contents(:welcome).reload.comment_age
0
     assert_response :success
0
   end
0
+
0
+ def test_should_destroy_comment
0
+ comment = contents(:welcome_comment)
0
+
0
+ xhr :delete, :destroy, :id => '3', :article_id => '1'
0
+ assert_response :success
0
+ assert_equal [comment], assigns(:comments)
0
+ assert_raise(ActiveRecord::RecordNotFound) { comment.reload }
0
+ end
0
+
0
+ def test_should_destroy_comments
0
+ comment = contents(:welcome_comment)
0
+
0
+ xhr :delete, :destroy, :comment => ['3'], :article_id => '1'
0
+ assert_response :success
0
+ assert_equal [comment], assigns(:comments)
0
+ assert_raise(ActiveRecord::RecordNotFound) { comment.reload }
0
+ end
0
+
0
+ def test_should_list_comments_on_article
0
+ get :index, :article_id => '1'
0
+ assert_response :success
0
+ end
0
+