adds poll::final_recounts

This commit is contained in:
Juanjo Bazán
2017-01-30 11:36:49 +01:00
parent 886c179a71
commit 01d115dd7a
3 changed files with 47 additions and 1 deletions

View File

@@ -0,0 +1,19 @@
class Poll
class FinalRecount < ActiveRecord::Base
belongs_to :booth_assignment, class_name: "Poll::BoothAssignment"
belongs_to :officer_assignment, class_name: "Poll::OfficerAssignment"
validates :booth_assignment_id, presence: true
validates :officer_assignment_id, presence: true, uniqueness: {scope: :booth_assignment_id}
validates :count, presence: true, numericality: {only_integer: true}
before_save :update_logs
def update_logs
if self.count_changed? && self.count_was.present?
self.count_log += ":#{self.count_was.to_s}"
self.officer_assignment_id_log += ":#{self.officer_assignment_id_was.to_s}"
end
end
end
end

View File

@@ -0,0 +1,15 @@
class CreatePollFinalRecount < ActiveRecord::Migration
def change
create_table :poll_final_recounts do |t|
t.integer :booth_assignment_id
t.integer :officer_assignment_id
t.integer :count
t.text :count_log, default: ""
t.datetime :created_at, null: false
t.datetime :updated_at, null: false
t.text :officer_assignment_id_log, default: ""
end
add_index :poll_final_recounts, :booth_assignment_id
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: 20170128214244) do
ActiveRecord::Schema.define(version: 20170130101121) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -398,6 +398,18 @@ ActiveRecord::Schema.define(version: 20170128214244) do
t.string "location"
end
create_table "poll_final_recounts", force: :cascade do |t|
t.integer "booth_assignment_id"
t.integer "officer_assignment_id"
t.integer "count"
t.text "count_log", default: ""
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "officer_assignment_id_log", default: ""
end
add_index "poll_final_recounts", ["booth_assignment_id"], name: "index_poll_final_recounts_on_booth_assignment_id", using: :btree
create_table "poll_officer_assignments", force: :cascade do |t|
t.integer "booth_assignment_id"
t.integer "officer_id"