Changes the way question#copy_attributes_from_proposal works

This commit is contained in:
kikito
2016-11-11 19:11:53 +01:00
parent e5e3fe32da
commit 38efad77f3
3 changed files with 8 additions and 3 deletions

View File

@@ -43,7 +43,8 @@ class Poll::Question < ActiveRecord::Base
self.description = proposal.description
self.summary = proposal.summary
self.question = proposal.question
self.geozones = Geozone.all
self.all_geozones = true
self.valid_answers = I18n.t('poll_questions.default_valid_answers')
end
end
@@ -56,9 +57,10 @@ class Poll::Question < ActiveRecord::Base
where(poll_id: Poll.answerable_by(user).pluck(:id))
.joins('LEFT OUTER JOIN "geozones_poll_questions" ON "geozones_poll_questions"."question_id" = "poll_questions"."id"')
.where('(poll_questions.all_geozones = ? or geozones_poll_questions.geozone_id = ?)',
.where('(poll_questions.all_geozones = ? OR geozones_poll_questions.geozone_id = ?)',
true,
user.geozone_id || -1) # user.geozone_id can be nil, which would throw errors on sql
.distinct
end
end

View File

@@ -385,6 +385,8 @@ en:
cant_answer_incoming: "This poll has not yet started."
cant_answer_expired: "This poll has finished."
cant_answer_wrong_geozone: "The following questions are not available in your geozone."
poll_questions:
default_valid_answers: "Yes, No"
proposal_ballots:
title: "Votings"
description_html: "The following citizen proposals that have reached the <strong>required supports</strong> and will be voted."

View File

@@ -15,12 +15,13 @@ RSpec.describe Poll::Question, type: :model do
p = create(:proposal)
q = create(:poll_question)
q.copy_attributes_from_proposal(p)
expect(q.valid_answers).to eq(['Yes', 'No'])
expect(q.author).to eq(p.author)
expect(q.author_visible_name).to eq(p.author.name)
expect(q.proposal_id).to eq(p.id)
expect(q.title).to eq(p.title)
expect(q.question).to eq(p.question)
expect(q.geozones).to eq(Geozone.all)
expect(q.all_geozones).to be_true
end
end