Skip to content

Commit

Permalink
Merge pull request #90 from wearefuturegov/BSP-70-change-qualificatio…
Browse files Browse the repository at this point in the history
…n-list-and-order

BSP-70 added in new qualification names and ordering
  • Loading branch information
apricot13 authored Jun 14, 2024
2 parents 8077bad + b49ae44 commit 6c6467c
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 28 deletions.
8 changes: 6 additions & 2 deletions app/models/employee.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ def accepted_roles
scope :qualifications, -> (qualification_id) {
if qualification_id === "NONE"
left_joins(:employee_qualifications).where(employee_qualifications: { id: nil })
elsif qualification_id === "UNAPPROVED"
left_joins(:qualifications).where(qualifications: { approved: false })
else
# get the highest qualification for each employee
subquery = EmployeeQualification.select('employee_id, MAX(qualification_id) as max_qualification_id').group(:employee_id).to_sql
Expand Down Expand Up @@ -206,8 +208,10 @@ def self.options_for_job_title

def self.options_for_qualifications
instance = new
qualifications = Qualification.all.map { |qualifications| [qualifications.name, qualifications.id] }
qualifications + [['No qualifications', 'NONE']]
qualifications = Qualification.all.approved(true).map { |qualifications| [qualifications.name, qualifications.id] }
qualifications += [['Unapproved qualifications', 'UNAPPROVED']]
qualifications += [['No saved qualifications', 'NONE']]
qualifications
end


Expand Down
29 changes: 20 additions & 9 deletions app/models/qualification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,27 @@ class Qualification < ApplicationRecord
# this is more for reference now that the content is in the table but its needed for seeding the database and rake tasks
def accepted_qualifications
[
{ name: "Level 7", order: 8 },
{ name: "QTS", order: 7 },
{ name: "EYC", order: 6 },
{ name: "EYPS", order: 5 },
{ name: "Level 6", order: 4 },
{ name: "Level 5", order: 3 },
{ name: "Level 4", order: 2 },
{ name: "Level 3", order: 1 },
{ name: "Level 2", order: 0 }
{ name: "Unqualified", order: 0 },
{ name: "Level 2", order: 1 },
{ name: "Level 3", order: 2 },
{ name: "Level 4", order: 3 },
{ name: "Level 5", order: 4 },
{ name: "Level 6", order: 5 },
{ name: "Early Years Professional Status", order: 6 },
{ name: "Early Years Teacher Status", order: 7 },
{ name: "Qualified Teacher Status", order: 8 },
{ name: "Level 7", order: 9 }
]
end


# add approved scope
scope :approved, -> (status = true) {
where(approved: status)
}

end




25 changes: 25 additions & 0 deletions app/views/admin/employees/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,31 @@


<%= render "admin/shared/collapsible", name: "Qualifications", id: "employee-qualifications" do %>


<% if @employee.employee_qualifications.any? { |eq| !eq.qualification.approved } %>
<div class="error">
<h2 class="error__title">Some of this employee's previous qualifications are no longer approved</h2>
<p class="error__list">
Some of this employees previous qualifications are no longer approved an admin will need to update them as unapproved qualifications do not show for users.
<br />
<br />
The following are the unnapproved qualifications for this employee, please update them to approved options if they are still valid.
</p>
<ul class="error__list">
<% @employee.employee_qualifications.each do |qualification| %>
<% if !qualification.qualification.approved %>
<li><%= qualification.qualification.name %> <%= qualification.achieved_on.strftime("%d/%m/%Y") if qualification.achieved_on %></li>
<% end %>
<% end %>
</ul>
</div>
<% end %>





<%= render "employees/editors/qualifications", f: f %>
<% end %>

Expand Down
12 changes: 11 additions & 1 deletion app/views/admin/employees/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,16 @@


<%= render "admin/shared/collapsible", name: "Qualifications", id: "employee-qualifications" do %>

<% if @employee.employee_qualifications.any? { |eq| !eq.qualification.approved } %>
<div class="error">
<h2 class="error__title">Some of this employee's previous qualifications are no longer approved</h2>
<p class="error__list">
Some of this employees previous qualifications are no longer approved an admin will need to update them as unapproved qualifications do not show for users.
</p>
</div>
<% end %>

<% if @employee.employee_qualifications.present? %>
<table class="table--employee-info">
<tr class="table-column">
Expand All @@ -182,7 +192,7 @@
</tr>
<% @employee.employee_qualifications.each do |qualification| %>
<tr class="table-column">
<td><%= qualification.qualification.name %></td>
<td><%= qualification.qualification.name %> <%= "(unapproved)" if !qualification.qualification.approved %></td>
<td><%= qualification.achieved_on.strftime("%d/%m/%Y") if qualification.achieved_on %></td>
</tr>
<% end %>
Expand Down
4 changes: 3 additions & 1 deletion app/views/employees/editors/_qualifications.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<% if Qualification.exists? %>
<fieldset class="field-group">
<legend>
<h2 class="field-group__legend">What qualifications does this person have?</h2>
<p class="field-group__hint">Please only tick the highest full and relevant Early Years Qualification</p>
</legend>

<% Qualification.all.each do |qualification| %>
<% Qualification.all.approved(true).each do |qualification| %>
<% employee_qualification = @employee.employee_qualifications.find_or_initialize_by(qualification_id: qualification.id) %>
<%= f.fields_for :employee_qualifications, employee_qualification do |eq| %>

Expand All @@ -28,3 +29,4 @@
<% end %>

</fieldset>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddApprovedColToQualifications < ActiveRecord::Migration[6.1]
def change
add_column :qualifications, :approved, :boolean, default: false
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2024_06_14_193034) do
ActiveRecord::Schema.define(version: 2024_06_14_204249) do

