From 39aa290ea6e6408218710722dce1b5de6a950954 Mon Sep 17 00:00:00 2001 From: Dawa Ometto Date: Wed, 12 Apr 2017 19:42:26 +0200 Subject: [PATCH 1/4] Expose page's SHA id in Page view. Closes 1222. --- lib/gollum/views/has_page.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/gollum/views/has_page.rb b/lib/gollum/views/has_page.rb index ff17b16b..f287ea28 100644 --- a/lib/gollum/views/has_page.rb +++ b/lib/gollum/views/has_page.rb @@ -11,5 +11,9 @@ module Precious def format @page.format.to_s end + + def id + @page.sha + end end end From df9382bbc3caa9e420e1e7e957775afdc56625b5 Mon Sep 17 00:00:00 2001 From: Dawa Ometto Date: Wed, 12 Apr 2017 19:50:40 +0200 Subject: [PATCH 2/4] Add test for Page view #sha. Fix h1 title test. --- test/test_page_view.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test/test_page_view.rb b/test/test_page_view.rb index af069896..9d2c16db 100644 --- a/test/test_page_view.rb +++ b/test/test_page_view.rb @@ -51,6 +51,16 @@ context "Precious::Views::Page" do EOS end + test 'page has sha id' do + title = 'test' + @wiki.write_page(title, :markdown, 'Test' + "\n # 3", commit_details) + page = @wiki.page(title) + + @view = Precious::Views::Page.new + @view.instance_variable_set :@page, page + assert_equal "345e6aef713208c8d50cdea23b85e6ad831f0449", @view.sha + end + test "h1 title can be disabled" do title = 'H1' @wiki.write_page(title, :markdown, '# 1 & 2 ' + "\n # 3", commit_details) @@ -63,6 +73,6 @@ EOS # Title is based on file name when h1_title is false. actual = @view.title - assert_equal 'H1', title + assert_equal title, actual end end From 16ea6245e34d7a0e572f79ce767b3b28789a25ca Mon Sep 17 00:00:00 2001 From: Dawa Ometto Date: Wed, 12 Apr 2017 23:00:07 +0200 Subject: [PATCH 3/4] Follow page renames in history view --- bin/gollum | 6 ++++++ lib/gollum/app.rb | 2 +- lib/gollum/helpers.rb | 4 ++++ test/test_app_helpers.rb | 9 +++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/bin/gollum b/bin/gollum index a3aa6bc1..8cbb5c40 100755 --- a/bin/gollum +++ b/bin/gollum @@ -111,6 +111,12 @@ MSG opts.on("--no-live-preview", "Disable the live preview feature in page editor.") do wiki_options[:live_preview] = false end + opts.on("--follow-renames", "Follow pages across renames in the History view. Default except on jruby.") do + wiki_options[:follow_renames] = true + end + opts.on("--no-follow-renames", "Do not follow pages across renames in the History view.") do + wiki_options[:follow_renames] = false + end opts.on("--allow-uploads [MODE]", [:dir, :page], "Enable file uploads.", "If set to 'dir', Gollum will store all uploads in the '/uploads/' directory.", "If set to 'page', Gollum will store each upload at the currently edited page.") do |mode| diff --git a/lib/gollum/app.rb b/lib/gollum/app.rb index 7a951d43..dc84ab52 100644 --- a/lib/gollum/app.rb +++ b/lib/gollum/app.rb @@ -404,7 +404,7 @@ module Precious @page = wiki_page(params[:splat].first).page @page_num = [params[:page].to_i, 1].max unless @page.nil? - @versions = @page.versions :page => @page_num + @versions = @page.versions(:page => @page_num, :follow => settings.wiki_options.fetch(:follow_renames, git_adapter == 'rjgit' ? false : true)) mustache :history else redirect to("/") diff --git a/lib/gollum/helpers.rb b/lib/gollum/helpers.rb index b83d56ce..b080e0dc 100644 --- a/lib/gollum/helpers.rb +++ b/lib/gollum/helpers.rb @@ -6,6 +6,10 @@ module Precious EMOJI_PATHNAME = Pathname.new(Gemojione.images_path).freeze + def git_adapter + defined?(Gollum::GIT_ADAPTER) ? Gollum::GIT_ADAPTER : DEFAULT_ADAPTER.match(/(.*)_adapter/)[1] + end + def join_page_name(name, ext) "#{name}#{ext}" end diff --git a/test/test_app_helpers.rb b/test/test_app_helpers.rb index 549afff2..fcbea6e3 100644 --- a/test/test_app_helpers.rb +++ b/test/test_app_helpers.rb @@ -4,6 +4,15 @@ require File.expand_path(File.join(File.dirname(__FILE__), "helper")) context "Precious::Helpers" do include Precious::Helpers + test "return git adapter" do + if defined?(Gollum::GIT_ADAPTER) + result = Gollum::GIT_ADAPTER + else + Gollum::GIT_ADAPTER = result = 'grit' + end + assert_equal result, git_adapter + end + test "extracting paths from URLs" do assert_nil extract_path('Eye-Of-Sauron') assert_equal 'Mordor', extract_path('Mordor/Sauron') From cabe9f353b695618a1d0879abced3c3ff9a36929 Mon Sep 17 00:00:00 2001 From: Dawa Ometto Date: Wed, 12 Apr 2017 23:31:47 +0200 Subject: [PATCH 4/4] Fix tests --- lib/gollum/views/latest_changes.rb | 8 ---- test/examples/lotr.git/logs/HEAD | 1 + test/examples/lotr.git/logs/refs/heads/master | 1 + .../2c/e9aa9509f2ac35921e2900a922cfeb5bed76ae | Bin 0 -> 543 bytes .../72/39e2921c2962365509b2f6950da6a85931f30e | Bin 0 -> 65 bytes .../f8/03c64d11407b23797325e3843f3f378b78f611 | 3 ++ test/examples/lotr.git/refs/heads/master | 2 +- test/helper.rb | 13 +----- test/test_app.rb | 38 +++++++++--------- test/test_latest_changes_view.rb | 13 ++---- test/test_page_view.rb | 2 +- 11 files changed, 30 insertions(+), 51 deletions(-) create mode 100644 test/examples/lotr.git/objects/2c/e9aa9509f2ac35921e2900a922cfeb5bed76ae create mode 100644 test/examples/lotr.git/objects/72/39e2921c2962365509b2f6950da6a85931f30e create mode 100644 test/examples/lotr.git/objects/f8/03c64d11407b23797325e3843f3f378b78f611 diff --git a/lib/gollum/views/latest_changes.rb b/lib/gollum/views/latest_changes.rb index 8707e489..e217ce6d 100644 --- a/lib/gollum/views/latest_changes.rb +++ b/lib/gollum/views/latest_changes.rb @@ -23,7 +23,6 @@ module Precious :date_full => v.authored_date, :files => v.stats.files.map { |f,*rest| page_path = extract_renamed_path_destination(f) - page_path = remove_page_extentions(page_path) { :file => f, :link => "#{page_path}/#{v.id}" } @@ -32,13 +31,6 @@ module Precious end end - def remove_page_extentions(page_path) - Gollum::Markup.formats.values.each do |format| - page_path = page_path.gsub(/\.#{format[:regexp]}$/, '') - end - return page_path - end - def extract_renamed_path_destination(file) return file.gsub(/{.* => (.*)}/, '\1').gsub(/.* => (.*)/, '\1') end diff --git a/test/examples/lotr.git/logs/HEAD b/test/examples/lotr.git/logs/HEAD index 2b0e49e0..31af843f 100644 --- a/test/examples/lotr.git/logs/HEAD +++ b/test/examples/lotr.git/logs/HEAD @@ -9,3 +9,4 @@ cfea406f5f77afc7fb673a43e97721234385b1bd 629aa678272b017a4d136d35e77ac94d80b08dc 7d6aeab8b84c895f21f6c66b84a457b0fced9693 563cc3701db990caf63e4ce9c3697a062890ca48 James Dabbs 1361843315 -0500 push 563cc3701db990caf63e4ce9c3697a062890ca48 874f597a5659b4c3b153674ea04e406ff393975e Charles Pence 1363478075 -0400 push 874f597a5659b4c3b153674ea04e406ff393975e 7bdfe65face6f7cf9877d8c1d8c1dd974a63745e Nathan Lowe 1421012322 -0500 push +7bdfe65face6f7cf9877d8c1d8c1dd974a63745e f803c64d11407b23797325e3843f3f378b78f611 Dawa Ometto 1492034760 +0200 push diff --git a/test/examples/lotr.git/logs/refs/heads/master b/test/examples/lotr.git/logs/refs/heads/master index 2b0e49e0..31af843f 100644 --- a/test/examples/lotr.git/logs/refs/heads/master +++ b/test/examples/lotr.git/logs/refs/heads/master @@ -9,3 +9,4 @@ cfea406f5f77afc7fb673a43e97721234385b1bd 629aa678272b017a4d136d35e77ac94d80b08dc 7d6aeab8b84c895f21f6c66b84a457b0fced9693 563cc3701db990caf63e4ce9c3697a062890ca48 James Dabbs 1361843315 -0500 push 563cc3701db990caf63e4ce9c3697a062890ca48 874f597a5659b4c3b153674ea04e406ff393975e Charles Pence 1363478075 -0400 push 874f597a5659b4c3b153674ea04e406ff393975e 7bdfe65face6f7cf9877d8c1d8c1dd974a63745e Nathan Lowe 1421012322 -0500 push +7bdfe65face6f7cf9877d8c1d8c1dd974a63745e f803c64d11407b23797325e3843f3f378b78f611 Dawa Ometto 1492034760 +0200 push diff --git a/test/examples/lotr.git/objects/2c/e9aa9509f2ac35921e2900a922cfeb5bed76ae b/test/examples/lotr.git/objects/2c/e9aa9509f2ac35921e2900a922cfeb5bed76ae new file mode 100644 index 0000000000000000000000000000000000000000..37314bd5e084ae5141dabce246a34f7775b49187 GIT binary patch literal 543 zcmV+)0^t340V^p=O;s>6GG#C{FfcPQQE`mYPa(P=kCc zbpwi0lQZ*6!GW-9oBWHpVLuXmxEcd*nf$c8^Y&K;RAo?RN=i;@v0hOML)DouwWq6H zZEt9V@0M_`v|AAIO9x_MP-aQK~wzIA(yPO(7M#JlC^m!uYfRK2-n#JcaHtHP?S%Xb?TPh#_) z+}8|K<&m100#Q{vL*{17+K72JA9x#;#Ch^-Ga@Tts)939Qj-!18CH~^SX`o;TUt_* h4|d(x35@5~EIGAmk^jaWw`^anuXpOS0szgO@{om;4c-6% literal 0 HcmV?d00001 diff --git a/test/examples/lotr.git/objects/72/39e2921c2962365509b2f6950da6a85931f30e b/test/examples/lotr.git/objects/72/39e2921c2962365509b2f6950da6a85931f30e new file mode 100644 index 0000000000000000000000000000000000000000..5003c645d32ccb06eead895e2bb5be2152b3b9d5 GIT binary patch literal 65 zcmV-H0KWft0ZYosPf{>5VsOhWDlYL$%uUttNrW)CoHBEg@^zdN)6+Bain-j1@>3AJ X;KbbW%;HoX_r%=v)Ko42O=lPtH%TH6 literal 0 HcmV?d00001 diff --git a/test/examples/lotr.git/objects/f8/03c64d11407b23797325e3843f3f378b78f611 b/test/examples/lotr.git/objects/f8/03c64d11407b23797325e3843f3f378b78f611 new file mode 100644 index 00000000..427d87e5 --- /dev/null +++ b/test/examples/lotr.git/objects/f8/03c64d11407b23797325e3843f3f378b78f611 @@ -0,0 +1,3 @@ +x1 +0 E; 8R:t(LMBߐ#tx:ϓ:wM0 1ST Y˄ a;&Br.Nҕ +1>'Ec_,nX{|zB| =\-ZkR޼*W6? K \ No newline at end of file diff --git a/test/examples/lotr.git/refs/heads/master b/test/examples/lotr.git/refs/heads/master index 81879653..3a743f29 100644 --- a/test/examples/lotr.git/refs/heads/master +++ b/test/examples/lotr.git/refs/heads/master @@ -1 +1 @@ -7bdfe65face6f7cf9877d8c1d8c1dd974a63745e +f803c64d11407b23797325e3843f3f378b78f611 diff --git a/test/helper.rb b/test/helper.rb index d4dd54ac..228f7369 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -90,15 +90,4 @@ def context(*args, &block) klass.class_eval &block end -$contexts = [] - -# Commit file to wiki, overwriting previous versions of that file -def commit_test_file(wiki, dir, filename, ext, content) - committer = Gollum::Committer.new(wiki, :message => "Added testfile", :parent => wiki.repo.head.commit) - committer.add_to_index(dir, filename, ext, content, true) - committer.after_commit do |committer, sha| - wiki.clear_cache - committer.update_working_dir(dir, filename, ext) - end - committer.commit -end +$contexts = [] \ No newline at end of file diff --git a/test/test_app.rb b/test/test_app.rb index ec884f5e..9882387f 100644 --- a/test/test_app.rb +++ b/test/test_app.rb @@ -123,7 +123,7 @@ context "Frontend" do post "/edit/A", :header => 'header', :footer => 'footer', :page => "A", :sidebar => 'sidebar', :message => 'def' follow_redirect! - assert_equal "/A", last_request.fullpath + assert_equal "/A.md", last_request.fullpath assert last_response.ok? @wiki.clear_cache @@ -150,7 +150,7 @@ context "Frontend" do post "/rename/B", :rename => "/C", :message => 'def' follow_redirect! - assert_equal '/C', last_request.fullpath + assert_equal '/C.md', last_request.fullpath assert last_response.ok? @wiki.clear_cache @@ -189,7 +189,7 @@ context "Frontend" do post "/rename/G/H", :rename => "/I/C", :message => 'def' follow_redirect! - assert_equal '/I/C', last_request.fullpath + assert_equal '/I/C.md', last_request.fullpath assert last_response.ok? @wiki.clear_cache @@ -206,7 +206,7 @@ context "Frontend" do post "/rename/G/H", :rename => "K/C", :message => 'def' follow_redirect! - assert_equal '/G/K/C', last_request.fullpath + assert_equal '/G/K/C.md', last_request.fullpath assert last_response.ok? @wiki.clear_cache @@ -272,7 +272,7 @@ context "Frontend" do end test "create redirects to page if already exists" do - name = "A" + name = "A.md" get "/create/#{name}" follow_redirect! assert_equal "/#{name}", last_request.fullpath @@ -548,19 +548,6 @@ context "Frontend" do assert_match /meta name="robots" content="noindex, nofollow"/, last_response.body end - test "show revision of specific file" do - shas = {} - ["First revision of testfile", "Second revision of testfile"].each do |content| - new_commit = commit_test_file(@wiki, "revisions", "testfile", "log", content) - shas[new_commit] = content - end - shas.each do |sha, content| - get "revisions/testfile.log/#{sha}" - assert last_response.ok? - assert_match /#{content}/, last_response.body - end - end - def app Precious::App end @@ -689,12 +676,25 @@ context "Frontend with lotr" do post "/edit/Mordor/Orc", :content => 'not so big smelly creatures', :page => 'Orc', :path => 'Mordor', :message => 'minor edit' - assert_equal 'http://example.org/Mordor/Orc', last_response.headers['Location'] + assert_equal 'http://example.org/Mordor/Orc.md', last_response.headers['Location'] get "/Mordor/Orc" assert_match /not so big smelly creatures/, last_response.body end + test "show revision of specific file" do + old_sha = "df26e61e707116f81ebc6b935ec6d1676b7e96c4" + update_sha = "f803c64d11407b23797325e3843f3f378b78f611" + + get "Data.csv/#{old_sha}" + assert last_response.ok? + assert_no_match /Samwise,Gamgee/, last_response.body + + get "Data.csv/#{update_sha}" + assert last_response.ok? + assert_match /Samwise,Gamgee/, last_response.body + end + test "existing emoji" do get "/emoji/heart" assert_equal 200, last_response.status diff --git a/test/test_latest_changes_view.rb b/test/test_latest_changes_view.rb index fe6d08de..5d4e2f41 100644 --- a/test/test_latest_changes_view.rb +++ b/test/test_latest_changes_view.rb @@ -21,10 +21,10 @@ context "Precious::Views::LatestChanges" do body = last_response.body assert body.include?('Charles Pence'), "/latest_changes should include the Author Charles Pence" - assert body.include?('a8ad3c0'), "/latest_changes should include the :latest_changes_count commit" - assert !body.include?('60f12f4'), "/latest_changes should not include more than latest_changes_count commits" + assert body.include?('1db89eb'), "/latest_changes should include the :latest_changes_count commit" + assert !body.include?('a8ad3c0'), "/latest_changes should not include more than latest_changes_count commits" assert body.include?('Data-Two.csv'), "/latest_changes include links to modified files in #{body}" - assert body.include?('Hobbit.md'), "/latest_changes should include links to modified pages in #{body}" + assert body.include?('Hobbit.md'), "/latest_changes should include links to modified pages in #{body}" end test "extract destination file name in case of path renaming" do @@ -33,13 +33,6 @@ context "Precious::Views::LatestChanges" do assert_equal "newDirectoryName/fileName.md", view.extract_renamed_path_destination("{oldDirectoryName => newDirectoryName}/fileName.md") end - test "remove page extentions" do - view = Precious::Views::LatestChanges.new - assert_equal "page", view.remove_page_extentions("page.wiki") - assert_equal "page-wiki", view.remove_page_extentions("page-wiki.md") - assert_equal "file.any_extention", view.remove_page_extentions("file.any_extention") - end - teardown do FileUtils.rm_rf(@path) end diff --git a/test/test_page_view.rb b/test/test_page_view.rb index 9d2c16db..1565b29e 100644 --- a/test/test_page_view.rb +++ b/test/test_page_view.rb @@ -58,7 +58,7 @@ EOS @view = Precious::Views::Page.new @view.instance_variable_set :@page, page - assert_equal "345e6aef713208c8d50cdea23b85e6ad831f0449", @view.sha + assert_equal "594e928cc5dcb6d833dfb86bb36076fd4a84eea7", @view.id end test "h1 title can be disabled" do