Skip to content

Commit

Permalink
Remove officing results date picker for current date
Browse files Browse the repository at this point in the history
  • Loading branch information
bertocq committed Oct 17, 2017
1 parent da95d29 commit 04910fe
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 33 deletions.
16 changes: 6 additions & 10 deletions app/controllers/officing/results_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Officing::ResultsController < Officing::BaseController
before_action :load_partial_results, only: :new

before_action :load_officer_assignment, only: :create
before_action :check_booth_and_date, only: :create
before_action :check_officer_assignment, only: :create
before_action :build_results, only: :create

def new
Expand All @@ -32,13 +32,9 @@ def index

private

def check_booth_and_date
def check_officer_assignment
if @officer_assignment.blank?
go_back_to_new(t("officing.results.flash.error_wrong_booth"))
elsif results_params[:date].blank? ||
Date.parse(results_params[:date]) < @poll.starts_at.to_date ||
Date.parse(results_params[:date]) > @poll.ends_at.to_date
go_back_to_new(t("officing.results.flash.error_wrong_date"))
end
end

Expand All @@ -55,7 +51,7 @@ def build_results
go_back_to_new if question.blank?

partial_result = ::Poll::PartialResult.find_or_initialize_by(booth_assignment_id: @officer_assignment.booth_assignment_id,
date: results_params[:date],
date: Date.current,
question_id: question_id,
answer: answer)
partial_result.officer_assignment_id = @officer_assignment.id
Expand All @@ -71,7 +67,7 @@ def build_results

def build_recounts
recount = ::Poll::Recount.find_or_initialize_by(booth_assignment_id: @officer_assignment.booth_assignment_id,
date: results_params[:date])
date: Date.current)
recount.officer_assignment_id = @officer_assignment.id
recount.author = current_user
recount.origin = 'booth'
Expand All @@ -84,7 +80,7 @@ def build_recounts
end

def go_back_to_new(alert = nil)
params[:d] = results_params[:date]
params[:d] = Date.current
params[:oa] = results_params[:officer_assignment_id]
flash.now[:alert] = (alert || t("officing.results.flash.error_create"))
load_officer_assignments
Expand Down Expand Up @@ -119,7 +115,7 @@ def load_partial_results
end

def results_params
params.permit(:officer_assignment_id, :date, :questions, :whites, :nulls, :total)
params.permit(:officer_assignment_id, :questions, :whites, :nulls, :total)
end

def index_params
Expand Down
11 changes: 0 additions & 11 deletions app/views/officing/results/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@
</div>
</div>

<div class="row">
<div class="small-12 medium-6 column">
<label><%= t("officing.results.new.date") %></label>
<%= select_tag :date,
poll_dates_select_options(@poll),
{ prompt: t("officing.results.new.select_date"),
label: false } %>
</div>
</div>

<% @poll.questions.each do |question| %>
<div class="row">
<div class="small-12 column">
Expand Down Expand Up @@ -101,4 +91,3 @@
</table>

<% end %>

2 changes: 0 additions & 2 deletions config/locales/en/officing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ en:
create: "Results saved"
error_create: "Results NOT saved. Error in data."
error_wrong_booth: "Wrong booth. Results NOT saved."
error_wrong_date: "Wrong date. Results NOT saved."
new:
title: "%{poll} - Add results"
not_allowed: "You are allowed to add results for this poll"
booth: "Booth"
date: "Date"
select_booth: "Select booth"
select_date: "Select date"
ballots_white: "Totally blank ballots"
ballots_null: "Invalid ballots"
ballots_total: "Total ballots"
Expand Down
4 changes: 1 addition & 3 deletions config/locales/es/officing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ es:
create: "Datos guardados"
error_create: "Resultados NO añadidos. Error en los datos"
error_wrong_booth: "Urna incorrecta. Resultados NO guardados."
error_wrong_date: "Fecha incorrecta. Resultados NO guardados."
new:
title: "%{poll} - Añadir resultados"
not_allowed: "No tienes permiso para introducir resultados"
booth: "Urna"
date: "Día"
select_booth: "Elige urna"
select_date: "Elige día"
ballots_white: "Papeletas totalmente en blanco"
ballots_null: "Papeletas nulas"
ballots_total: "Papeletas totales"
Expand Down Expand Up @@ -67,4 +65,4 @@ es:
submit: Confirmar voto
success: "¡Voto introducido!"
can_vote:
submit_disable_with: "Espera, confirmando voto..."
submit_disable_with: "Espera, confirmando voto..."
10 changes: 3 additions & 7 deletions spec/features/officing/results_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@
expect(page).to_not have_content('Your results')

booth_name = @officer_assignment.booth_assignment.booth.name
date = I18n.l(@poll.starts_at.to_date, format: :long)
select booth_name, from: 'officer_assignment_id'
select date, from: 'date'

fill_in "questions[#{@question_1.id}][0]", with: '100'
fill_in "questions[#{@question_1.id}][1]", with: '200'
Expand All @@ -71,8 +69,8 @@

expect(page).to have_content('Your results')

within("#results_#{@officer_assignment.booth_assignment_id}_#{@poll.starts_at.to_date.strftime('%Y%m%d')}") do
expect(page).to have_content(date)
within("#results_#{@officer_assignment.booth_assignment_id}_#{Date.current.strftime('%Y%m%d')}") do
expect(page).to have_content(I18n.l(Date.current, format: :long))
expect(page).to have_content(booth_name)
end
end
Expand All @@ -81,7 +79,7 @@
partial_result = create(:poll_partial_result,
officer_assignment: @officer_assignment,
booth_assignment: @officer_assignment.booth_assignment,
date: @poll.starts_at,
date: Date.current,
question: @question_1,
answer: @question_1.valid_answers[0],
author: @poll_officer.user,
Expand All @@ -94,9 +92,7 @@
visit new_officing_poll_result_path(@poll)

booth_name = partial_result.booth_assignment.booth.name
date = I18n.l(partial_result.date, format: :long)
select booth_name, from: 'officer_assignment_id'
select date, from: 'date'

fill_in "questions[#{@question_1.id}][0]", with: '5555'
fill_in "questions[#{@question_1.id}][1]", with: '200'
Expand Down

0 comments on commit 04910fe

Please sign in to comment.