Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2019-06-29 04:08:35 +0300
committerStan Hu <stanhu@gmail.com>2019-06-29 08:08:46 +0300
commit0e341a6e58fc3afca20781cf1f4cbf214b9503ba (patch)
treee7956368ac4d93dd6c900a676fc095a0d52f651d /spec/helpers
parentdf717efaabd9ab11806495244e1e5fa515c01f1f (diff)
Fix attachments using the wrong URLs in e-mails
Prior to https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/29889, only the project context were set for the Markdown renderer. For a note on an issuable, the group context was set to `nil` because `note.noteable.try(:group)` attempted to get the issuable's group, which doesn't exist. To make group notifications work, now both the project and group context are set. The context gets passed to `RelativeLinkFilter`, which previously assumed that it wasn't possible to have both a group and a project in the Markdown context. However, if a group were defined, it would take precedence, and the URL rendered for uploads would be `/group/-/uploads` instead of `/group/project/uploads/`. This led to 404s in e-mails. However, now that we have both project and group in the context, we render the Markdown giving priority to the project context if is set. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/63910
Diffstat (limited to 'spec/helpers')
-rw-r--r--spec/helpers/markup_helper_spec.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/spec/helpers/markup_helper_spec.rb b/spec/helpers/markup_helper_spec.rb
index 597c8f836a9..6c6410cee9b 100644
--- a/spec/helpers/markup_helper_spec.rb
+++ b/spec/helpers/markup_helper_spec.rb
@@ -50,6 +50,43 @@ describe MarkupHelper do
expect(markdown(actual, project: second_project)).to match(expected)
end
end
+
+ describe 'uploads' do
+ let(:text) { "![ImageTest](/uploads/test.png)" }
+ let(:group) { create(:group) }
+
+ subject { helper.markdown(text) }
+
+ describe 'inside a project' do
+ it 'renders uploads relative to project' do
+ expect(subject).to include("#{project.full_path}/uploads/test.png")
+ end
+ end
+
+ describe 'inside a group' do
+ before do
+ helper.instance_variable_set(:@group, group)
+ helper.instance_variable_set(:@project, nil)
+ end
+
+ it 'renders uploads relative to the group' do
+ expect(subject).to include("#{group.full_path}/-/uploads/test.png")
+ end
+ end
+
+ describe "with a group in the context" do
+ let(:project_in_group) { create(:project, group: group) }
+
+ before do
+ helper.instance_variable_set(:@group, group)
+ helper.instance_variable_set(:@project, project_in_group)
+ end
+
+ it 'renders uploads relative to project' do
+ expect(subject).to include("#{project_in_group.path_with_namespace}/uploads/test.png")
+ end
+ end
+ end
end
describe '#markdown_field' do