forked from thoughtbot/paperclip
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split test cases for multiple storages
- Loading branch information
Showing
3 changed files
with
95 additions
and
88 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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'helper' | ||
|
||
class FileSystemTest < Test::Unit::TestCase | ||
context "Filesystem" do | ||
setup do | ||
rebuild_model :styles => { :thumbnail => "25x25#" } | ||
@dummy = Dummy.create! | ||
|
||
@dummy.avatar = File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "5k.png")) | ||
end | ||
|
||
should "allow file assignment" do | ||
assert @dummy.save | ||
end | ||
|
||
should "store the original" do | ||
@dummy.save | ||
assert File.exists?(@dummy.avatar.path) | ||
end | ||
|
||
should "store the thumbnail" do | ||
@dummy.save | ||
assert File.exists?(@dummy.avatar.path(:thumbnail)) | ||
end | ||
|
||
should "clean up file objects" do | ||
File.stubs(:exist?).returns(true) | ||
Paperclip::Tempfile.any_instance.expects(:close).at_least_once() | ||
Paperclip::Tempfile.any_instance.expects(:unlink).at_least_once() | ||
|
||
@dummy.save! | ||
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
require 'helper' | ||
require 'aws/s3' | ||
|
||
class S3LiveTest < Test::Unit::TestCase | ||
unless ENV["S3_TEST_BUCKET"].blank? | ||
context "Using S3 for real, an attachment with S3 storage" do | ||
setup do | ||
rebuild_model :styles => { :thumb => "100x100", :square => "32x32#" }, | ||
:storage => :s3, | ||
:bucket => ENV["S3_TEST_BUCKET"], | ||
:path => ":class/:attachment/:id/:style.:extension", | ||
:s3_credentials => File.new(File.join(File.dirname(__FILE__), "..", "s3.yml")) | ||
|
||
Dummy.delete_all | ||
@dummy = Dummy.new | ||
end | ||
|
||
should "be extended by the S3 module" do | ||
assert Dummy.new.avatar.is_a?(Paperclip::Storage::S3) | ||
end | ||
|
||
context "when assigned" do | ||
setup do | ||
@file = File.new(File.join(File.dirname(__FILE__), '..', 'fixtures', '5k.png'), 'rb') | ||
@dummy.avatar = @file | ||
end | ||
|
||
teardown { @file.close } | ||
|
||
should "still return a Tempfile when sent #to_file" do | ||
assert_equal Paperclip::Tempfile, @dummy.avatar.to_file.class | ||
end | ||
|
||
context "and saved" do | ||
setup do | ||
@dummy.save | ||
end | ||
|
||
should "be on S3" do | ||
assert true | ||
end | ||
|
||
should "generate a tempfile with the right name" do | ||
file = @dummy.avatar.to_file | ||
assert_match /^original.*\.png$/, File.basename(file.path) | ||
end | ||
end | ||
end | ||
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