From 6c998768e8e4a7f8dcd853140d8ceefaca06a946 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 3 Oct 2017 00:19:12 +0200 Subject: [PATCH 1/2] Fix Poll Recount model spec after default amount value added --- app/models/poll/recount.rb | 8 ++++---- spec/models/poll/recount_spec.rb | 24 ++++++++++++------------ 2 files changed, 16 insertions(+), 16 deletions(-) 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..bec531d96 100644 --- a/spec/models/poll/recount_spec.rb +++ b/spec/models/poll/recount_spec.rb @@ -17,7 +17,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 +32,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 +47,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,7 +68,7 @@ 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.white_amount_log).to eq(":0:33:32") expect(poll_recount.officer_assignment_id_log).to eq(":101:102") end @@ -78,24 +78,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(":#{first_author.id}:#{second_author.id}:#{third_author.id}") end end From ccb80ce96705551aec6b1707e87cc32233d8c375 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 3 Oct 2017 11:40:36 +0200 Subject: [PATCH 2/2] Fix recount spec to take into account already existing values and mandatory officer_assigment --- spec/models/poll/recount_spec.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spec/models/poll/recount_spec.rb b/spec/models/poll/recount_spec.rb index bec531d96..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 @@ -69,7 +71,7 @@ describe Poll::Recount do poll_recount.save expect(poll_recount.white_amount_log).to eq(":0:33:32") - expect(poll_recount.officer_assignment_id_log).to eq(":101:102") + expect(poll_recount.officer_assignment_id_log).to eq(":#{officer_assignment.id}:101:102") end it "should update author_id if amount changes" do @@ -95,7 +97,7 @@ describe Poll::Recount do poll_recount.save! expect(poll_recount.white_amount_log).to eq(":0:33:32") - expect(poll_recount.author_id_log).to eq(":#{first_author.id}:#{second_author.id}:#{third_author.id}") + expect(poll_recount.author_id_log).to eq(":#{author.id}:#{first_author.id}:#{second_author.id}") end end