Change post vote value to boolean

This commit is contained in:
Rei
2014-01-16 20:34:41 +08:00
parent 5186ed5ce2
commit b55644c522
7 changed files with 24 additions and 18 deletions

View File

@@ -2,7 +2,7 @@ require 'test_helper'
class PostVoteTest < ActiveSupport::TestCase
test "should create post vote" do
vote = create(:post_vote, value: 'up')
vote = create(:post_vote, up: true)
assert_not_nil vote
assert_equal 'up', vote.value
assert vote.up?
@@ -12,12 +12,12 @@ class PostVoteTest < ActiveSupport::TestCase
post = create(:post)
assert_equal 0, post.votes
create(:post_vote, post: post, value: 'up')
create(:post_vote, post: post, up: true)
post.reload
assert_equal 1, post.votes_up
assert_equal 0, post.votes_down
create(:post_vote, post: post, value: 'down')
create(:post_vote, post: post, up: false)
post.reload
assert_equal 1, post.votes_up
assert_equal 1, post.votes_down
@@ -26,17 +26,17 @@ class PostVoteTest < ActiveSupport::TestCase
test "should inc post votes after vote update" do
post = create(:post)
vote = create(:post_vote, post: post, value: 'up')
vote = create(:post_vote, post: post, up: true)
post.reload
assert_equal 1, post.votes_up
assert_equal 0, post.votes_down
vote.update_attribute :value, 'down'
vote.update_attribute :up, false
post.reload
assert_equal 0, post.votes_up
assert_equal 1, post.votes_down
vote.update_attribute :value, 'up'
vote.update_attribute :up, true
post.reload
assert_equal 1, post.votes_up
assert_equal 0, post.votes_down