Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
gms-gs committed Jul 2, 2024
1 parent d5bb6e2 commit 04f731e
Show file tree
Hide file tree
Showing 22 changed files with 79 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<% @pagy, @audits = audits %>

<table class="govuk-table">
<thead class="govuk-table__head">
<tr class="govuk-table__row">
Expand All @@ -8,10 +6,10 @@
</tr>
</thead>
<tbody class="govuk-table__body">
<% @audits.each do |audit| %>
<% audits.last.each do |audit| %>
<%= render SupportInterface::AuditTrailItemComponent.new(audit: audit) %>
<% end %>
</tbody>
</table>

<%= govuk_pagination(pagy: @pagy) %>
<%= govuk_pagination(pagy: audits.first) %>
2 changes: 1 addition & 1 deletion app/components/support_interface/audit_trail_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def audits

audits = audits.includes(:user).order(created_at: :desc)

pagy(audits, page: params[:page], items: 60)
pagy(audits, items: 60)
end

attr_reader :audited_thing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
support_interface_reasons_for_rejection_application_choices_path(
'structured_rejection_reasons[id]' => @reason_key,
'recruitment_cycle_year' => @recruitment_cycle_year,
'page' => 1,
),
) %>
</h2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def breadcrumb_items

unless top_level_reason?
breadcrumb_items[@search_attribute.titleize] = support_interface_reasons_for_rejection_application_choices_path(
page: 1,
'structured_rejection_reasons[id]' => @search_attribute,
'recruitment_cycle_year' => @recruitment_cycle_year,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<%= govuk_link_to(
sub_reason_label(sub_reason),
support_interface_reasons_for_rejection_application_choices_path(
page: 1,
"structured_rejection_reasons[#{sub_reason_key}]": sub_reason,
recruitment_cycle_year: recruitment_cycle_year,
),
Expand Down
1 change: 1 addition & 0 deletions app/components/utility/paginated_filter_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<%= render FilterComponent.new(filter: filter) do |component| %>
<%= content %>
<%= govuk_pagination(pagy: @pagy) %>
<% end %>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ module SupportInterface
class ApplicationFormsController < SupportInterfaceController
def index
@filter = SupportInterface::ApplicationsFilter.new(params:)
result = @filter.filter_records(ApplicationForm)
@pagy = result[:pagy]
@application_forms = result[:records]
@pagy, @application_forms = @filter.filter_records(ApplicationForm)
end

def show
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/support_interface/candidates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def index
@candidates = @candidates.where(id: candidate_number)
end

@pagy, @candidates = pagy(@candidates, page: params[:page], items: 30)
@pagy, @candidates = pagy(@candidates, items: 30)
end

def show
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def history
@pagy, @data_exports = pagy(@data_exports, items: PAGE_SIZE)
end


def view_export_information
@data_export = DataExport::EXPORT_TYPES[params[:data_export_type].to_sym]
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ class DuplicateMatchesController < SupportInterfaceController
def index
@filter = SupportInterface::DuplicateMatchesFilter.new(params:)

if @filter.applied_filters[:query].present?
matches_scope = duplicate_matches(resolved: resolved?).joins(:candidates).where('CONCAT(email_address) ILIKE ?', "%#{@filter.applied_filters[:query]}%")
else
matches_scope = duplicate_matches(resolved: resolved?)
end
matches_scope = if @filter.applied_filters[:query].present?
duplicate_matches(resolved: resolved?).joins(:candidates).where('CONCAT(email_address) ILIKE ?', "%#{@filter.applied_filters[:query]}%")
else
duplicate_matches(resolved: resolved?)
end

@pagy, @matches = pagy(matches_scope, items: DUPLICATE_MATCHES_PER_PAGE)
@under_review_count = duplicate_matches(resolved: false).count
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/support_interface/email_log_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def index
emails = emails.where(column => @filter.applied_filters[column])
end

@pagy, @emails = pagy(emails, page: params[:page], items: 30)
@pagy, @emails = pagy(emails, items: 30)
end
end
end
20 changes: 10 additions & 10 deletions app/controllers/support_interface/performance_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ def unavailable_choices_removed_sites

private

def unavailable_choices_detail(category, title)
@monitor = SupportInterface::ApplicationMonitor.new
@application_forms = @monitor.send(category)
@pagy, @application_forms = pagy(@application_forms, items: 30)

render(
:unavailable_choices_detail,
locals: { title: title }
)
end
def unavailable_choices_detail(category, title)
@monitor = SupportInterface::ApplicationMonitor.new
@application_forms = @monitor.send(category)
@pagy, @application_forms = pagy(@application_forms, items: 30)

render(
:unavailable_choices_detail,
locals: { title: title },
)
end

def year_param
params.fetch(:year, RecruitmentCycle.current_year)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/support_interface/providers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def index
providers_scope = @filter.filter_records(
Provider
.includes(:courses, :provider_agreements, :provider_users)
.order(:name)
.order(:name),
)

@pagy, @providers = pagy(providers_scope, items: 30)
Expand Down
8 changes: 4 additions & 4 deletions app/models/support_interface/applications_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,20 @@ def filter_records(application_forms)
.where('application_choices.provider_ids @> ?', "{#{applied_filters[:provider_id]}}")
end

pagy, records = pagy(
pagy_obj, records = pagy(
application_forms
.joins(:candidate)
.preload(
:candidate,
application_choices: { current_course_option: { course: :provider } }
application_choices: { current_course_option: { course: :provider } },
)
.distinct
.order(updated_at: :desc),
page: applied_filters[:page] || 1,
items: 30
items: 30,
)

{ pagy: pagy, records: records }
[pagy_obj, records]
end

def filters
Expand Down
12 changes: 8 additions & 4 deletions app/queries/reasons_for_rejection_applications_query.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class ReasonsForRejectionApplicationsQuery
include Pagy::Backend

attr_accessor :filters
attr_reader :recruitment_cycle_year

Expand All @@ -9,11 +11,13 @@ def initialize(filters)

def call
application_choices = ApplicationChoice
.where(current_recruitment_cycle_year: recruitment_cycle_year)
.where.not(structured_rejection_reasons: nil)
.order(created_at: :desc)
.where(current_recruitment_cycle_year: recruitment_cycle_year)
.where.not(structured_rejection_reasons: nil)
.order(created_at: :desc)

@pagy, @application_choices = pagy(apply_filters(application_choices), items: 30)
application_choices = apply_filters(application_choices)
@pagy, results = pagy(application_choices, page: filters[:page], items: 30)
results
end

private
Expand Down
1 change: 1 addition & 0 deletions config/initializers/pagy.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
require 'pagy/extras/metadata'
require 'pagy/extras/headers'
require 'pagy/extras/array'
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
require 'rails_helper'
require 'pagy'

RSpec.describe SupportInterface::DuplicateMatchesTableComponent do
include Pagy::Backend

before do
@duplicate_match1 = build(
:duplicate_match,
Expand All @@ -23,11 +26,11 @@
end

it 'renders the correct match descriptions' do
_, matches = pagy_array([@duplicate_match1, @duplicate_match2], page: 1, items: SupportInterface::DuplicateMatchesController::DUPLICATE_MATCHES_PER_PAGE)

result = render_inline(
described_class.new(
matches: Kaminari.paginate_array([@duplicate_match1, @duplicate_match2])
.page(1)
.per(SupportInterface::DuplicateMatchesController::DUPLICATE_MATCHES_PER_PAGE),
matches: matches,
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def render_result(

it 'renders the link back to communication' do
reason_path = support_interface_reasons_for_rejection_application_choices_path(
page: 1,
'structured_rejection_reasons[id]' => 'communication_and_scheduling',
'recruitment_cycle_year' => RecruitmentCycle.current_year,
)
Expand Down
3 changes: 2 additions & 1 deletion spec/models/support_interface/applications_filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
def verify_filtered_applications_for_params(expected_applications, params:)
applications = ApplicationForm.all
filter = described_class.new(params:)
expect(filter.filter_records(applications)).to match_array(expected_applications)
filtered_records = filter.filter_records(applications)
expect(filtered_records[:records]).to match_array(expected_applications)
end

describe '#filter_records' do
Expand Down
2 changes: 2 additions & 0 deletions spec/queries/reasons_for_rejection_applications_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
{
structured_rejection_reasons: { 'id' => 'visa_sponsorship' },
recruitment_cycle_year: RecruitmentCycle.current_year,
page: 1,
}
end

Expand All @@ -57,6 +58,7 @@
{
structured_rejection_reasons: { 'personal_statement' => 'quality_of_writing' },
recruitment_cycle_year: RecruitmentCycle.current_year,
page: 1,
}
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'rails_helper'

RSpec.feature 'Providers should be able to sort applications' do
RSpec.describe 'Providers should be able to sort applications' do
include CourseOptionHelpers
include DfESignInHelpers

Expand All @@ -11,15 +11,14 @@
and_i_sign_in_to_the_provider_interface

when_i_visit_the_provider_applications_page
then_i_should_not_see_a_paginator

given_my_organisation_has_more_than_30_applications
when_i_visit_the_provider_applications_page
then_i_should_see_a_paginator
then_i_see_a_paginator

when_i_click_next
then_i_should_see_page_2
then_i_should_see_a_paginator_for_page_2
then_i_see_page_2
then_i_see_a_paginator_for_page_2
end

def given_i_am_a_provider_user_with_dfe_sign_in
Expand Down Expand Up @@ -53,7 +52,7 @@ def when_i_visit_the_provider_applications_page
visit provider_interface_applications_path
end

def then_i_should_not_see_a_paginator
def then_i_not_see_a_paginator
expect(page).to have_no_link('Next')
expect(page).to have_no_content('Showing 1 to')
end
Expand All @@ -71,32 +70,25 @@ def given_my_organisation_has_more_than_30_applications
end
end

def then_i_should_see_a_paginator
def then_i_see_a_paginator
expect(page).to have_link('Next')
expect(page).to have_link('2')
expect(page).to have_content('Showing 1 to')
end

def when_i_click_next
click_link_or_button 'Next'
end

def then_i_should_see_page_2
def then_i_see_page_2
expect(page).to have_current_path(provider_interface_applications_path(page: '2'))
end

def when_i_click_prev
click_link_or_button 'Previous'
end

def then_i_should_see_a_paginator_for_page_2
def then_i_see_a_paginator_for_page_2
expect(page).to have_link('Previous')
expect(page).to have_link('1')
expect(page).to have_content('Showing 31 to')
end

def then_i_should_not_see_a_paginator
expect(page).to have_no_link('Next')
expect(page).to have_no_content('Showing 1 to')
end
end
Loading

0 comments on commit 04f731e

Please sign in to comment.