Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/staff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Staff < ApplicationRecord

validates :name, presence: true

scope :assessors, -> { where(assess_permission: true) }
scope :assessors, -> { where(assess_permission: true).order(:name) }
Copy link
Collaborator

@Hassanmir92 Hassanmir92 Sep 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this scope is not used anywhere else then I would rename this scope to be assessors_by_name so it's clear. Or if this scope is used anywhere else then to create a different scope with the name above.

scope :not_archived, -> { where(archived: false) }
scope :archived, -> { where(archived: true) }

Expand Down
32 changes: 28 additions & 4 deletions spec/requests/assessor/applications/assign-assessor/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,52 @@
end

let(:application_form) { create :application_form, :submitted }
let(:signed_in_staff) { create(:staff, :with_assess_permission) }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be better to either have the signed in user not have assess permission so that it doesn't appear in your tests or give a name to it so you don't have to force a "sort" on your expectation.


before do
create(:staff, :with_assess_permission, name: "Active Assessor")
create(:staff, :with_assess_permission, name: "Zachary Assessor")
create(:staff, :with_assess_permission, name: "Aaron Assessor")
create(:staff, :with_assess_permission, name: "Bernard Assessor")
create(
:staff,
:with_assess_permission,
:archived,
name: "Archived Assessor",
)
sign_in(create(:staff, :with_assess_permission))
sign_in(signed_in_staff)
assign_assessor
end

it "displays the page with the 'Select an assessor' title" do
expect(response.body).to include("Select an assessor")
end

it "displays the active assessor as an option" do
expect(response.body).to include("Active Assessor")
it "displays the active assessors as options" do
expect(response.body).to include("Aaron Assessor")
expect(response.body).to include("Bernard Assessor")
expect(response.body).to include("Zachary Assessor")
end

it "does not display the archived assessor as an option" do
expect(response.body).not_to include("Archived Assessor")
end

it "displays the assessors in alphabetical order" do
assessor_names =
Nokogiri
.HTML(response.body)
.css(".govuk-radios__label")
.map(&:text)
.map(&:strip)
.reject { |name| name == "Not assigned" }

expected_names = [
"Aaron Assessor",
"Bernard Assessor",
"Zachary Assessor",
signed_in_staff.name,
].sort

expect(assessor_names).to eq(expected_names)
end
end
44 changes: 34 additions & 10 deletions spec/requests/assessor/applications/assign-reviewer/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,57 @@

RSpec.describe "GET /assessor/applications/:reference/assign-reviewer",
type: :request do
subject(:assign_assessor) do
subject(:assign_reviewer) do
get "/assessor/applications/#{application_form.reference}/assign-reviewer"
end

let(:application_form) { create :application_form, :submitted }
let(:signed_in_staff) { create(:staff, :with_assess_permission) }

before do
create(:staff, :with_assess_permission, name: "Active Assessor")
create(:staff, :with_assess_permission, name: "Zachary Reviewer")
create(:staff, :with_assess_permission, name: "Aaron Reviewer")
create(:staff, :with_assess_permission, name: "Bernard Reviewer")
create(
:staff,
:with_assess_permission,
:archived,
name: "Archived Assessor",
name: "Archived Reviewer",
)
sign_in(create(:staff, :with_assess_permission))
assign_assessor
sign_in(signed_in_staff)
assign_reviewer
end

it "displays the page with the 'Select an reviewer' title" do
it "displays the page with the 'Select a reviewer' title" do
expect(response.body).to include("Select a reviewer")
end

it "displays the active assessor as an option" do
expect(response.body).to include("Active Assessor")
it "displays the active reviewers as options" do
expect(response.body).to include("Aaron Reviewer")
expect(response.body).to include("Bernard Reviewer")
expect(response.body).to include("Zachary Reviewer")
end

it "does not display the archived assessor as an option" do
expect(response.body).not_to include("Archived Assessor")
it "does not display the archived reviewer as an option" do
expect(response.body).not_to include("Archived Reviewer")
end

it "displays the reviewers in alphabetical order" do
reviewer_names =
Nokogiri
.HTML(response.body)
.css(".govuk-radios__label")
.map(&:text)
.map(&:strip)
.reject { |name| name == "Not assigned" }

expected_names = [
"Aaron Reviewer",
"Bernard Reviewer",
"Zachary Reviewer",
signed_in_staff.name,
].sort

expect(reviewer_names).to eq(expected_names)
end
end