Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
add is_comment_type method + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mickey committed Dec 6, 2010
1 parent 053c0d9 commit fd99784
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/comment_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def self.included(comment_model)
comment_model.scope :recent, comment_model.order('created_at DESC')
end

def is_comment_type?(type)
type.to_s == role.singularize.to_s
end

module Finders
# Helper class method to lookup all comments assigned
# to all commentable types for a given user.
Expand All @@ -32,11 +36,6 @@ def find_commentable(commentable_str, commentable_id)
model = commentable_str.constantize
model.respond_to?(:find_comments_for) ? model.find(commentable_id) : nil
end

def is_comment_type?(type)
type.to_s == role.ro_s
end

end
end
end
18 changes: 18 additions & 0 deletions test/acts_as_commentable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,22 @@ def test_add_comment
assert_equal [public_comment], wall.public_comments
end

def test_is_comment_type
post = Post.create(:text => "Awesome post !")
comment = Comment.new(:title => "First Comment", :comment => 'Super comment')
post.add_comment(comment)
assert_equal true, comment.is_comment_type?(:comment)

wall = Wall.create(:name => "wall")
private_comment = Comment.new(:title => "First Comment", :comment => 'Super comment')
wall.add_private_comment(private_comment)
assert_equal true, private_comment.is_comment_type?(:private)

public_comment = Comment.new(:title => "First Comment", :comment => 'Super comment')
wall.add_public_comment(public_comment)
assert_equal true, public_comment.is_comment_type?(:public)
assert_equal false, public_comment.is_comment_type?(:comment)

end

end

0 comments on commit fd99784

Please sign in to comment.