mugshot 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +22 -0
- data/LICENSE +20 -0
- data/README.rdoc +18 -0
- data/Rakefile +70 -0
- data/VERSION +1 -0
- data/config.ru +5 -0
- data/features/retrieve_original_image.feature +12 -0
- data/features/retrieve_resized_image.feature +12 -0
- data/features/step_definitions/general_steps.rb +8 -0
- data/features/step_definitions/retrieve_original_image_steps.rb +15 -0
- data/features/step_definitions/retrieve_resized_image_steps.rb +14 -0
- data/features/support/env.rb +27 -0
- data/features/support/files/test.jpg +0 -0
- data/gems.yml +11 -0
- data/gems_dev.yml +14 -0
- data/lib/mugshot/application.rb +33 -0
- data/lib/mugshot/fs_storage.rb +22 -0
- data/lib/mugshot/image.rb +15 -0
- data/lib/mugshot/storage.rb +8 -0
- data/lib/mugshot.rb +18 -0
- data/mugshot.gemspec +98 -0
- data/spec/files/test.jpg +0 -0
- data/spec/mugshot/application_spec.rb +77 -0
- data/spec/mugshot/fs_storage_spec.rb +28 -0
- data/spec/mugshot/image_spec.rb +25 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/test.html +4 -0
- metadata +185 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Fernando Meyer
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
= farofus-mugshot
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but
|
13
|
+
bump version in a commit by itself I can ignore when I pull)
|
14
|
+
* Send me a pull request. Bonus points for topic branches.
|
15
|
+
|
16
|
+
== Copyright
|
17
|
+
|
18
|
+
Copyright (c) 2009 Fernando Meyer. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
task :default => :spec
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'jeweler'
|
8
|
+
namespace :gem do
|
9
|
+
Jeweler::Tasks.new do |gem|
|
10
|
+
gem.name = "mugshot"
|
11
|
+
gem.summary = %Q{Image server}
|
12
|
+
gem.description = %Q{Image server}
|
13
|
+
gem.email = %w{cainanunes@gmail.com fabriciolopesvital@gmail.com fmcamargo@gmail.com gcirne@gmail.com jose@peleteiro.net}
|
14
|
+
gem.homepage = "http://github.com/timebeta/mugshot"
|
15
|
+
gem.authors = ["Cainã Nunes", "Fabrício Lopes", "Fernando Meyer", "Guilherme Cirne", "José Peleteiro"]
|
16
|
+
|
17
|
+
## depedencies
|
18
|
+
gems = YAML.load_file 'gems.yml'
|
19
|
+
gems.each do |depgem|
|
20
|
+
gem.add_dependency(depgem[:name], depgem[:version])
|
21
|
+
end
|
22
|
+
|
23
|
+
## developments depedencies
|
24
|
+
gems = YAML.load_file 'gems_dev.yml'
|
25
|
+
gems.each do |depgem|
|
26
|
+
gem.add_development_dependency(depgem[:name], depgem[:version])
|
27
|
+
end
|
28
|
+
|
29
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
30
|
+
end
|
31
|
+
end
|
32
|
+
rescue LoadError
|
33
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
34
|
+
end
|
35
|
+
|
36
|
+
require 'spec/rake/spectask'
|
37
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
38
|
+
spec.libs << 'lib' << 'spec'
|
39
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
40
|
+
spec.rcov = true
|
41
|
+
spec.rcov_dir = 'doc/coverage'
|
42
|
+
spec.rcov_opts = %w{--text-summary --failure-threshold 100 --exclude spec/*,gems/*,/usr/lib/ruby/*}
|
43
|
+
end
|
44
|
+
task :spec => 'gem:check_dependencies'
|
45
|
+
|
46
|
+
require 'cucumber/rake/task'
|
47
|
+
Cucumber::Rake::Task.new(:features)
|
48
|
+
task :features => 'gem:check_dependencies'
|
49
|
+
|
50
|
+
begin
|
51
|
+
require 'reek/adapters/rake_task'
|
52
|
+
Reek::RakeTask.new do |t|
|
53
|
+
t.fail_on_error = true
|
54
|
+
t.verbose = false
|
55
|
+
t.source_files = 'lib/**/*.rb'
|
56
|
+
end
|
57
|
+
rescue LoadError
|
58
|
+
task :reek do
|
59
|
+
abort "Reek is not available. In order to run reek, you must: sudo gem install reek"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
begin
|
64
|
+
require 'yard'
|
65
|
+
YARD::Rake::YardocTask.new
|
66
|
+
rescue LoadError
|
67
|
+
task :yardoc do
|
68
|
+
abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
|
69
|
+
end
|
70
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/config.ru
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
Feature: Retrieve original image
|
2
|
+
|
3
|
+
Scenario: Successful retrieval of original image
|
4
|
+
When I upload an image
|
5
|
+
And I ask for the original image
|
6
|
+
|
7
|
+
Then I should get the original image
|
8
|
+
|
9
|
+
Scenario: Image doesn't exist
|
10
|
+
When I ask for an image that doesn't exist
|
11
|
+
|
12
|
+
Then I should get a 404 response
|
@@ -0,0 +1,12 @@
|
|
1
|
+
Feature: Retrieve resized image
|
2
|
+
|
3
|
+
Scenario: Successful retrieval of resized image
|
4
|
+
When I upload an image
|
5
|
+
And I ask for the resized image
|
6
|
+
|
7
|
+
Then I should get the resized image
|
8
|
+
|
9
|
+
Scenario: Image doesn't exist
|
10
|
+
When I ask for a resized image that doesn't exist
|
11
|
+
|
12
|
+
Then I should get a 404 response
|
@@ -0,0 +1,8 @@
|
|
1
|
+
When /^I upload an image$/ do
|
2
|
+
post '/', "file" => Rack::Test::UploadedFile.new("features/support/files/test.jpg", "image/jpeg")
|
3
|
+
@image_id = last_response.body
|
4
|
+
end
|
5
|
+
|
6
|
+
Then /^I should get a (\d+) response$/ do |response_code|
|
7
|
+
last_response.status.should == response_code.to_i
|
8
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
When /^I ask for the original image$/ do
|
2
|
+
get "/#{@image_id}.jpg"
|
3
|
+
@retrieved_image = last_response.body
|
4
|
+
end
|
5
|
+
|
6
|
+
When /^I ask for an image that doesn't exist$/ do
|
7
|
+
get '/nonexistant.jpg'
|
8
|
+
end
|
9
|
+
|
10
|
+
Then /^I should get the original image$/ do
|
11
|
+
require 'digest/md5'
|
12
|
+
original_image = Magick::Image.read('features/support/files/test.jpg').first.to_blob
|
13
|
+
@retrieved_image.should == original_image
|
14
|
+
last_response.status.should == 200
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
When /^I ask for the resized image$/ do
|
2
|
+
get "/200x200/#{@image_id}.jpg"
|
3
|
+
@retrieved_image = last_response.body
|
4
|
+
end
|
5
|
+
|
6
|
+
When /^I ask for a resized image that doesn't exist$/ do
|
7
|
+
get '/200x200/nonexistant.jpg'
|
8
|
+
end
|
9
|
+
|
10
|
+
Then /^I should get the resized image$/ do
|
11
|
+
resized_image = Magick::Image.read('features/support/files/test.jpg').first.resize!(200, 200).to_blob
|
12
|
+
@retrieved_image.should == resized_image
|
13
|
+
last_response.status.should == 200
|
14
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
|
2
|
+
|
3
|
+
gems = YAML.load_file(File.join(File.dirname(__FILE__), '..', '..', 'gems_dev.yml'))
|
4
|
+
gems.each do |depgem|
|
5
|
+
gem "#{depgem[:name]}", "#{depgem[:version]}"
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'mugshot'
|
9
|
+
|
10
|
+
require 'rack/test'
|
11
|
+
require 'spec/expectations'
|
12
|
+
|
13
|
+
require 'pp'
|
14
|
+
|
15
|
+
module CucumberWorld
|
16
|
+
include Rack::Test::Methods
|
17
|
+
|
18
|
+
def app
|
19
|
+
Mugshot::Application.new(Mugshot::FSStorage.new('/tmp/mugshot/cucumber'))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
World(CucumberWorld)
|
23
|
+
|
24
|
+
After do
|
25
|
+
require 'fileutils'
|
26
|
+
FileUtils.rm_rf("/tmp/mugshot/cucumber")
|
27
|
+
end
|
Binary file
|
data/gems.yml
ADDED
data/gems_dev.yml
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
|
3
|
+
class Mugshot::Application < Sinatra::Base
|
4
|
+
|
5
|
+
before do
|
6
|
+
content_type :jpg
|
7
|
+
end
|
8
|
+
|
9
|
+
post '/?' do
|
10
|
+
content_type :html
|
11
|
+
@storage.write(params['file'][:tempfile].read)
|
12
|
+
end
|
13
|
+
|
14
|
+
get '/:size/:id.:ext' do |size, id, ext|
|
15
|
+
size = size.split("x")
|
16
|
+
image = @storage.read(id)
|
17
|
+
halt 404 if image.nil?
|
18
|
+
image.resize! size[0].to_i, size[1].to_i
|
19
|
+
image.to_blob
|
20
|
+
end
|
21
|
+
|
22
|
+
get '/:id.:ext' do |id, ext|
|
23
|
+
image = @storage.read(id)
|
24
|
+
halt 404 if image.nil?
|
25
|
+
image.to_blob
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
|
30
|
+
def initialize(storage)
|
31
|
+
@storage = storage
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class Mugshot::FSStorage < Mugshot::Storage
|
2
|
+
def write(bin)
|
3
|
+
returning asset_id do |id|
|
4
|
+
File.open(File.join(@root_path, id), "w") do |fw|
|
5
|
+
fw.write(bin)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def read(id)
|
11
|
+
file = File.join(@root_path, id)
|
12
|
+
return nil unless File.exist? file
|
13
|
+
Mugshot::Image.new File.open(file)
|
14
|
+
end
|
15
|
+
|
16
|
+
protected
|
17
|
+
|
18
|
+
def initialize(root_path)
|
19
|
+
@root_path = root_path
|
20
|
+
FileUtils.mkdir_p(root_path)
|
21
|
+
end
|
22
|
+
end
|
data/lib/mugshot.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
gems = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'gems.yml'))
|
2
|
+
gems.each do |depgem|
|
3
|
+
gem "#{depgem[:name]}", "#{depgem[:version]}"
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'fileutils'
|
8
|
+
require 'uuid'
|
9
|
+
require 'active_support'
|
10
|
+
require 'RMagick'
|
11
|
+
|
12
|
+
module Mugshot
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'mugshot/image'
|
16
|
+
require 'mugshot/storage'
|
17
|
+
require 'mugshot/fs_storage'
|
18
|
+
require 'mugshot/application'
|
data/mugshot.gemspec
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{mugshot}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Cain\303\243 Nunes", "Fabr\303\255cio Lopes", "Fernando Meyer", "Guilherme Cirne", "Jos\303\251 Peleteiro"]
|
12
|
+
s.date = %q{2009-11-10}
|
13
|
+
s.description = %q{Image server}
|
14
|
+
s.email = ["cainanunes@gmail.com", "fabriciolopesvital@gmail.com", "fmcamargo@gmail.com", "gcirne@gmail.com", "jose@peleteiro.net"]
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"config.ru",
|
27
|
+
"features/retrieve_original_image.feature",
|
28
|
+
"features/retrieve_resized_image.feature",
|
29
|
+
"features/step_definitions/general_steps.rb",
|
30
|
+
"features/step_definitions/retrieve_original_image_steps.rb",
|
31
|
+
"features/step_definitions/retrieve_resized_image_steps.rb",
|
32
|
+
"features/support/env.rb",
|
33
|
+
"features/support/files/test.jpg",
|
34
|
+
"gems.yml",
|
35
|
+
"gems_dev.yml",
|
36
|
+
"lib/mugshot.rb",
|
37
|
+
"lib/mugshot/application.rb",
|
38
|
+
"lib/mugshot/fs_storage.rb",
|
39
|
+
"lib/mugshot/image.rb",
|
40
|
+
"lib/mugshot/storage.rb",
|
41
|
+
"spec/files/test.jpg",
|
42
|
+
"spec/mugshot/application_spec.rb",
|
43
|
+
"spec/mugshot/fs_storage_spec.rb",
|
44
|
+
"spec/mugshot/image_spec.rb",
|
45
|
+
"spec/spec.opts",
|
46
|
+
"spec/spec_helper.rb",
|
47
|
+
"spec/test.html"
|
48
|
+
]
|
49
|
+
s.homepage = %q{http://github.com/timebeta/mugshot}
|
50
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
51
|
+
s.require_paths = ["lib"]
|
52
|
+
s.rubygems_version = %q{1.3.5}
|
53
|
+
s.summary = %q{Image server}
|
54
|
+
s.test_files = [
|
55
|
+
"spec/mugshot/application_spec.rb",
|
56
|
+
"spec/mugshot/fs_storage_spec.rb",
|
57
|
+
"spec/mugshot/image_spec.rb",
|
58
|
+
"spec/spec_helper.rb"
|
59
|
+
]
|
60
|
+
|
61
|
+
if s.respond_to? :specification_version then
|
62
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
63
|
+
s.specification_version = 3
|
64
|
+
|
65
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
66
|
+
s.add_runtime_dependency(%q<activesupport>, ["= 2.3.4"])
|
67
|
+
s.add_runtime_dependency(%q<rmagick>, ["= 2.12.2"])
|
68
|
+
s.add_runtime_dependency(%q<sinatra>, ["= 0.9.4"])
|
69
|
+
s.add_runtime_dependency(%q<uuid>, ["= 2.0.2"])
|
70
|
+
s.add_development_dependency(%q<activesupport>, ["= 2.3.4"])
|
71
|
+
s.add_development_dependency(%q<rspec>, ["= 1.2.9"])
|
72
|
+
s.add_development_dependency(%q<cucumber>, ["= 0.4.3"])
|
73
|
+
s.add_development_dependency(%q<rack-test>, ["= 0.5.0"])
|
74
|
+
s.add_development_dependency(%q<yard>, [">= 0"])
|
75
|
+
else
|
76
|
+
s.add_dependency(%q<activesupport>, ["= 2.3.4"])
|
77
|
+
s.add_dependency(%q<rmagick>, ["= 2.12.2"])
|
78
|
+
s.add_dependency(%q<sinatra>, ["= 0.9.4"])
|
79
|
+
s.add_dependency(%q<uuid>, ["= 2.0.2"])
|
80
|
+
s.add_dependency(%q<activesupport>, ["= 2.3.4"])
|
81
|
+
s.add_dependency(%q<rspec>, ["= 1.2.9"])
|
82
|
+
s.add_dependency(%q<cucumber>, ["= 0.4.3"])
|
83
|
+
s.add_dependency(%q<rack-test>, ["= 0.5.0"])
|
84
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
85
|
+
end
|
86
|
+
else
|
87
|
+
s.add_dependency(%q<activesupport>, ["= 2.3.4"])
|
88
|
+
s.add_dependency(%q<rmagick>, ["= 2.12.2"])
|
89
|
+
s.add_dependency(%q<sinatra>, ["= 0.9.4"])
|
90
|
+
s.add_dependency(%q<uuid>, ["= 2.0.2"])
|
91
|
+
s.add_dependency(%q<activesupport>, ["= 2.3.4"])
|
92
|
+
s.add_dependency(%q<rspec>, ["= 1.2.9"])
|
93
|
+
s.add_dependency(%q<cucumber>, ["= 0.4.3"])
|
94
|
+
s.add_dependency(%q<rack-test>, ["= 0.5.0"])
|
95
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
data/spec/files/test.jpg
ADDED
Binary file
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Mugshot::Application do
|
4
|
+
before :each do
|
5
|
+
@storage = mock(Mugshot::Storage)
|
6
|
+
def app
|
7
|
+
Mugshot::Application.new(@storage)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'POST /' do
|
12
|
+
it "should create image" do
|
13
|
+
file_read = nil
|
14
|
+
File.open("spec/files/test.jpg") {|f| file_read = f.read}
|
15
|
+
@storage.should_receive(:write).with(file_read)
|
16
|
+
|
17
|
+
post '/', "file" => Rack::Test::UploadedFile.new("spec/files/test.jpg", "image/jpeg")
|
18
|
+
|
19
|
+
last_response.status.should == 200
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should return image id" do
|
23
|
+
@storage.stub!(:write).and_return("batata")
|
24
|
+
|
25
|
+
post '/', "file" => Rack::Test::UploadedFile.new("spec/files/test.jpg", "image/jpeg")
|
26
|
+
|
27
|
+
last_response.body.should == "batata"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'GET /:size/:id.:ext' do
|
32
|
+
it 'should return resized image' do
|
33
|
+
image = mock('image')
|
34
|
+
image.stub!(:to_blob).and_return('image data')
|
35
|
+
image.should_receive(:resize!).with(200, 200)
|
36
|
+
@storage.stub!(:read).with('batata').and_return(image)
|
37
|
+
|
38
|
+
get '/200x200/batata.jpg'
|
39
|
+
|
40
|
+
last_response.status.should == 200
|
41
|
+
last_response.content_type == "image/jpg"
|
42
|
+
last_response.body.should == "image data"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should halt 404 when image doesn't exist" do
|
46
|
+
@storage.stub!(:read).with("batata").and_return(nil)
|
47
|
+
|
48
|
+
get '/200x200/batata.jpg'
|
49
|
+
|
50
|
+
last_response.status.should == 404
|
51
|
+
last_response.body.should be_empty
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "GET /:id" do
|
56
|
+
it "should return original image" do
|
57
|
+
image = mock('image')
|
58
|
+
image.stub!(:to_blob).and_return('image data')
|
59
|
+
@storage.stub!(:read).with('batata').and_return(image)
|
60
|
+
|
61
|
+
get '/batata.jpg'
|
62
|
+
|
63
|
+
last_response.status.should == 200
|
64
|
+
last_response.content_type == "image/jpg"
|
65
|
+
last_response.body.should == "image data"
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should halt 404 when image doesn't exist" do
|
69
|
+
@storage.stub!(:read).with("batata").and_return(nil)
|
70
|
+
|
71
|
+
get '/batata.jpg'
|
72
|
+
|
73
|
+
last_response.status.should == 404
|
74
|
+
last_response.body.should be_empty
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Mugshot::FSStorage do
|
4
|
+
before :each do
|
5
|
+
@fs = Mugshot::FSStorage.new("/tmp/mugshot/spec")
|
6
|
+
end
|
7
|
+
|
8
|
+
after :each do
|
9
|
+
require 'fileutils'
|
10
|
+
FileUtils.rm_rf("/tmp/mugshot/spec")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should write an image to the filesystem and read it back" do
|
14
|
+
bin = File.open("spec/files/test.jpg").read
|
15
|
+
|
16
|
+
image = Mugshot::Image.new File.open("spec/files/test.jpg")
|
17
|
+
Mugshot::Image.stub!(:new).and_return(image)
|
18
|
+
|
19
|
+
id = @fs.write(bin)
|
20
|
+
image2 = @fs.read(id)
|
21
|
+
|
22
|
+
image2.should == image
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return nil when an image with the given id doesn't exist on the filesystem" do
|
26
|
+
@fs.read('nonexistant-id').should be_nil
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Mugshot::Image do
|
4
|
+
before :each do
|
5
|
+
@magick_image = mock(Magick::Image)
|
6
|
+
Magick::Image.stub!(:read).and_return([@magick_image])
|
7
|
+
|
8
|
+
@image = Mugshot::Image.new File.open("spec/files/test.jpg")
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should return image as a blob' do
|
12
|
+
blob_data = 'blob data'
|
13
|
+
@magick_image.stub!(:to_blob).and_return(blob_data)
|
14
|
+
|
15
|
+
@image.to_blob.should == blob_data
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should resize image' do
|
19
|
+
width = 300
|
20
|
+
height = 200
|
21
|
+
@magick_image.should_receive(:resize!).with(width, height)
|
22
|
+
|
23
|
+
@image.resize! width, height
|
24
|
+
end
|
25
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
|
6
|
+
gems = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'gems_dev.yml'))
|
7
|
+
gems.each do |depgem|
|
8
|
+
gem "#{depgem[:name]}", "#{depgem[:version]}"
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'mugshot'
|
12
|
+
|
13
|
+
require 'spec'
|
14
|
+
require 'spec/autorun'
|
15
|
+
require 'rack/test'
|
16
|
+
require 'pp'
|
17
|
+
|
18
|
+
Spec::Runner::QuietBacktraceTweaker::IGNORE_PATTERNS << /\/Library\//
|
19
|
+
|
20
|
+
Spec::Runner.configure do |config|
|
21
|
+
config.include Rack::Test::Methods
|
22
|
+
end
|
data/spec/test.html
ADDED
metadata
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mugshot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "Cain\xC3\xA3 Nunes"
|
8
|
+
- "Fabr\xC3\xADcio Lopes"
|
9
|
+
- Fernando Meyer
|
10
|
+
- Guilherme Cirne
|
11
|
+
- "Jos\xC3\xA9 Peleteiro"
|
12
|
+
autorequire:
|
13
|
+
bindir: bin
|
14
|
+
cert_chain: []
|
15
|
+
|
16
|
+
date: 2009-11-10 00:00:00 -02:00
|
17
|
+
default_executable:
|
18
|
+
dependencies:
|
19
|
+
- !ruby/object:Gem::Dependency
|
20
|
+
name: activesupport
|
21
|
+
type: :runtime
|
22
|
+
version_requirement:
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 2.3.4
|
28
|
+
version:
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: rmagick
|
31
|
+
type: :runtime
|
32
|
+
version_requirement:
|
33
|
+
version_requirements: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - "="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.12.2
|
38
|
+
version:
|
39
|
+
- !ruby/object:Gem::Dependency
|
40
|
+
name: sinatra
|
41
|
+
type: :runtime
|
42
|
+
version_requirement:
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.9.4
|
48
|
+
version:
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: uuid
|
51
|
+
type: :runtime
|
52
|
+
version_requirement:
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: 2.0.2
|
58
|
+
version:
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: activesupport
|
61
|
+
type: :development
|
62
|
+
version_requirement:
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 2.3.4
|
68
|
+
version:
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
type: :development
|
72
|
+
version_requirement:
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - "="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.2.9
|
78
|
+
version:
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: cucumber
|
81
|
+
type: :development
|
82
|
+
version_requirement:
|
83
|
+
version_requirements: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - "="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 0.4.3
|
88
|
+
version:
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rack-test
|
91
|
+
type: :development
|
92
|
+
version_requirement:
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 0.5.0
|
98
|
+
version:
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
name: yard
|
101
|
+
type: :development
|
102
|
+
version_requirement:
|
103
|
+
version_requirements: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: "0"
|
108
|
+
version:
|
109
|
+
description: Image server
|
110
|
+
email:
|
111
|
+
- cainanunes@gmail.com
|
112
|
+
- fabriciolopesvital@gmail.com
|
113
|
+
- fmcamargo@gmail.com
|
114
|
+
- gcirne@gmail.com
|
115
|
+
- jose@peleteiro.net
|
116
|
+
executables: []
|
117
|
+
|
118
|
+
extensions: []
|
119
|
+
|
120
|
+
extra_rdoc_files:
|
121
|
+
- LICENSE
|
122
|
+
- README.rdoc
|
123
|
+
files:
|
124
|
+
- .document
|
125
|
+
- .gitignore
|
126
|
+
- LICENSE
|
127
|
+
- README.rdoc
|
128
|
+
- Rakefile
|
129
|
+
- VERSION
|
130
|
+
- config.ru
|
131
|
+
- features/retrieve_original_image.feature
|
132
|
+
- features/retrieve_resized_image.feature
|
133
|
+
- features/step_definitions/general_steps.rb
|
134
|
+
- features/step_definitions/retrieve_original_image_steps.rb
|
135
|
+
- features/step_definitions/retrieve_resized_image_steps.rb
|
136
|
+
- features/support/env.rb
|
137
|
+
- features/support/files/test.jpg
|
138
|
+
- gems.yml
|
139
|
+
- gems_dev.yml
|
140
|
+
- lib/mugshot.rb
|
141
|
+
- lib/mugshot/application.rb
|
142
|
+
- lib/mugshot/fs_storage.rb
|
143
|
+
- lib/mugshot/image.rb
|
144
|
+
- lib/mugshot/storage.rb
|
145
|
+
- mugshot.gemspec
|
146
|
+
- spec/files/test.jpg
|
147
|
+
- spec/mugshot/application_spec.rb
|
148
|
+
- spec/mugshot/fs_storage_spec.rb
|
149
|
+
- spec/mugshot/image_spec.rb
|
150
|
+
- spec/spec.opts
|
151
|
+
- spec/spec_helper.rb
|
152
|
+
- spec/test.html
|
153
|
+
has_rdoc: true
|
154
|
+
homepage: http://github.com/timebeta/mugshot
|
155
|
+
licenses: []
|
156
|
+
|
157
|
+
post_install_message:
|
158
|
+
rdoc_options:
|
159
|
+
- --charset=UTF-8
|
160
|
+
require_paths:
|
161
|
+
- lib
|
162
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: "0"
|
167
|
+
version:
|
168
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: "0"
|
173
|
+
version:
|
174
|
+
requirements: []
|
175
|
+
|
176
|
+
rubyforge_project:
|
177
|
+
rubygems_version: 1.3.5
|
178
|
+
signing_key:
|
179
|
+
specification_version: 3
|
180
|
+
summary: Image server
|
181
|
+
test_files:
|
182
|
+
- spec/mugshot/application_spec.rb
|
183
|
+
- spec/mugshot/fs_storage_spec.rb
|
184
|
+
- spec/mugshot/image_spec.rb
|
185
|
+
- spec/spec_helper.rb
|