Commit 4a1e98e4 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge pull request #6650 from lloeki/wiki_images_attachments

Added ability to serve files in wiki repository
parents 66098dbb c1ccc3a5
......@@ -12,12 +12,10 @@ class Projects::WikisController < Projects::ApplicationController
def show
@page = @project_wiki.find_page(params[:id], params[:version_id])
gollum_wiki = @project_wiki.wiki
file = gollum_wiki.file(params[:id], gollum_wiki.ref, true)
if @page
render 'show'
elsif file
elsif file = @project_wiki.find_file(params[:id], params[:version_id])
if file.on_disk?
send_file file.on_disk_path, disposition: 'inline'
else
......
......@@ -72,6 +72,15 @@ class ProjectWiki
end
end
def find_file(name, version = nil, try_on_disk = true)
version = wiki.ref if version.nil? # Gollum::Wiki#file ?
if wiki_file = wiki.file(name, version, try_on_disk)
wiki_file
else
nil
end
end
def create_page(title, content, format = :markdown, message = nil)
commit = commit_details(:created, message, title)
......
......@@ -149,6 +149,40 @@ describe ProjectWiki do
end
end
describe '#find_file' do
before do
file = Gollum::File.new(subject.wiki)
Gollum::Wiki.any_instance.
stub(:file).with('image.jpg', 'master', true).
and_return(file)
Gollum::File.any_instance.
stub(:mime_type).
and_return('image/jpeg')
Gollum::Wiki.any_instance.
stub(:file).with('non-existant', 'master', true).
and_return(nil)
end
after do
Gollum::Wiki.any_instance.unstub(:file)
Gollum::File.any_instance.unstub(:mime_type)
end
it 'returns the latest version of the file if it exists' do
file = subject.find_file('image.jpg')
file.mime_type.should == 'image/jpeg'
end
it 'returns nil if the page does not exist' do
subject.find_file('non-existant').should == nil
end
it 'returns a Gollum::File instance' do
file = subject.find_file('image.jpg')
file.should be_a Gollum::File
end
end
describe "#create_page" do
after do
destroy_page(subject.pages.first.page)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment