|
6 | 6 | describe 'asdb:list' do |
7 | 7 | subject(:task) { execute_task('asdb:list') } |
8 | 8 |
|
9 | | - let(:file1) { create(:active_storage_blob, filename: 'file1', created_at: Time.now - 1.hour) } |
10 | | - let(:file2) { create(:active_storage_blob, filename: 'file2', created_at: Time.now - 5.hour) } |
11 | | - let(:file3) { create(:active_storage_blob, filename: 'file3', created_at: Time.now - 3.hour) } |
| 9 | + let(:file1) { create(:active_storage_blob, filename: 'some file 1', created_at: Time.now - 1.hour) } |
| 10 | + let(:file2) { create(:active_storage_blob, filename: 'some file 2', created_at: Time.now - 5.hour) } |
| 11 | + let(:file3) { create(:active_storage_blob, filename: 'some file 3', created_at: Time.now - 3.hour) } |
12 | 12 |
|
13 | 13 | before do |
14 | 14 | [file1, file2, file3] |
15 | 15 | end |
16 | 16 |
|
17 | | - it { is_expected.to match /file1.+file2.+file3/m } |
18 | | - |
19 | | - it 'prints the list of 3 files' do |
20 | | - expect(task.split("\n").size).to be 3 |
| 17 | + it 'prints the columns header + the list of 3 files', :aggregate_failures do |
| 18 | + pattern = /#{file3.id} #{file3.filename}.+#{file2.id} #{file2.filename}.+#{file1.id} #{file1.filename}/m |
| 19 | + expect(task).to match pattern |
| 20 | + expect(task.split("\n").size).to be 4 |
21 | 21 | end |
22 | 22 | end |
23 | 23 |
|
24 | | - describe 'asdb:get' do |
25 | | - subject(:task) { execute_task('asdb:get') } |
| 24 | + describe 'asdb:download' do |
| 25 | + subject(:task) { execute_task('asdb:download') } |
26 | 26 |
|
27 | 27 | it 'exits showing the required arguments' do |
28 | 28 | with_captured_stderr do |
29 | | - expect { task }.to raise_exception(SystemExit, /Required arguments/) |
| 29 | + expect { task }.to raise_exception(SystemExit, /Required arguments: source blob id, destination path/) |
30 | 30 | end |
31 | 31 | end |
32 | 32 |
|
33 | | - context 'with only the source specified' do |
34 | | - subject(:task) { execute_task('asdb:get', src: 'some_file') } |
| 33 | + context 'with a missing source' do |
| 34 | + subject(:task) { execute_task('asdb:download', blob_id: 'some_file') } |
| 35 | + |
| 36 | + before do |
| 37 | + allow(File).to receive(:writable?).and_return(true) |
| 38 | + end |
35 | 39 |
|
36 | | - it 'exits showing the required arguments' do |
| 40 | + it 'exits showing a not found error' do |
37 | 41 | with_captured_stderr do |
38 | | - expect { task }.to raise_exception(SystemExit, /Required arguments/) |
| 42 | + expect { task }.to raise_exception(SystemExit, /Source file not found/) |
39 | 43 | end |
40 | 44 | end |
41 | 45 | end |
42 | 46 |
|
43 | 47 | context 'with an invalid destination' do |
44 | | - subject(:task) { execute_task('asdb:get', src: 'some_file', dst: 'some_path') } |
| 48 | + subject(:task) { execute_task('asdb:download', blob_id: 'some_file', destination: 'some_path') } |
| 49 | + |
| 50 | + let(:blob) { build_stubbed(:active_storage_blob) } |
45 | 51 |
|
46 | 52 | before do |
47 | 53 | allow(File).to receive(:writable?).and_return(false) |
| 54 | + allow(ActiveStorage::Blob).to receive(:find_by).and_return(blob) |
48 | 55 | end |
49 | 56 |
|
50 | 57 | it 'exits showing a write error' do |
|
54 | 61 | end |
55 | 62 | end |
56 | 63 |
|
57 | | - context 'with a missing source' do |
58 | | - subject(:task) { execute_task('asdb:get', src: 'some_file', dst: 'some_path') } |
| 64 | + context 'with valid arguments' do |
| 65 | + subject(:task) { execute_task('asdb:download', blob_id: 'some_file', destination: 'some_path') } |
| 66 | + |
| 67 | + let(:blob) { build_stubbed(:active_storage_blob) } |
59 | 68 |
|
60 | 69 | before do |
61 | | - allow(File).to receive(:writable?).and_return(true) |
| 70 | + allow(File).to receive_messages(binwrite: 1000, writable?: true) |
| 71 | + allow(ActiveStorage::Blob).to receive(:find_by).and_return(blob) |
| 72 | + allow(blob).to receive(:download).and_return('some data') |
62 | 73 | end |
63 | 74 |
|
64 | | - it 'exits showing a not found error' do |
65 | | - with_captured_stderr do |
66 | | - expect { task }.to raise_exception(SystemExit, /Source file not found/) |
67 | | - end |
| 75 | + it 'prints the number of bytes written' do |
| 76 | + expect(task).to eq "1000 bytes written - some_path\n" |
68 | 77 | end |
69 | 78 | end |
| 79 | + end |
70 | 80 |
|
71 | | - context 'with valid arguments' do |
72 | | - subject(:task) { execute_task('asdb:get', src: blob.filename.to_s, dst: 'some_path') } |
| 81 | + describe 'asdb:search' do |
| 82 | + subject(:task) { execute_task('asdb:search') } |
73 | 83 |
|
74 | | - let(:blob) { build_stubbed(:active_storage_blob) } |
75 | | - let(:blobs) { instance_double(ActiveRecord::Relation) } |
| 84 | + let(:blob) { build_stubbed(:active_storage_blob) } |
| 85 | + |
| 86 | + it 'exits showing the required arguments' do |
| 87 | + with_captured_stderr do |
| 88 | + expect { task }.to raise_exception(SystemExit, /Required arguments/) |
| 89 | + end |
| 90 | + end |
| 91 | + |
| 92 | + context 'when no files are found' do |
| 93 | + subject(:task) { execute_task('asdb:search', filename: 'just ') } |
| 94 | + |
| 95 | + it 'prints "No results" message' do |
| 96 | + expect(task).to eq "No results\n" |
| 97 | + end |
| 98 | + end |
| 99 | + |
| 100 | + context 'with there are some results' do |
| 101 | + subject(:task) { execute_task('asdb:search', filename: 'just ') } |
76 | 102 |
|
77 | 103 | before do |
78 | | - allow(File).to receive_messages(binwrite: 1000, writable?: true) |
79 | | - allow(ActiveStorage::Blob).to receive(:order).and_return(blobs) |
80 | | - allow(blobs).to receive(:find_by).and_return(blob) |
81 | | - allow(blob).to receive(:download).and_return('some data') |
| 104 | + create(:active_storage_blob, filename: 'just a file', created_at: Time.now - 1.hour) |
| 105 | + create(:active_storage_blob, filename: 'just another file', created_at: Time.now - 5.hour) |
| 106 | + create(:active_storage_blob, filename: 'the last file', created_at: Time.now - 3.hour) |
82 | 107 | end |
83 | 108 |
|
84 | | - it 'prints the number of bytes written' do |
85 | | - expect(task).to eq "1000 bytes written\n" |
| 109 | + it 'prints the files that matches', :aggregate_failures do |
| 110 | + expect(task).to match /just another file.+just a file/m |
| 111 | + expect(task.split("\n").size).to be 3 |
86 | 112 | end |
87 | 113 | end |
88 | 114 | end |
|
0 commit comments