Skip to content

Commit 35616fb

Browse files
committed
Add a School model
1 parent ef75901 commit 35616fb

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ GEM
192192
nio4r (2.5.8)
193193
nokogiri (1.14.2-aarch64-linux)
194194
racc (~> 1.4)
195+
nokogiri (1.14.2-arm64-darwin)
196+
racc (~> 1.4)
195197
nokogiri (1.14.2-x86_64-linux)
196198
racc (~> 1.4)
197199
open-uri (0.3.0)
@@ -340,6 +342,7 @@ GEM
340342

341343
PLATFORMS
342344
aarch64-linux
345+
arm64-darwin-22
343346
x86_64-linux
344347

345348
DEPENDENCIES

app/models/school.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# frozen_string_literal: true
2+
3+
class School < ApplicationRecord
4+
validates :organisation_id, presence: true
5+
validates :name, presence: true
6+
end

spec/factories/school.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
FactoryBot.define do
4+
factory :school do
5+
organisation_id { SecureRandom.uuid }
6+
sequence(:name) { |n| "School #{n}" }
7+
end
8+
end

spec/models/school_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# frozen_string_literal: true
2+
3+
require 'rails_helper'
4+
5+
RSpec.describe School do
6+
describe 'validations' do
7+
subject(:school) { build(:school) }
8+
9+
it 'has a valid default factory' do
10+
expect(school).to be_valid
11+
end
12+
13+
it 'can save the default factory' do
14+
expect { school.save! }.not_to raise_error
15+
end
16+
17+
it 'is invalid if no organisation_id' do
18+
school.organisation_id = ' '
19+
expect(school).to be_invalid
20+
end
21+
22+
it 'is invalid if organisation_id is not a UUID' do
23+
school.organisation_id = 'invalid'
24+
expect(school).to be_invalid
25+
end
26+
27+
it 'is invalid if no name' do
28+
school.name = ' '
29+
expect(school).to be_invalid
30+
end
31+
end
32+
end

0 commit comments

Comments
 (0)