-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathupdate_spec.rb
73 lines (58 loc) · 2.32 KB
/
update_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Lesson::Update, type: :unit do
let(:school) { create(:school) }
let(:teacher) { create(:teacher, school:) }
let(:student) { create(:student, school:) }
let(:lesson) { create(:lesson, name: 'Test Lesson', user_id: teacher.id) }
let!(:student_project) { create(:project, remixed_from_id: lesson.project.id, user_id: student.id) }
let(:current_user) { authenticated_user }
let(:lesson_params) do
{ name: 'New Name' }
end
before do
authenticated_in_hydra_as(teacher)
end
it 'returns a successful operation response' do
response = described_class.call(lesson:, lesson_params:, current_user:)
expect(response.success?).to be(true)
end
it 'updates the lesson' do
response = described_class.call(lesson:, lesson_params:, current_user:)
expect(response[:lesson].name).to eq('New Name')
end
it 'updates the project name' do
described_class.call(lesson:, lesson_params:, current_user:)
expect(lesson.project.name).to eq('New Name')
end
it 'updates the student project name' do
described_class.call(lesson:, lesson_params:, current_user:)
expect(student_project.reload.name).to eq('New Name')
end
it 'returns the lesson in the operation response' do
response = described_class.call(lesson:, lesson_params:, current_user:)
expect(response[:lesson]).to be_a(Lesson)
end
context 'when updating fails' do
let(:lesson_params) { { name: ' ' } }
before do
allow(Sentry).to receive(:capture_exception)
end
it 'does not update the lesson' do
response = described_class.call(lesson:, lesson_params:, current_user:)
expect(response[:lesson].reload.name).to eq('Test Lesson')
end
it 'returns a failed operation response' do
response = described_class.call(lesson:, lesson_params:, current_user:)
expect(response.failure?).to be(true)
end
it 'returns the error message in the operation response' do
response = described_class.call(lesson:, lesson_params:, current_user:)
expect(response[:error]).to match(/Error updating lesson/)
end
it 'sent the exception to Sentry' do
described_class.call(lesson:, lesson_params:, current_user:)
expect(Sentry).to have_received(:capture_exception).with(kind_of(StandardError))
end
end
end