removes answer <-> voter association
This commit is contained in:
@@ -3,8 +3,6 @@ class Poll::Answer < ActiveRecord::Base
|
||||
belongs_to :question, -> { with_hidden }
|
||||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
||||
|
||||
has_one :voter
|
||||
|
||||
delegate :poll, :poll_id, to: :question
|
||||
|
||||
validates :question, presence: true
|
||||
@@ -16,6 +14,6 @@ class Poll::Answer < ActiveRecord::Base
|
||||
scope :by_question, -> (question_id) { where(question_id: question_id) }
|
||||
|
||||
def record_voter_participation
|
||||
Poll::Voter.create_from_user(author, {poll_id: poll_id, answer_id: id})
|
||||
Poll::Voter.create_from_user(author, {poll_id: poll_id})
|
||||
end
|
||||
end
|
||||
@@ -2,7 +2,6 @@ class Poll
|
||||
class Voter < ActiveRecord::Base
|
||||
belongs_to :poll
|
||||
belongs_to :booth_assignment
|
||||
belongs_to :answer
|
||||
|
||||
validates :poll, presence: true
|
||||
validates :document_number, presence: true, uniqueness: { scope: [:poll_id, :document_type], message: :has_voted }
|
||||
@@ -26,7 +25,6 @@ class Poll
|
||||
def self.create_from_user(user, options = {})
|
||||
poll_id = options[:poll_id]
|
||||
booth_assignment_id = options[:booth_assignment_id]
|
||||
answer_id = options[:answer_id]
|
||||
|
||||
Voter.create(
|
||||
document_type: user.document_type,
|
||||
@@ -35,8 +33,7 @@ class Poll
|
||||
booth_assignment_id: booth_assignment_id,
|
||||
gender: user.gender,
|
||||
geozone_id: user.geozone_id,
|
||||
age: user.age,
|
||||
answer_id: answer_id
|
||||
age: user.age
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
@@ -87,9 +87,9 @@ feature 'Poll Questions' do
|
||||
expect(page).to have_link('Answer this question')
|
||||
end
|
||||
|
||||
scenario 'Records participarion', :js do
|
||||
scenario 'Records participation', :js do
|
||||
question = create(:poll_question, poll: poll, valid_answers: 'Han Solo, Chewbacca')
|
||||
user = create(:user, :level_two, geozone: geozone)
|
||||
user = create(:user, :level_two, geozone: geozone, gender: 'female', date_of_birth: 33.years.ago)
|
||||
|
||||
login_as user
|
||||
visit question_path(question)
|
||||
@@ -99,9 +99,12 @@ feature 'Poll Questions' do
|
||||
|
||||
expect(page).to_not have_link('Han Solo')
|
||||
|
||||
answer = Poll::Answer.by_question(question.id).by_author(user.id).first
|
||||
expect(answer.voter.document_number).to eq(user.document_number)
|
||||
expect(answer.voter.poll_id).to eq(poll.id)
|
||||
voter = poll.voters.first
|
||||
expect(voter.document_number).to eq(user.document_number)
|
||||
expect(voter.geozone_id).to eq(user.geozone_id)
|
||||
expect(voter.gender).to eq(user.gender)
|
||||
expect(voter.age).to eq(33)
|
||||
expect(voter.poll_id).to eq(poll.id)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -16,12 +16,12 @@ describe Poll::Answer do
|
||||
describe "#record_voter_participation" do
|
||||
it "creates a poll_voter with user and poll data" do
|
||||
answer = create(:poll_answer)
|
||||
expect(answer.voter).to be_nil
|
||||
expect(answer.poll.voters).to be_blank
|
||||
|
||||
answer.record_voter_participation
|
||||
voter = answer.reload.voter
|
||||
expect(answer.poll.reload.voters.size).to eq(1)
|
||||
voter = answer.poll.voters.first
|
||||
|
||||
expect(voter.answer).to eq(answer)
|
||||
expect(voter.document_number).to eq(answer.author.document_number)
|
||||
expect(voter.poll_id).to eq(answer.poll.id)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user