Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Action buttons for pitch approval; display status on myspot pitches i…

…ndex
  • Loading branch information...
commit e99ee785f0dfb0326273cddc85640535549a9e4f 1 parent a19d57a
@veezus veezus authored
View
41 '
@@ -0,0 +1,41 @@
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+
+describe Admin::PitchesController do
+ route_matches('/admin/pitches', :get, :controller => 'admin/pitches', :action => 'index')
+ route_matches('/admin/pitches/1/approve', :put, :controller => 'admin/pitches', :action => 'approve', :id => '1')
+ route_matches('/admin/pitches/1/unapprove', :put, :controller => 'admin/pitches', :action => 'unapprove', :id => '1')
+
+ before do
+ controller.stub!(:current_user).and_return(Factory(:admin))
+ end
+
+ describe "approve" do
+ before do
+ @pitch = Factory(:pitch)
+ controller.stub!(:redirect_to)
+ end
+ it "should set a flash message" do
+ put :approve, :id => @pitch.id
+ flash[:success].should_not be_nil
+ end
+ it "should redirect back" do
+ controller.should_receive(:redirect_to).with(:back)
+ put :approve, :id => @pitch.id
+ end
+ end
+
+ describe "unapprove" do
+ before do
+ @pitch = active_pitch
+ controller.stub!(:redirect_to)
+ end
+ it "should set a flash message" do
+ put :unapprove, :id => @pitch.id
+ flash[:success].should_not be_nil
+ end
+ it "should redirect back" do
+ controller.should_receive(:redirect_to).with(:back)
+ put :unapprove, :id => @pitch.id
+ end
+ end
+end
View
4 app/controllers/admin/pitches_controller.rb
@@ -22,13 +22,13 @@ def fact_checker_chooser
def approve
current_pitch.approve!
flash[:success] = "You have approved the pitch '#{current_pitch.headline}'!"
- redirect_to admin_pitches_path
+ redirect_to :back
end
def unapprove
current_pitch.unapprove!
flash[:success] = "You have un-approved the pitch '#{current_pitch.headline}'!"
- redirect_to admin_pitches_path
+ redirect_to :back
end
View
3  app/views/myspot/pitches/_pitch.html.haml
@@ -3,6 +3,9 @@
= link_to image_tag(pitch.featured_image.url(:thumb)), pitch_url(pitch)
PITCH:
= link_to h(pitch.headline), pitch_url(pitch)
+ - if pitch.unapproved?
+ %br/
+ .status{:id => pitch.id} Pending approval
%td.created= pitch.created_at.to_s(:date)
%td.donations
= render :partial => "shared/table_progress_bar", :locals => {:pitch => pitch}
View
4 app/views/pitches/_action_buttons.html.haml
@@ -2,9 +2,9 @@
.block-spacer-negative
- if pitch.approvable_by?(current_user)
- if pitch.unapproved?
- .centered= link_to image_tag("approve.gif"), approve_admin_pitch_path(pitch), :title => "Approve This Pitch"
+ .centered= link_to image_tag("approve.gif"), approve_admin_pitch_path(pitch), :method => :put, :title => "Approve This Pitch"
- elsif pitch.active?
- .centered= link_to image_tag("unapprove.gif"), unapprove_admin_pitch_path(pitch), :title => "Un-approve This Pitch"
+ .centered= link_to image_tag("unapprove.gif"), unapprove_admin_pitch_path(pitch), :method => :put, :title => "Un-approve This Pitch"
- if pitch.editable_by?(current_user)
.centered= link_to image_tag("edit_this_pitch_b.png"), edit_pitch_path(pitch), :title => "Edit This Pitch"
View
4 public/stylesheets/screen_spotus.css
@@ -1134,3 +1134,7 @@ a.prev{
padding: 5px 0 5px 245px;
background-color:#FFFFCC;
}
+.pitches .status {
+ color:#990000;
+ font-weight: bold;
+}
View
34 spec/controllers/admin/pitches_controller_spec.rb
@@ -4,4 +4,38 @@
route_matches('/admin/pitches', :get, :controller => 'admin/pitches', :action => 'index')
route_matches('/admin/pitches/1/approve', :put, :controller => 'admin/pitches', :action => 'approve', :id => '1')
route_matches('/admin/pitches/1/unapprove', :put, :controller => 'admin/pitches', :action => 'unapprove', :id => '1')
+
+ before do
+ controller.stub!(:current_user).and_return(Factory(:admin))
+ end
+
+ describe "approve" do
+ before do
+ @pitch = Factory(:pitch)
+ controller.stub!(:redirect_to)
+ end
+ it "should set a flash message" do
+ put :approve, :id => @pitch.id
+ flash[:success].should_not be_nil
+ end
+ it "should redirect back" do
+ controller.should_receive(:redirect_to).with(:back)
+ put :approve, :id => @pitch.id
+ end
+ end
+
+ describe "unapprove" do
+ before do
+ @pitch = active_pitch
+ controller.stub!(:redirect_to)
+ end
+ it "should set a flash message" do
+ put :unapprove, :id => @pitch.id
+ flash[:success].should_not be_nil
+ end
+ it "should redirect back" do
+ controller.should_receive(:redirect_to).with(:back)
+ put :unapprove, :id => @pitch.id
+ end
+ end
end
View
7 spec/views/myspot/pitches/index.html.haml_spec.rb
@@ -5,7 +5,7 @@
@user = Factory(:user)
@story = Factory(:story)
@pitch = Factory(:pitch, :user => @user, :story => @story)
- assigns[:pitches] = [@pitch]
+ assigns[:pitches] = [@pitch, active_pitch]
template.stub!(:current_user).and_return(@user)
end
@@ -18,6 +18,11 @@
response.should have_tag("a[href=?]", story_path(@story), "Go to story")
end
+ it "should display 'pending' if a pitch is awaiting approval" do
+ do_render
+ response.should have_tag(".status#?", @pitch.id, "Pending approval")
+ end
+
def do_render
render 'myspot/pitches/index'
end
Please sign in to comment.
Something went wrong with that request. Please try again.