Fix record_voter_participation and usage on specs

This commit is contained in:
Bertocq
2017-10-07 10:48:24 +02:00
parent 6a0197a61b
commit 9a396fe634
3 changed files with 6 additions and 8 deletions

View File

@@ -17,8 +17,6 @@ class Poll::Answer < ActiveRecord::Base
scope :by_question, ->(question_id) { where(question_id: question_id) }
def record_voter_participation(token)
Poll::Voter.find_or_create_by(user: author, poll: poll, origin: "web") do |poll_voter|
poll_voter.token = token unless poll_voter.token.present?
end
Poll::Voter.find_or_create_by(user: author, poll: poll, origin: "web", token: token)
end
end

View File

@@ -46,7 +46,7 @@ describe Poll::Answer do
answer = create(:poll_answer, question: question, author: author, answer: "Yes")
expect(answer.poll.voters).to be_blank
answer.record_voter_participation
answer.record_voter_participation('token')
expect(poll.reload.voters.size).to eq(1)
voter = poll.voters.first
@@ -57,12 +57,12 @@ describe Poll::Answer do
it "updates a poll_voter with user and poll data" do
answer = create(:poll_answer, question: question, author: author, answer: "Yes")
answer.record_voter_participation
answer.record_voter_participation('token')
expect(poll.reload.voters.size).to eq(1)
answer = create(:poll_answer, question: question, author: author, answer: "No")
answer.record_voter_participation
answer.record_voter_participation('token')
expect(poll.reload.voters.size).to eq(1)

View File

@@ -76,7 +76,7 @@ describe :voter do
it "should not be valid if the user has voted via web" do
answer = create(:poll_answer)
answer.record_voter_participation
answer.record_voter_participation('token')
voter = build(:poll_voter, poll: answer.question.poll, user: answer.author)
expect(voter).to_not be_valid
@@ -169,4 +169,4 @@ describe :voter do
expect(voter.document_type).to eq("1")
end
end
end
end