riiif 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/.rubocop_todo.yml +153 -0
- data/Rakefile +10 -4
- data/app/controllers/riiif/images_controller.rb +33 -33
- data/app/models/riiif/file.rb +23 -23
- data/app/models/riiif/image.rb +8 -8
- data/lib/riiif/abstract_file_system_resolver.rb +26 -0
- data/lib/riiif/akubra_system_file_resolver.rb +7 -16
- data/lib/riiif/file_system_file_resolver.rb +8 -19
- data/lib/riiif/http_file_resolver.rb +27 -27
- data/lib/riiif/rails/routes.rb +1 -1
- data/lib/riiif/routes.rb +4 -4
- data/lib/riiif/version.rb +1 -1
- data/lib/riiif.rb +4 -3
- data/riiif.gemspec +16 -14
- data/spec/controllers/riiif/images_controller_spec.rb +132 -0
- data/spec/models/riiif/akubra_system_file_resolver_spec.rb +12 -0
- data/spec/models/riiif/file_system_file_resolver_spec.rb +41 -0
- data/spec/models/{http_file_resolver_spec.rb → riiif/http_file_resolver_spec.rb} +8 -8
- data/spec/models/{image_spec.rb → riiif/image_spec.rb} +47 -47
- data/spec/routing/redirect_spec.rb +4 -4
- data/spec/routing/resize_routes_spec.rb +28 -28
- data/spec/spec_helper.rb +1 -4
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +1 -2
- metadata +49 -18
- data/spec/controllers/images_controller_spec.rb +0 -138
- data/spec/models/akubra_system_file_resolver_spec.rb +0 -13
- data/spec/models/file_system_file_resolver_spec.rb +0 -19
data/riiif.gemspec
CHANGED
@@ -4,24 +4,26 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'riiif/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'riiif'
|
8
8
|
spec.version = Riiif::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.description =
|
12
|
-
spec.summary =
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
9
|
+
spec.authors = ['Justin Coyne']
|
10
|
+
spec.email = ['justin@curationexperts.com']
|
11
|
+
spec.description = 'A IIIF image server'
|
12
|
+
spec.summary = 'A rails engine that support IIIF requests'
|
13
|
+
spec.homepage = 'https://github.com/curationexperts/riiif'
|
14
|
+
spec.license = 'APACHE2'
|
15
15
|
|
16
|
-
spec.files = `git ls-files|grep -v spec/samples`.split(
|
16
|
+
spec.files = `git ls-files|grep -v spec/samples`.split($INPUT_RECORD_SEPARATOR)
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
-
spec.add_development_dependency "rake"
|
23
|
-
spec.add_development_dependency "engine_cart", '~> 0.8'
|
24
|
-
spec.add_development_dependency "rspec-rails"
|
25
|
-
spec.add_development_dependency "sqlite3"
|
26
21
|
spec.add_dependency 'rails', '> 3.2.0'
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
23
|
+
spec.add_development_dependency 'rake'
|
24
|
+
spec.add_development_dependency 'engine_cart', '~> 0.8'
|
25
|
+
spec.add_development_dependency 'rspec-rails'
|
26
|
+
spec.add_development_dependency 'sqlite3'
|
27
|
+
spec.add_development_dependency 'rubocop', '~> 0.41.2'
|
28
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 1.5'
|
27
29
|
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'open-uri'
|
3
|
+
|
4
|
+
describe Riiif::ImagesController do
|
5
|
+
let(:filename) { File.expand_path('spec/samples/world.jp2') }
|
6
|
+
routes { Riiif::Engine.routes }
|
7
|
+
|
8
|
+
describe '#show' do
|
9
|
+
it 'sends images to the service' do
|
10
|
+
image = double
|
11
|
+
expect(Riiif::Image).to receive(:new).with('abcd1234').and_return(image)
|
12
|
+
expect(image).to receive(:render).with('region' => 'full', 'size' => 'full',
|
13
|
+
'rotation' => '0', 'quality' => 'default',
|
14
|
+
'format' => 'jpg').and_return('IMAGEDATA')
|
15
|
+
get :show, id: 'abcd1234', action: 'show', region: 'full', size: 'full',
|
16
|
+
rotation: '0', quality: 'default', format: 'jpg'
|
17
|
+
expect(response).to be_successful
|
18
|
+
expect(response.body).to eq 'IMAGEDATA'
|
19
|
+
expect(response.headers['Link']).to eq '<http://iiif.io/api/image/2/level1.json>;rel="profile"'
|
20
|
+
expect(response.headers['Access-Control-Allow-Origin']).to eq '*'
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'with an unauthorized image' do
|
24
|
+
let(:auth) { double('no auth service', can?: false) }
|
25
|
+
let(:not_found_image) { double('not_found_image', render: 'test data') }
|
26
|
+
before do
|
27
|
+
allow(controller).to receive(:authorization_service).and_return(auth)
|
28
|
+
allow(controller).to receive(:not_found_image).and_return(not_found_image)
|
29
|
+
end
|
30
|
+
it 'renders 401' do
|
31
|
+
get :show, id: 'abcd1234', action: 'show', region: 'full', size: 'full',
|
32
|
+
rotation: '0', quality: 'default', format: 'jpg'
|
33
|
+
expect(response.body).to eq 'test data'
|
34
|
+
expect(response.code).to eq '401'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'with a invalid region' do
|
39
|
+
it 'renders 400' do
|
40
|
+
image = double('an image')
|
41
|
+
allow(image).to receive(:render).and_raise Riiif::InvalidAttributeError
|
42
|
+
allow(Riiif::Image).to receive(:new).with('abcd1234').and_return(image)
|
43
|
+
get :show, id: 'abcd1234', action: 'show', region: '`szoW0', size: 'full',
|
44
|
+
rotation: '0', quality: 'default', format: 'jpg'
|
45
|
+
expect(response.code).to eq '400'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'with a nonexistent image' do
|
50
|
+
it "errors when a default image isn't sent" do
|
51
|
+
expect(Riiif::Image).to receive(:new).with('bad_id').and_raise(OpenURI::HTTPError.new('fail', StringIO.new))
|
52
|
+
expect do
|
53
|
+
get :show, id: 'bad_id', action: 'show', region: 'full', size: 'full',
|
54
|
+
rotation: '0', quality: 'default', format: 'jpg'
|
55
|
+
end.to raise_error(StandardError)
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'with a default image set' do
|
59
|
+
around do |example|
|
60
|
+
old_value = Riiif.not_found_image
|
61
|
+
Riiif.not_found_image = filename
|
62
|
+
example.run
|
63
|
+
Riiif.not_found_image = old_value
|
64
|
+
end
|
65
|
+
|
66
|
+
it "sends the default 'not found' image for failed http files" do
|
67
|
+
not_found_image = double
|
68
|
+
expect(Riiif::Image).to receive(:new) do |_id, file|
|
69
|
+
raise Riiif::ImageNotFoundError unless file.present?
|
70
|
+
not_found_image
|
71
|
+
end.twice
|
72
|
+
expect(not_found_image).to receive(:render).with('region' => 'full', 'size' => 'full',
|
73
|
+
'rotation' => '0', 'quality' => 'default',
|
74
|
+
'format' => 'jpg').and_return('default-image-data')
|
75
|
+
|
76
|
+
get :show, id: 'bad_id', action: 'show', region: 'full', size: 'full',
|
77
|
+
rotation: '0', quality: 'default', format: 'jpg'
|
78
|
+
expect(response).to be_not_found
|
79
|
+
expect(response.body).to eq 'default-image-data'
|
80
|
+
end
|
81
|
+
|
82
|
+
it "sends the default 'not found' image for failed files on the filesystem" do
|
83
|
+
not_found_image = double
|
84
|
+
expect(Riiif::Image).to receive(:new) do |_id, file|
|
85
|
+
raise Riiif::ImageNotFoundError unless file.present?
|
86
|
+
not_found_image
|
87
|
+
end.twice
|
88
|
+
expect(not_found_image).to receive(:render).with('region' => 'full', 'size' => 'full',
|
89
|
+
'rotation' => '0', 'quality' => 'default',
|
90
|
+
'format' => 'jpg').and_return('default-image-data')
|
91
|
+
|
92
|
+
get :show, id: 'bad_id', action: 'show', region: 'full', size: 'full',
|
93
|
+
rotation: '0', quality: 'default', format: 'jpg'
|
94
|
+
expect(response).to be_not_found
|
95
|
+
expect(response.body).to eq 'default-image-data'
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe 'info' do
|
102
|
+
it 'returns info' do
|
103
|
+
image = double
|
104
|
+
expect(Riiif::Image).to receive(:new).with('abcd1234').and_return(image)
|
105
|
+
expect(image).to receive(:info).and_return(width: 6000, height: 4000)
|
106
|
+
get :info, id: 'abcd1234', format: 'json'
|
107
|
+
expect(response).to be_successful
|
108
|
+
json = JSON.parse(response.body)
|
109
|
+
expect(json).to eq '@context' => 'http://iiif.io/api/image/2/context.json',
|
110
|
+
'@id' => 'http://test.host/images/abcd1234',
|
111
|
+
'width' => 6000,
|
112
|
+
'height' => 4000,
|
113
|
+
'profile' => ['http://iiif.io/api/image/2/level1.json', 'formats' => %w(jpg png)],
|
114
|
+
'protocol' => 'http://iiif.io/api/image'
|
115
|
+
expect(response.headers['Link']).to eq '<http://iiif.io/api/image/2/level1.json>;rel="profile"'
|
116
|
+
expect(response.headers['Content-Type']).to eq 'application/ld+json; charset=utf-8'
|
117
|
+
expect(response.headers['Access-Control-Allow-Origin']).to eq '*'
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'with an unauthorized image' do
|
121
|
+
let(:auth) { double('no auth service', can?: false) }
|
122
|
+
before do
|
123
|
+
allow(controller).to receive(:authorization_service).and_return(auth)
|
124
|
+
end
|
125
|
+
it 'renders 401' do
|
126
|
+
get :info, id: 'abcd1234', format: 'json'
|
127
|
+
expect(response.body).to eq '{"error":"unauthorized"}'
|
128
|
+
expect(response.code).to eq '401'
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Riiif::AkubraSystemFileResolver do
|
4
|
+
subject { described_class.new(Rails.root.join('../spec/samples/'), 'jp2', [[0, 2], [2, 2], [4, 1]]) }
|
5
|
+
it "raises an error when the file isn't found" do
|
6
|
+
expect { subject.find('demo:2') }.to raise_error Riiif::ImageNotFoundError
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'gets the jpeg2000 file' do
|
10
|
+
expect(subject.find('demo:1').path).to eq Riiif::File.new(Dir.glob(subject.pathroot + '22/7e/9/info%3Afedora%2Fdemo%3A1%2Fjp2%2Fjp2.0').first).path
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Riiif::FileSystemFileResolver do
|
4
|
+
let(:resolver) { described_class.new }
|
5
|
+
|
6
|
+
describe '#find' do
|
7
|
+
subject { resolver.find(id) }
|
8
|
+
|
9
|
+
context "when the file isn't found" do
|
10
|
+
let(:id) { '1234' }
|
11
|
+
it 'raises an error' do
|
12
|
+
expect { subject }.to raise_error Riiif::ImageNotFoundError
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'when the file is found' do
|
17
|
+
let(:id) { 'world' }
|
18
|
+
it 'returns the jpeg2000 file' do
|
19
|
+
expect(subject.path).to eq resolver.root + '/spec/samples/world.jp2'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#pattern' do
|
25
|
+
subject { resolver.pattern(id) }
|
26
|
+
|
27
|
+
context 'with dashes' do
|
28
|
+
let(:id) { 'foo-bar-baz' }
|
29
|
+
it 'accepts ids with dashes' do
|
30
|
+
expect { subject }.not_to raise_error
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'with colins' do
|
35
|
+
let(:id) { 'fo:baz' }
|
36
|
+
it 'accepts ids with colins' do
|
37
|
+
expect { subject }.not_to raise_error
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -1,17 +1,17 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Riiif::HTTPFileResolver do
|
4
|
-
subject {
|
4
|
+
subject { described_class.new }
|
5
5
|
|
6
6
|
before do
|
7
|
-
Dir.glob(
|
7
|
+
Dir.glob('tmp/network_files/*') do |f|
|
8
8
|
File.unlink(f)
|
9
9
|
end
|
10
|
-
subject.id_to_uri =
|
10
|
+
subject.id_to_uri = ->(id) { id }
|
11
11
|
end
|
12
12
|
|
13
13
|
it "raises an error when the file isn't found" do
|
14
|
-
expect(Kernel).to receive(:open).and_raise(OpenURI::HTTPError.new(
|
14
|
+
expect(Kernel).to receive(:open).and_raise(OpenURI::HTTPError.new('failure', StringIO.new))
|
15
15
|
begin
|
16
16
|
subject.find('1234')
|
17
17
|
rescue Riiif::ImageNotFoundError => e
|
@@ -20,14 +20,14 @@ describe Riiif::HTTPFileResolver do
|
|
20
20
|
expect(e.original_exception).to be_an OpenURI::HTTPError
|
21
21
|
end
|
22
22
|
|
23
|
-
context
|
24
|
-
let(:credentials) {
|
23
|
+
context 'when basic authentication credentials are set' do
|
24
|
+
let(:credentials) { %w(username s0s3kr3t) }
|
25
25
|
before do
|
26
26
|
subject.basic_auth_credentials = credentials
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
30
|
-
expect(Kernel).to receive(:open).with(
|
29
|
+
it 'uses basic auth credentials' do
|
30
|
+
expect(Kernel).to receive(:open).with('1234', http_basic_authentication: credentials)
|
31
31
|
subject.find('1234')
|
32
32
|
end
|
33
33
|
end
|
@@ -3,149 +3,149 @@ require 'spec_helper'
|
|
3
3
|
describe Riiif::Image do
|
4
4
|
before { Rails.cache.clear }
|
5
5
|
let(:filename) { File.expand_path('spec/samples/world.jp2') }
|
6
|
-
subject {
|
7
|
-
describe
|
6
|
+
subject { described_class.new('world') }
|
7
|
+
describe 'happy path' do
|
8
8
|
before do
|
9
9
|
expect(subject.image).to receive(:execute).with("convert #{filename} jpg:-").and_return('imagedata')
|
10
10
|
end
|
11
|
-
it
|
11
|
+
it 'renders' do
|
12
12
|
expect(subject.render('size' => 'full', format: 'jpg')).to eq 'imagedata'
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
it
|
17
|
-
img =
|
16
|
+
it 'is able to override the file used for the Image' do
|
17
|
+
img = described_class.new('some_id', Riiif::File.new(filename))
|
18
18
|
expect(img.id).to eq 'some_id'
|
19
19
|
expect(img.info).to eq height: 400, width: 800
|
20
20
|
end
|
21
21
|
|
22
|
-
describe
|
23
|
-
it
|
22
|
+
describe 'without a format' do
|
23
|
+
it 'raises an error' do
|
24
24
|
expect { subject.render('size' => 'full') }.to raise_error ArgumentError
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
describe
|
29
|
-
it
|
30
|
-
expect(subject.info).to eq height: 400, width:800
|
28
|
+
describe 'info' do
|
29
|
+
it 'returns the data' do
|
30
|
+
expect(subject.info).to eq height: 400, width: 800
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
context
|
34
|
+
context 'using HTTPFileResolver' do
|
35
35
|
before do
|
36
|
-
|
37
|
-
|
36
|
+
described_class.file_resolver = Riiif::HTTPFileResolver.new
|
37
|
+
described_class.file_resolver.id_to_uri = lambda do |id|
|
38
38
|
"https://upload.wikimedia.org/wikipedia/commons/thumb/a/a4/#{id}.jpg/600px-#{id}.jpg"
|
39
39
|
end
|
40
40
|
end
|
41
41
|
after do
|
42
|
-
|
42
|
+
described_class.file_resolver = Riiif::FileSystemFileResolver.new
|
43
43
|
end
|
44
44
|
|
45
|
-
describe
|
46
|
-
subject {
|
47
|
-
it
|
48
|
-
expect(subject.info).to eq height: 390, width:600
|
45
|
+
describe 'get info' do
|
46
|
+
subject { described_class.new('Cave_26,_Ajanta') }
|
47
|
+
it 'is easy' do
|
48
|
+
expect(subject.info).to eq height: 390, width: 600
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
context
|
53
|
-
subject {
|
52
|
+
context 'when the rendered image is in the cache' do
|
53
|
+
subject { described_class.new('Cave_26,_Ajanta') }
|
54
54
|
before { allow(Rails.cache).to receive(:fetch).and_return('expected') }
|
55
55
|
|
56
|
-
it
|
57
|
-
expect(
|
56
|
+
it 'does not fetch the file' do
|
57
|
+
expect(described_class.file_resolver).not_to receive(:find)
|
58
58
|
expect(subject.render(region: 'full', format: 'png')).to eq 'expected'
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
describe
|
64
|
-
describe
|
65
|
-
it
|
63
|
+
describe 'mogrify' do
|
64
|
+
describe 'region' do
|
65
|
+
it 'returns the original when specifing full size' do
|
66
66
|
expect(subject.image).to receive(:execute).with("convert #{filename} png:-")
|
67
67
|
subject.render(region: 'full', format: 'png')
|
68
68
|
end
|
69
|
-
it
|
69
|
+
it 'handles absolute geometry' do
|
70
70
|
expect(subject.image).to receive(:execute).with("convert -crop 60x75+80+15 #{filename} png:-")
|
71
71
|
subject.render(region: '80,15,60,75', format: 'png')
|
72
72
|
end
|
73
|
-
it
|
73
|
+
it 'handles percent geometry' do
|
74
74
|
expect(subject.image).to receive(:execute).with("identify -format %hx%w #{filename}").and_return('131x175')
|
75
75
|
expect(subject.image).to receive(:execute).with("convert -crop 80%x70+18+13 #{filename} png:-")
|
76
76
|
subject.render(region: 'pct:10,10,80,70', format: 'png')
|
77
77
|
end
|
78
|
-
it
|
78
|
+
it 'raises an error for invalid geometry' do
|
79
79
|
expect { subject.render(region: '150x75', format: 'png') }.to raise_error Riiif::InvalidAttributeError
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
-
describe
|
84
|
-
it
|
83
|
+
describe 'resize' do
|
84
|
+
it 'returns the original when specifing full size' do
|
85
85
|
expect(subject.image).to receive(:execute).with("convert #{filename} png:-")
|
86
86
|
subject.render(size: 'full', format: 'png')
|
87
87
|
end
|
88
|
-
it
|
88
|
+
it 'handles integer percent sizes' do
|
89
89
|
expect(subject.image).to receive(:execute).with("convert -resize 50% #{filename} png:-")
|
90
90
|
subject.render(size: 'pct:50', format: 'png')
|
91
91
|
end
|
92
|
-
it
|
92
|
+
it 'handles float percent sizes' do
|
93
93
|
expect(subject.image).to receive(:execute).with("convert -resize 12.5% #{filename} png:-")
|
94
94
|
subject.render(size: 'pct:12.5', format: 'png')
|
95
95
|
end
|
96
|
-
it
|
96
|
+
it 'handles w,' do
|
97
97
|
expect(subject.image).to receive(:execute).with("convert -resize 50 #{filename} png:-")
|
98
98
|
subject.render(size: '50,', format: 'png')
|
99
99
|
end
|
100
|
-
it
|
100
|
+
it 'handles ,h' do
|
101
101
|
expect(subject.image).to receive(:execute).with("convert -resize x50 #{filename} png:-")
|
102
102
|
subject.render(size: ',50', format: 'png')
|
103
103
|
end
|
104
|
-
it
|
104
|
+
it 'handles w,h' do
|
105
105
|
expect(subject.image).to receive(:execute).with("convert -resize 150x75! #{filename} png:-")
|
106
106
|
subject.render(size: '150,75', format: 'png')
|
107
107
|
end
|
108
|
-
it
|
108
|
+
it 'handles bestfit (!w,h)' do
|
109
109
|
expect(subject.image).to receive(:execute).with("convert -resize 150x75 #{filename} png:-")
|
110
110
|
subject.render(size: '!150,75', format: 'png')
|
111
111
|
end
|
112
|
-
it
|
112
|
+
it 'raises an error for invalid size' do
|
113
113
|
expect { subject.render(size: '150x75', format: 'png') }.to raise_error Riiif::InvalidAttributeError
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
|
-
describe
|
118
|
-
it
|
117
|
+
describe 'rotate' do
|
118
|
+
it 'returns the original when specifing full size' do
|
119
119
|
expect(subject.image).to receive(:execute).with("convert #{filename} png:-")
|
120
120
|
subject.render(rotation: '0', format: 'png')
|
121
121
|
end
|
122
|
-
it
|
122
|
+
it 'handles floats' do
|
123
123
|
expect(subject.image).to receive(:execute).with("convert -virtual-pixel white +distort srt 22.5 #{filename} png:-")
|
124
124
|
subject.render(rotation: '22.5', format: 'png')
|
125
125
|
end
|
126
|
-
it
|
126
|
+
it 'raises an error for invalid angle' do
|
127
127
|
expect { subject.render(rotation: '150x', format: 'png') }.to raise_error Riiif::InvalidAttributeError
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
131
|
-
describe
|
132
|
-
it
|
131
|
+
describe 'quality' do
|
132
|
+
it 'returns the original when specifing default' do
|
133
133
|
expect(subject.image).to receive(:execute).with("convert #{filename} png:-")
|
134
134
|
subject.render(quality: 'default', format: 'png')
|
135
135
|
end
|
136
|
-
it
|
136
|
+
it 'returns the original when specifing color' do
|
137
137
|
expect(subject.image).to receive(:execute).with("convert #{filename} png:-")
|
138
138
|
subject.render(quality: 'color', format: 'png')
|
139
139
|
end
|
140
|
-
it
|
140
|
+
it 'converts to grayscale' do
|
141
141
|
expect(subject.image).to receive(:execute).with("convert -colorspace Gray #{filename} png:-")
|
142
142
|
subject.render(quality: 'grey', format: 'png')
|
143
143
|
end
|
144
|
-
it
|
144
|
+
it 'converts to bitonal' do
|
145
145
|
expect(subject.image).to receive(:execute).with("convert -colorspace Gray -type Bilevel #{filename} png:-")
|
146
146
|
subject.render(quality: 'bitonal', format: 'png')
|
147
147
|
end
|
148
|
-
it
|
148
|
+
it 'raises an error for invalid angle' do
|
149
149
|
expect { subject.render(rotation: '150x', format: 'png') }.to raise_error Riiif::InvalidAttributeError
|
150
150
|
end
|
151
151
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
4
|
-
it
|
5
|
-
get
|
6
|
-
expect(response).to redirect_to
|
3
|
+
describe 'GET /abcd%2F1234', type: :request do
|
4
|
+
it 'redirects, without unescaping' do
|
5
|
+
get '/images/abcd%2F1234'
|
6
|
+
expect(response).to redirect_to '/images/abcd%2F1234/info.json'
|
7
7
|
end
|
8
8
|
end
|
@@ -1,58 +1,58 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe 'routes' do
|
4
4
|
routes { Riiif::Engine.routes }
|
5
5
|
|
6
6
|
describe 'for conversion' do
|
7
|
-
it
|
7
|
+
it 'routes GET /abcd1234/full/full/0/default.jpg' do
|
8
8
|
expect(
|
9
|
-
get:
|
10
|
-
).to route_to(controller:
|
11
|
-
region: 'full', size: 'full', rotation: '0',
|
12
|
-
quality: 'default', format: 'jpg', model:
|
9
|
+
get: '/abcd1234/full/full/0/default.jpg'
|
10
|
+
).to route_to(controller: 'riiif/images', id: 'abcd1234', action: 'show',
|
11
|
+
region: 'full', size: 'full', rotation: '0',
|
12
|
+
quality: 'default', format: 'jpg', model: 'riiif/image')
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
15
|
+
it 'routes requests with floating point percent size' do
|
16
16
|
expect(
|
17
|
-
get:
|
18
|
-
).to route_to(controller:
|
17
|
+
get: '/abcd1234/full/pct:12.5/22.5/default.jpg'
|
18
|
+
).to route_to(controller: 'riiif/images', id: 'abcd1234', action: 'show',
|
19
19
|
region: 'full', size: 'pct:12.5', rotation: '22.5',
|
20
|
-
quality: 'default', format: 'jpg', model:
|
20
|
+
quality: 'default', format: 'jpg', model: 'riiif/image')
|
21
21
|
end
|
22
|
-
it
|
22
|
+
it 'routes requests with pixel size' do
|
23
23
|
expect(
|
24
|
-
get:
|
25
|
-
).to route_to(controller:
|
24
|
+
get: '/abcd1234/full/100,50/22.5/default.jpg'
|
25
|
+
).to route_to(controller: 'riiif/images', id: 'abcd1234', action: 'show',
|
26
26
|
region: 'full', size: '100,50', rotation: '22.5',
|
27
|
-
quality: 'default', format: 'jpg', model:
|
27
|
+
quality: 'default', format: 'jpg', model: 'riiif/image')
|
28
28
|
end
|
29
|
-
it
|
29
|
+
it 'routes requests with dashes in the id' do
|
30
30
|
expect(
|
31
|
-
get:
|
32
|
-
).to route_to(controller:
|
31
|
+
get: '/abcd-1234-5678/full/full/0/default.jpg'
|
32
|
+
).to route_to(controller: 'riiif/images', id: 'abcd-1234-5678', action: 'show',
|
33
33
|
region: 'full', size: 'full', rotation: '0',
|
34
|
-
quality: 'default', format: 'jpg', model:
|
34
|
+
quality: 'default', format: 'jpg', model: 'riiif/image')
|
35
35
|
end
|
36
36
|
|
37
|
-
describe
|
38
|
-
it
|
37
|
+
describe 'route helper' do
|
38
|
+
it 'takes all the options' do
|
39
39
|
expect(image_path('abcd1234', region: 'full', size: '100,50', rotation: '22.5', quality: 'default',
|
40
|
-
|
40
|
+
format: 'jpg')).to eq '/images/abcd1234/full/100,50/22.5/default.jpg'
|
41
41
|
end
|
42
|
-
it
|
42
|
+
it 'has defaults' do
|
43
43
|
expect(image_path('abcd1234', size: '100,50')).to eq '/images/abcd1234/full/100,50/0/default.jpg'
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
describe
|
49
|
-
it
|
48
|
+
describe 'for info' do
|
49
|
+
it 'routes GET /abcd1234/info.json' do
|
50
50
|
expect(
|
51
|
-
get:
|
52
|
-
).to route_to(controller:
|
53
|
-
action:
|
51
|
+
get: '/abcd1234/info.json'
|
52
|
+
).to route_to(controller: 'riiif/images', id: 'abcd1234',
|
53
|
+
action: 'info', format: 'json', model: 'riiif/image')
|
54
54
|
end
|
55
|
-
it
|
55
|
+
it 'has a route helper' do
|
56
56
|
expect(info_path('abcd1234')).to eq '/images/abcd1234/info.json'
|
57
57
|
end
|
58
58
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,17 +1,14 @@
|
|
1
1
|
require 'engine_cart'
|
2
|
-
ENV[
|
3
|
-
|
2
|
+
ENV['RAILS_ENV'] ||= 'test'
|
4
3
|
|
5
4
|
EngineCart.load_application!
|
6
5
|
require 'rspec/rails'
|
7
6
|
|
8
|
-
|
9
7
|
RSpec.configure do |config|
|
10
8
|
config.run_all_when_everything_filtered = true
|
11
9
|
|
12
10
|
config.infer_spec_type_from_file_location!
|
13
11
|
|
14
|
-
|
15
12
|
# Run specs in random order to surface order dependencies. If you find an
|
16
13
|
# order dependency and want to debug it, you can fix the order by providing
|
17
14
|
# the seed, which is printed after each run.
|