updates the sp responsible_name when creating/editing a sp

This commit is contained in:
kikito
2016-04-06 19:23:05 +02:00
parent 3c8416e863
commit 32a60515c6
2 changed files with 14 additions and 0 deletions

View File

@@ -36,6 +36,8 @@ class SpendingProposal < ActiveRecord::Base
scope :for_render, -> { includes(:geozone) }
before_validation :update_responsible_name
def description
super.try :html_safe
end
@@ -120,4 +122,8 @@ class SpendingProposal < ActiveRecord::Base
end
end
def update_responsible_name
self.responsible_name = author.try(:username)
end
end

View File

@@ -261,4 +261,12 @@ describe SpendingProposal do
end
end
describe "responsible_name" do
it "gets updated with the user name" do
u = create(:user, username: "manolo")
sp = create(:spending_proposal, author: u)
expect(sp.responsible_name).to eq("manolo")
end
end
end