summaryrefslogtreecommitdiff
path: root/spec/mailers
diff options
context:
space:
mode:
authorAlex Kalderimis <akalderimis@gitlab.com>2019-08-21 19:23:27 +0000
committerMayra Cabrera <mcabrera@gitlab.com>2019-08-21 19:23:27 +0000
commitac94033b2db012f6d9e2dcca2bf48f7ac94f38a0 (patch)
treeb8971803961b85ab06c293b5fbfdff0a398b582e /spec/mailers
parent2ef59c7e4bf133b6d92277b081fb1eb76bc3d0d9 (diff)
downloadgitlab-ce-ac94033b2db012f6d9e2dcca2bf48f7ac94f38a0.tar.gz
Handle namespaced models
We encountered issues with setting module headers for namespaced models. These changes address this. We retain the namespacing, but transform the classnames to make them into safe email headers.
Diffstat (limited to 'spec/mailers')
-rw-r--r--spec/mailers/notify_spec.rb67
1 files changed, 67 insertions, 0 deletions
diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb
index dcc4b70a382..6cba7df114c 100644
--- a/spec/mailers/notify_spec.rb
+++ b/spec/mailers/notify_spec.rb
@@ -543,6 +543,73 @@ describe Notify do
end
end
+ describe '#mail_thread' do
+ set(:mail_thread_note) { create(:note) }
+
+ let(:headers) do
+ {
+ from: 'someone@test.com',
+ to: 'someone-else@test.com',
+ subject: 'something',
+ template_name: '_note_email' # re-use this for testing
+ }
+ end
+
+ let(:mailer) do
+ mailer = described_class.new
+ mailer.instance_variable_set(:@note, mail_thread_note)
+ mailer
+ end
+
+ context 'the model has no namespace' do
+ class TopLevelThing
+ include Referable
+ include Noteable
+
+ def to_reference(*_args)
+ 'tlt-ref'
+ end
+
+ def id
+ 'tlt-id'
+ end
+ end
+
+ subject do
+ mailer.send(:mail_thread, TopLevelThing.new, headers)
+ end
+
+ it 'has X-GitLab-Namespaced-Thing-ID header' do
+ expect(subject.header['X-GitLab-TopLevelThing-ID'].value).to eq('tlt-id')
+ end
+ end
+
+ context 'the model has a namespace' do
+ module Namespaced
+ class Thing
+ include Referable
+ include Noteable
+
+ def to_reference(*_args)
+ 'some-reference'
+ end
+
+ def id
+ 'some-id'
+ end
+ end
+ end
+
+ subject do
+ mailer.send(:mail_thread, Namespaced::Thing.new, headers)
+ end
+
+ it 'has X-GitLab-Namespaced-Thing-ID header' do
+ expect(subject.header['X-GitLab-Namespaced-Thing-ID'].value).to eq('some-id')
+ end
+ end
+ end
+
context 'for issue notes' do
let(:host) { Gitlab.config.gitlab.host }