Skip to content

Commit

Permalink
Merge pull request refinery#251 from resolve/split_approved_rejected_…
Browse files Browse the repository at this point in the history
…actions

Split rejected and approved comment actions into separate controller act...
  • Loading branch information
parndt committed Jul 6, 2012
2 parents e41a230 + dd3480f commit 213f7f2
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 26 deletions.
36 changes: 18 additions & 18 deletions app/controllers/refinery/blog/admin/comments_controller.rb
Expand Up @@ -16,31 +16,31 @@ def index
end

def approved
unless params[:id].present?
@comments = Refinery::Blog::Comment.approved.page(params[:page])
@comments = Refinery::Blog::Comment.approved.page(params[:page])

render :index
else
@comment = Refinery::Blog::Comment.find(params[:id])
@comment.approve!
flash[:notice] = t('approved', :scope => 'refinery.blog.admin.comments', :author => @comment.name)
render :index
end

def approve
@comment = Refinery::Blog::Comment.find(params[:id])
@comment.approve!
flash[:notice] = t('approved', :scope => 'refinery.blog.admin.comments', :author => @comment.name)

redirect_to refinery.url_for(:action => params[:return_to] || 'index', :id => nil)
end
redirect_to refinery.blog_admin_comments_path
end

def rejected
unless params[:id].present?
@comments = Refinery::Blog::Comment.rejected.page(params[:page])
@comments = Refinery::Blog::Comment.rejected.page(params[:page])

render :index
end

render :index
else
@comment = Refinery::Blog::Comment.find(params[:id])
@comment.reject!
flash[:notice] = t('rejected', :scope => 'refinery.blog.admin.comments', :author => @comment.name)
def reject
@comment = Refinery::Blog::Comment.find(params[:id])
@comment.reject!
flash[:notice] = t('rejected', :scope => 'refinery.blog.admin.comments', :author => @comment.name)

redirect_to refinery.url_for(:action => params[:return_to] || 'index', :id => nil)
end
redirect_to refinery.blog_admin_comments_path
end

end
Expand Down
6 changes: 4 additions & 2 deletions app/views/refinery/blog/admin/comments/_comment.html.erb
Expand Up @@ -11,10 +11,12 @@
<%= link_to refinery_icon_tag('zoom.png'), refinery.blog_admin_comment_path(comment),
:title => t('.read') %>
<%= link_to refinery_icon_tag("cross.png"),
refinery.rejected_blog_admin_comment_path(comment, :return_to => request.path.split('/').last.gsub(/^comments$/, 'index')),
refinery.reject_blog_admin_comment_path(comment),
:method => :post,
:title => t('.reject') unless comment.rejected? %>
<%= link_to refinery_icon_tag("tick.png"),
refinery.approved_blog_admin_comment_path(comment, :return_to => request.path.split('/').last.gsub(/^comments$/, 'index')),
refinery.approve_blog_admin_comment_path(comment),
:method => :post,
:title => t('.approve') unless comment.approved? %>
</span>
</li>
10 changes: 6 additions & 4 deletions app/views/refinery/blog/admin/comments/show.html.erb
Expand Up @@ -9,12 +9,14 @@
<%= link_to t('.back'), refinery.blog_admin_comments_path, :class => "back_icon" %>
</li>
<li>
<%= link_to t('.reject'), refinery.rejected_blog_admin_comment_path(@comment, :return_to => 'rejected'),
:class => 'comment_cross_icon' unless @comment.rejected? %>
<%= link_to t('.reject'), refinery.reject_blog_admin_comment_path(@comment),
:method => :post,
:class => 'comment_cross_icon' unless @comment.rejected? %>
</li>
<li>
<%= link_to t('.approve'), refinery.approved_blog_admin_comment_path(@comment, :return_to => 'approved'),
:class => 'comment_tick_icon' unless @comment.approved? %>
<%= link_to t('.approve'), refinery.approve_blog_admin_comment_path(@comment),
:method => :post,
:class => 'comment_tick_icon' unless @comment.approved? %>
</li>
</ul>
</div>
Expand Down
4 changes: 2 additions & 2 deletions config/routes.rb
Expand Up @@ -30,8 +30,8 @@
get :rejected
end
member do
get :approved
get :rejected
post :approve
post :reject
end
end

Expand Down
84 changes: 84 additions & 0 deletions spec/controllers/refinery/blog/admin/comments_controller_spec.rb
@@ -0,0 +1,84 @@
require "spec_helper"

module Refinery
module Blog
module Admin
describe CommentsController do
refinery_login_with :refinery_user

describe "#index" do
let!(:comment) { FactoryGirl.create(:blog_comment) }

it "succeeds" do
get :index
response.should be_success
response.should render_template(:index)
end

it "assigns unmoderated comments" do
get :index
assigns(:comments).first.should eq(comment)
end
end

describe "#approved" do
let!(:comment) { FactoryGirl.create(:approved_comment) }

it "succeeds" do
get :approved
response.should be_success
response.should render_template(:index)
end

it "assigns approved comments" do
get :approved
assigns(:comments).first.should eq(comment)
end
end

describe "#approve" do
let!(:comment) { FactoryGirl.create(:blog_comment) }

it "redirects on success" do
post :approve, :id => comment.id
response.should be_redirect
end

it "approves the comment" do
post :approve, :id => comment.id
Refinery::Blog::Comment.approved.count.should eq(1)
end
end

describe "#rejected" do
let!(:comment) { FactoryGirl.create(:rejected_comment) }

it "succeeds" do
get :rejected
response.should be_success
response.should render_template(:index)
end

it "assigns rejected comments" do
get :rejected
assigns(:comments).first.should eq(comment)
end
end

describe "#reject" do
let!(:comment) { FactoryGirl.create(:blog_comment) }

it "redirects on success" do
post :reject, :id => comment.id
response.should be_redirect
end

it "rejects the comment" do
post :reject, :id => comment.id
Refinery::Blog::Comment.rejected.count.should eq(1)
end
end
end
end
end
end

0 comments on commit 213f7f2

Please sign in to comment.