aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/refinery/blog/admin/comments_controller.rb36
-rw-r--r--app/views/refinery/blog/admin/comments/_comment.html.erb6
-rw-r--r--app/views/refinery/blog/admin/comments/show.html.erb10
-rw-r--r--config/routes.rb2
-rw-r--r--spec/controllers/refinery/blog/admin/comments_controller_spec.rb84
5 files changed, 114 insertions, 24 deletions
diff --git a/app/controllers/refinery/blog/admin/comments_controller.rb b/app/controllers/refinery/blog/admin/comments_controller.rb
index 18246ee..ce4ac70 100644
--- a/app/controllers/refinery/blog/admin/comments_controller.rb
+++ b/app/controllers/refinery/blog/admin/comments_controller.rb
@@ -16,31 +16,31 @@ module Refinery
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
diff --git a/app/views/refinery/blog/admin/comments/_comment.html.erb b/app/views/refinery/blog/admin/comments/_comment.html.erb
index c007294..fe72030 100644
--- a/app/views/refinery/blog/admin/comments/_comment.html.erb
+++ b/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>
diff --git a/app/views/refinery/blog/admin/comments/show.html.erb b/app/views/refinery/blog/admin/comments/show.html.erb
index 2246c2f..5cd34f9 100644
--- a/app/views/refinery/blog/admin/comments/show.html.erb
+++ b/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>
diff --git a/config/routes.rb b/config/routes.rb
index fd7272d..011d451 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -32,6 +32,8 @@ Refinery::Core::Engine.routes.draw do
member do
get :approved
get :rejected
+ post :approve
+ post :reject
end
end
diff --git a/spec/controllers/refinery/blog/admin/comments_controller_spec.rb b/spec/controllers/refinery/blog/admin/comments_controller_spec.rb
new file mode 100644
index 0000000..dc7aef8
--- /dev/null
+++ b/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