persists responsible name, even if the user is erased

This commit is contained in:
kikito
2016-04-11 12:21:11 +02:00
parent 5e19f33c49
commit 5fec3b9858
2 changed files with 12 additions and 4 deletions

View File

@@ -123,7 +123,7 @@ class SpendingProposal < ActiveRecord::Base
end
def set_responsible_name
self.responsible_name = author.try(:document_number)
self.responsible_name = author.try(:document_number) if author.try(:document_number).present?
end
end

View File

@@ -262,10 +262,18 @@ describe SpendingProposal do
end
describe "responsible_name" do
let(:user) { create(:user, document_number: "123456") }
let!(:spending_proposal) { create(:spending_proposal, author: user) }
it "gets updated with the document_number" do
u = create(:user, document_number: "123456")
sp = create(:spending_proposal, author: u)
expect(sp.responsible_name).to eq("123456")
expect(spending_proposal.responsible_name).to eq("123456")
end
it "does not get updated if the user is erased" do
user.erase
expect(user.document_number).to be_blank
spending_proposal.touch
expect(spending_proposal.responsible_name).to eq("123456")
end
end