# These are extensions that must be enabled in order to support this database
enable_extension "pg_trgm"
Expand Down Expand Up @@ -73,6 +73,7 @@
t.integer "order"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.boolean "approved", default: false
end

create_table "services", force: :cascade do |t|
Expand Down
2 changes: 1 addition & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def employee_attributes
surname: FFaker::Name.last_name,
forenames: FFaker::Name.first_name,
job_title: Employee.new.accepted_job_titles.sample,
qualifications: Qualification.all.sample(rand(0..Qualification.count)),
qualifications: Qualification.all.approved(true).sample(rand(0..Qualification.count)),
roles: accepted_roles.sample(rand(1..accepted_roles.size)) ,

employed_from: FFaker::Time.date(year_latest: 18, year_range: 65 - 18),
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/employees_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
surname: FFaker::Name.last_name,
forenames: FFaker::Name.first_name,
job_title: Employee.new.accepted_job_titles.sample,
qualifications: Qualification.all.sample,
qualifications: Qualification.all.approved(true).sample,
roles: Employee.new.accepted_roles.sample,

employed_from: FFaker::Time.date(year_latest: 18, year_range: 65 - 18),
Expand Down
4 changes: 2 additions & 2 deletions spec/features/managing_employees_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
fill_in :employee_safeguarding_achieved_on, with: safeguarding_achieved_on
check :employee_has_designated_safeguarding_lead
fill_in :employee_designated_safeguarding_lead_achieved_on, with: designated_safeguarding_lead_achieved_on
Qualification.all.each do |qualification|
Qualification.all.approved(true).each do |qualification|
check(qualification.name)
end
click_button 'Continue'
Expand Down Expand Up @@ -135,7 +135,7 @@
expect(page).to have_checked_field(:employee_has_safeguarding)
expect(page).to have_field(:employee_designated_safeguarding_lead_achieved_on, with: designated_safeguarding_lead_achieved_on)
expect(page).to have_checked_field(:employee_has_designated_safeguarding_lead)
Qualification.all.each do |qualification|
Qualification.all.approved(true).each do |qualification|
expect(page).to have_checked_field(qualification.name)
end
end
Expand Down
24 changes: 14 additions & 10 deletions spec/models/employee_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,23 @@
end
end


describe '.options_for_qualifications' do
it 'returns an array of options for qualifications' do
expect(Employee.options_for_qualifications).to match_array([
include('Level 2', a_kind_of(Integer)),
include('Level 3', a_kind_of(Integer)),
include('Level 4', a_kind_of(Integer)),
include('Level 5', a_kind_of(Integer)),
include('Level 6', a_kind_of(Integer)),
include('EYPS', a_kind_of(Integer)),
include('QTS', a_kind_of(Integer)),
include('EYC', a_kind_of(Integer)),
['No qualifications', 'NONE']
# include('Unqualified', a_kind_of(Integer)),
# include('Level 2', a_kind_of(Integer)),
# include('Level 3', a_kind_of(Integer)),
# include('Level 4', a_kind_of(Integer)),
# include('Level 5', a_kind_of(Integer)),
# include('Level 6', a_kind_of(Integer)),
# include('Early Years Professional Status', a_kind_of(Integer)),
# include('Early Years Teacher Status', a_kind_of(Integer)),
# include('Qualified Teacher Status', a_kind_of(Integer)),
# include('Level 7', a_kind_of(Integer)),
['Unapproved qualifications', 'UNAPPROVED'],
['No saved qualifications', 'NONE']
])
end
end
end
end

0 comments on commit 6c6467c

Please sign in to comment.