added comment button to posts

This commit is contained in:
Skud
2013-02-08 14:22:49 +11:00
parent a0a88bee11
commit f66b4a64a3
3 changed files with 25 additions and 2 deletions

View File

@@ -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

View File

@@ -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'

View File

@@ -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