Skip to content

Commit

Permalink
2012 - feat(cms): Remove archived establishments from selection optio…
Browse files Browse the repository at this point in the history
…ns (#1990)
  • Loading branch information
threedaymonk authored Dec 6, 2024
2 parents daf1c70 + 029f383 commit b6e581f
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 13 deletions.
1 change: 1 addition & 0 deletions app/controllers/support/establishment_groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def index
respond_to do |format|
format.json do
render json: EstablishmentGroup
.active
.where(query, q: "%#{params.fetch(:q)}%")
.limit(50)
.each { |g| g.ukprn = "N/A" if g.ukprn.nil? }
Expand Down
1 change: 1 addition & 0 deletions app/controllers/support/organisations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def index
SQL

results = Organisation
.active
.includes([:establishment_type])
.where(query, q: "%#{params.fetch(:q)}%")
.limit(50)
Expand Down
2 changes: 1 addition & 1 deletion app/models/local_authority.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def eligible_for_school_picker?
end

def organisations_for_multi_school_picker
organisations.local_authority_maintained
organisations.local_authority_maintained.active
end

def org_type
Expand Down
3 changes: 2 additions & 1 deletion app/models/support/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ module Support
# Types of procurement or "categories of spend"
#
class Category < ApplicationRecord
include Support::Concerns::ScopeActive

belongs_to :tower, class_name: "Support::Tower", foreign_key: "support_tower_id", optional: true
has_many :cases, class_name: "Support::Case"
belongs_to :parent, class_name: "Support::Category", optional: true
Expand All @@ -24,7 +26,6 @@ class Category < ApplicationRecord
scope :sub_categories, -> { where.not(parent_id: nil) }
scope :ordered_by_title, -> { order(Arel.sql("case when support_categories.title = 'Or' then 1 else 0 end ASC, support_categories.title ASC")) }
scope :except_for, ->(title) { where.not(title:) }
scope :active, -> { where(archived: false) }
scope :with_live_cases, -> { joins(:cases).merge(Case.live) }

delegate :title, to: :tower, prefix: true, allow_nil: true
Expand Down
7 changes: 7 additions & 0 deletions app/models/support/concerns/scope_active.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Support::Concerns::ScopeActive
extend ActiveSupport::Concern

included do
scope :active, -> { where(archived: false) }
end
end
3 changes: 2 additions & 1 deletion app/models/support/email_template.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Support
class EmailTemplate < ApplicationRecord
include Support::Concerns::ScopeActive

STAGE_VALUES = [0, 1, 2, 3, 4].freeze

belongs_to :group, class_name: "Support::EmailTemplateGroup", foreign_key: "template_group_id"
Expand All @@ -12,7 +14,6 @@ class EmailTemplate < ApplicationRecord

default_scope { order(:title) }

scope :active, -> { where(archived: false) }
scope :by_groups, ->(template_group_ids) { where(template_group_id: template_group_ids) }
scope :by_stages, ->(stages, include_null: false) { include_null ? where(stage: stages).or(where(stage: nil)) : where(stage: stages) }
scope :without_stage, -> { where(stage: nil) }
Expand Down
4 changes: 3 additions & 1 deletion app/models/support/establishment_group.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Support::EstablishmentGroup < ApplicationRecord
include Support::Concerns::ScopeActive

belongs_to :establishment_group_type, class_name: "Support::EstablishmentGroupType"
has_many :cases, class_name: "Support::Case", as: :organisation

Expand Down Expand Up @@ -32,6 +34,6 @@ def eligible_for_school_picker?
end

def organisations_for_multi_school_picker
organisations
organisations.active
end
end
1 change: 1 addition & 0 deletions app/models/support/organisation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module Support
#
class Organisation < ApplicationRecord
include Filterable
include Support::Concerns::ScopeActive

belongs_to :establishment_type,
counter_cache: true,
Expand Down
39 changes: 39 additions & 0 deletions db/migrate/20241127115728_update_archived_columns.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class UpdateArchivedColumns < ActiveRecord::Migration[7.2]
def up
tables = %w[
support_establishment_groups
support_email_template_groups
support_categories
support_procurement_stages
request_for_help_categories
support_organisations
local_authorities
support_email_templates
]

tables.each do |table|
execute "UPDATE #{table} SET archived = false WHERE archived IS NULL;"

change_column_default table, :archived, false
change_column_null table, :archived, false
end
end

def down
tables = %w[
support_establishment_groups
support_email_template_groups
support_categories
support_procurement_stages
request_for_help_categories
support_organisations
local_authorities
support_email_templates
]

tables.each do |table|
change_column_default table, :archived, nil
change_column_null table, :archived, true
end
end
end
10 changes: 5 additions & 5 deletions 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[7.2].define(version: 2024_11_25_131721) do
ActiveRecord::Schema[7.2].define(version: 2024_11_27_115728) do
create_sequence "evaluation_refs"
create_sequence "framework_refs"

Expand Down Expand Up @@ -403,7 +403,7 @@
t.string "name", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "archived"
t.boolean "archived", default: false, null: false
t.datetime "archived_at"
t.index ["la_code"], name: "index_local_authorities_on_la_code", unique: true
t.index ["name"], name: "index_local_authorities_on_name", unique: true
Expand Down Expand Up @@ -644,7 +644,7 @@
t.uuid "parent_id"
t.string "tower"
t.uuid "support_tower_id"
t.boolean "archived", default: false
t.boolean "archived", default: false, null: false
t.index ["slug"], name: "index_support_categories_on_slug", unique: true
t.index ["support_tower_id"], name: "index_support_categories_on_support_tower_id"
t.index ["title", "parent_id"], name: "index_support_categories_on_title_and_parent_id", unique: true
Expand Down Expand Up @@ -779,7 +779,7 @@
t.uuid "establishment_group_type_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "archived"
t.boolean "archived", default: false, null: false
t.datetime "archived_at"
t.date "opened_date"
t.date "closed_date"
Expand Down Expand Up @@ -901,7 +901,7 @@
t.string "federation_name"
t.string "federation_code"
t.uuid "local_authority_id"
t.boolean "archived"
t.boolean "archived", default: false, null: false
t.datetime "archived_at"
t.date "closed_date"
t.string "reason_establishment_opened"
Expand Down
1 change: 1 addition & 0 deletions spec/factories/support/organisation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
phase { (0..7).to_a.sample }
gender { (0..3).to_a.sample }
status { 1 }
archived { false }

association :establishment_type,
factory: :support_establishment_type
Expand Down
1 change: 1 addition & 0 deletions spec/factories/support/support_establishment_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
factory: :support_establishment_group_type

address { {} }
archived { false }

trait :with_no_address do
address { { "town": "", "county": "", "street": "", "locality": "", "postcode": "" } }
Expand Down
6 changes: 6 additions & 0 deletions spec/features/engagement/create_case_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,17 @@

before do
create_list(:support_organisation, 3, trust_code: group.uid)
create(:support_organisation, name: "Archived School", archived: true, trust_code: group.uid)
select_organisation "Group 1"
valid_form_data_without_organisation
click_on "Save and continue"
end

it "does not show an archived school as an option to select" do
expect(page).to have_text "0 of 3 schools"
expect(page).not_to have_text "Archived School"
end

it "navigates to the same supplier question when more than one school is chosen and saves answers" do
check "School #1"
check "School #2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,19 @@ def complete_procurement_amount_step

expect(page).not_to have_text "There is a problem"
expect(find("h1.govuk-heading-l")).to have_text "Search for an academy trust or federation"

autocomplete_group_step

expect(find("h1.govuk-heading-l")).to have_text "Is this the academy trust or federation you're buying for?"

expect(values[0]).to have_text "Testing Multi Academy Trust"
expect(values[1]).to have_text "Boundary House Shr, 91 Charter House Street, EC1M 6HR"
end

it "doesn't include archived schools in the dropdown" do
fill_in "Enter the name, postcode or unique reference number (URN) of your school", with: "10025"
expect(page).to have_text "Greendale Academy for Bright Sparks"
expect(page).not_to have_text "Archived Org"
end
end

describe "the school confirmation page" do
Expand Down Expand Up @@ -343,6 +348,12 @@ def complete_procurement_amount_step

expect(values[0]).to have_text "Greendale Academy for Bright Sparks, St James's Passage, Duke's Place, EC3A 5DE"
end

it "doesn't include archived establishment groups in the dropdown" do
fill_in "Enter name, Unique group identifier (UID) or UK Provider Reference Number (UKPRN)", with: "10025"
expect(page).to have_text "Testing Multi Academy Trust"
expect(page).not_to have_text "Archived Group"
end
end

describe "the group confirmation page" do
Expand Down Expand Up @@ -379,16 +390,19 @@ def complete_procurement_amount_step
end

describe "allows to select and confirm schools in the group" do
before do
it "does not show an archived school as an option to select" do
expect(page).to have_text "0 of 2 schools"
expect(page).not_to have_text "Archived Org"
end

it "saves selected schools" do
check "Specialist School for Testing"
check "Greendale Academy for Bright Sparks"
click_continue

choose "Yes"
click_continue
end

it "saves selected schools" do
expect(FrameworkRequest.first.school_urns).to match_array(%w[100253 100254])
end
end
Expand Down
14 changes: 14 additions & 0 deletions spec/support/shared/user_with_many_orgs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
trust_code: "2314",
local_authority:)

create(:support_organisation, :with_address,
urn: "100255",
name: "Archived Org",
establishment_type: foundation,
trust_code: "2314",
local_authority:,
archived: true)

create(:support_establishment_group, :with_address,
uid: "2314",
name: "Testing Multi Academy Trust",
Expand All @@ -39,5 +47,11 @@
uid: "2315",
name: "New Academy Trust",
establishment_group_type: sat)

create(:support_establishment_group, :with_address,
uid: "2316",
name: "Archived Group",
establishment_group_type: sat,
archived: true)
end
end

0 comments on commit b6e581f

Please sign in to comment.