|
6 | 6 | describe "asdb:list" do |
7 | 7 | subject(:task) { execute_task("asdb:list") } |
8 | 8 |
|
9 | | - let!(:first_file) { create(:active_storage_blob, filename: "some file 1", created_at: 1.hour.ago) } |
10 | | - let!(:second_file) { create(:active_storage_blob, filename: "some file 2", created_at: 5.hours.ago) } |
11 | | - let!(:third_file) { create(:active_storage_blob, filename: "some file 3", created_at: 3.hours.ago) } |
| 9 | + let!(:first_file) { create(:active_storage_blob, filename: "some file 1") } |
| 10 | + let!(:second_file) { create(:active_storage_blob, filename: "some file 2") } |
| 11 | + let!(:third_file) { create(:active_storage_blob, filename: "some file 3") } |
12 | 12 |
|
13 | 13 | it "prints the columns header + the list of 3 files", :aggregate_failures do |
14 | 14 | pattern = /#{third_file.id} #{third_file.filename}.+#{second_file.id} #{second_file.filename}.+#{first_file.id} #{first_file.filename}/m |
|
29 | 29 | context "with a missing source" do |
30 | 30 | subject(:task) { execute_task("asdb:download", blob_id: "some_file") } |
31 | 31 |
|
32 | | - before do |
33 | | - allow(File).to receive(:writable?).and_return(true) |
34 | | - end |
35 | | - |
36 | 32 | it "exits showing a not found error" do |
37 | 33 | with_captured_stderr do |
38 | 34 | expect { task }.to raise_exception(SystemExit, /Source file not found/) |
|
46 | 42 | let(:blob) { build_stubbed(:active_storage_blob) } |
47 | 43 |
|
48 | 44 | before do |
49 | | - allow(File).to receive(:writable?).and_return(false) |
| 45 | + allow(File).to receive(:writable?).with(".").and_return(false) |
50 | 46 | allow(ActiveStorage::Blob).to receive(:find_by).and_return(blob) |
51 | 47 | end |
52 | 48 |
|
|
63 | 59 | let(:blob) { build_stubbed(:active_storage_blob) } |
64 | 60 |
|
65 | 61 | before do |
66 | | - allow(File).to receive_messages(binwrite: 1000, writable?: true) |
| 62 | + allow(File).to receive_messages(binwrite: 1000) |
| 63 | + allow(File).to receive(:writable?).with(".").and_return(true) |
67 | 64 | allow(ActiveStorage::Blob).to receive(:find_by).and_return(blob) |
68 | 65 | allow(blob).to receive(:download).and_return("some data") |
69 | 66 | end |
70 | 67 |
|
71 | | - it "prints the number of bytes written" do |
| 68 | + it "downloads the blob and writes it to the destination", :aggregate_failures do |
72 | 69 | expect(task).to eq "1000 bytes written - some_path\n" |
| 70 | + expect(blob).to have_received(:download) |
| 71 | + expect(File).to have_received(:binwrite).with("some_path", "some data") |
73 | 72 | end |
74 | 73 | end |
75 | 74 | end |
|
93 | 92 | end |
94 | 93 | end |
95 | 94 |
|
96 | | - context "with there are some results" do |
| 95 | + context "when there are some results" do |
97 | 96 | subject(:task) { execute_task("asdb:search", filename: "just ") } |
98 | 97 |
|
99 | 98 | before do |
100 | | - create(:active_storage_blob, filename: "just a file", created_at: 1.hour.ago) |
101 | | - create(:active_storage_blob, filename: "just another file", created_at: 5.hours.ago) |
102 | | - create(:active_storage_blob, filename: "the last file", created_at: 3.hours.ago) |
| 99 | + create(:active_storage_blob, filename: "just a file") |
| 100 | + create(:active_storage_blob, filename: "just another file") |
| 101 | + create(:active_storage_blob, filename: "the last file") |
103 | 102 | end |
104 | 103 |
|
105 | 104 | it "prints the files that matches", :aggregate_failures do |
|
0 commit comments