Repository: DFE-Digital/register-early-career-teachers-public
Pull request #508: [1500] Make extensions visible on the claim ECT record check page
Author: login: avinhurry
Created: 2025-04-23T17:53:01Z | Merged: 2025-04-24T15:35:59Z

### Context

Surfacing the `extensions` number on the check ECT record page because it's useful information for appropriate bodies.

### Before/After

| Before | After |
|--------|-------|
|<img width="565" alt="image" src="https://github.com/user-attachments/assets/8dcc7ac3-cac6-4acc-9a3b-34df47a8403c" />|<img width="583" alt="image" src="https://github.com/user-attachments/assets/35642a98-26be-4b7a-8879-c1f1bf9a9fd2" />|

### Changes proposed

- Fix pluralisation of decimal term counts
- Surface extensions on the check details page
- Optimise calculation by using active record


Diff:
diff --git a/app/helpers/appropriate_body_helper.rb b/app/helpers/appropriate_body_helper.rb
index 1ffae7def..3dd7ed3e9 100644
--- a/app/helpers/appropriate_body_helper.rb
+++ b/app/helpers/appropriate_body_helper.rb
@@ -56,6 +56,16 @@ def trs_alerts_text(alerts_present)
     end
   end
 
+  def induction_extensions(teacher)
+    return if teacher.blank?
+
+    @induction_extensions ||= Teachers::InductionExtensions.new(teacher)
+  end
+
+  def show_extensions_row?(teacher)
+    induction_extensions(teacher)&.extended?
+  end
+
 private
 
   def pending_induction_submission_full_name(pending_induction_submission)
diff --git a/app/services/teachers/induction_extensions.rb b/app/services/teachers/induction_extensions.rb
index c54813b99..f99d6230d 100644
--- a/app/services/teachers/induction_extensions.rb
+++ b/app/services/teachers/induction_extensions.rb
@@ -12,7 +12,7 @@ def yes_or_no
   def formatted_number_of_terms
     return "None" if number_of_terms.zero?
 
-    [number_of_terms, "term".pluralize(number_of_terms.round)].join(" ")
+    "#{number_of_terms} #{'term'.pluralize(number_of_terms)}"
   end
 
   def extended?
@@ -22,6 +22,6 @@ def extended?
 private
 
   def number_of_terms
-    teacher.induction_extensions.sum(&:number_of_terms)
+    teacher.induction_extensions.sum(:number_of_terms)
   end
 end
diff --git a/app/views/appropriate_bodies/claim_an_ect/check_ect/edit.html.erb b/app/views/appropriate_bodies/claim_an_ect/check_ect/edit.html.erb
index 8edf75afa..df5b0db83 100644
--- a/app/views/appropriate_bodies/claim_an_ect/check_ect/edit.html.erb
+++ b/app/views/appropriate_bodies/claim_an_ect/check_ect/edit.html.erb
@@ -83,6 +83,13 @@
         )
       )
     end if @pending_induction_submission.trs_induction_status.present?
+
+    if show_extensions_row?(@teacher)
+      sl.with_row do |r|
+        r.with_key(text: "Extensions")
+        r.with_value(text: induction_extensions(@teacher).formatted_number_of_terms)
+      end
+    end
   end
 %>
 
diff --git a/spec/services/teachers/induction_extensions_spec.rb b/spec/services/teachers/induction_extensions_spec.rb
index 650719054..986008854 100644
--- a/spec/services/teachers/induction_extensions_spec.rb
+++ b/spec/services/teachers/induction_extensions_spec.rb
@@ -22,22 +22,28 @@
       allow(teacher.induction_extensions).to receive(:sum).and_return(total)
     end
 
-    context "when gt 1" do
+    context "when greater than 1" do
       let(:total) { 5.1 }
 
       it { expect(formatted_number_of_terms).to eql("#{total} terms") }
     end
 
-    context "when lt 1" do
+    context "when less than 1" do
       let(:total) { 0.777777 }
 
-      it { expect(formatted_number_of_terms).to eql("#{total} term") }
+      it { expect(formatted_number_of_terms).to eql("#{total} terms") }
     end
 
-    context "when eq 1" do
+    context "when 1" do
       let(:total) { 1.0 }
 
       it { expect(formatted_number_of_terms).to eql("#{total} term") }
     end
+
+    context "when 1.2" do
+      let(:total) { 1.2 }
+
+      it { expect(formatted_number_of_terms).to eql("#{total} terms") }
+    end
   end
 end
diff --git a/spec/views/appropriate_bodies/claim_an_ect/check_ect/edit.html.erb_spec.rb b/spec/views/appropriate_bodies/claim_an_ect/check_ect/edit.html.erb_spec.rb
index cc376d12d..23dcd6875 100644
--- a/spec/views/appropriate_bodies/claim_an_ect/check_ect/edit.html.erb_spec.rb
+++ b/spec/views/appropriate_bodies/claim_an_ect/check_ect/edit.html.erb_spec.rb
@@ -84,4 +84,34 @@
       end
     end
   end
