-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow a Fog::Storage uploader to be passed in for uploading of genera…
…ted tiles
- Loading branch information
1 parent
d027a89
commit 499f45e
Showing
6 changed files
with
89 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,7 @@ gemspec | |
|
||
gem "rspec" | ||
gem "rake" | ||
group :test do | ||
gem "fog" | ||
gem "pry" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,66 @@ | ||
require 'spec_helper' | ||
require 'pry' | ||
require 'RMagick' | ||
include Magick | ||
|
||
describe DZT::Tiler do | ||
before :each do | ||
@fixtures_dir = File.expand_path(File.join(__FILE__, '../../fixtures')) | ||
end | ||
it "slices an image" do | ||
Dir.mktmpdir do |tmpdir| | ||
tiler = DZT::Tiler.new( | ||
context 'storing files locally' do | ||
it "slices an image and stores files" do | ||
Dir.mktmpdir do |tmpdir| | ||
tiler = DZT::Tiler.new( | ||
source: File.join(@fixtures_dir, "francisco-jose-de-goya-y-lucientes-senora-sabasa-garcia.jpg"), | ||
destination: tmpdir | ||
) | ||
tiler.slice! | ||
expect(Dir["#{tmpdir}/*"].map { |dir| dir.split("/").last.to_i }.sort).to eq((0..12).to_a) | ||
# center | ||
image = Magick::Image::read("#{tmpdir}/11/1_1.jpg").first | ||
expect(image.columns).to eq(512) | ||
expect(image.rows).to eq(512) | ||
# edge | ||
image = Magick::Image::read("#{tmpdir}/11/2_2.jpg").first | ||
expect(image.columns).to eq(168) | ||
expect(image.rows).to eq(443) | ||
end | ||
end | ||
end | ||
context 'uploading resultant files to S3' do | ||
before :each do | ||
Fog.mock! | ||
Fog::Mock.reset | ||
@s3_uploader = Fog::Storage.new( | ||
provider: 'AWS', | ||
aws_access_key_id: 'id', | ||
aws_secret_access_key: 'secret' | ||
) | ||
@bucket = @s3_uploader.directories.create(key: 'tiled-images') | ||
@tiler = DZT::Tiler.new( | ||
source: File.join(@fixtures_dir, "francisco-jose-de-goya-y-lucientes-senora-sabasa-garcia.jpg"), | ||
destination: tmpdir | ||
s3_key: 'dztiles', | ||
s3_bucket: 'tiled-images', | ||
uploader: @s3_uploader, | ||
s3_acl: 'public-read' | ||
) | ||
tiler.slice! | ||
Dir["#{tmpdir}/*"].map { |dir| dir.split("/").last.to_i }.sort.should == (0..12).to_a | ||
# center | ||
image = Magick::Image::read("#{tmpdir}/11/1_1.jpg").first | ||
image.columns.should == 512 | ||
image.rows.should == 512 | ||
# edge | ||
image = Magick::Image::read("#{tmpdir}/11/2_2.jpg").first | ||
image.columns.should == 168 | ||
image.rows.should == 443 | ||
end | ||
it 'slices the images' do | ||
@tiler.slice! | ||
file = @bucket.files.select { |f| f.key == '/dztiles/11/1_1.jpg' }.first | ||
image = Image.from_blob(file.body).first | ||
expect(image.columns).to eq(512) | ||
expect(image.rows).to eq(512) | ||
file = @bucket.files.select { |f| f.key == '/dztiles/11/2_2.jpg' }.first | ||
image = Image.from_blob(file.body).first | ||
expect(image.columns).to eq(168) | ||
expect(image.rows).to eq(443) | ||
end | ||
it 'stores the files properly' do | ||
expect_any_instance_of(Fog::Storage::AWS::Mock).to receive(:put_object).at_least(53).times do |*args| | ||
expect(args.last).to eq("Content-Type" => "image/jpeg", "x-amz-acl" => "public-read") | ||
end | ||
@tiler.slice! | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,6 @@ | |
|
||
describe DZT do | ||
it "has a version" do | ||
DZT::VERSION.should_not be_nil | ||
expect(DZT::VERSION).to_not be_nil | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
require 'rspec' | ||
require 'tmpdir' | ||
require 'dzt' | ||
require 'fog' |