Skip to content

Commit 380449e

Browse files
committed
Refactoring towards RevisionDir, step 4
1 parent 383035e commit 380449e

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

lib/files_in_my_diff/tmp_dir.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ def create!
5151
def decorate(changes)
5252
raise DirectoryError, "Directory for #{@sha} not yet created" if @dir.nil?
5353

54-
# TODO
55-
decorated = changes
56-
{ dir: @dir, sha: @sha, changes: decorated }
54+
d_changes = changes.map do |change|
55+
change => { path:, type: }
56+
{ full_path: File.join(@dir, path), relative_path: path, type: }
57+
end
58+
{ dir: @dir, sha: @sha, changes: d_changes }
5759
end
5860
end
5961
end

test/tmp_dir/revision_dir_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@ def test_that_decorating_fails_if_dir_not_created
2727
assert_raises(TmpDir::DirectoryError) { subject.decorate([]) }
2828
end
2929

30+
def test_that_decorate_adds_full_paths_to_tmp_dir_for_each_change
31+
subject = subject()
32+
subject.create!
33+
result = subject.decorate([{ path: 'a/b/c', type: :modified }, { path: 'd/e/f', type: :added }])
34+
35+
assert_equal(
36+
{ dir: 'some_tmpdir/files_in_my_diff/ab12cd34', sha: 'ab12cd34', changes: [
37+
{ full_path: 'some_tmpdir/files_in_my_diff/ab12cd34/a/b/c', relative_path: 'a/b/c', type: :modified },
38+
{ full_path: 'some_tmpdir/files_in_my_diff/ab12cd34/d/e/f', relative_path: 'd/e/f', type: :added },
39+
], },
40+
result,
41+
)
42+
end
43+
3044
private
3145

3246
def subject(sha: 'ab12cd34', file_strategy: file_strategy_stub)

0 commit comments

Comments
 (0)