From 8ca4cc22b078fb267cd00a8e2d014e2d669e5691 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 8 Feb 2017 14:55:44 +0100 Subject: [PATCH] Adds specs for creating failed officing census calls --- app/controllers/officing/residence_controller.rb | 4 ++-- spec/features/officing/residence_spec.rb | 12 ++++++++++-- spec/models/officing/residence_spec.rb | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/app/controllers/officing/residence_controller.rb b/app/controllers/officing/residence_controller.rb index 708d59109..9f24d3a90 100644 --- a/app/controllers/officing/residence_controller.rb +++ b/app/controllers/officing/residence_controller.rb @@ -8,7 +8,7 @@ class Officing::ResidenceController < Officing::BaseController end def create - @residence = Officing::Residence.new(residence_params) + @residence = Officing::Residence.new(residence_params.merge(officer: current_user.poll_officer)) if @residence.save redirect_to new_officing_voter_path(id: @residence.user.id), notice: t("officing.residence.flash.create") else @@ -34,4 +34,4 @@ class Officing::ResidenceController < Officing::BaseController redirect_to officing_root_path, notice: t("officing.residence.flash.not_allowed") end end -end \ No newline at end of file +end diff --git a/spec/features/officing/residence_spec.rb b/spec/features/officing/residence_spec.rb index b40eb8ca0..69ffd9d21 100644 --- a/spec/features/officing/residence_spec.rb +++ b/spec/features/officing/residence_spec.rb @@ -52,10 +52,11 @@ feature 'Residence' do end click_button 'Validate document' - expect(page).to have_content /\d errors? prevented the verification of this document/ + expect(page).to have_content(/\d errors? prevented the verification of this document/) end scenario "Error on Census (document number)" do + initial_failed_census_calls_count = officer.failed_census_calls_count within("#side_menu") do click_link "Validate document" end @@ -67,6 +68,13 @@ feature 'Residence' do click_button 'Validate document' expect(page).to have_content 'The Census was unable to verify this document' + + officer.reload + fcc = FailedCensusCall.last + expect(fcc).to be + expect(fcc.poll_officer).to eq(officer) + expect(officer.failed_census_calls.last).to eq(fcc) + expect(officer.failed_census_calls_count).to eq(initial_failed_census_calls_count + 1) end scenario "Error on Census (year of birth)" do @@ -85,4 +93,4 @@ feature 'Residence' do end -end \ No newline at end of file +end diff --git a/spec/models/officing/residence_spec.rb b/spec/models/officing/residence_spec.rb index a9052fedc..208122703 100644 --- a/spec/models/officing/residence_spec.rb +++ b/spec/models/officing/residence_spec.rb @@ -93,5 +93,19 @@ describe Officing::Residence do expect(user.geozone).to eq(geozone) end + it "stores failed census calls" do + residence = build(:officing_residence, :invalid, document_number: "12345678Z") + residence.save + + expect(FailedCensusCall.count).to eq(1) + expect(FailedCensusCall.first).to have_attributes({ + user_id: residence.user.id, + poll_officer_id: residence.officer.id, + document_number: "12345678Z", + document_type: "1", + year_of_birth: Time.current.year + }) + end + end end