|
1 | 1 | RSpec.describe Chapter do |
2 | | - it { should validate_presence_of(:city) } |
3 | | - it { should validate_length_of(:description).is_at_most(280) } |
| 2 | + it { is_expected.to validate_presence_of(:city) } |
| 3 | + it { is_expected.to validate_length_of(:description).is_at_most(280) } |
4 | 4 |
|
5 | 5 | context 'validations' do |
6 | | - context '#slug' do |
| 6 | + describe '#slug' do |
7 | 7 | it 'a chapter must have a slug set' do |
8 | 8 | chapter = Chapter.new(name: 'London', city: 'London', email: 'london@codebar.io') |
9 | 9 | chapter.save |
|
19 | 19 | end |
20 | 20 | end |
21 | 21 |
|
22 | | - context '#time_zone' do |
| 22 | + describe '#time_zone' do |
23 | 23 | it 'requires a time zone' do |
24 | 24 | chapter = Fabricate(:chapter) |
25 | 25 | expect(chapter).to be_valid |
|
32 | 32 | end |
33 | 33 |
|
34 | 34 | context 'scopes' do |
35 | | - context '#active' do |
| 35 | + describe '#active' do |
36 | 36 | it 'only returns active Chapters' do |
37 | 37 | 1.times { Fabricate(:chapter) } |
38 | 38 | 2.times { Fabricate(:chapter, active: false) } |
|
65 | 65 | expect(Rails.cache.read(cache_key)).to be_nil |
66 | 66 | end |
67 | 67 | end |
| 68 | + |
| 69 | + describe '#eligible_students' do |
| 70 | + let(:chapter) { Fabricate(:chapter) } |
| 71 | + let(:student_group) { Fabricate(:group, chapter: chapter, name: 'Students') } |
| 72 | + |
| 73 | + it 'includes only students with accepted TOC who are not banned' do |
| 74 | + eligible_student = Fabricate(:member, groups: [student_group], accepted_toc_at: Time.zone.now) |
| 75 | + _ineligible_no_toc = Fabricate(:member, groups: [student_group], accepted_toc_at: nil) |
| 76 | + _ineligible_banned = Fabricate(:banned_member, groups: [student_group], accepted_toc_at: Time.zone.now) |
| 77 | + |
| 78 | + expect(chapter.eligible_students).to contain_exactly(eligible_student) |
| 79 | + end |
| 80 | + |
| 81 | + it 'returns empty relation when no eligible students' do |
| 82 | + Fabricate(:member, groups: [student_group], accepted_toc_at: nil) |
| 83 | + expect(chapter.eligible_students).to be_empty |
| 84 | + end |
| 85 | + end |
| 86 | + |
| 87 | + describe '#eligible_coaches' do |
| 88 | + let(:chapter) { Fabricate(:chapter) } |
| 89 | + let(:coach_group) { Fabricate(:group, chapter: chapter, name: 'Coaches') } |
| 90 | + |
| 91 | + it 'includes only coaches with accepted TOC who are not banned' do |
| 92 | + eligible_coach = Fabricate(:member, groups: [coach_group], accepted_toc_at: Time.zone.now) |
| 93 | + _ineligible_no_toc = Fabricate(:member, groups: [coach_group], accepted_toc_at: nil) |
| 94 | + _ineligible_banned = Fabricate(:banned_member, groups: [coach_group], accepted_toc_at: Time.zone.now) |
| 95 | + |
| 96 | + expect(chapter.eligible_coaches).to contain_exactly(eligible_coach) |
| 97 | + end |
| 98 | + |
| 99 | + it 'returns empty relation when no eligible coaches' do |
| 100 | + Fabricate(:member, groups: [coach_group], accepted_toc_at: nil) |
| 101 | + expect(chapter.eligible_coaches).to be_empty |
| 102 | + end |
| 103 | + end |
68 | 104 | end |
0 commit comments