summaryrefslogtreecommitdiff
path: root/spec/controllers/projects/wikis_controller_spec.rb
diff options
context:
space:
mode:
authorFrancisco Javier López <fjlopez@gitlab.com>2018-10-17 15:47:05 +0000
committerDouwe Maan <douwe@gitlab.com>2018-10-17 15:47:05 +0000
commitb8cf360e2ae446db1f21c0275e2047d776730a05 (patch)
tree08aad72c9813659459247c74fc46b6db4bc2cd91 /spec/controllers/projects/wikis_controller_spec.rb
parent11152ddf3d4f977232676fea38eca28b7b6e6ddd (diff)
downloadgitlab-ce-b8cf360e2ae446db1f21c0275e2047d776730a05.tar.gz
Fixed bug with the content disposition with wiki attachments
Diffstat (limited to 'spec/controllers/projects/wikis_controller_spec.rb')
-rw-r--r--spec/controllers/projects/wikis_controller_spec.rb56
1 files changed, 45 insertions, 11 deletions
diff --git a/spec/controllers/projects/wikis_controller_spec.rb b/spec/controllers/projects/wikis_controller_spec.rb
index 30623b6cb3d..6d75152857b 100644
--- a/spec/controllers/projects/wikis_controller_spec.rb
+++ b/spec/controllers/projects/wikis_controller_spec.rb
@@ -22,20 +22,18 @@ describe Projects::WikisController do
subject { get :show, namespace_id: project.namespace, project_id: project, id: wiki_title }
- context 'when page content encoding is invalid' do
- it 'limits the retrieved pages for the sidebar' do
- expect(controller).to receive(:load_wiki).and_return(project_wiki)
+ it 'limits the retrieved pages for the sidebar' do
+ expect(controller).to receive(:load_wiki).and_return(project_wiki)
- # empty? call
- expect(project_wiki).to receive(:pages).with(limit: 1).and_call_original
- # Sidebar entries
- expect(project_wiki).to receive(:pages).with(limit: 15).and_call_original
+ # empty? call
+ expect(project_wiki).to receive(:pages).with(limit: 1).and_call_original
+ # Sidebar entries
+ expect(project_wiki).to receive(:pages).with(limit: 15).and_call_original
- subject
+ subject
- expect(response).to have_http_status(:ok)
- expect(response.body).to include(wiki_title)
- end
+ expect(response).to have_http_status(:ok)
+ expect(response.body).to include(wiki_title)
end
context 'when page content encoding is invalid' do
@@ -48,6 +46,42 @@ describe Projects::WikisController do
expect(flash[:notice]).to eq 'The content of this page is not encoded in UTF-8. Edits can only be made via the Git repository.'
end
end
+
+ context 'when page is a file' do
+ include WikiHelpers
+
+ let(:path) { upload_file_to_wiki(project, user, file_name) }
+
+ before do
+ subject
+ end
+
+ subject { get :show, namespace_id: project.namespace, project_id: project, id: path }
+
+ context 'when file is an image' do
+ let(:file_name) { 'dk.png' }
+
+ it 'renders the content inline' do
+ expect(response.headers['Content-Disposition']).to match(/^inline/)
+ end
+
+ context 'when file is a svg' do
+ let(:file_name) { 'unsanitized.svg' }
+
+ it 'renders the content as an attachment' do
+ expect(response.headers['Content-Disposition']).to match(/^attachment/)
+ end
+ end
+ end
+
+ context 'when file is a pdf' do
+ let(:file_name) { 'git-cheat-sheet.pdf' }
+
+ it 'sets the content type to application/octet-stream' do
+ expect(response.headers['Content-Type']).to eq 'application/octet-stream'
+ end
+ end
+ end
end
describe 'POST #preview_markdown' do