Commit a4b8d3eb authored by azul's avatar azul

Merge remote-tracking branch 'origin/master' into merge-master

parents 27a02177 8a4cc1a1
Changes in Crabgrass 0.7.0
--------------------------
Changes in Crabgrass 0.6.3
--------------------------
......
......@@ -50,16 +50,16 @@ module Group::Groups
ids = [ids] unless ids.is_a? Array
return [] unless ids.any?
parentids = parent_ids(ids)
(ids + parentids + committee_ids(ids + parentids)).flatten.uniq
(ids + parentids + committee_ids(ids + parentids)).flatten.uniq.compact
end
# returns an array of committee ids given an array of group ids.
def committee_ids(ids)
Group.where(parent_id: ids).pluck(:id)
Group.where.not(parent_id: nil).where(parent_id: ids).pluck(:id)
end
def parent_ids(ids)
Group.where(id: ids).pluck(:parent_id)
Group.where(id: ids).where.not(parent_id: nil).pluck(:parent_id)
end
def can_have_committees?
......
......@@ -218,9 +218,19 @@ module Crabgrass::Theme::Loader
# ensures the directory exists
def ensure_dir(dir)
FileUtils.mkdir_p(dir) unless File.exist?(dir)
unless File.directory?(dir)
raise format('For the theme to work, "%s" must be a directory.', 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