diff --git a/app/models/form/setup/questions/created_by_id.rb b/app/models/form/setup/questions/created_by_id.rb index eee7d9485..f32163a0f 100644 --- a/app/models/form/setup/questions/created_by_id.rb +++ b/app/models/form/setup/questions/created_by_id.rb @@ -13,8 +13,9 @@ class Form::Setup::Questions::CreatedById < ::Form::Question answer_opts = { "" => "Select an option" } return answer_opts unless ActiveRecord::Base.connected? - User.select(:id, :name).each_with_object(answer_opts) do |user, hsh| - hsh[user.id] = user.name + User.select(:id, :name, :email).each_with_object(answer_opts) do |user, hsh| + hsh[user.id] = user.name if user.name.present? + hsh[user.id] = user.email if user.name.blank? hsh end end diff --git a/spec/models/form/setup/questions/created_by_id_spec.rb b/spec/models/form/setup/questions/created_by_id_spec.rb index 84a7083be..80744d94b 100644 --- a/spec/models/form/setup/questions/created_by_id_spec.rb +++ b/spec/models/form/setup/questions/created_by_id_spec.rb @@ -10,11 +10,13 @@ RSpec.describe Form::Setup::Questions::CreatedById, type: :model do let(:form) { instance_double(Form) } let!(:user_1) { FactoryBot.create(:user, name: "first user") } let!(:user_2) { FactoryBot.create(:user, name: "second user") } + let!(:user_3) { FactoryBot.create(:user, name: nil, email: "madeupmail@example.com") } let(:expected_answer_options) do { "" => "Select an option", user_1.id => user_1.name, user_2.id => user_2.name, + user_3.id => user_3.email, } end