comment_test.rb
1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require 'test_helper'
class CommentTest < ActiveSupport::TestCase
should 'vote in a comment' do
comment = create_comment
person = create_user('voter').person
person.vote(comment, 5)
assert_equal 1, comment.voters_who_voted.length
assert_equal 5, comment.votes_total
end
should 'like a comment' do
comment = create_comment
person = create_user('voter').person
assert !comment.voted_by?(person, true)
person.vote_for(comment)
assert comment.voted_by?(person, true)
assert !comment.voted_by?(person, false)
end
should 'count voters for' do
comment = create_comment
person = create_user('voter').person
person2 = create_user('voter2').person
person3 = create_user('voter3').person
person.vote_for(comment)
person2.vote_for(comment)
person3.vote_against(comment)
assert_equal 2, comment.votes_for
end
should 'count votes againts' do
comment = create_comment
person = create_user('voter').person
person2 = create_user('voter2').person
person3 = create_user('voter3').person
person.vote_against(comment)
person2.vote_against(comment)
person3.vote_for(comment)
assert_equal 2, comment.votes_against
end
should 'be able to remove a voted comment' do
comment = create_comment
person = create_user('voter').person
person.vote(comment, 5)
comment.destroy
end
private
def create_comment(args = {})
owner = create_user('testuser').person
article = create(TextileArticle, :profile_id => owner.id)
create(Comment, { :name => 'foo', :email => 'foo@example.com', :source => article }.merge(args))
end
end