Commit ef2c6157 authored by azul's avatar azul

Merge branch 'fix-symlink-issue-in-production' into 'master'

fix: symlink fix - this time with a test

See merge request !279
parents 76f0163c ec86e9f3
Changes in Crabgrass 0.7.0
--------------------------
Changes in Crabgrass 0.6.3
--------------------------
......
......@@ -217,10 +217,19 @@ module Crabgrass::Theme::Loader
# ensures the directory exists
def ensure_dir(dir)
resolved = File.symlink?(dir) ? File.readlink(dir) : dir
resolved = resolve_dir(dir)
FileUtils.mkdir_p(resolved) unless File.exist?(resolved)
unless File.directory?(resolved)
raise format('For the theme to work, "%s" must be a directory.', resolved)
end
end
# return absolute path of the target of a symlink
def resolve_dir(dir)
if File.symlink?(dir)
File.expand_path(File.readlink(dir), File.dirname(dir))
else
dir
end
end
end
require 'minitest/autorun'
$LOAD_PATH.unshift(File.expand_path('../lib', File.dirname(__FILE__)))
module Crabgrass
class Theme
end
end
require_relative '../test_helper'
require 'tmpdir'
require 'pathname'
require 'fileutils'
require 'crabgrass/theme/loader'
require 'byebug'
class Crabgrass::Theme::LoaderTest < MiniTest::Test
class TestDummy
include Crabgrass::Theme::Loader
end
def test_resolve_path
Dir.mktmpdir do |dir|
dir = Pathname.new(dir)
parent = dir + 'nest/some/more'
link = parent + 'link'
target = dir + 'nest/other/branch'
parent.mkpath
target.mkpath
symlink = File.symlink('../../other/branch', link)
assert_equal target.to_s, TestDummy.new.send(:resolve_dir, link.to_s)
assert File.exist?(TestDummy.new.send(:resolve_dir, link))
end
end
end
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