|
110 | 110 |
|
111 | 111 | before { upload } |
112 | 112 |
|
113 | | - it { is_expected.to be_truthy } |
| 113 | + it { is_expected.to be true } |
114 | 114 |
|
115 | 115 | it "deletes the file" do |
116 | 116 | expect { delete }.to change(ActiveStorageDB::File, :count).from(1).to(0) |
|
119 | 119 | context "when the attachment is not found" do |
120 | 120 | subject(:delete) { service.delete("#{key}!") } |
121 | 121 |
|
122 | | - it { is_expected.to be_falsey } |
| 122 | + it { is_expected.to be false } |
123 | 123 | end |
124 | 124 | end |
125 | 125 |
|
126 | 126 | describe ".delete_prefixed" do |
127 | 127 | subject(:delete_prefixed) { service.delete_prefixed(key[0..10]) } |
128 | 128 |
|
129 | | - before { upload } |
| 129 | + let(:other_file) { create(:active_storage_db_file, ref: "unrelated_prefix_file") } |
| 130 | + |
| 131 | + before do |
| 132 | + other_file |
| 133 | + upload |
| 134 | + end |
130 | 135 |
|
131 | | - it "deletes the files" do |
132 | | - expect { delete_prefixed }.to change(ActiveStorageDB::File, :count).from(1).to(0) |
| 136 | + it "deletes only matching files", :aggregate_failures do |
| 137 | + expect { delete_prefixed }.to change(ActiveStorageDB::File, :count).by(-1) |
| 138 | + expect(ActiveStorageDB::File.find_by(ref: "unrelated_prefix_file")).to be_present |
133 | 139 | end |
134 | 140 |
|
135 | 141 | context "when no files match the prefix" do |
|
151 | 157 | context "with an existing file" do |
152 | 158 | before { upload } |
153 | 159 |
|
154 | | - after { service.delete(key) } |
155 | | - |
156 | 160 | it "downloads the data" do |
157 | 161 | expect(download).to eq fixture_data |
158 | 162 | end |
|
167 | 171 | it "yields multiple chunks when data exceeds chunk size", :aggregate_failures do |
168 | 172 | chunks = [] |
169 | 173 | service.download(key) { |chunk| chunks << chunk } |
170 | | - # fixture_data is a PNG (~100 bytes), chunk size is 100 bytes, |
171 | | - # so we expect at least 1 chunk yielded via the streaming path |
172 | | - expect(chunks).not_to be_empty |
| 174 | + # fixture_data is 126 bytes, chunk size is 100 bytes, |
| 175 | + # so we expect exactly 2 chunks via the streaming path |
| 176 | + expect(chunks.size).to eq 2 |
173 | 177 | expect(chunks.join).to eq fixture_data |
174 | 178 | end |
175 | 179 | end |
|
192 | 196 |
|
193 | 197 | before { upload } |
194 | 198 |
|
195 | | - after { service.delete(key) } |
196 | | - |
197 | 199 | it { is_expected.to eq fixture_data[range] } |
198 | 200 |
|
199 | 201 | context "when the attachment is not found" do |
|
206 | 208 | describe ".exist?" do |
207 | 209 | subject { service.exist?(key) } |
208 | 210 |
|
209 | | - it { is_expected.to be_falsey } |
| 211 | + it { is_expected.to be false } |
210 | 212 |
|
211 | 213 | context "when a file is uploaded" do |
212 | 214 | before { upload } |
213 | 215 |
|
214 | | - after { service.delete(key) } |
215 | | - |
216 | | - it { is_expected.to be_truthy } |
| 216 | + it { is_expected.to be true } |
217 | 217 | end |
218 | 218 | end |
219 | 219 |
|
|
226 | 226 | describe ".upload" do |
227 | 227 | it "uploads the data" do |
228 | 228 | expect(upload).to be_a ActiveStorageDB::File |
229 | | - ensure |
230 | | - service.delete(key) |
231 | 229 | end |
232 | 230 |
|
233 | 231 | context "with the checksum" do |
234 | 232 | let(:upload) { service.upload(key, StringIO.new(fixture_data), checksum: checksum) } |
235 | 233 |
|
236 | 234 | it "uploads the data" do |
237 | 235 | expect(upload).to be_a ActiveStorageDB::File |
238 | | - ensure |
239 | | - service.delete(key) |
240 | 236 | end |
241 | 237 | end |
242 | 238 |
|
|
256 | 252 | context "with a duplicate key" do |
257 | 253 | before { upload } |
258 | 254 |
|
259 | | - after { service.delete(key) } |
260 | | - |
261 | 255 | it "raises a uniqueness error" do |
262 | 256 | expect { |
263 | 257 | service.upload(key, StringIO.new(fixture_data)) |
|
286 | 280 | end |
287 | 281 | end |
288 | 282 |
|
289 | | - after { service.delete(key) } |
290 | | - |
291 | 283 | it { is_expected.to start_with "#{url_options[:protocol]}#{url_options[:host]}" } |
292 | 284 |
|
293 | 285 | it "generates a token that contains the expected fields" do |
|
0 commit comments