Skip to content

Commit

Permalink
Action buttons partial and blog post logic
Browse files Browse the repository at this point in the history
  • Loading branch information
veezus committed Mar 2, 2009
1 parent 6e55945 commit 633618b
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 10 deletions.
5 changes: 5 additions & 0 deletions app/models/pitch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ def editable_by?(user)
end
end

def postable_by?(other_user)
return false if other_user.nil?
user == other_user || other_user.admin?
end

def current_funding
self[:current_funding] || 0
end
Expand Down
11 changes: 11 additions & 0 deletions app/views/pitches/_action_buttons.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- if pitch.editable_by?(current_user) || pitch.featureable_by?(current_user) || pitch.postable_by?(current_user)
.block-spacer-negative
- if pitch.editable_by?(current_user)
.centered= link_to image_tag("edit_this_pitch_b.png"), edit_pitch_path(pitch)
- if pitch.featureable_by?(current_user)
- if pitch.featured?
.centered= link_to image_tag('un-feature.gif'), unfeature_pitch_path(pitch), :method => :put
- else
.centered= link_to image_tag('feature_this_pitch.png'), feature_pitch_path(pitch), :method => :put
- if pitch.postable_by?(current_user)
= link_to image_tag('make_blog_post.gif'), new_pitch_post_path(pitch)
10 changes: 0 additions & 10 deletions app/views/pitches/_keywords.html.haml
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
%h3 Keywords
.double_content_border
%p= h pitch.keywords
- if pitch.editable_by?(current_user)
.block-spacer-negative
.centered= link_to image_tag("edit_this_pitch_b.png"), edit_pitch_path(pitch)
- if pitch.featureable_by?(current_user)
- if pitch.featured?
.block-spacer-negative
.centered= link_to 'Un-feature this pitch', unfeature_pitch_path(pitch), :method => :put
- else
.block-spacer-negative
.centered= link_to image_tag('feature_this_pitch.png'), feature_pitch_path(pitch), :method => :put
1 change: 1 addition & 0 deletions app/views/pitches/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
= link_to h(tip.headline), tip_url(tip)
- else
%p No related Tips yet. Stay tuned.
= render :partial => 'action_buttons', :locals => {:pitch => @pitch}
= render :partial => 'posts', :locals => {:pitch => @pitch}
.block-spacer-negative
= render :partial => 'keywords', :locals => {:pitch => @pitch}
Expand Down
Binary file added public/images/make_blog_post.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/un-feature.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions spec/models/pitch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -554,5 +554,23 @@
end
end
end

describe "#postable_by?" do
before do
@pitch = Factory(:pitch)
end
it "should return true if the passed in user is the reporter" do
@pitch.postable_by?(@pitch.user).should be_true
end
it "should return true if the passed in user is an admin" do
@pitch.postable_by?(Factory(:admin)).should be_true
end
it "should return false otherwise" do
@pitch.postable_by?(Factory(:user)).should be_false
end
it "should return false if the passed in user is nil" do
@pitch.postable_by?(nil).should be_false
end
end
end

12 changes: 12 additions & 0 deletions spec/views/pitches/show.html.haml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@
template.should_not have_tag('a[href$=?]', edit_pitch_path(@pitch))
end

it "should have a make a blog post button if the user is allowed to" do
@pitch.stub!(:postable_by?).and_return(true)
do_render
template.should have_tag('a[href=?]', new_pitch_post_path(@pitch))
end

it "should not have a make a blog post button if the user isn't allowed to" do
@pitch.stub!(:postable_by?).and_return(false)
do_render
template.should_not have_tag('a[href=?]', new_pitch_post_path(@pitch))
end

it "should render short description" do
do_render
template.should have_tag('p', /#{@pitch.short_description}/i)
Expand Down

0 comments on commit 633618b

Please sign in to comment.