Skip to content

Commit

Permalink
Rename all Project.not_completed scopes to Project.active
Browse files Browse the repository at this point in the history
Now that we have the project state as an enumerable, we get Project.active
scope for free and we can use it to replace any instances of
Project.not_completed
  • Loading branch information
lozette committed Apr 5, 2024
1 parent 97b860d commit f8c0af5
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/controllers/all/regions/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def show
return not_found_error unless Project.regions.include?(region)

@region = region
@pager, @projects = pagy(Project.not_completed.by_region(region).ordered_by_significant_date.includes(:assigned_to))
@pager, @projects = pagy(Project.active.by_region(region).ordered_by_significant_date.includes(:assigned_to))
AcademiesApiPreFetcherService.new.call!(@projects)
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/all/trusts/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def show
authorize Project, :index?

@trust = Api::AcademiesApi::Client.new.get_trust(incoming_trust_ukprn).object
@pager, @projects = pagy(Project.not_completed.by_trust_ukprn(@trust.ukprn).ordered_by_significant_date.includes(:assigned_to))
@pager, @projects = pagy(Project.active.by_trust_ukprn(@trust.ukprn).ordered_by_significant_date.includes(:assigned_to))

AcademiesApiPreFetcherService.new.call!(@projects)
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/all/users/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def index
def show
authorize Project, :index?
@user = User.find(user_id)
@pager, @projects = pagy(Project.not_completed.assigned_to(@user))
@pager, @projects = pagy(Project.active.assigned_to(@user))
end

private def user_id
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/service_support/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ class ServiceSupport::ProjectsController < ApplicationController

def without_academy_urn
authorize Project, :index?
@pager, @projects = pagy(Conversion::Project.not_completed.no_academy_urn.by_conversion_date)
@pager, @projects = pagy(Conversion::Project.active.no_academy_urn.by_conversion_date)

AcademiesApiPreFetcherService.new.call!(@projects)
end

def with_academy_urn
authorize Project, :index?
@pager, @projects = pagy(Conversion::Project.not_completed.with_academy_urn.by_conversion_date)
@pager, @projects = pagy(Conversion::Project.active.with_academy_urn.by_conversion_date)

AcademiesApiPreFetcherService.new.call!(@projects)
end
Expand Down
2 changes: 1 addition & 1 deletion app/forms/conversion/create_project_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def region
end

private def urn_unique_for_in_progress_conversions
errors.add(:urn, :duplicate) if Conversion::Project.not_completed.where(urn: urn).any?
errors.add(:urn, :duplicate) if Conversion::Project.active.where(urn: urn).any?
end

def directive_academy_order_responses
Expand Down
2 changes: 1 addition & 1 deletion app/forms/create_project_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def yes_no_responses
end

private def urn_unique_for_in_progress_transfers
errors.add(:urn, :duplicate) if Transfer::Project.not_completed.where(urn: urn).any?
errors.add(:urn, :duplicate) if Transfer::Project.active.where(urn: urn).any?
end

private def value_at_position(hash, position)
Expand Down
4 changes: 2 additions & 2 deletions app/services/by_local_authority_project_fetcher_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ def local_authorities_with_projects
end

def projects_for_local_authority(local_authority_code)
all_projects = Project.not_completed.select(:id, :urn, :incoming_trust_ukprn)
all_projects = Project.active.select(:id, :urn, :incoming_trust_ukprn)
projects_for_local_authority = all_projects.select { |p| p.establishment.local_authority_code == local_authority_code }

Project.where(id: projects_for_local_authority.pluck(:id)).includes(:assigned_to).ordered_by_significant_date
end

private def projects_by_local_authority
projects = Project.not_completed.select(:id, :urn, :incoming_trust_ukprn, :type)
projects = Project.active.select(:id, :urn, :incoming_trust_ukprn, :type)

AcademiesApiPreFetcherService.new.call!(projects)

Expand Down
2 changes: 1 addition & 1 deletion app/services/by_region_project_fetcher_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def regional_casework_services_projects(region)
end

private def projects_by_region
projects = Project.not_completed
projects = Project.active
return false unless projects.any?

projects.group_by(&:region)
Expand Down
4 changes: 2 additions & 2 deletions spec/models/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -531,15 +531,15 @@
end
end

describe "not_completed scope" do
describe "active scope" do
before { mock_successful_api_responses(urn: any_args, ukprn: any_args) }

it "only returns projects where state = 0" do
completed_project = create(:conversion_project, completed_at: Date.today - 1.year, state: 1)
in_progress_project_1 = create(:conversion_project, completed_at: nil, state: 0)
in_progress_project_2 = create(:conversion_project, completed_at: nil, state: 0)

projects = Project.not_completed
projects = Project.active

expect(projects).to include(in_progress_project_1, in_progress_project_2)
expect(projects).to_not include(completed_project)
Expand Down

0 comments on commit f8c0af5

Please sign in to comment.