Skip to content

Commit 8349dc1

Browse files
committed
Rename Invitation -> TeacherInvitation
To match the two `/teacher_invitations` API endpoints added in previous commits. The invitation is already kind of specific to teachers and in any case, I think it will be simpler to extract duplication if/when we come to add other invitations, e.g. for school owners, rather than try to come up with a generic invitation model upfront. Note that I've left the `InvitationMailer` & `InvitationPreview` unchanged, because they both already have `#invite_teacher` methods which are already sufficient to discriminate between different types of invitation.
1 parent ea1c1d6 commit 8349dc1

File tree

12 files changed

+36
-31
lines changed

12 files changed

+36
-31
lines changed

app/controllers/api/teacher_invitations_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def accept
2626
private
2727

2828
def load_invitation
29-
@invitation = Invitation.find_by_token_for!(:teacher_invitation, params[:token])
29+
@invitation = TeacherInvitation.find_by_token_for!(:teacher_invitation, params[:token])
3030
end
3131

3232
def ensure_invitation_email_matches_user_email

app/models/invitation.rb renamed to app/models/teacher_invitation.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
class Invitation < ApplicationRecord
3+
class TeacherInvitation < ApplicationRecord
44
delegate :name, to: :school, prefix: true
55

66
belongs_to :school
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class RenameInvitationsToTeacherInvitations < ActiveRecord::Migration[7.1]
2+
def change
3+
rename_table :invitations, :teacher_invitations
4+
end
5+
end

db/schema.rb

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/concepts/school_teacher/invite.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def call(school:, school_teacher_params:, token:)
1717

1818
def invite_teacher(school, school_teacher_params, _token)
1919
email_address = school_teacher_params.fetch(:email_address)
20-
Invitation.create!(school:, email_address:)
20+
TeacherInvitation.create!(school:, email_address:)
2121
end
2222
end
2323
end

spec/concepts/school_teacher/invite_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
expect(response.success?).to be(true)
1717
end
1818

19-
it 'creates an Invitation' do
20-
expect { described_class.call(school:, school_teacher_params:, token:) }.to change(Invitation, :count)
19+
it 'creates a TeacherInvitation' do
20+
expect { described_class.call(school:, school_teacher_params:, token:) }.to change(TeacherInvitation, :count)
2121
end
2222

2323
context 'when creation fails' do

spec/factories/invitation.rb renamed to spec/factories/teacher_invitation.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
FactoryBot.define do
4-
factory :invitation do
4+
factory :teacher_invitation do
55
email_address { '[email protected]' }
66
school factory: :verified_school
77
end

spec/features/teacher_invitations/accepting_an_invitation_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
end
2222

2323
context 'when invitation does not exist' do
24-
let(:invitation) { build(:invitation) }
24+
let(:invitation) { build(:teacher_invitation) }
2525
let!(:token) { invitation.generate_token_for(:teacher_invitation) }
2626

2727
it 'responds 404 Not Found' do
@@ -33,7 +33,7 @@
3333
context 'when invitation exists' do
3434
let(:school) { create(:verified_school) }
3535
let(:invitation_email) { user.email }
36-
let(:invitation) { create(:invitation, email_address: invitation_email, school:) }
36+
let(:invitation) { create(:teacher_invitation, email_address: invitation_email, school:) }
3737
let!(:token) { invitation.generate_token_for(:teacher_invitation) }
3838

3939
context 'when invitation token is not valid because invitation email has changed' do

spec/features/teacher_invitations/viewing_an_invitation_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
end
2222

2323
context 'when invitation does not exist' do
24-
let(:invitation) { build(:invitation) }
24+
let(:invitation) { build(:teacher_invitation) }
2525
let!(:token) { invitation.generate_token_for(:teacher_invitation) }
2626

2727
it 'responds 404 Not Found' do
@@ -32,7 +32,7 @@
3232

3333
context 'when invitation exists' do
3434
let(:invitation_email) { user.email }
35-
let(:invitation) { create(:invitation, email_address: invitation_email) }
35+
let(:invitation) { create(:teacher_invitation, email_address: invitation_email) }
3636
let!(:token) { invitation.generate_token_for(:teacher_invitation) }
3737

3838
context 'when invitation token is not valid because invitation email has changed' do

spec/mailers/invitation_mailer_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
describe 'invite_teacher' do
77
subject(:email) { described_class.with(invitation:).invite_teacher }
88

9-
let(:invitation) { create(:invitation) }
9+
let(:invitation) { create(:teacher_invitation) }
1010

1111
before do
1212
allow(ENV).to receive(:fetch).with('EDITOR_PUBLIC_URL').and_return('http://example.com')

spec/mailers/previews/invitation_preview.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
class InvitationPreview < ActionMailer::Preview
55
def invite_teacher
66
school = School.new(name: 'Elmwood Secondary School')
7-
invitation = Invitation.new(email_address: '[email protected]', school:)
7+
invitation = TeacherInvitation.new(email_address: '[email protected]', school:)
88
InvitationMailer.with(invitation:).invite_teacher
99
end
1010
end

spec/models/invitation_spec.rb renamed to spec/models/teacher_invitation_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22

33
require 'rails_helper'
44

5-
RSpec.describe Invitation do
5+
RSpec.describe TeacherInvitation do
66
include ActionMailer::TestHelper
77
include ActiveSupport::Testing::TimeHelpers
88

99
it 'has a valid factory' do
10-
invitation = build(:invitation)
10+
invitation = build(:teacher_invitation)
1111

1212
expect(invitation).to be_valid
1313
end
1414

1515
it 'is invalid with an incorrectly formatted email address' do
16-
invitation = build(:invitation, email_address: 'not-an-email-address')
16+
invitation = build(:teacher_invitation, email_address: 'not-an-email-address')
1717

1818
expect(invitation).not_to be_valid
1919
end
2020

2121
it 'is invalid with an unverified school' do
2222
school = build(:school, verified_at: nil)
23-
invitation = build(:invitation, school:)
23+
invitation = build(:teacher_invitation, school:)
2424

2525
expect(invitation).not_to be_valid
2626
end
@@ -34,14 +34,14 @@
3434
end
3535

3636
it 'generates a token for teacher invitation' do
37-
invitation = create(:invitation)
37+
invitation = create(:teacher_invitation)
3838
token = invitation.generate_token_for(:teacher_invitation)
3939

4040
expect(described_class.find_by_token_for(:teacher_invitation, token)).to eq(invitation)
4141
end
4242

4343
it 'generates a token valid for 30 days' do
44-
invitation = create(:invitation)
44+
invitation = create(:teacher_invitation)
4545
token = invitation.generate_token_for(:teacher_invitation)
4646

4747
travel 31.days do
@@ -50,7 +50,7 @@
5050
end
5151

5252
it 'invalidates the token if the email address changes' do
53-
invitation = create(:invitation)
53+
invitation = create(:teacher_invitation)
5454
token = invitation.generate_token_for(:teacher_invitation)
5555

5656
invitation.update(email_address: '[email protected]')
@@ -60,7 +60,7 @@
6060

6161
it 'delegates #school_name to School#name' do
6262
school = build(:school, name: 'school-name')
63-
invitation = build(:invitation, school:)
63+
invitation = build(:teacher_invitation, school:)
6464

6565
expect(invitation.school_name).to eq('school-name')
6666
end

0 commit comments

Comments
 (0)