logs user info in officer_assignments

In case user is no longer a poll officer, info on who did what is
stored in officer_assignment
This commit is contained in:
Juanjo Bazán
2017-02-08 15:50:13 +01:00
parent cb75be8f6a
commit d7000e399f
4 changed files with 25 additions and 1 deletions

View File

@@ -15,5 +15,11 @@ class Poll
scope :voting_days, -> { where(final: false) }
scope :final, -> { where(final: true) }
before_create :log_user_data
def log_user_data
self.user_data_log = "#{officer.user_id} - #{officer.user.name_and_email}"
end
end
end

View File

@@ -0,0 +1,5 @@
class AddUserDataLogToPollOfficerAssignments < ActiveRecord::Migration
def change
add_column :poll_officer_assignments, :user_data_log, :string, default: ""
end
end

View File

@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170203163317) do
ActiveRecord::Schema.define(version: 20170208114548) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -433,6 +433,7 @@ ActiveRecord::Schema.define(version: 20170203163317) do
t.datetime "updated_at", null: false
t.date "date", null: false
t.boolean "final", default: false
t.string "user_data_log", default: ""
end
create_table "poll_officers", force: :cascade do |t|

View File

@@ -0,0 +1,12 @@
require 'rails_helper'
describe :officer_assignment do
it "should log user data on creation" do
user = create(:user, username: "Larry Bird", email: "larry@lege.nd")
officer = create(:poll_officer, user: user)
oa = create(:poll_officer_assignment, officer: officer)
expect(oa.reload.user_data_log).to eq "#{user.id} - Larry Bird (larry@lege.nd)"
end
end