updates the sp responsible_name when creating/editing a sp
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user