Fix Poll Recount model spec after default amount value added

This commit is contained in:
Bertocq
2017-10-03 00:19:12 +02:00
parent fbbbd38932
commit 6c998768e8
2 changed files with 16 additions and 16 deletions

View File

@@ -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

View File

@@ -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