apache_image_resizer 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -0
- data/COPYING +663 -0
- data/ChangeLog +5 -0
- data/README +70 -0
- data/Rakefile +18 -0
- data/lib/apache/image_resizer.rb +90 -0
- data/lib/apache/image_resizer/util.rb +302 -0
- data/lib/apache/image_resizer/version.rb +31 -0
- data/lib/apache/mock_constants.rb +14 -0
- data/spec/apache/image_resizer/util_spec.rb +7 -0
- data/spec/apache/image_resizer_spec.rb +136 -0
- data/spec/spec_helper.rb +4 -0
- metadata +85 -0
@@ -0,0 +1,31 @@
|
|
1
|
+
module Apache
|
2
|
+
|
3
|
+
class ImageResizer
|
4
|
+
|
5
|
+
module Version
|
6
|
+
|
7
|
+
MAJOR = 0
|
8
|
+
MINOR = 0
|
9
|
+
TINY = 1
|
10
|
+
|
11
|
+
class << self
|
12
|
+
|
13
|
+
# Returns array representation.
|
14
|
+
def to_a
|
15
|
+
[MAJOR, MINOR, TINY]
|
16
|
+
end
|
17
|
+
|
18
|
+
# Short-cut for version string.
|
19
|
+
def to_s
|
20
|
+
to_a.join('.')
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
VERSION = Version.to_s
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
describe Apache::ImageResizer do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@base = '/base'
|
7
|
+
@uri = @base + '/prefix/%s/path'
|
8
|
+
|
9
|
+
@handler = described_class.new(:verbosity => -1)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#handler' do
|
13
|
+
|
14
|
+
def self.it_should(type, what, expected_msg = what, &block)
|
15
|
+
it "should #{type} #{what}" do
|
16
|
+
mock_request(&block)
|
17
|
+
|
18
|
+
actual_msg = nil
|
19
|
+
|
20
|
+
@handler.handler(@request) { |msg|
|
21
|
+
actual_msg = msg
|
22
|
+
nil
|
23
|
+
}.should == Apache.const_get(type == :pass ? :OK : :DECLINED)
|
24
|
+
|
25
|
+
expected_msg = nil if type == :pass
|
26
|
+
actual_msg.should == expected_msg
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it_should :decline, 'No URL' do
|
31
|
+
@uri = nil
|
32
|
+
end
|
33
|
+
|
34
|
+
it_should :decline, 'Invalid Format' do
|
35
|
+
@uri = '/'
|
36
|
+
end
|
37
|
+
|
38
|
+
it_should :decline, 'No Path' do
|
39
|
+
@uri %= 'r100'
|
40
|
+
@uri.sub!(/[^\/]+\z/, '')
|
41
|
+
end
|
42
|
+
|
43
|
+
it_should :decline, 'Invalid Directives' do
|
44
|
+
@uri %= 'r10000'
|
45
|
+
end
|
46
|
+
|
47
|
+
it_should :decline, 'Read Error: Magick::ImageMagickError' do
|
48
|
+
mock_uri(path = '/source-path')
|
49
|
+
|
50
|
+
Magick::Image.should_receive(:read).with(path).once.and_raise(Magick::ImageMagickError)
|
51
|
+
Magick::Image.should_receive(:read).with("jpeg:#{path}").once.and_raise(Magick::ImageMagickError)
|
52
|
+
end
|
53
|
+
|
54
|
+
it_should :decline, 'Write Error: Magick::ImageMagickError' do
|
55
|
+
target = mock_uri(path = '/source-path')
|
56
|
+
mock_image(path, target, format = 'jpeg', true)
|
57
|
+
end
|
58
|
+
|
59
|
+
it_should :decline, 'Resize Error: Magick::ImageMagickError' do
|
60
|
+
target = mock_uri(path = '/source-path')
|
61
|
+
mock_image(path, target, format = 'jpeg', true, true)
|
62
|
+
end
|
63
|
+
|
64
|
+
it_should :pass, 'resize' do
|
65
|
+
target = mock_uri(path = '/source-path')
|
66
|
+
mock_image(path, target, format = 'jpeg')
|
67
|
+
|
68
|
+
@request.should_receive(:content_type=).with("image/#{format}").once.and_return(true)
|
69
|
+
@request.should_receive(:status=).with(Apache::HTTP_OK).once.and_return(true)
|
70
|
+
@request.should_receive(:send_fd).with(target).once.and_return(true)
|
71
|
+
end
|
72
|
+
|
73
|
+
def mock_request(&block)
|
74
|
+
@request = mock('Request')
|
75
|
+
|
76
|
+
instance_eval(&block) if block
|
77
|
+
|
78
|
+
@request.should_receive(:subprocess_env).once.and_return('REDIRECT_URL' => @uri)
|
79
|
+
@request.should_receive(:add_common_vars).with(no_args).once.and_return(nil)
|
80
|
+
@request.should_receive(:path_info).with(no_args).once.and_return(@base)
|
81
|
+
end
|
82
|
+
|
83
|
+
def mock_uri(path)
|
84
|
+
mock_lookup_uri(:orig, path)
|
85
|
+
mock_lookup_uri(:base, base = '/real-base')
|
86
|
+
|
87
|
+
@uri %= 'r100'
|
88
|
+
File.should_receive(:exist?).with(target = @uri.sub(@base, base)).once.and_return(false)
|
89
|
+
|
90
|
+
target
|
91
|
+
end
|
92
|
+
|
93
|
+
def mock_lookup_uri(uri, path)
|
94
|
+
@request.should_receive(:lookup_uri).with(case uri
|
95
|
+
when :orig then @uri % 'original'
|
96
|
+
when :base then @base
|
97
|
+
else uri
|
98
|
+
end).once.and_return(OpenStruct.new(:status => Apache::HTTP_OK, :filename => path))
|
99
|
+
end
|
100
|
+
|
101
|
+
def mock_image(source, target, format, fail_write = false, fail_resize = false)
|
102
|
+
img = mock('Image')
|
103
|
+
Magick::Image.should_receive(:read).with(source).once.and_return([img])
|
104
|
+
|
105
|
+
img.should_receive(:columns).with(no_args).once.and_return(123)
|
106
|
+
img.should_receive(:rows).with(no_args).once.and_return(456)
|
107
|
+
img.should_not_receive(:crop!)
|
108
|
+
|
109
|
+
if fail_resize
|
110
|
+
img.should_receive(:resize_to_fit!).with(100.0, 456).once.and_raise(Magick::ImageMagickError)
|
111
|
+
img.should_not_receive(:write)
|
112
|
+
|
113
|
+
File.should_not_receive(:open)
|
114
|
+
File.should_not_receive(:exist?).with(File.dirname(target))
|
115
|
+
FileUtils.should_not_receive(:mkdir_p)
|
116
|
+
else
|
117
|
+
img.should_receive(:resize_to_fit!).with(100.0, 456).once.and_return(nil)
|
118
|
+
|
119
|
+
File.should_receive(:exist?).with(File.dirname(target)).once.and_return(true)
|
120
|
+
FileUtils.should_not_receive(:mkdir_p)
|
121
|
+
|
122
|
+
if fail_write
|
123
|
+
img.should_receive(:write).with(target).once.and_raise(Magick::ImageMagickError)
|
124
|
+
img.should_receive(:write).with("jpeg:#{target}").once.and_raise(Magick::ImageMagickError)
|
125
|
+
File.should_not_receive(:open)
|
126
|
+
else
|
127
|
+
img.should_receive(:format).with(no_args).once.and_return(format)
|
128
|
+
img.should_receive(:write).with(target).once.and_return(img)
|
129
|
+
File.should_receive(:open).with(target).once.and_yield(target)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: apache_image_resizer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jens Wille
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-11-03 00:00:00 Z
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Apache module providing image resizing functionality.
|
22
|
+
email: jens.wille@uni-koeln.de
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files:
|
28
|
+
- README
|
29
|
+
- COPYING
|
30
|
+
- ChangeLog
|
31
|
+
files:
|
32
|
+
- lib/apache/image_resizer.rb
|
33
|
+
- lib/apache/mock_constants.rb
|
34
|
+
- lib/apache/image_resizer/util.rb
|
35
|
+
- lib/apache/image_resizer/version.rb
|
36
|
+
- ChangeLog
|
37
|
+
- COPYING
|
38
|
+
- README
|
39
|
+
- Rakefile
|
40
|
+
- spec/apache/image_resizer_spec.rb
|
41
|
+
- spec/apache/image_resizer/util_spec.rb
|
42
|
+
- spec/spec_helper.rb
|
43
|
+
- .rspec
|
44
|
+
homepage: http://github.com/blackwinter/apache_image_resizer
|
45
|
+
licenses: []
|
46
|
+
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options:
|
49
|
+
- --title
|
50
|
+
- apache_image_resizer Application documentation (v0.0.1)
|
51
|
+
- --line-numbers
|
52
|
+
- --main
|
53
|
+
- README
|
54
|
+
- --all
|
55
|
+
- --charset
|
56
|
+
- UTF-8
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
hash: 3
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
version: "0"
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
|
+
requirements: []
|
78
|
+
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 1.8.11
|
81
|
+
signing_key:
|
82
|
+
specification_version: 3
|
83
|
+
summary: Apache module providing image resizing functionality.
|
84
|
+
test_files: []
|
85
|
+
|