+
+  describe 'extensions' do
+    context 'with no extensions but with a teacher' do
+      it 'does not display the row' do
+        render
+        expect(rendered).not_to have_css('.govuk-summary-list__key', text: 'Extensions')
+        expect(rendered).not_to have_css('.govuk-summary-list__value', text: '0.0')
+      end
+    end
+
+    context 'with no extensions and no teacher' do
+      let(:teacher) { nil }
+
+      it 'does not display the row' do
+        render
+        expect(rendered).not_to have_css('.govuk-summary-list__key', text: 'Extensions')
+        expect(rendered).not_to have_css('.govuk-summary-list__value', text: '0.0')
+      end
+    end
+
+    context 'with extensions and teacher' do
+      let!(:extension) { create(:induction_extension, teacher:) }
+
+      it 'displays the row' do
+        render
+        expect(rendered).to have_css('.govuk-summary-list__key', text: 'Extensions')
+        expect(rendered).to have_css('.govuk-summary-list__value', text: '1.2 terms')
+      end
+    end
+  end
 end


Reviews:
user: login: tonyheadford
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-24T08:08:08Z
user: login: tonyheadford
body: looks great, one minor niggle about an indent
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-24T08:09:51Z
user: login: avinhurry
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-24T08:19:53Z
user: login: peteryates
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-24T08:50:02Z
user: login: peteryates
state: APPROVED
author_association: MEMBER
submitted_at: 2025-04-24T08:50:23Z
user: login: tonyheadford
state: APPROVED
author_association: COLLABORATOR
submitted_at: 2025-04-24T08:52:21Z

Review comments:
diff_hunk: @@ -83,8 +83,15 @@
         )
       )
     end if @pending_induction_submission.trs_induction_status.present?
-  end
-%>
+
+  if show_extensions_row?(@teacher)
+      sl.with_row do |r| 
path: app/views/appropriate_bodies/claim_an_ect/check_ect/edit.html.erb
user: login: tonyheadford
body: is the indent slightly out here?
created_at: 2025-04-24T08:08:08Z
author_association: COLLABORATOR
diff_hunk: @@ -83,8 +83,15 @@
         )
       )
     end if @pending_induction_submission.trs_induction_status.present?
-  end
-%>
+
+  if show_extensions_row?(@teacher)
+      sl.with_row do |r| 
path: app/views/appropriate_bodies/claim_an_ect/check_ect/edit.html.erb
user: login: avinhurry
body: yeah, it was, thanks! 

I've updated here: https://github.com/DFE-Digital/register-early-career-teachers-public/pull/508/commits/f55f4578591e0052dbb6cebf60da885b29adf3b1
created_at: 2025-04-24T08:19:53Z
author_association: CONTRIBUTOR
diff_hunk: @@ -22,6 +22,6 @@ def extended?
 private
 
   def number_of_terms
-    teacher.induction_extensions.sum(&:number_of_terms)
+    teacher.induction_extensions.sum(:number_of_terms)
path: app/services/teachers/induction_extensions.rb
user: login: peteryates
body: 🏅 
created_at: 2025-04-24T08:50:02Z
author_association: MEMBER

PR comments:
user: login: github-actions[bot]
created_at: 2025-04-23T17:57:42Z
body: Review app deployed to https://cpd-ec2-review-508-web.test.teacherservices.cloud
<!-- Sticky Pull Request Comment -->
author_association: NONE
user: login: sonarqubecloud[bot]
created_at: 2025-04-24T08:19:43Z
body: ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=DFE-Digital_register-early-career-teachers-public&pullRequest=508) **Quality Gate passed**  
Issues  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=DFE-Digital_register-early-career-teachers-public&pullRequest=508&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=DFE-Digital_register-early-career-teachers-public&pullRequest=508&issueStatuses=ACCEPTED)

Measures  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=DFE-Digital_register-early-career-teachers-public&pullRequest=508&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=DFE-Digital_register-early-career-teachers-public&pullRequest=508&metric=new_coverage&view=list)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=DFE-Digital_register-early-career-teachers-public&pullRequest=508&metric=new_duplicated_lines_density&view=list)  
  
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=DFE-Digital_register-early-career-teachers-public&pullRequest=508)


author_association: NONE
user: login: emily-prudence-dfe
created_at: 2025-04-24T13:23:55Z
body: Looks great @avinhurry, merge away
author_association: CONTRIBUTOR
user: login: github-actions[bot]
created_at: 2025-04-24T15:37:53Z
body: Review app ECF2 deployed to <https://ec2-review-508-web.test.teacherservices.cloud> was deleted
<!-- Sticky Pull Request Commentaks -->
author_association: NONE