ungulate 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/ungulate/file_upload.rb +2 -1
- data/lib/ungulate/job.rb +4 -1
- data/spec/ungulate/file_upload_spec.rb +4 -0
- data/spec/ungulate/job_spec.rb +30 -17
- data/ungulate.gemspec +2 -2
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.6
|
data/lib/ungulate/file_upload.rb
CHANGED
@@ -32,7 +32,8 @@ class Ungulate::FileUpload
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def condition(key)
|
35
|
-
conditions.find {|condition| condition.first == key}
|
35
|
+
found_key, found_value = conditions.find {|condition| condition.first == key}
|
36
|
+
found_value if found_value
|
36
37
|
end
|
37
38
|
|
38
39
|
def conditions
|
data/lib/ungulate/job.rb
CHANGED
@@ -45,7 +45,9 @@ module Ungulate
|
|
45
45
|
method, x, y = instruction
|
46
46
|
image = Magick::Image.from_blob(source).first
|
47
47
|
@logger.info "Performing #{method} with #{x}, #{y}"
|
48
|
-
|
48
|
+
processed_image = image.send(method, x, y)
|
49
|
+
image.destroy!
|
50
|
+
[name, processed_image]
|
49
51
|
end
|
50
52
|
end
|
51
53
|
|
@@ -68,6 +70,7 @@ module Ungulate
|
|
68
70
|
{},
|
69
71
|
'public-read',
|
70
72
|
{'Content-Type' => MIME::Types.type_for(image.format).to_s})
|
73
|
+
image.destroy!
|
71
74
|
end
|
72
75
|
end
|
73
76
|
|
data/spec/ungulate/job_spec.rb
CHANGED
@@ -6,7 +6,7 @@ module Ungulate
|
|
6
6
|
before do
|
7
7
|
ENV['AMAZON_ACCESS_KEY_ID'] = 'test-key-id'
|
8
8
|
ENV['AMAZON_SECRET_ACCESS_KEY'] = 'test-secret'
|
9
|
-
@bucket = mock('Bucket')
|
9
|
+
@bucket = mock('Bucket', :put => nil)
|
10
10
|
@sqs = mock('Sqs')
|
11
11
|
@s3 = mock('S3')
|
12
12
|
@q = mock('Queue')
|
@@ -127,42 +127,50 @@ module Ungulate
|
|
127
127
|
end
|
128
128
|
|
129
129
|
describe :processed_versions do
|
130
|
-
|
131
|
-
job = Job.new
|
130
|
+
before do
|
131
|
+
@job = Job.new
|
132
132
|
versions = {
|
133
133
|
:large => [ :resize_to_fit, 100, 200 ],
|
134
134
|
:small => [ :resize_to_fill, 64, 64 ],
|
135
135
|
}
|
136
|
-
job.stub(:versions).and_return(versions)
|
137
|
-
job.stub(:key).and_return('someimage.jpg')
|
136
|
+
@job.stub(:versions).and_return(versions)
|
137
|
+
@job.stub(:key).and_return('someimage.jpg')
|
138
138
|
|
139
|
-
job.stub(:source).and_return(:data)
|
140
|
-
@source_image = mock('Image')
|
139
|
+
@job.stub(:source).and_return(:data)
|
140
|
+
@source_image = mock('Image', :destroy! => nil)
|
141
141
|
Magick::Image.stub(:from_blob).with(:data).and_return([@source_image])
|
142
142
|
|
143
143
|
@source_image.stub(:resize_to_fit).with(100, 200).and_return(:large_image)
|
144
144
|
@source_image.stub(:resize_to_fill).with(64, 64).and_return(:small_image)
|
145
|
+
end
|
145
146
|
|
146
|
-
|
147
|
+
context "result" do
|
148
|
+
subject { @job.processed_versions }
|
149
|
+
it { should include([:large, :large_image]) }
|
150
|
+
it { should include([:small, :small_image]) }
|
147
151
|
end
|
148
152
|
|
149
|
-
it
|
150
|
-
|
153
|
+
it "should destroy the image object" do
|
154
|
+
@source_image.should_receive(:destroy!)
|
155
|
+
@job.processed_versions
|
156
|
+
end
|
151
157
|
|
152
158
|
it "should memoize" do
|
153
|
-
job
|
154
|
-
job.
|
155
|
-
job.processed_versions.should == :cache
|
159
|
+
@job.instance_variable_set('@processed_versions', :cache)
|
160
|
+
@job.processed_versions.should == :cache
|
156
161
|
end
|
157
162
|
end
|
158
163
|
|
159
164
|
describe :process do
|
160
|
-
|
161
|
-
|
162
|
-
@
|
163
|
-
@little = mock('Image', :to_blob => 'littledata', :format => 'JPEG')
|
165
|
+
before do
|
166
|
+
@big = mock('Image', :destroy! => nil, :to_blob => 'bigdata', :format => 'JPEG')
|
167
|
+
@little = mock('Image', :destroy! => nil, :to_blob => 'littledata', :format => 'JPEG')
|
164
168
|
@mime_type = mock('MimeType', :to_s => 'image/jpeg')
|
165
169
|
MIME::Types.stub(:type_for).with('JPEG').and_return(@mime_type)
|
170
|
+
end
|
171
|
+
|
172
|
+
subject do
|
173
|
+
job = Job.new
|
166
174
|
job.stub(:processed_versions).and_return([[:big, @big], [:little, @little]])
|
167
175
|
job.stub(:bucket).and_return(@bucket)
|
168
176
|
job.stub(:version_key).with(:big).and_return('path/to/someimage_big.jpg')
|
@@ -172,6 +180,11 @@ module Ungulate
|
|
172
180
|
|
173
181
|
after { subject.process }
|
174
182
|
|
183
|
+
it "should destroy the image objects" do
|
184
|
+
@big.should_receive(:destroy!)
|
185
|
+
@little.should_receive(:destroy!)
|
186
|
+
end
|
187
|
+
|
175
188
|
it "should send each processed version to S3" do
|
176
189
|
@bucket.should_receive(:put).with('path/to/someimage_big.jpg',
|
177
190
|
'bigdata',
|
data/ungulate.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ungulate}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.6"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Andrew Bruce"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-05-21}
|
13
13
|
s.default_executable = %q{ungulate_server.rb}
|
14
14
|
s.description = %q{WIP}
|
15
15
|
s.email = %q{andrew@camelpunch.com}
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 6
|
9
|
+
version: 0.0.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Andrew Bruce
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-05-21 00:00:00 +01:00
|
18
18
|
default_executable: ungulate_server.rb
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|