Skip to content

Commit 97fafda

Browse files
committed
Use subject in user content report spec
1 parent 38d3c0d commit 97fafda

File tree

1 file changed

+55
-30
lines changed

1 file changed

+55
-30
lines changed

spec/lib/user_content_report_spec.rb

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,65 +3,90 @@
33
require 'rails_helper'
44

55
RSpec.describe UserContentReport do
6+
subject(:report) { described_class.new(reported_content:) }
7+
68
describe '#related_request_for_comment' do
7-
it 'returns the RfC when the RfC itself is reported' do
8-
rfc = build_stubbed(:rfc)
9+
context 'when a PfC is reported' do
10+
let(:reported_content) { build_stubbed(:rfc) }
911

10-
expect(described_class.new(reported_content: rfc).related_request_for_comment).to eq rfc
12+
it 'returns the RfC itself' do
13+
expect(report.related_request_for_comment).to eq reported_content
14+
end
1115
end
1216

13-
it 'returns the associated RfC when a comment is reported' do
14-
rfc = create(:rfc)
15-
comment = create(:comment, file: rfc.file)
16-
expect(described_class.new(reported_content: comment).related_request_for_comment).to eq rfc
17+
context 'when a comment is reported' do
18+
let(:rfc) { create(:rfc) }
19+
let(:reported_content) { create(:comment, file: rfc.file) }
20+
21+
it 'returns the associated RfC' do
22+
expect(report.related_request_for_comment).to eq rfc
23+
end
1724
end
1825
end
1926

2027
describe '#reported_message' do
2128
let(:message) { 'This message is reported.' }
2229

23-
it 'returns the comments text' do
24-
comment = build_stubbed(:comment, text: message)
30+
context 'when a comment is reported' do
31+
let(:reported_content) { build_stubbed(:comment, text: message) }
2532

26-
expect(described_class.new(reported_content: comment).reported_message).to eq message
33+
it 'returns the comments text' do
34+
expect(report.reported_message).to eq message
35+
end
2736
end
2837

29-
it 'returns the RfCs question' do
30-
rfc = build_stubbed(:rfc, question: message)
38+
context 'when a PfC is reported' do
39+
let(:reported_content) { build_stubbed(:rfc, question: message) }
3140

32-
expect(described_class.new(reported_content: rfc).reported_message).to eq message
41+
it 'returns the RfCs question' do
42+
expect(report.reported_message).to eq message
43+
end
3344
end
3445
end
3546

3647
describe '#course_url' do
37-
it 'has no course URL if the LTI parameters are absent' do
38-
rfc = build_stubbed(:rfc)
48+
context 'when the LTI parameter is missing' do
49+
let(:reported_content) { build_stubbed(:rfc) }
3950

40-
expect(described_class.new(reported_content: rfc).course_url).to be_nil
51+
it 'returns no course URL' do
52+
expect(report.course_url).to be_nil
53+
end
4154
end
4255

43-
it 'has no course URL if the required LTI attribute is missing' do
44-
rfc = create(:rfc)
56+
context 'when the LTI parameter has no retrun URL' do
57+
let(:reported_content) { create(:rfc) }
4558

46-
create(:lti_parameter, :without_return_url,
47-
exercise: rfc.file.request_for_comment.exercise,
48-
study_group: rfc.submission.study_group)
59+
before do
60+
create(:lti_parameter, :without_return_url,
61+
exercise: reported_content.file.request_for_comment.exercise,
62+
study_group: reported_content.submission.study_group)
63+
end
4964

50-
expect(described_class.new(reported_content: rfc).course_url).to be_nil
65+
it 'returns no course URL' do
66+
expect(report.course_url).to be_nil
67+
end
5168
end
5269

53-
it 'returns the LTI parameter course URL' do
54-
rfc = create(:rfc)
70+
context 'when the LTI parameter has the retrun URL' do
71+
let(:reported_content) { create(:rfc) }
5572

56-
create(:lti_parameter,
57-
exercise: rfc.file.request_for_comment.exercise,
58-
study_group: rfc.submission.study_group)
73+
before do
74+
create(:lti_parameter,
75+
exercise: reported_content.file.request_for_comment.exercise,
76+
study_group: reported_content.submission.study_group)
77+
end
5978

60-
expect(described_class.new(reported_content: rfc).course_url).to match(%r{https.+/courses/})
79+
it 'returns the LTI parameter course URL' do
80+
expect(report.course_url).to match(%r{https.+/courses/})
81+
end
6182
end
6283
end
6384

64-
it 'raise an error if an unsupported model is reported' do
65-
expect { described_class.new(reported_content: Exercise.new) }.to raise_error('Exercise is not configured for content reports.')
85+
context 'when an unsupported model is reported' do
86+
let(:reported_content) { Exercise.new }
87+
88+
it 'raise an error' do
89+
expect { report }.to raise_error('Exercise is not configured for content reports.')
90+
end
6691
end
6792
end

0 commit comments

Comments
 (0)