shows valuator description in admin edit form
This commit is contained in:
7
app/helpers/valuators_helper.rb
Normal file
7
app/helpers/valuators_helper.rb
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
module ValuatorsHelper
|
||||||
|
|
||||||
|
def valuator_label(valuator)
|
||||||
|
truncate([valuator.name, valuator.email, valuator.description].compact.join(' - '), length: 100)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -6,4 +6,8 @@ class Valuator < ActiveRecord::Base
|
|||||||
has_many :spending_proposals, through: :valuation_assignments
|
has_many :spending_proposals, through: :valuation_assignments
|
||||||
|
|
||||||
validates :user_id, presence: true, uniqueness: true
|
validates :user_id, presence: true, uniqueness: true
|
||||||
|
|
||||||
|
def description_or_email
|
||||||
|
description.present? ? description : email
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
<%= f.label :valuator_ids, t("admin.spending_proposals.edit.assigned_valuators") %>
|
<%= f.label :valuator_ids, t("admin.spending_proposals.edit.assigned_valuators") %>
|
||||||
|
|
||||||
<%= f.collection_check_boxes :valuator_ids, @valuators, :id, :email do |b| %>
|
<%= f.collection_check_boxes :valuator_ids, @valuators, :id, :email do |b| %>
|
||||||
<%= b.label(title: [b.object.name, b.object.description].compact.join(' : ')) { b.check_box + b.text} %>
|
<%= b.label(title: valuator_label(b.object)) { b.check_box + truncate(b.object.description_or_email, length: 60) } %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<p class="clear">
|
<p class="clear">
|
||||||
|
|||||||
18
spec/models/valuator_spec.rb
Normal file
18
spec/models/valuator_spec.rb
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
describe Valuator do
|
||||||
|
|
||||||
|
describe "#description_or_email" do
|
||||||
|
it "should return description if present" do
|
||||||
|
valuator = create(:valuator, description: "Urbanism manager")
|
||||||
|
|
||||||
|
expect(valuator.description_or_email).to eq("Urbanism manager")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return email if not description present" do
|
||||||
|
valuator = create(:valuator)
|
||||||
|
|
||||||
|
expect(valuator.description_or_email).to eq(valuator.email)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user