Skip to content

Commit

Permalink
Refactor archived condition to be a concern with an active scope
Browse files Browse the repository at this point in the history
  • Loading branch information
serenaabbott11 committed Nov 29, 2024
1 parent 222dde2 commit 7614a73
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 4 deletions.
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.where.not(archived: true)
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
2 changes: 1 addition & 1 deletion app/models/support/establishment_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ def eligible_for_school_picker?
end

def organisations_for_multi_school_picker
organisations.where.not(archived: true)
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

0 comments on commit 7614a73

Please sign in to comment.