diff --git a/lib/gollum/file.rb b/lib/gollum/file.rb index 6ba564a2..c0150c34 100644 --- a/lib/gollum/file.rb +++ b/lib/gollum/file.rb @@ -44,8 +44,8 @@ module Gollum def raw_data return nil unless @blob - if @blob.is_symlink - new_path = @blob.symlink_target(self.path) + if !@wiki.repo.bare && @blob.is_symlink + new_path = @blob.symlink_target(::File.join(@wiki.repo.path, '..', self.path)) return IO.read(new_path) if new_path end diff --git a/lib/gollum/page.rb b/lib/gollum/page.rb index 4da58670..2abea5aa 100644 --- a/lib/gollum/page.rb +++ b/lib/gollum/page.rb @@ -182,8 +182,8 @@ module Gollum def raw_data return nil unless @blob - if @blob.is_symlink - new_path = @blob.symlink_target(::File.join(@wiki.repo.path, self.path)) + if !@wiki.repo.bare && @blob.is_symlink + new_path = @blob.symlink_target(::File.join(@wiki.repo.path, '..', self.path)) return IO.read(new_path) if new_path end diff --git a/test/test_app.rb b/test/test_app.rb index 62135158..3ef56e90 100644 --- a/test/test_app.rb +++ b/test/test_app.rb @@ -485,11 +485,13 @@ context "Frontend with lotr" do # . # ├── Bilbo-Baggins.md # ├── Data.csv + # |-- Data-Two.csv -> Data.csv # ├── Gondor # │ ├── Boromir.md # │ ├── _Footer.md # │ ├── _Header.md # │ └── _Sidebar.md + # |-- Hobbit.md -> Bilbo-Baggins.md # ├── Home.textile # ├── Mordor # │ ├── Eye-Of-Sauron.md @@ -528,6 +530,11 @@ context "Frontend with lotr" do assert body.include?("Eye Of Sauron"), "/pages/Mordor/ should include the page 'Eye Of Sauron'" end + test "symbolic link pages" do + get "/Hobbit" + assert_match /Bilbo Baggins/, last_response.body + end + # base path requires 'map' in a config.ru to work correctly. test "create pages within sub-directories using base path" do Precious::App.set(:wiki_options, { :base_path => 'wiki' }) diff --git a/test/test_file.rb b/test/test_file.rb index 68b85a70..b9e22194 100644 --- a/test/test_file.rb +++ b/test/test_file.rb @@ -21,21 +21,25 @@ context "File" do assert_equal commit.author.name, file.version.author.name end + test "accessing tree" do + assert_nil @wiki.file("Mordor") + end +end + +context "File with checkout" do + setup do + @path = cloned_testpath("examples/lotr.git") + @wiki = Gollum::Wiki.new(@path) + end + + teardown do + FileUtils.rm_rf(@path) + end + test "symbolic link" do commit = @wiki.repo.commits.first file = @wiki.file("Data-Two.csv") - # Since we don't have a checkout here (bare repos in testing), these - # symbolic links won't resolve. Stub IO.read to simulate the behavior - # and make sure all is working well. - path_to_link = File.expand_path(File.join('..', '..', 'Data.csv'), __FILE__) - File.expects(:file?).with(path_to_link).returns(true) - IO.expects(:read).with(path_to_link).returns('symlink test') - - assert_equal file.raw_data, 'symlink test' + assert_match /^FirstName,LastName\n/, file.raw_data end - - test "accessing tree" do - assert_nil @wiki.file("Mordor") - end -end \ No newline at end of file +end diff --git a/test/test_page.rb b/test/test_page.rb index 08b46253..95ef0e05 100644 --- a/test/test_page.rb +++ b/test/test_page.rb @@ -34,23 +34,6 @@ context "Page" do assert_nil @wiki.page('Bilbo_Baggins') end - test "get existing page with symbolic link" do - page = @wiki.page("Hobbit") - assert_equal Gollum::Page, page.class - assert_equal 'Hobbit.md', page.path - assert_equal :markdown, page.format - - # Since we don't have a checkout here (bare repos in testing), these - # symbolic links won't resolve. Stub IO.read to simulate the behavior - # and make sure all is working well. - path_to_link = File.expand_path(File.join('..', 'examples', 'lotr.git', 'Bilbo-Baggins.md'), __FILE__) - File.expects(:file?).with(path_to_link).returns(true).at_least_once - IO.expects(:read).with(path_to_link).returns("# Bilbo Baggins\n\nBilbo Baggins").at_least_once - - assert page.raw_data =~ /^# Bilbo Baggins\n\nBilbo Baggins/ - assert page.formatted_data =~ %r{
Bilbo Baggins} - end - test "get existing page where filename contains whitespace, with hypen" do assert_equal @wiki.page('Samwise Gamgee').path, @wiki.page('Samwise-Gamgee').path end @@ -214,6 +197,26 @@ context "Page" do end end +context "with a checkout" do + setup do + @path = cloned_testpath("examples/lotr.git") + @wiki = Gollum::Wiki.new(@path) + end + + teardown do + FileUtils.rm_rf(@path) + end + + test "get existing page with symbolic link" do + page = @wiki.page("Hobbit") + assert_equal Gollum::Page, page.class + assert page.raw_data =~ /^# Bilbo Baggins\n\nBilbo Baggins/ + assert page.formatted_data =~ %r{
Bilbo Baggins} + assert_equal 'Hobbit.md', page.path + assert_equal :markdown, page.format + end +end + context "within a sub-directory" do setup do @wiki = Gollum::Wiki.new(testpath("examples/lotr.git"), { :page_file_dir => 'Rivendell' })