Skip to content

Commit 775617b

Browse files
committed
Apply test optimizations and fixes from PR #2596
Fixes broken tests due to fabricator changes: - Update controller and view to use event_student_spaces? and event_coach_spaces? - Update test files to work with optimized fabricators - Add UNLOGGED tables rake task for test performance Full suite: 17.2s → 13.9s (19% improvement)
1 parent 055ebaa commit 775617b

14 files changed

Lines changed: 53 additions & 21 deletions

app/controllers/workshop_invitation_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ def invitation_params
9191
end
9292

9393
def available_spaces?(workshop, invitation)
94-
(invitation.role.eql?('Student') && workshop.student_spaces?) ||
95-
(invitation.role.eql?('Coach') && workshop.coach_spaces?)
94+
(invitation.role.eql?('Student') && workshop.event_student_spaces?) ||
95+
(invitation.role.eql?('Coach') && workshop.event_coach_spaces?)
9696
end
9797

9898
# Inline from InvitationControllerConcerns

app/views/workshop_invitation/show.html.haml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
= @invitation.member.bans.active.first.reason
8181
- else
8282
- if @invitation.for_coach?
83-
- if @workshop.coach_spaces?
83+
- if @workshop.event_coach_spaces?
8484
= link_to 'Keep your skills up-to-date!', edit_member_path
8585
%span.d-block
8686
%small= I18n.t('workshop_invitation.coach_skills_tooltip')
@@ -91,7 +91,7 @@
9191
- else
9292
= render partial: 'workshop_invitation/waiting_list', locals: { invitation: @invitation }
9393
- else
94-
- if @workshop.student_spaces?
94+
- if @workshop.event_student_spaces?
9595
= simple_form_for @invitation, url: :accept_invitation, method: :post do |f|
9696
= f.input :tutorial, collection: @tutorial_titles, include_blank: true
9797
= f.input :note, required: false, input_html: { rows: 3, maxlength: 100 }, hint: 'Anything else we should know?', placeholder: 'e.g. I need help understanding selectors'

lib/tasks/test_unlogged.rake

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
namespace :db do
2+
namespace :test do
3+
desc "Convert all tables to UNLOGGED for faster test performance"
4+
task unlogged: :environment do
5+
raise "This task only works in test environment" unless Rails.env.test?
6+
7+
tables = ActiveRecord::Base.connection.tables
8+
converted = 0
9+
tables.each do |table|
10+
next if table == "schema_migrations" || table == "ar_internal_metadata"
11+
result = ActiveRecord::Base.connection.execute(
12+
"SELECT relpersistence FROM pg_class WHERE relname = '#{table}'"
13+
)
14+
if result.first && result.first["relpersistence"] != "u"
15+
ActiveRecord::Base.connection.execute("ALTER TABLE #{table} SET UNLOGGED")
16+
converted += 1
17+
end
18+
end
19+
puts "Converted #{converted} tables to UNLOGGED" if converted > 0
20+
end
21+
end
22+
end
23+
24+
# Auto-run after db:test:prepare
25+
Rake::Task["db:test:prepare"].enhance do
26+
Rake::Task["db:test:unlogged"].invoke if Rails.env.test?
27+
end

spec/fabricators/workshop_fabricator.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
date_and_time Time.zone.now + 2.days
33
ends_at { |attrs| attrs[:date_and_time] + 2.hours }
44
chapter
5+
student_spaces { |transients| transients[:student_count] || 10 }
6+
coach_spaces { |transients| transients[:coach_count] || 10 }
57
after_build do |workshop, transients|
68
Fabricate(:workshop_sponsor,
79
workshop: workshop,
810
sponsor: Fabricate(:sponsor,
911
seats: transients[:student_count] || 10,
10-
number_of_coaches: transients[:coach_count || 10]),
12+
number_of_coaches: transients[:coach_count] || 10),
1113
host: true)
1214
end
1315

spec/features/accepting_invitation_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
let(:invitation_route) { invitation_path(invitation) }
66
let(:accept_invitation_route) { accept_invitation_path(invitation) }
77
let(:reject_invitation_route) { reject_invitation_path(invitation) }
8-
let(:set_no_available_slots) { invitation.workshop.host.update_attribute(:seats, 0) }
8+
let(:set_no_available_slots) { invitation.workshop.update_attribute(:student_spaces, 0) }
99
let!(:tutorial) { Fabricate(:tutorial) }
1010

1111
it_behaves_like 'invitation route'

spec/features/admin/chapters_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
end
3232

3333
context '#editing a chapter' do
34-
let(:chapter) { Fabricate(:chapter) }
34+
let(:chapter) { Fabricate(:chapter_with_organiser) }
3535

3636
context 'organiser editing their chapter' do
3737
before do
@@ -146,7 +146,7 @@
146146
end
147147

148148
context 'eligible members tooltip' do
149-
let(:chapter) { Fabricate(:chapter_with_groups) }
149+
let(:chapter) { Fabricate(:chapter) }
150150

151151
before do
152152
login_as_admin(member)

spec/features/admin/event_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
RSpec.feature 'Event creation', type: :feature do
22
let(:member) { Fabricate(:member) }
3-
let(:chapter) { Fabricate(:chapter_with_groups) }
3+
let(:chapter) { Fabricate(:chapter) }
44

55
describe 'an authorised member' do
66
before do

spec/features/admin/filtering_sponsors_list_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
end
77

88
describe 'when visiting the sponsors page' do
9-
let!(:sponsors) { Fabricate.times(2, :sponsor_with_contacts) }
9+
let!(:sponsors) { Fabricate.times(2, :sponsor) }
1010

1111
before(:each) do
1212
visit admin_sponsors_path

spec/features/admin/manage_event_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
RSpec.feature 'Managing events', type: :feature do
22
let(:member) { Fabricate(:member) }
3-
let!(:chapter) { Fabricate(:chapter_with_groups) }
3+
let!(:chapter) { Fabricate(:chapter) }
44
let!(:event) { Fabricate(:event, confirmation_required: true) }
55

66
before do

spec/features/admin/managing_organisers_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
RSpec.feature 'Managing organisers', type: :feature do
22
let(:member) { Fabricate(:member) }
3-
let(:chapter) { Fabricate(:chapter) }
3+
let(:chapter) { Fabricate(:chapter_with_organiser) }
44

55
scenario 'non admin cannot manage organisers' do
66
login(member)

0 commit comments

Comments
 (0)