Skip to content

Commit 6f6ec5d

Browse files
committed
Fix CI again
1 parent a66fa4e commit 6f6ec5d

File tree

2 files changed

+31
-53
lines changed

2 files changed

+31
-53
lines changed

.rspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
--color
22
--require spec_helper
3+
--format documentation
4+

spec/lib/attache/download_spec.rb

Lines changed: 29 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
let(:reldirname) { "path#{rand}" }
99
let(:geometry) { CGI.escape('2x2#') }
1010
let(:file) { StringIO.new(IO.binread("spec/fixtures/transparent.gif"), 'rb') }
11+
let(:remote_url) { "http://example.com/image.jpg" }
1112

1213
before do
1314
allow(Attache).to receive(:logger).and_return(Logger.new('/dev/null'))
1415
allow(Attache).to receive(:localdir).and_return(Dir.tmpdir) # forced, for safety
15-
allow_any_instance_of(Attache::VHost).to receive(:storage_get).and_return(nil)
16-
allow_any_instance_of(Attache::VHost).to receive(:backup).and_return(nil)
1716
end
1817

1918
after do
@@ -29,7 +28,16 @@
2928
subject { proc { middleware.call Rack::MockRequest.env_for("http://example.com/view/#{reldirname}/#{geometry}/#{filename}", "HTTP_HOST" => "example.com") } }
3029

3130
context 'not in local cache' do
31+
before do
32+
Attache.cache.delete("example.com/#{reldirname}/#{filename}")
33+
end
34+
3235
context 'no cloud storage configured' do
36+
before do
37+
allow_any_instance_of(Attache::VHost).to receive(:storage).and_return(nil)
38+
allow_any_instance_of(Attache::VHost).to receive(:bucket).and_return(nil)
39+
end
40+
3341
it 'should respond not found' do
3442
code, headers, body = subject.call
3543
expect(code).to eq(404)
@@ -64,6 +72,7 @@
6472
context 'available remotely' do
6573
before do
6674
allow_any_instance_of(Attache::VHost).to receive(:storage_get).and_return(file)
75+
allow_any_instance_of(Attache::VHost).to receive(:storage_url).and_return(remote_url)
6776
end
6877

6978
it 'should proceed normally' do
@@ -72,12 +81,8 @@
7281
end
7382

7483
context 'geometry is "remote"' do
75-
let(:remote_url) { "http://example.com/image.jpg" }
76-
let(:geometry) { CGI.escape('remote') }
7784

78-
before do
79-
allow_any_instance_of(Attache::VHost).to receive(:storage_url).and_return(remote_url)
80-
end
85+
let(:geometry) { CGI.escape('remote') }
8186

8287
it 'should send remote file' do
8388
expect(Attache.cache).not_to receive(:fetch)
@@ -113,55 +118,26 @@
113118
end
114119
end
115120

116-
context 'geometry is "remote"' do
117-
let(:remote_url) { "http://example.com/image.jpg" }
118-
let(:geometry) { CGI.escape('remote') }
121+
context 'rendering' do
122+
context 'non image' do
123+
let(:file) { StringIO.new(IO.binread("spec/fixtures/sample.txt"), 'rb') }
124+
let(:filename) { "hello#{rand}.txt" }
119125

120-
before do
121-
allow_any_instance_of(Attache::VHost).to receive(:storage_url).and_return(remote_url)
122-
end
123-
124-
it 'should send remote file' do
125-
expect(Attache.cache).not_to receive(:fetch)
126-
expect_any_instance_of(Attache::VHost).to receive(:storage_url)
127-
code, headers, body = subject.call
128-
response_content = ''
129-
body.each {|p| response_content += p }
130-
expect(response_content).to eq('')
131-
expect(code).to eq(302)
132-
expect(headers['Location']).to eq(remote_url)
133-
expect(headers['Cache-Control']).to eq("private, no-cache")
134-
end
135-
end
136-
end
137-
138-
context 'rendering' do
139-
context 'non image' do
140-
let(:file) { StringIO.new(IO.binread("spec/fixtures/sample.txt"), 'rb') }
141-
let(:filename) { "hello#{rand}.txt" }
142-
143-
before do
144-
Attache.cache.write("example.com/#{reldirname}/#{filename}", file)
145-
end
146-
147-
it 'should output as png' do
148-
expect_any_instance_of(Attache::ResizeJob).to receive(:make_nonimage_preview).exactly(1).times.and_call_original
149-
code, headers, body = subject.call
150-
expect(code).to eq(200)
151-
expect(headers['Content-Type']).to eq("image/png")
152-
end
153-
end
154-
155-
context 'image' do
156-
before do
157-
Attache.cache.write("example.com/#{reldirname}/#{filename}", file)
126+
it 'should output as png' do
127+
expect_any_instance_of(Attache::ResizeJob).to receive(:make_nonimage_preview).exactly(1).times.and_call_original
128+
code, headers, body = subject.call
129+
expect(code).to eq(200)
130+
expect(headers['Content-Type']).to eq("image/png")
131+
end
158132
end
159133

160-
it 'should output as gif' do
161-
expect_any_instance_of(Attache::ResizeJob).not_to receive(:make_nonimage_preview)
162-
code, headers, body = subject.call
163-
expect(code).to eq(200)
164-
expect(headers['Content-Type']).to eq("image/gif")
134+
context 'image' do
135+
it 'should output as gif' do
136+
expect_any_instance_of(Attache::ResizeJob).not_to receive(:make_nonimage_preview)
137+
code, headers, body = subject.call
138+
expect(code).to eq(200)
139+
expect(headers['Content-Type']).to eq("image/gif")
140+
end
165141
end
166142
end
167143
end

0 commit comments

Comments
 (0)