Skip to content
Browse files

Merge pull request #251 from resolve/split_approved_rejected_actions

Split rejected and approved comment actions into separate controller act...
  • Loading branch information...
2 parents e41a230 + dd3480f commit 213f7f20ef83736f2f63cc36b1a2b7a87eba10d6 @parndt parndt committed
View
36 app/controllers/refinery/blog/admin/comments_controller.rb
@@ -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
View
6 app/views/refinery/blog/admin/comments/_comment.html.erb
@@ -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>
View
10 app/views/refinery/blog/admin/comments/show.html.erb
@@ -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>
View
4 config/routes.rb
@@ -30,8 +30,8 @@
get :rejected
end
member do
- get :approved
- get :rejected
+ post :approve
+ post :reject
end
end
View
84 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.
Something went wrong with that request. Please try again.