Browse Source

Show also users from owning_organisation

pull/1012/head
Jack S 4 years ago
parent
commit
5b33b51e5a
  1. 7
      app/models/form/lettings/questions/created_by_id.rb
  2. 18
      spec/models/form/lettings/questions/created_by_id_spec.rb

7
app/models/form/lettings/questions/created_by_id.rb

@ -20,9 +20,12 @@ class Form::Lettings::Questions::CreatedById < ::Form::Question
end end
def displayed_answer_options(log, _user = nil) def displayed_answer_options(log, _user = nil)
return answer_options unless log.owning_organisation return answer_options unless log.owning_organisation && log.managing_organisation
user_ids = [""]
user_ids += log.owning_organisation.users.pluck(:id)
user_ids += log.managing_organisation.users.pluck(:id)
user_ids = log.owning_organisation.users.pluck(:id) + [""]
answer_options.select { |k, _v| user_ids.include?(k) } answer_options.select { |k, _v| user_ids.include?(k) }
end end

18
spec/models/form/lettings/questions/created_by_id_spec.rb

@ -8,8 +8,9 @@ RSpec.describe Form::Lettings::Questions::CreatedById, type: :model do
let(:page) { instance_double(Form::Page) } let(:page) { instance_double(Form::Page) }
let(:subsection) { instance_double(Form::Subsection) } let(:subsection) { instance_double(Form::Subsection) }
let(:form) { instance_double(Form) } let(:form) { instance_double(Form) }
let(:user_1) { FactoryBot.create(:user, name: "first user") } let(:user_1) { create(:user, name: "first user") }
let(:user_2) { FactoryBot.create(:user, name: "second user") } let(:user_2) { create(:user, name: "second user") }
let(:user_3) { create(:user, name: "third user") }
let!(:expected_answer_options) do let!(:expected_answer_options) do
{ {
"" => "Select an option", "" => "Select an option",
@ -51,7 +52,7 @@ RSpec.describe Form::Lettings::Questions::CreatedById, type: :model do
end end
context "when the current user is support" do context "when the current user is support" do
let(:support_user) { FactoryBot.build(:user, :support) } let(:support_user) { build(:user, :support) }
it "is shown in check answers" do it "is shown in check answers" do
expect(question.hidden_in_check_answers?(nil, support_user)).to be false expect(question.hidden_in_check_answers?(nil, support_user)).to be false
@ -59,7 +60,7 @@ RSpec.describe Form::Lettings::Questions::CreatedById, type: :model do
end end
context "when the current user is not support" do context "when the current user is not support" do
let(:user) { FactoryBot.build(:user) } let(:user) { build(:user) }
it "is not shown in check answers" do it "is not shown in check answers" do
expect(question.hidden_in_check_answers?(nil, user)).to be true expect(question.hidden_in_check_answers?(nil, user)).to be true
@ -67,11 +68,18 @@ RSpec.describe Form::Lettings::Questions::CreatedById, type: :model do
end end
context "when the owning organisation is already set" do context "when the owning organisation is already set" do
let(:lettings_log) { FactoryBot.create(:lettings_log, owning_organisation: user_2.organisation) } let(:lettings_log) do
create(
:lettings_log,
owning_organisation: user_2.organisation,
managing_organisation: user_3.organisation,
)
end
let(:expected_answer_options) do let(:expected_answer_options) do
{ {
"" => "Select an option", "" => "Select an option",
user_2.id => "#{user_2.name} (#{user_2.email})", user_2.id => "#{user_2.name} (#{user_2.email})",
user_3.id => "#{user_3.name} (#{user_3.email})",
} }
end end

Loading…
Cancel
Save