Merge pull request #1408 from consul/polls-failed-officing-census-calls
Polls failed officing census calls
This commit is contained in:
@@ -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
|
||||
end
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
class FailedCensusCall < ActiveRecord::Base
|
||||
belongs_to :user, counter_cache: true
|
||||
belongs_to :poll_officer, class_name: 'Poll::Officer', counter_cache: true
|
||||
end
|
||||
|
||||
@@ -41,6 +41,17 @@ class Officing::Residence
|
||||
end
|
||||
end
|
||||
|
||||
def store_failed_census_call
|
||||
FailedCensusCall.create({
|
||||
user: user,
|
||||
document_number: document_number,
|
||||
document_type: document_type,
|
||||
year_of_birth: year_of_birth,
|
||||
poll_officer: officer
|
||||
})
|
||||
|
||||
end
|
||||
|
||||
def user_exists?
|
||||
find_user_by_document.present?
|
||||
end
|
||||
@@ -54,6 +65,7 @@ class Officing::Residence
|
||||
return if errors.any?
|
||||
|
||||
unless residency_valid?
|
||||
store_failed_census_call
|
||||
errors.add(:residence_in_madrid, false)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,6 +2,7 @@ class Poll
|
||||
class Officer < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
has_many :officer_assignments, class_name: "Poll::OfficerAssignment"
|
||||
has_many :failed_census_calls, foreign_key: :poll_officer_id
|
||||
|
||||
validates :user_id, presence: true, uniqueness: true
|
||||
|
||||
@@ -22,4 +23,4 @@ class Poll
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
class AddOfficerIdToFailedCensusCalls < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :failed_census_calls, :poll_officer_id, :integer, index: true
|
||||
add_foreign_key :failed_census_calls, :poll_officers
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddFailedCensusCallsCountToPollOfficers < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :poll_officers, :failed_census_calls_count, :integer, default: 0
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddYearOfBirthToFailedCensusCalls < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :failed_census_calls, :year_of_birth, :integer
|
||||
end
|
||||
end
|
||||
@@ -282,6 +282,8 @@ ActiveRecord::Schema.define(version: 20170208160130) do
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "district_code"
|
||||
t.integer "poll_officer_id"
|
||||
t.integer "year_of_birth"
|
||||
end
|
||||
|
||||
add_index "failed_census_calls", ["user_id"], name: "index_failed_census_calls_on_user_id", using: :btree
|
||||
@@ -438,6 +440,7 @@ ActiveRecord::Schema.define(version: 20170208160130) do
|
||||
|
||||
create_table "poll_officers", force: :cascade do |t|
|
||||
t.integer "user_id"
|
||||
t.integer "failed_census_calls_count", default: 0
|
||||
end
|
||||
|
||||
create_table "poll_partial_results", force: :cascade do |t|
|
||||
@@ -842,6 +845,7 @@ ActiveRecord::Schema.define(version: 20170208160130) do
|
||||
add_foreign_key "administrators", "users"
|
||||
add_foreign_key "annotations", "legislations"
|
||||
add_foreign_key "annotations", "users"
|
||||
add_foreign_key "failed_census_calls", "poll_officers"
|
||||
add_foreign_key "failed_census_calls", "users"
|
||||
add_foreign_key "flags", "users"
|
||||
add_foreign_key "geozones_polls", "geozones"
|
||||
|
||||
@@ -478,9 +478,14 @@ FactoryGirl.define do
|
||||
|
||||
factory :officing_residence, class: 'Officing::Residence' do
|
||||
user
|
||||
association :officer, factory: :poll_officer
|
||||
document_number
|
||||
document_type "1"
|
||||
year_of_birth "1980"
|
||||
|
||||
trait :invalid do
|
||||
year_of_birth Time.current.year
|
||||
end
|
||||
end
|
||||
|
||||
factory :organization do
|
||||
|
||||
@@ -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
|
||||
end
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user