Skip to content

Commit

Permalink
Reuse constants
Browse files Browse the repository at this point in the history
  • Loading branch information
simfeld committed Mar 9, 2024
1 parent 5b3ec9b commit fa7e971
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions spec/models/event/course_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,11 @@ def person(name, role)
context 'validations' do
let(:kind_with_validation) { Fabricate(:event_kind, validate_course_number: true) }
let(:kind_without_validation) { event_kinds(:lpk) }
VALID_NUMBERS = ['PBS CH 947-00', 'PBS CH XX 007-99', 'PBS CH AB 123-45'].freeze
INVALID_NUMBERS = ['PBS CH 000-FP', 'PBS XY XX 475-31', 'CH AB 123-45', 'PBS CH 123-456',
'PBS CH AB 12-345', 'PBSCHAB123-45'].freeze

context 'course number' do
VALID_NUMBERS = ['PBS CH 947-00', 'PBS CH XX 007-99', 'PBS CH AB 123-45'].freeze
INVALID_NUMBERS = ['PBS CH 000-FP', 'PBS XY XX 475-31', 'CH AB 123-45', 'PBS CH 123-456',
'PBS CH AB 12-345', 'PBSCHAB123-45'].freeze

subject { Fabricate(:course, groups: [groups(:be)], kind: kind_with_validation, number: 'PBS CH BE 123-24') }

Expand Down Expand Up @@ -271,13 +271,13 @@ def person(name, role)
end

it 'is invalid for a number not matching the expected format' do
subject.number = '1234'
subject.number = INVALID_NUMBERS.first
expect(subject.valid?).to be_falsey
expect(subject.errors[:number]).to be_present
end

it 'is valid for a number matching the expected format' do
subject.number = 'PBS CH BE 123-24'
subject.number = VALID_NUMBERS.first
expect(subject.valid?).to be_truthy
end

Expand All @@ -294,7 +294,7 @@ def person(name, role)
end

it 'is valid for a number not matching the expected format' do
subject.number = '1234'
subject.number = INVALID_NUMBERS.first
expect(subject.valid?).to be_truthy
end

Expand All @@ -313,22 +313,22 @@ def person(name, role)

it 'is valid for an event kind with validation enabled and a valid number' do
subject.kind = kind_with_validation
subject.number = 'PBS CH BE 123-24'
subject.number = VALID_NUMBERS.first
subject.validate!
puts subject.errors.full_messages
expect(subject.valid?).to be_truthy
end

it 'is invalid for an event kind with validation enabled and an invalid number' do
subject.kind = kind_with_validation
subject.number = '1234'
subject.number = INVALID_NUMBERS.first
expect(subject.valid?).to be_falsey
expect(subject.errors[:number]).to be_present
end

it 'is valid for an event kind with validation disabled and an invalid number' do
subject.kind = kind_without_validation
subject.number = '1234'
subject.number = INVALID_NUMBERS.first
expect(subject.valid?).to be_truthy
end
end
Expand Down

0 comments on commit fa7e971

Please sign in to comment.