From 3f68c6726a91da5e869f735a8510cf3fa7f59113 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 23 Nov 2015 18:05:29 +0100 Subject: [PATCH] maintains responsible name when user is erased --- app/models/proposal.rb | 2 +- spec/models/proposal_spec.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/models/proposal.rb b/app/models/proposal.rb index 547a262a7..22fb55cbd 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -134,7 +134,7 @@ class Proposal < ActiveRecord::Base protected def set_responsible_name - if author && author.level_two_or_three_verified? + if author && author.document_number? self.responsible_name = author.document_number end end diff --git a/spec/models/proposal_spec.rb b/spec/models/proposal_spec.rb index 30f514a33..db9c356d0 100644 --- a/spec/models/proposal_spec.rb +++ b/spec/models/proposal_spec.rb @@ -97,6 +97,17 @@ describe Proposal do expect(proposal).to be_valid proposal.responsible_name = "12345678Z" end + + it "should not be updated when the author is deleted" do + author = create(:user, :level_three, document_number: "12345678Z") + proposal.author = author + proposal.save + + proposal.author.erase + + proposal.save + expect(proposal.responsible_name).to eq "12345678Z" + end end describe "tag_list" do