Skip to content

Commit

Permalink
fixing merge_file and merge_dir; adding test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
romand committed Apr 17, 2012
1 parent 325f9aa commit 640a87a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/iron_worker_ng/feature/common/merge_dir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class Feature < IronWorkerNG::Feature::Base
def initialize(path, dest)
raise 'No such directory - ' + path unless Dir.exist? path
@path = File.expand_path(path)
@dest = Pathname.new(dest).cleanpath.to_s
@dest = dest
@dest = Pathname.new(dest).cleanpath.to_s + '/' unless @dest.empty?
end

def hash_string
Expand All @@ -28,7 +29,7 @@ def bundle(zip)
IronWorkerNG::Logger.debug "Bundling dir with path='#{@path}' and dest='#{@dest}'"

Dir.glob(@path + '/**/**') do |path|
zip.add(@dest + '/' + File.basename(@path) + path[@path.length .. -1], path)
zip.add(@dest + File.basename(@path) + path[@path.length .. -1], path)
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/iron_worker_ng/feature/common/merge_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Feature < IronWorkerNG::Feature::Base
def initialize(path, dest)
@path = File.expand_path(path)
@dest = dest
@dest += '/' unless @dest.empty? or @dest.end_with? '/'
end

def hash_string
Expand All @@ -18,7 +19,7 @@ def hash_string
def bundle(zip)
IronWorkerNG::Logger.debug "Bundling file with path='#{@path}' and dest='#{@dest}'"

zip.add(@dest + '/' + File.basename(@path), @path)
zip.add(@dest + File.basename(@path), @path)
end
end

Expand Down
22 changes: 22 additions & 0 deletions test/test_common_features.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ def test_merge_file
end
end

def test_merge_file_no_dest
code = code_bundle('test') do
merge_file('Gemfile')
merge_worker('test/hello.rb')
end

inspect_zip(code) do |zip|
assert zip.find_entry('Gemfile')
end
end

def test_merge_dir_check
assert_raise RuntimeError, "should check if merged dir exists" do
code_bundle('test') do
Expand All @@ -33,6 +44,17 @@ def test_merge_dir
end
end

def test_merge_dir_no_dest
code = code_bundle('test') do
merge_dir('test')
merge_worker('test/hello.rb')
end

inspect_zip(code) do |zip|
assert zip.find_entry('test/hello.rb')
end
end

def test_symlinks
File.unlink 'test/data/dir1/dir2' if
File.symlink? 'test/data/dir1/dir2'
Expand Down

0 comments on commit 640a87a

Please sign in to comment.