From f66b4a64a35482116aec45e1fae75b81006bfc0a Mon Sep 17 00:00:00 2001 From: Skud Date: Fri, 8 Feb 2013 14:22:49 +1100 Subject: [PATCH] added comment button to posts --- app/models/ability.rb | 8 ++++++-- app/views/posts/_single.html.haml | 4 ++++ spec/views/posts/show.html.haml_spec.rb | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/app/models/ability.rb b/app/models/ability.rb index d80864758..19c89e177 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -20,12 +20,16 @@ class Ability can :update, ScientificName can :destroy, ScientificName - # anyone can create a post, but only the author can edit/destroy - # it. + # anyone can create a post, or comment on a post, + # but only the author can edit/destroy it. can :create, Post can :update, Post, :author_id => member.id can :destroy, Post, :author_id => member.id + can :create, Comment + can :update, Comment, :author_id => member.id + can :destroy, Comment, :author_id => member.id + # same deal for gardens and plantings can :create, Garden can :update, Garden, :owner_id => member.id diff --git a/app/views/posts/_single.html.haml b/app/views/posts/_single.html.haml index fa6c40f3e..f8d31f2fb 100644 --- a/app/views/posts/_single.html.haml +++ b/app/views/posts/_single.html.haml @@ -24,3 +24,7 @@ - if can? :destroy, post = link_to 'Delete', post, method: :delete, | data: { confirm: 'Are you sure?' }, :class => 'btn' + + - if can? :create, Comment + .post-actions + =link_to 'Comment', new_comment_path(), :class => 'btn' diff --git a/spec/views/posts/show.html.haml_spec.rb b/spec/views/posts/show.html.haml_spec.rb index d42cff34a..6a4cf0039 100644 --- a/spec/views/posts/show.html.haml_spec.rb +++ b/spec/views/posts/show.html.haml_spec.rb @@ -34,4 +34,19 @@ describe "posts/show" do rendered.should_not match(/a href="http:\/\/evil.com"/) end + context "signed in" do + before(:each) do + sign_in @author + controller.stub(:current_user) { @author } + @post = assign(:post, + FactoryGirl.create(:post, :author => @author)) + render + end + + it 'shows a comment button' do + assert_select "a[href=#{new_comment_path}]", "Comment" + end + + end + end