-
Notifications
You must be signed in to change notification settings - Fork 1
/
answer_test.rb
51 lines (39 loc) · 1.3 KB
/
answer_test.rb
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
require 'test_helper'
class AnswerTest < ActiveSupport::TestCase
def setup
@answer = answers(:one)
@answer_with_vote_info = Answer.with_vote_info(1).first
end
# validations
test "Validates presence of user" do
assert_presence_validation(@answer, :user)
end
test "Validates presence of question_id" do
assert_presence_validation(@answer, :question_id)
end
test "Validates presence of text" do
assert_presence_validation(@answer, :text)
end
# self.with_vote_info
test "with_vote_info returns vote_tally" do
assert(
@answer_with_vote_info.has_attribute?(:vote_tally),
"doesn't return vote_tally"
)
end
test "with_vote_info returns vote_tally as an integer string" do
vote_tally = @answer_with_vote_info.vote_tally
assert !vote_tally.empty?, "current_user_vote is empty"
assert vote_tally =~ /^\d*$/, "current_user_vote contains non-digits"
end
test "with_vote_info returns current_user_vote" do
assert(
@answer_with_vote_info.has_attribute?(:current_user_vote),
"doesn't return current_user_vote"
)
end
test "with_vote_info returns current_user_vote as an integer string" do
vote = @answer_with_vote_info.current_user_vote
assert ["-1", "0", "1"].include?(vote), "current_user_vote isn't in [-1, 0, 1]"
end
end