From 38efad77f31995a012a88c945ea18e0a67d66f89 Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 11 Nov 2016 19:11:53 +0100 Subject: [PATCH] Changes the way question#copy_attributes_from_proposal works --- app/models/poll/question.rb | 6 ++++-- config/locales/en.yml | 2 ++ spec/models/poll/question_spec.rb | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/models/poll/question.rb b/app/models/poll/question.rb index d56990f17..13245c384 100644 --- a/app/models/poll/question.rb +++ b/app/models/poll/question.rb @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index b032b5805..7c9abd2b9 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 required supports and will be voted." diff --git a/spec/models/poll/question_spec.rb b/spec/models/poll/question_spec.rb index 92e019027..6cb38d023 100644 --- a/spec/models/poll/question_spec.rb +++ b/spec/models/poll/question_spec.rb @@ -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