|
28 | 28 | end
|
29 | 29 | end
|
30 | 30 |
|
31 |
| - describe '#show' do |
32 |
| - subject { get :show, as: :json, params: { course_id: course, id: timeline } } |
33 |
| - |
34 |
| - context 'when the user is a manager of the course' do |
35 |
| - let(:user) { create(:course_manager, course: course).user } |
36 |
| - |
37 |
| - it { is_expected.to render_template(:show) } |
38 |
| - end |
39 |
| - |
40 |
| - context 'when the user is a student' do |
41 |
| - let(:user) { create(:course_student, course: course).user } |
42 |
| - |
43 |
| - it { expect { subject }.to raise_error(CanCan::AccessDenied) } |
44 |
| - end |
45 |
| - end |
46 |
| - |
47 | 31 | describe '#create' do
|
48 | 32 | subject do
|
49 | 33 | post :create, as: :json, params: {
|
|
65 | 49 | expect(new_timeline.weight).to eq(2)
|
66 | 50 | end
|
67 | 51 |
|
68 |
| - context 'when an array of times are given' do |
69 |
| - let(:item) { create(:course_lesson_plan_item, course: course) } |
70 |
| - # Convert Ruby Time to string because of differences in micro/nano-second precision between |
71 |
| - # database and in-memory time representations. See https://stackoverflow.com/a/20403290. |
72 |
| - let(:start_time) { 1.day.from_now.to_s } |
73 |
| - let(:bonus_end_time) { 2.days.from_now.to_s } |
74 |
| - let(:end_time) { 3.days.from_now.to_s } |
75 |
| - |
76 |
| - subject do |
77 |
| - post :create, as: :json, params: { |
78 |
| - course_id: course, |
79 |
| - reference_timeline: { |
80 |
| - title: title, |
81 |
| - reference_times_attributes: [ |
82 |
| - { |
83 |
| - lesson_plan_item_id: item.id, |
84 |
| - start_at: start_time, |
85 |
| - bonus_end_at: bonus_end_time, |
86 |
| - end_at: end_time |
87 |
| - } |
88 |
| - ] |
89 |
| - } |
90 |
| - } |
91 |
| - end |
92 |
| - |
93 |
| - it 'creates the timeline, the given times, and their associations' do |
94 |
| - expect { subject }. |
95 |
| - to change { course.reference_timelines.size }.by(1). |
96 |
| - and change { item.reference_times.size }.by(1) |
97 |
| - |
98 |
| - is_expected.to have_http_status(:ok) |
99 |
| - is_expected.to render_template(partial: '_reference_timeline') |
100 |
| - |
101 |
| - new_timeline = assigns(:reference_timeline) |
102 |
| - expect(new_timeline.title).to eq(title) |
103 |
| - expect(new_timeline.reference_times.size).to eq(1) |
104 |
| - |
105 |
| - new_time = new_timeline.reference_times.first |
106 |
| - expect(new_time.lesson_plan_item.id).to eq(item.id) |
107 |
| - expect(new_time.start_at).to eq(start_time) |
108 |
| - expect(new_time.bonus_end_at).to eq(bonus_end_time) |
109 |
| - expect(new_time.end_at).to eq(end_time) |
110 |
| - end |
111 |
| - end |
112 |
| - |
113 | 52 | context 'when cannot be saved' do
|
114 | 53 | before do
|
115 | 54 | allow(timeline).to receive(:save).and_return(false)
|
|
0 commit comments