From 2e3b5aad49f037213089f11603e8cdfc1be72c2c Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 19 Sep 2017 01:22:30 +0200 Subject: [PATCH] Totally remove Poll::FinalRecount model, table spec and factory --- .rubocop_todo.yml | 1 - app/models/poll/final_recount.rb | 19 --------- ...170918231410_remove_poll_final_recounts.rb | 11 +++++ db/schema.rb | 18 +-------- spec/factories.rb | 7 ---- spec/models/poll/final_recount_spec.rb | 40 ------------------- 6 files changed, 12 insertions(+), 84 deletions(-) delete mode 100644 app/models/poll/final_recount.rb create mode 100644 db/migrate/20170918231410_remove_poll_final_recounts.rb delete mode 100644 spec/models/poll/final_recount_spec.rb diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 4704696e5..288c964c1 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -283,7 +283,6 @@ Lint/ParenthesesAsGroupedExpression: # Cop supports --auto-correct. Lint/StringConversionInInterpolation: Exclude: - - 'app/models/poll/final_recount.rb' - 'app/models/poll/null_result.rb' - 'app/models/poll/partial_result.rb' - 'app/models/poll/white_result.rb' diff --git a/app/models/poll/final_recount.rb b/app/models/poll/final_recount.rb deleted file mode 100644 index 3647c85ca..000000000 --- a/app/models/poll/final_recount.rb +++ /dev/null @@ -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 \ No newline at end of file diff --git a/db/migrate/20170918231410_remove_poll_final_recounts.rb b/db/migrate/20170918231410_remove_poll_final_recounts.rb new file mode 100644 index 000000000..369a959bb --- /dev/null +++ b/db/migrate/20170918231410_remove_poll_final_recounts.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 45598ff4e..240abcdaa 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # 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 enable_extension "plpgsql" @@ -586,20 +586,6 @@ ActiveRecord::Schema.define(version: 20170914154743) 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: "" - 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| t.integer "author_id" t.integer "amount" @@ -1101,8 +1087,6 @@ ActiveRecord::Schema.define(version: 20170914154743) do add_foreign_key "organizations", "users" add_foreign_key "poll_answers", "poll_questions", column: "question_id" 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_officer_assignments", column: "officer_assignment_id" add_foreign_key "poll_officer_assignments", "poll_booth_assignments", column: "booth_assignment_id" diff --git a/spec/factories.rb b/spec/factories.rb index b1c6e7174..b90f68175 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -507,13 +507,6 @@ FactoryGirl.define do date Date.current 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 poll association :user, :level_two diff --git a/spec/models/poll/final_recount_spec.rb b/spec/models/poll/final_recount_spec.rb deleted file mode 100644 index bccd772ca..000000000 --- a/spec/models/poll/final_recount_spec.rb +++ /dev/null @@ -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 \ No newline at end of file