Totally remove Poll::FinalRecount model, table spec and factory

This commit is contained in:
Bertocq
2017-09-19 01:22:30 +02:00
parent a3bf69e78d
commit 2e3b5aad49
6 changed files with 12 additions and 84 deletions

View File

@@ -283,7 +283,6 @@ Lint/ParenthesesAsGroupedExpression:
# Cop supports --auto-correct. # Cop supports --auto-correct.
Lint/StringConversionInInterpolation: Lint/StringConversionInInterpolation:
Exclude: Exclude:
- 'app/models/poll/final_recount.rb'
- 'app/models/poll/null_result.rb' - 'app/models/poll/null_result.rb'
- 'app/models/poll/partial_result.rb' - 'app/models/poll/partial_result.rb'
- 'app/models/poll/white_result.rb' - 'app/models/poll/white_result.rb'

View File

@@ -1,19 +0,0 @@
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 :date, presence: true, uniqueness: {scope: :booth_assignment_id}
validates :count, presence: true, numericality: {only_integer: true}
before_save :update_logs
def update_logs
if count_changed? && count_was.present?
self.count_log += ":#{count_was.to_s}"
self.officer_assignment_id_log += ":#{officer_assignment_id_was.to_s}"
end
end
end
end

View File

@@ -0,0 +1,11 @@
class RemovePollFinalRecounts < ActiveRecord::Migration
def change
remove_index :poll_final_recounts, column: :booth_assignment_id
remove_index :poll_final_recounts, column: :officer_assignment_id
remove_foreign_key :poll_final_recounts, column: "booth_assignment_id"
remove_foreign_key :poll_final_recounts, column: "officer_assignment_id"
drop_table :poll_final_recounts
end
end

View File

@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170914154743) do ActiveRecord::Schema.define(version: 20170918231410) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@@ -586,20 +586,6 @@ ActiveRecord::Schema.define(version: 20170914154743) do
t.string "location" t.string "location"
end 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: ""
t.date "date", null: false
end
add_index "poll_final_recounts", ["booth_assignment_id"], name: "index_poll_final_recounts_on_booth_assignment_id", using: :btree
add_index "poll_final_recounts", ["officer_assignment_id"], name: "index_poll_final_recounts_on_officer_assignment_id", using: :btree
create_table "poll_null_results", force: :cascade do |t| create_table "poll_null_results", force: :cascade do |t|
t.integer "author_id" t.integer "author_id"
t.integer "amount" t.integer "amount"
@@ -1101,8 +1087,6 @@ ActiveRecord::Schema.define(version: 20170914154743) do
add_foreign_key "organizations", "users" add_foreign_key "organizations", "users"
add_foreign_key "poll_answers", "poll_questions", column: "question_id" add_foreign_key "poll_answers", "poll_questions", column: "question_id"
add_foreign_key "poll_booth_assignments", "polls" add_foreign_key "poll_booth_assignments", "polls"
add_foreign_key "poll_final_recounts", "poll_booth_assignments", column: "booth_assignment_id"
add_foreign_key "poll_final_recounts", "poll_officer_assignments", column: "officer_assignment_id"
add_foreign_key "poll_null_results", "poll_booth_assignments", column: "booth_assignment_id" add_foreign_key "poll_null_results", "poll_booth_assignments", column: "booth_assignment_id"
add_foreign_key "poll_null_results", "poll_officer_assignments", column: "officer_assignment_id" add_foreign_key "poll_null_results", "poll_officer_assignments", column: "officer_assignment_id"
add_foreign_key "poll_officer_assignments", "poll_booth_assignments", column: "booth_assignment_id" add_foreign_key "poll_officer_assignments", "poll_booth_assignments", column: "booth_assignment_id"

View File

@@ -507,13 +507,6 @@ FactoryGirl.define do
date Date.current date Date.current
end end
factory :poll_final_recount, class: 'Poll::FinalRecount' do
association :officer_assignment, factory: [:poll_officer_assignment, :final]
association :booth_assignment, factory: :poll_booth_assignment
count (1..100).to_a.sample
date (1.month.ago.to_datetime..1.month.from_now.to_datetime).to_a.sample
end
factory :poll_voter, class: 'Poll::Voter' do factory :poll_voter, class: 'Poll::Voter' do
poll poll
association :user, :level_two association :user, :level_two

View File

@@ -1,40 +0,0 @@
require 'rails_helper'
describe :final_recount do
it "should update count_log if count changes" do
final_recount = create(:poll_final_recount, count: 33)
expect(final_recount.count_log).to eq("")
final_recount.count = 33
final_recount.save
final_recount.count = 32
final_recount.save
final_recount.count = 34
final_recount.save
expect(final_recount.count_log).to eq(":33:32")
end
it "should update officer_assignment_id_log if count changes" do
final_recount = create(:poll_final_recount, count: 33)
expect(final_recount.count_log).to eq("")
final_recount.count = 33
final_recount.officer_assignment = create(:poll_officer_assignment, id: 111)
final_recount.save
final_recount.count = 32
final_recount.officer_assignment = create(:poll_officer_assignment, id: 112)
final_recount.save
final_recount.count = 34
final_recount.officer_assignment = create(:poll_officer_assignment, id: 113)
final_recount.save
expect(final_recount.officer_assignment_id_log).to eq(":111:112")
end
end