|
3 | 3 | require 'rails_helper' |
4 | 4 |
|
5 | 5 | RSpec.describe UserContentReport do |
| 6 | + subject(:report) { described_class.new(reported_content:) } |
| 7 | + |
6 | 8 | 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) } |
9 | 11 |
|
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 |
11 | 15 | end |
12 | 16 |
|
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 |
17 | 24 | end |
18 | 25 | end |
19 | 26 |
|
20 | 27 | describe '#reported_message' do |
21 | 28 | let(:message) { 'This message is reported.' } |
22 | 29 |
|
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) } |
25 | 32 |
|
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 |
27 | 36 | end |
28 | 37 |
|
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) } |
31 | 40 |
|
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 |
33 | 44 | end |
34 | 45 | end |
35 | 46 |
|
36 | 47 | 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) } |
39 | 50 |
|
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 |
41 | 54 | end |
42 | 55 |
|
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) } |
45 | 58 |
|
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 |
49 | 64 |
|
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 |
51 | 68 | end |
52 | 69 |
|
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) } |
55 | 72 |
|
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 |
59 | 78 |
|
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 |
61 | 82 | end |
62 | 83 | end |
63 | 84 |
|
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 |
66 | 91 | end |
67 | 92 | end |
0 commit comments