Skip to content

Commit 5bd2248

Browse files
committed
Check if authentication information is absent if not available.
1 parent 0c33eef commit 5bd2248

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

app/mailers/report_mailer.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ class ReportMailer < ApplicationMailer
66

77
def report_content
88
@reported_content = params.fetch(:reported_content)
9-
@exercise_url = "#{SETTINGS[:exercises_base_url]}/#{@reported_content.exercise.uuid}"
9+
exercise_id = @reported_content.exercise.uuid
10+
base_url = SETTINGS[:exercises_base_url]
11+
@exercise_url = "#{base_url}/#{exercise_id}" if exercise_id && base_url
1012

1113
mail(subject: I18n.t('report_mailer.report_content.subject', content_name: @reported_content.model_name.human))
1214
end

app/views/report_mailer/report_content.text.slim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
== "\n\n"
99
- if @exercise_url.present?
1010
== t('.authentication')
11+
== "\n\n"
1112
== @exercise_url

spec/mailers/report_mailer_spec.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
subject(:mail) { described_class.with(reported_content:).report_content }
88

99
context 'when an RfC is reported' do
10-
let(:exercise) { reported_content.exercise }
10+
let(:exercise) { create(:fibonacci, uuid: SecureRandom.uuid) }
1111
let(:question) { 'Inappropriate content for RfC.' }
12-
let(:reported_content) { create(:rfc, question:) }
12+
let(:reported_content) { create(:rfc, question:, exercise:) }
1313

1414
it 'sets the correct sender' do
1515
expect(mail.from).to include('[email protected]')
@@ -25,10 +25,16 @@
2525
end
2626

2727
it 'includes the exersice url for the LTI consumer' do
28-
stub_const('ReportMailer::SETTINGS', {exercises_base_url: 'https://a.com/exersices/'})
28+
stub_const('ReportMailer::SETTINGS', {exercises_base_url: 'https://a.com/exersices'})
29+
2930
expect(mail.text_part.body).to include("https://a.com/exersices/#{exercise.uuid}")
3031
expect(mail.html_part.body).to include("https://a.com/exersices/#{exercise.uuid}")
3132
end
33+
34+
it 'dose not include the exersice URL when not configured' do
35+
expect(mail.text_part.body).not_to include(I18n.t('report_mailer.report_content.authentication'))
36+
expect(mail.html_part.body).not_to include(I18n.t('report_mailer.report_content.authentication'))
37+
end
3238
end
3339
end
3440
end

0 commit comments

Comments
 (0)