Skip to content

Commit

Permalink
add Recent Comments page for moderators - closes ryanb#29
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanb committed Jul 25, 2011
1 parent 29aa4be commit 70b9941
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 2 deletions.
4 changes: 4 additions & 0 deletions app/controllers/comments_controller.rb
@@ -1,6 +1,10 @@
class CommentsController < ApplicationController
load_and_authorize_resource

def index
@comments = @comments.recent.paginate(:page => params[:page], :per_page => 50)
end

def new
@comment = Comment.new(:parent_id => params[:parent_id], :episode_id => params[:episode_id], :user => current_user)
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/ability.rb
Expand Up @@ -22,7 +22,7 @@ def initialize(user)
if user.moderator?
can :show, :episodes
can :update, :episodes, :notes
can [:update, :destroy], :comments
can [:update, :destroy, :index], :comments
can :ban, :users
can :revert, :versions
end
Expand Down
8 changes: 8 additions & 0 deletions app/views/comments/index.html.erb
@@ -0,0 +1,8 @@
<% title "Recent Comments" %>

<div class="content">
<div id="comments">
<%= render @comments %>
<%= will_paginate :previous_label => h("< Previous Page"), :next_label => h("Next Page >") %>
</div>
</div>
3 changes: 3 additions & 0 deletions app/views/layouts/application.html.erb
Expand Up @@ -39,6 +39,9 @@
<li><%= link_to_unless_current "Browse Episodes", root_url %></li>
<li><%= link_to_unless_current "About RailsCasts", about_path %></li>
<li><%= link_to_unless_current "Feedback", feedback_path %></li>
<% if can? :index, :comments %>
<li><%= link_to_unless_current "Recent Comments", comments_path %></li>
<% end %>
</ul>
<%= form_tag episodes_path, :method => "get" do %>
<%= text_field_tag :search, params[:search], :size => 35 %>
Expand Down
4 changes: 3 additions & 1 deletion spec/models/ability_spec.rb
Expand Up @@ -36,6 +36,7 @@
@ability.should_not be_able_to(:create, :comments)
@ability.should_not be_able_to(:update, :comments)
@ability.should_not be_able_to(:destroy, :comments)
@ability.should_not be_able_to(:index, :comments)
end
end

Expand Down Expand Up @@ -108,9 +109,10 @@
@ability.should be_able_to(:revert, :versions)
end

it "can update and destroy any any comments" do
it "can list, update and destroy any comments" do
@ability.should be_able_to(:update, Factory(:comment, :user => User.new, :created_at => 20.minutes.ago))
@ability.should be_able_to(:destroy, Factory(:comment, :user => User.new, :created_at => 20.minutes.ago))
@ability.should be_able_to(:index, :comments)
end

it "can view episodes which are not yet published" do
Expand Down
7 changes: 7 additions & 0 deletions spec/requests/comments_request_spec.rb
Expand Up @@ -63,4 +63,11 @@
click_on "undo"
page.should have_content("Hello world!")
end

it "lists recent comments" do
login Factory(:user, :admin => true)
comment = Factory(:comment, :content => "Hello world!")
visit comments_path
page.should have_content("Hello world!")
end
end

0 comments on commit 70b9941

Please sign in to comment.