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:
@@ -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
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddUserDataLogToPollOfficerAssignments < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :poll_officer_assignments, :user_data_log, :string, default: ""
|
||||
end
|
||||
end
|
||||
@@ -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|
|
||||
|
||||
12
spec/models/poll/officer_assignment_spec.rb
Normal file
12
spec/models/poll/officer_assignment_spec.rb
Normal 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
|
||||
Reference in New Issue
Block a user