From b9d7375dbaf610b879d50e72fa75b9a872a5d687 Mon Sep 17 00:00:00 2001 From: Dawa Ometto Date: Sat, 4 Apr 2020 13:43:29 +0200 Subject: [PATCH] Fix migration script when using page-file-dir (#1542) --- bin/gollum-migrate-tags | 3 ++- test/test_migrate.rb | 51 ++++++++++++++++++++++++++--------------- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/bin/gollum-migrate-tags b/bin/gollum-migrate-tags index c52d59b4..b6e38198 100755 --- a/bin/gollum-migrate-tags +++ b/bin/gollum-migrate-tags @@ -81,6 +81,7 @@ begin const = setting.to_s.upcase Object.const_set(const, value) unless Object.const_defined?(const) end + wiki_options[:page_file_dir] = setting(:page_file_dir) ? setting(:page_file_dir) : wiki_options[:page_file_dir] # Allow settings :page_file_dir through PAGE_FILE_DIR constant. rescue OptionParser::InvalidOption puts "gollum-migrate-tags: #{$!.message}" puts "gollum-migrate-tags: try 'gollum-migrate-tags --help' for more information" @@ -261,7 +262,7 @@ wiki.pages.each do |page| log(:info,"Page #{page.path}") new_data = page.formatted_data if setting(:no_dry_run) - path = ::File.join([wiki.path, wiki.page_file_dir, page.path].compact) + path = ::File.join(wiki.path, page.path) f = File.new(path, 'w') f.write(new_data) f.close diff --git a/test/test_migrate.rb b/test/test_migrate.rb index 87227463..22853652 100644 --- a/test/test_migrate.rb +++ b/test/test_migrate.rb @@ -23,7 +23,26 @@ waa [[Subsub/Zaa.md]] EOF -script_path = File.expand_path(File.join(File.dirname(__FILE__), '../', 'bin', 'gollum-migrate-tags')) +def load_script(**args) + settings = { + :run_silent => true, + :no_dry_run => true, + :prefer_relative => true, + :hyphenate => false, + :page_file_dir => nil, + }.merge(args) + + settings.each do |const, val| + const_name = const.to_s.upcase + Object.const_set(const_name, val) unless Object.const_defined?(const_name) && Object.const_get(const_name) == val + end + + script_path = File.expand_path(File.join(File.dirname(__FILE__), '../', 'bin', 'gollum-migrate-tags')) + + Dir.chdir(@path) do + load script_path + end +end unless ENV['TRAVIS'] @@ -35,33 +54,29 @@ unless ENV['TRAVIS'] end test 'repair broken links' do - PREFER_RELATIVE = true - RUN_SILENT = true - NO_DRY_RUN = true - HYPHENATE = false - - Dir.chdir(@path) do - load script_path - end + load_script + f = ::File.new(::File.join(@path, 'Subdir/Foo.md'), 'r') assert_equal result, f.read end - test 'change spaced filenames to hyphenated filenames' do - RUN_SILENT = true - NO_DRY_RUN = true - PREFER_RELATIVE = true - HYPHENATE = true - - Dir.chdir(@path) do - load script_path - end + test 'change spaced filenames to hyphenated filenames' do + load_script(hyphenate: true) f = ::File.new(::File.join(@path, 'Home.textile'), 'r') output = f.read assert_equal true, output.include?('[[Bilbo-Baggins.md]]') assert_equal true, output.include?('[[evil|Mordor/Eye-Of-Sauron.md]]') end + + test 'migration with page file dir' do + load_script(page_file_dir: 'Subdir') + + f = ::File.new(::File.join(@path, 'Subdir/Foo.md'), 'r') + output = f.read + assert_equal true, output.include?('[[Subsub/Zaa.md]]') + assert_equal true, output.include?('[[Samwi]]') + end teardown do FileUtils.rm_rf(@path)