|
8 | 8 | let(:reldirname) { "path#{rand}" } |
9 | 9 | let(:geometry) { CGI.escape('2x2#') } |
10 | 10 | let(:file) { StringIO.new(IO.binread("spec/fixtures/transparent.gif"), 'rb') } |
| 11 | + let(:remote_url) { "http://example.com/image.jpg" } |
11 | 12 |
|
12 | 13 | before do |
13 | 14 | allow(Attache).to receive(:logger).and_return(Logger.new('/dev/null')) |
14 | 15 | 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) |
17 | 16 | end |
18 | 17 |
|
19 | 18 | after do |
|
29 | 28 | subject { proc { middleware.call Rack::MockRequest.env_for("http://example.com/view/#{reldirname}/#{geometry}/#{filename}", "HTTP_HOST" => "example.com") } } |
30 | 29 |
|
31 | 30 | context 'not in local cache' do |
| 31 | + before do |
| 32 | + Attache.cache.delete("example.com/#{reldirname}/#{filename}") |
| 33 | + end |
| 34 | + |
32 | 35 | 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 | + |
33 | 41 | it 'should respond not found' do |
34 | 42 | code, headers, body = subject.call |
35 | 43 | expect(code).to eq(404) |
|
64 | 72 | context 'available remotely' do |
65 | 73 | before do |
66 | 74 | 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) |
67 | 76 | end |
68 | 77 |
|
69 | 78 | it 'should proceed normally' do |
|
72 | 81 | end |
73 | 82 |
|
74 | 83 | context 'geometry is "remote"' do |
75 | | - let(:remote_url) { "http://example.com/image.jpg" } |
76 | | - let(:geometry) { CGI.escape('remote') } |
77 | 84 |
|
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') } |
81 | 86 |
|
82 | 87 | it 'should send remote file' do |
83 | 88 | expect(Attache.cache).not_to receive(:fetch) |
|
113 | 118 | end |
114 | 119 | end |
115 | 120 |
|
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" } |
119 | 125 |
|
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 |
158 | 132 | end |
159 | 133 |
|
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 |
165 | 141 | end |
166 | 142 | end |
167 | 143 | end |
|
0 commit comments