|
21 | 21 | end |
22 | 22 |
|
23 | 23 | describe '#tile_dimensions' do |
24 | | - subject { instance.send(:tile_dimensions) } |
| 24 | + subject(:dimensions) { instance.send(:tile_dimensions) } |
25 | 25 |
|
26 | 26 | context "for an unrestricted image" do |
27 | 27 | context "explicit sizes" do |
|
51 | 51 | context 'for requests with "max" size' do |
52 | 52 | let(:ability) { instance_double(Ability) } |
53 | 53 | let(:permissive_ability) do |
54 | | - ability.tap { |x| allow(x).to receive(:can?).with(:download, subject).and_return(true) } |
| 54 | + ability.tap { |x| allow(x).to receive(:can?).with(:download, dimensions).and_return(true) } |
55 | 55 | end |
56 | 56 | let(:restricted_ability) do |
57 | | - ability.tap { |x| allow(x).to receive(:can?).with(:download, subject).and_return(false) } |
| 57 | + ability.tap { |x| allow(x).to receive(:can?).with(:download, dimensions).and_return(false) } |
58 | 58 | end |
59 | 59 | let(:options) { { size: 'max', region: '0,0,800,600' } } |
60 | 60 |
|
|
74 | 74 | let(:options) { { size: 'max', region: 'full' } } |
75 | 75 |
|
76 | 76 | it 'limits users to thumbnail sizes' do |
77 | | - expect(subject).to eq IIIF::Image::Dimension.new(width: 400, height: 400) |
| 77 | + expect(dimensions).to eq IIIF::Image::Dimension.new(width: 400, height: 400) |
78 | 78 | end |
79 | 79 | end |
80 | 80 |
|
81 | 81 | context "best fit size" do |
82 | 82 | let(:options) { { size: '!800,800', region: 'full' } } |
83 | 83 |
|
84 | 84 | it 'limits users to thumbnail sizes' do |
85 | | - expect(subject).to eq IIIF::Image::Dimension.new(width: 400, height: 400) |
| 85 | + expect(dimensions).to eq IIIF::Image::Dimension.new(width: 400, height: 400) |
86 | 86 | end |
87 | 87 | end |
88 | 88 |
|
89 | 89 | context "specified region" do |
90 | 90 | let(:options) { { size: 'max', region: '0,0,800,600' } } |
91 | 91 |
|
92 | 92 | it 'limits users to a maximum tiles size' do |
93 | | - expect(subject).to eq IIIF::Image::Dimension.new(width: 512, height: 512) |
| 93 | + expect(dimensions).to eq IIIF::Image::Dimension.new(width: 512, height: 512) |
94 | 94 | end |
95 | 95 | end |
96 | 96 | end |
|
112 | 112 | it 'allows the user to see the full-resolution image' do |
113 | 113 | allow(HTTP).to receive_message_chain(:timeout, :headers, :use).and_return(http_client) |
114 | 114 | allow(http_client).to receive(:get).and_return(double(body: nil)) |
115 | | - subject.response |
| 115 | + projection.response |
116 | 116 | expect(http_client).to have_received(:get).with(%r{/full/max/0/default.jpg}) |
117 | 117 | end |
118 | 118 | end |
|
123 | 123 | it 'returns original size when requested dimensions are larger' do |
124 | 124 | allow(HTTP).to receive_message_chain(:timeout, :headers, :use).and_return(http_client) |
125 | 125 | allow(http_client).to receive(:get).and_return(double(body: nil)) |
126 | | - subject.response |
| 126 | + projection.response |
127 | 127 | expect(http_client).to have_received(:get).with(%r{/full/!800,600/0/default.jpg}) |
128 | 128 | end |
129 | 129 | end |
|
141 | 141 | allow(HTTP).to receive_message_chain(:timeout, :headers, :use) |
142 | 142 | .and_return(http_client) |
143 | 143 | allow(http_client).to receive(:get).and_return(double(body: nil)) |
144 | | - subject.response |
| 144 | + projection.response |
145 | 145 | expect(http_client).to have_received(:get).with(%r{/full/!400,400/0/default.jpg}) |
146 | 146 | end |
147 | 147 | end |
|
153 | 153 | allow(HTTP).to receive_message_chain(:timeout, :headers, :use) |
154 | 154 | .and_return(http_client) |
155 | 155 | allow(http_client).to receive(:get).and_return(double(body: nil)) |
156 | | - subject.response |
| 156 | + projection.response |
157 | 157 | expect(http_client).to have_received(:get).with(%r{/full/!100,100/0/default.jpg}) |
158 | 158 | end |
159 | 159 | end |
|
165 | 165 | allow(HTTP).to receive_message_chain(:timeout, :headers, :use) |
166 | 166 | .and_return(http_client) |
167 | 167 | allow(http_client).to receive(:get).and_return(double(body: nil)) |
168 | | - subject.response |
| 168 | + projection.response |
169 | 169 | expect(http_client).to have_received(:get).with(%r{/full/!400,400/0/default.jpg}) |
170 | 170 | end |
171 | 171 | end |
|
177 | 177 | allow(HTTP).to receive_message_chain(:timeout, :headers, :use) |
178 | 178 | .and_return(http_client) |
179 | 179 | allow(http_client).to receive(:get).and_return(double(body: nil)) |
180 | | - subject.response |
| 180 | + projection.response |
181 | 181 | expect(http_client).to have_received(:get).with(%r{/square/100,100/0/default.jpg}) |
182 | 182 | end |
183 | 183 | end |
|
272 | 272 |
|
273 | 273 | describe '#region_dimensions' do |
274 | 274 | subject { instance.region_dimensions } |
| 275 | + |
275 | 276 | context 'for a full region' do |
276 | 277 | let(:options) { { size: 'full', region: 'full' } } |
277 | 278 |
|
278 | | - it 'uses the image dimensions' do |
279 | | - expect(subject).to eq IIIF::Image::Dimension.new(width: 800, height: 600) |
280 | | - end |
| 279 | + it { is_expected.to eq IIIF::Image::Dimension.new(width: 800, height: 600) } |
281 | 280 | end |
282 | 281 |
|
283 | 282 | context 'for square' do |
284 | 283 | let(:options) { { size: 'full', region: 'square' } } |
285 | 284 |
|
286 | | - it 'uses the image dimensions' do |
287 | | - expect(subject).to eq IIIF::Image::Dimension.new(width: 600, height: 600) |
288 | | - end |
| 285 | + it { is_expected.to eq IIIF::Image::Dimension.new(width: 600, height: 600) } |
289 | 286 | end |
290 | 287 |
|
291 | 288 | context 'for an explicit region' do |
292 | 289 | let(:options) { { size: 'full', region: '0,1,2,3' } } |
293 | 290 |
|
294 | | - it 'handles explicit region requests' do |
295 | | - expect(subject).to eq IIIF::Image::Dimension.new(width: 2, height: 3) |
296 | | - end |
| 291 | + it { is_expected.to eq IIIF::Image::Dimension.new(width: 2, height: 3) } |
297 | 292 | end |
298 | 293 |
|
299 | 294 | context 'for an region that contains negative values' do |
300 | 295 | let(:options) { { size: 'full', region: '-22832,-22832,22832,22832' } } |
301 | 296 |
|
302 | 297 | it 'raises an error' do |
303 | | - expect { subject }.to raise_error IIIF::Image::InvalidAttributeError |
| 298 | + expect { instance.region_dimensions }.to raise_error IIIF::Image::InvalidAttributeError |
304 | 299 | end |
305 | 300 | end |
306 | 301 | end |
|
0 commit comments