Skip to content

Commit

Permalink
Action buttons for pitch approval; display status on myspot pitches i…
Browse files Browse the repository at this point in the history
…ndex
  • Loading branch information
veezus committed Mar 10, 2009
1 parent a19d57a commit e99ee78
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 5 deletions.
41 changes: 41 additions & 0 deletions '
@@ -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
4 changes: 2 additions & 2 deletions app/controllers/admin/pitches_controller.rb
Expand Up @@ -22,13 +22,13 @@ def fact_checker_chooser
def approve def approve
current_pitch.approve! current_pitch.approve!
flash[:success] = "You have approved the pitch '#{current_pitch.headline}'!" flash[:success] = "You have approved the pitch '#{current_pitch.headline}'!"
redirect_to admin_pitches_path redirect_to :back
end end


def unapprove def unapprove
current_pitch.unapprove! current_pitch.unapprove!
flash[:success] = "You have un-approved the pitch '#{current_pitch.headline}'!" flash[:success] = "You have un-approved the pitch '#{current_pitch.headline}'!"
redirect_to admin_pitches_path redirect_to :back
end end




Expand Down
3 changes: 3 additions & 0 deletions app/views/myspot/pitches/_pitch.html.haml
Expand Up @@ -3,6 +3,9 @@
= link_to image_tag(pitch.featured_image.url(:thumb)), pitch_url(pitch) = link_to image_tag(pitch.featured_image.url(:thumb)), pitch_url(pitch)
PITCH: PITCH:
= link_to h(pitch.headline), pitch_url(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.created= pitch.created_at.to_s(:date)
%td.donations %td.donations
= render :partial => "shared/table_progress_bar", :locals => {:pitch => pitch} = render :partial => "shared/table_progress_bar", :locals => {:pitch => pitch}
Expand Down
4 changes: 2 additions & 2 deletions app/views/pitches/_action_buttons.html.haml
Expand Up @@ -2,9 +2,9 @@
.block-spacer-negative .block-spacer-negative
- if pitch.approvable_by?(current_user) - if pitch.approvable_by?(current_user)
- if pitch.unapproved? - 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? - 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) - if pitch.editable_by?(current_user)
.centered= link_to image_tag("edit_this_pitch_b.png"), edit_pitch_path(pitch), :title => "Edit This Pitch" .centered= link_to image_tag("edit_this_pitch_b.png"), edit_pitch_path(pitch), :title => "Edit This Pitch"
Expand Down
4 changes: 4 additions & 0 deletions public/stylesheets/screen_spotus.css
Expand Up @@ -1134,3 +1134,7 @@ a.prev{
padding: 5px 0 5px 245px; padding: 5px 0 5px 245px;
background-color:#FFFFCC; background-color:#FFFFCC;
} }
.pitches .status {
color:#990000;
font-weight: bold;
}
34 changes: 34 additions & 0 deletions spec/controllers/admin/pitches_controller_spec.rb
Expand Up @@ -4,4 +4,38 @@
route_matches('/admin/pitches', :get, :controller => 'admin/pitches', :action => 'index') 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/approve', :put, :controller => 'admin/pitches', :action => 'approve', :id => '1')
route_matches('/admin/pitches/1/unapprove', :put, :controller => 'admin/pitches', :action => 'unapprove', :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 end
7 changes: 6 additions & 1 deletion spec/views/myspot/pitches/index.html.haml_spec.rb
Expand Up @@ -5,7 +5,7 @@
@user = Factory(:user) @user = Factory(:user)
@story = Factory(:story) @story = Factory(:story)
@pitch = Factory(:pitch, :user => @user, :story => @story) @pitch = Factory(:pitch, :user => @user, :story => @story)
assigns[:pitches] = [@pitch] assigns[:pitches] = [@pitch, active_pitch]
template.stub!(:current_user).and_return(@user) template.stub!(:current_user).and_return(@user)
end end


Expand All @@ -18,6 +18,11 @@
response.should have_tag("a[href=?]", story_path(@story), "Go to story") response.should have_tag("a[href=?]", story_path(@story), "Go to story")
end 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 def do_render
render 'myspot/pitches/index' render 'myspot/pitches/index'
end end
Expand Down

0 comments on commit e99ee78

Please sign in to comment.