|
101 | 101 | end |
102 | 102 | end |
103 | 103 |
|
104 | | - describe '#grouped_lesson_plan_items_with_milestones' do |
105 | | - let(:course) { create(:course) } |
106 | | - let!(:milestones) do |
107 | | - [3.days.ago, 2.days.ago, 2.days.from_now].map do |start_at| |
108 | | - create(:course_lesson_plan_milestone, course: course, start_at: start_at) |
109 | | - end |
110 | | - end |
111 | | - let!(:lesson_plan_items) do |
112 | | - [3.days.ago, 2.days.ago, 1.day.from_now, 3.days.from_now].map do |start_at| |
113 | | - create(:course_lesson_plan_item, course: course, start_at: start_at) |
114 | | - end |
115 | | - end |
116 | | - subject { course.grouped_lesson_plan_items_with_milestones } |
117 | | - |
118 | | - context 'when no events fall under a milestone' do |
119 | | - let!(:empty_milestone) do |
120 | | - create(:course_lesson_plan_milestone, course: course, start_at: 4.days.ago) |
121 | | - end |
122 | | - it 'does not group any items under that milestone' do |
123 | | - expect(subject[empty_milestone]).to be_empty |
124 | | - end |
125 | | - end |
126 | | - |
127 | | - context 'when no milestones exist' do |
128 | | - let!(:milestones) { [] } |
129 | | - it 'groups all items under the nil milestone' do |
130 | | - expect(subject.length).to eq(1) |
131 | | - expect(subject.keys).to eq([nil]) |
132 | | - expect(subject[nil].each_cons(2).all? { |(a, b)| a.start_at <= b.start_at }).to \ |
133 | | - be_truthy |
134 | | - end |
135 | | - end |
136 | | - |
137 | | - context 'when the first milestone comes after the first event' do |
138 | | - before do |
139 | | - milestone_to_delete = milestones.shift |
140 | | - milestone_to_delete.destroy |
141 | | - end |
142 | | - |
143 | | - it 'groups all items before the first milestone under the nil milestone' do |
144 | | - expect(subject).to have_key(nil) |
145 | | - expect(subject[nil]).to contain_exactly(lesson_plan_items.first) |
146 | | - end |
147 | | - end |
148 | | - |
149 | | - context 'when the first milestone and the first event starts at the same time' do |
150 | | - it 'groups the first event under the first milestone' do |
151 | | - expect(subject[milestones.first]).to include(lesson_plan_items.first) |
152 | | - end |
153 | | - end |
154 | | - |
155 | | - context 'when no items exist' do |
156 | | - it 'creates the keys for all milestones' do |
157 | | - expect(subject.length).to eq(milestones.length) |
158 | | - end |
159 | | - end |
160 | | - end |
161 | | - |
162 | 104 | describe '#staff' do |
163 | 105 | let(:course) { create(:course, creator: owner, updater: owner) } |
164 | 106 | let(:course_owner) { course.course_users.find_by!(user: owner) } |
|
0 commit comments