fixes #69: Comment voting non functional

This commit is contained in:
albert
2011-09-14 17:46:42 -04:00
parent fcc6a78fd4
commit 22074eed1f
10 changed files with 73 additions and 31 deletions

View File

@@ -22,8 +22,10 @@ class CommentVotesControllerTest < ActionController::TestCase
should "fail silently on errors" do
Factory.create(:comment_vote, :comment => @comment)
post :create, {:format => "js", :comment_id => @comment.id, :score => 1}, {:user_id => @user.id}
assert_response :error
assert_difference("CommentVote.count", 0) do
post :create, {:format => "js", :comment_id => @comment.id, :score => 1}, {:user_id => @user.id}
assert_response :success
end
end
end
end

View File

@@ -45,12 +45,15 @@ class CommentTest < ActiveSupport::TestCase
user = Factory.create(:user)
post = Factory.create(:post)
c1 = Factory.create(:comment, :post => post)
assert_nothing_raised {c1.vote!(true)}
assert_raise(CommentVote::Error) {c1.vote!(true)}
comment_vote = c1.vote!(true)
assert_equal([], comment_vote.errors.full_messages)
comment_vote = c1.vote!(true)
assert_equal(["User has already voted for this comment"], comment_vote.errors.full_messages)
assert_equal(1, CommentVote.count)
c2 = Factory.create(:comment, :post => post)
assert_nothing_raised {c2.vote!(true)}
comment_vote = c2.vote!(true)
assert_equal([], comment_vote.errors.full_messages)
assert_equal(2, CommentVote.count)
end

View File

@@ -206,6 +206,30 @@ class UserTest < ActiveSupport::TestCase
assert(User.authenticate(@user.name, new_pass), "Authentication should have succeeded")
end
should "not change the password if the password and old password are blank" do
@user = Factory.create(:user, :password => "67890")
@user.update_attributes(:password => "", :old_password => "")
assert_equal(User.sha1("67890"), @user.password_hash)
end
should "not change the password if the old password is incorrect" do
@user = Factory.create(:user, :password => "67890")
@user.update_attributes(:password => "12345", :old_password => "abcdefg")
assert_equal(User.sha1("67890"), @user.password_hash)
end
should "not change the password if the old password is blank" do
@user = Factory.create(:user, :password => "67890")
@user.update_attributes(:password => "12345", :old_password => "")
assert_equal(User.sha1("67890"), @user.password_hash)
end
should "change the password if the old password is correct" do
@user = Factory.create(:user, :password => "67890")
@user.update_attributes(:password => "12345", :old_password => "67890")
assert_equal(User.sha1("12345"), @user.password_hash)
end
context "in the json representation" do
setup do
@user = Factory.create(:user)