diff --git a/app/models/poll/recount.rb b/app/models/poll/recount.rb index 97a909d1f..74a6fe937 100644 --- a/app/models/poll/recount.rb +++ b/app/models/poll/recount.rb @@ -1,6 +1,6 @@ class Poll::Recount < ActiveRecord::Base - VALID_ORIGINS = %w{ web booth letter } + VALID_ORIGINS = %w{web booth letter}.freeze belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' belongs_to :booth_assignment @@ -22,7 +22,7 @@ class Poll::Recount < ActiveRecord::Base [:white, :null, :total].each do |amount| next unless send("#{amount}_amount_changed?") && send("#{amount}_amount_was").present? - self["#{amount}_amount_log"] += ":#{send("#{amount}_amount_was").to_s}" + self["#{amount}_amount_log"] += ":#{send("#{amount}_amount_was")}" amounts_changed = true end @@ -30,7 +30,7 @@ class Poll::Recount < ActiveRecord::Base end def update_officer_author - self.officer_assignment_id_log += ":#{officer_assignment_id_was.to_s}" - self.author_id_log += ":#{author_id_was.to_s}" + self.officer_assignment_id_log += ":#{officer_assignment_id_was}" + self.author_id_log += ":#{author_id_was}" end end diff --git a/spec/models/poll/recount_spec.rb b/spec/models/poll/recount_spec.rb index 1ca0b41eb..2a5ed16a7 100644 --- a/spec/models/poll/recount_spec.rb +++ b/spec/models/poll/recount_spec.rb @@ -3,7 +3,9 @@ require 'rails_helper' describe Poll::Recount do describe "logging changes" do - let(:poll_recount) { create(:poll_recount) } + let(:author) { create(:user) } + let(:officer_assignment) { create(:poll_officer_assignment) } + let(:poll_recount) { create(:poll_recount, author: author, officer_assignment: officer_assignment) } it "should update white_amount_log if white_amount changes" do poll_recount.white_amount = 33 @@ -17,7 +19,7 @@ describe Poll::Recount do poll_recount.white_amount = 34 poll_recount.save - expect(poll_recount.white_amount_log).to eq(":33:32") + expect(poll_recount.white_amount_log).to eq(":0:33:32") end it "should update null_amount_log if null_amount changes" do @@ -32,7 +34,7 @@ describe Poll::Recount do poll_recount.null_amount = 34 poll_recount.save - expect(poll_recount.null_amount_log).to eq(":33:32") + expect(poll_recount.null_amount_log).to eq(":0:33:32") end it "should update total_amount_log if total_amount changes" do @@ -47,7 +49,7 @@ describe Poll::Recount do poll_recount.total_amount = 34 poll_recount.save - expect(poll_recount.total_amount_log).to eq(":33:32") + expect(poll_recount.total_amount_log).to eq(":0:33:32") end it "should update officer_assignment_id_log if amount changes" do @@ -68,8 +70,8 @@ describe Poll::Recount do poll_recount.officer_assignment = create(:poll_officer_assignment, id: 103) poll_recount.save - expect(poll_recount.white_amount_log).to eq(":33:32") - expect(poll_recount.officer_assignment_id_log).to eq(":101:102") + expect(poll_recount.white_amount_log).to eq(":0:33:32") + expect(poll_recount.officer_assignment_id_log).to eq(":#{officer_assignment.id}:101:102") end it "should update author_id if amount changes" do @@ -78,24 +80,24 @@ describe Poll::Recount do expect(poll_recount.white_amount_log).to eq("") expect(poll_recount.author_id_log).to eq("") - author_A = create(:poll_officer).user - author_B = create(:poll_officer).user - author_C = create(:poll_officer).user + first_author = create(:poll_officer).user + second_author = create(:poll_officer).user + third_author = create(:poll_officer).user poll_recount.white_amount = 33 - poll_recount.author_id = author_A.id + poll_recount.author_id = first_author.id poll_recount.save! poll_recount.white_amount = 32 - poll_recount.author_id = author_B.id + poll_recount.author_id = second_author.id poll_recount.save! poll_recount.white_amount = 34 - poll_recount.author_id = author_C.id + poll_recount.author_id = third_author.id poll_recount.save! - expect(poll_recount.white_amount_log).to eq(":33:32") - expect(poll_recount.author_id_log).to eq(":#{author_A.id}:#{author_B.id}") + expect(poll_recount.white_amount_log).to eq(":0:33:32") + expect(poll_recount.author_id_log).to eq(":#{author.id}:#{first_author.id}:#{second_author.id}") end end