Skip to content

Commit

Permalink
Built out tests for new feature
Browse files Browse the repository at this point in the history
  • Loading branch information
L33tH4x0r committed Feb 20, 2020
1 parent 92b1160 commit 2ed5a1f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/active_storage/send_zip_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ def self.construct_with_hash(files, temp_folder)
# Build directory strucutre recursively for hashes
if f.is_a? Hash
# Build folder for hash entry
folder = File.join(temp_folder, subfolder)
folder = File.join(temp_folder, subfolder.to_s)
Dir.mkdir(folder) unless Dir.exist?(folder)

filepaths += construct_with_hash(f, folder)
# Save attachement
else
filepaths << save_file_on_server(f, temp_folder, subfolder: subfolder)
filepaths << save_file_on_server(f, temp_folder, subfolder: subfolder.to_s)
end
end
end
Expand Down
29 changes: 17 additions & 12 deletions test/active_storage/send_zip_helper_test.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# frozen_string_literal: true

require 'test_helper'
require 'pathname'

class ActiveStorageMock
attr_reader :filename, :download

def initialize(filename)
def initialize(filename = 'foo.txt')
@filename = filename
@download = 'content of file'
end
Expand All @@ -17,15 +19,15 @@ def test_that_it_has_a_version_number

def test_it_should_save_one_active_support
files = [
ActiveStorageMock.new('foo.txt')
ActiveStorageMock.new
]

assert_produce_files files
end

def test_it_should_save_two_active_support
files = [
ActiveStorageMock.new('foo.txt'),
ActiveStorageMock.new,
ActiveStorageMock.new('bar.txt')
]

Expand All @@ -34,8 +36,8 @@ def test_it_should_save_two_active_support

def test_it_should_save_two_active_support
files = [
ActiveStorageMock.new('foo.txt'),
ActiveStorageMock.new('foo.txt')
ActiveStorageMock.new,
ActiveStorageMock.new
]

assert_produce_files files, count: 2
Expand All @@ -44,8 +46,8 @@ def test_it_should_save_two_active_support
def test_it_should_save_files_in_differents_folders
files = {
'folder A' => [
ActiveStorageMock.new('foo.txt'),
ActiveStorageMock.new('foo.txt')
ActiveStorageMock.new,
ActiveStorageMock.new
],
'folder B' => [
ActiveStorageMock.new('bar.txt')
Expand All @@ -63,16 +65,19 @@ def test_it_should_raise_an_exception
def test_it_should_save_files_in_differents_folders_with_root_files
files = {
'folder A' => [
ActiveStorageMock.new('foo.txt'),
ActiveStorageMock.new('foo.txt')
ActiveStorageMock.new,
ActiveStorageMock.new
],
'folder B' => [
ActiveStorageMock.new('bar.txt')
ActiveStorageMock.new('bar.txt'),
'folder C' => [
ActiveStorageMock.new
]
],
0 => ActiveStorageMock.new('foo.txt'),
0 => ActiveStorageMock.new,
1 => ActiveStorageMock.new('bar.txt')
}
assert_produce_nested_files files, folder_count: 4, files_count: 5
assert_produce_nested_files files, folder_count: 5, files_count: 6
end

private
Expand Down

0 comments on commit 2ed5a1f

Please sign in to comment.