test/unit/test_storage.rb in spontaneous-0.2.0.beta1 vs test/unit/test_storage.rb in spontaneous-0.2.0.beta2
- old
+ new
@@ -1,114 +1,120 @@
# encoding: UTF-8
require File.expand_path('../../test_helper', __FILE__)
require 'fog'
-class StorageTest < MiniTest::Spec
- def setup
+describe "Storage" do
+ before do
@site = setup_site
@config_dir = File.expand_path("../../fixtures/storage", __FILE__)
end
- def teardown
+ after do
teardown_site
end
- context "local storage" do
- setup do
+ describe "local" do
+ before do
@site.paths.add :config, File.expand_path(@config_dir / "default", __FILE__)
@site.load_config!
# sanity check
- @site.config.test_setting.should be_true
+ assert @site.config.test_setting
@storage = @site.storage
end
- should "be the default" do
+ it "be the default" do
@storage.must_be_instance_of Spontaneous::Storage::Local
end
- should "have the right base url" do
- @storage.public_url("test.jpg").should == "/media/test.jpg"
+ it "have the right base url" do
+ @storage.public_url("test.jpg").must_equal "/media/test.jpg"
end
- should "test for locality" do
- @storage.local?.should be_true
+ it "test for locality" do
+ assert @storage.local?
end
- should "provide a list of local storage backends" do
- @site.local_storage.should == [@storage]
+ it "provide a list of local storage backends" do
+ @site.local_storage.must_equal [@storage]
end
end
- context "cloud storage" do
- setup do
+
+ describe "cloud" do
+ before do
@bucket_name = "media.example.com"
@aws_credentials = {
:provider=>"AWS",
:aws_secret_access_key=>"SECRET_ACCESS_KEY",
:aws_access_key_id=>"ACCESS_KEY_ID"
}
::Fog.mock!
@connection = Fog::Storage.new(@aws_credentials)
- @connection.directories.create(:key => @bucket_name)
+ @bucket = @connection.directories.create(:key => @bucket_name)
@site.paths.add :config, File.expand_path(@config_dir / "cloud", __FILE__)
@site.load_config!
# sanity check
- @site.config.test_setting.should be_true
+ assert @site.config.test_setting
@storage = @site.storage
end
- should "be detected by configuration" do
+ it "be detected by configuration" do
@storage.must_be_instance_of Spontaneous::Storage::Cloud
end
- should "have the correct bucket name" do
- @storage.bucket_name.should == "media.example.com"
+ it "have the correct bucket name" do
+ @storage.bucket_name.must_equal "media.example.com"
end
- should "not test as local" do
- @storage.local?.should be_false
+ it "not test as local" do
+ refute @storage.local?
end
- context "remote files" do
- setup do
+ describe "remote files" do
+ before do
@existing_file = File.expand_path("../../fixtures/images/rose.jpg", __FILE__)
@media_path = %w(0003 0567 rose.jpg)
end
- should "have the correct mimetype" do
- file = @storage.copy(@existing_file, @media_path, "image/jpeg")
- file.content_type.should == "image/jpeg"
+
+ it "have the correct mimetype" do
+ file = @storage.copy(@existing_file, @media_path, { content_type: "image/jpeg" })
+ file.content_type.must_equal "image/jpeg"
end
- should "be given a far future expiry" do
+ it "is given a far future cache value" do
now = DateTime.now
DateTime.stubs(:now).returns(now)
- file = @storage.copy(@existing_file, @media_path, "image/jpeg")
- file.expires.should == (now + 20.years).to_s(:rfc822)
+ file = @storage.copy(@existing_file, @media_path, { content_type: "image/jpeg" })
+ file.cache_control.must_equal "max-age=31557600, public"
end
- should "be set as publicly visible" do
- file = @storage.copy(@existing_file, @media_path, "image/jpeg")
+ it "be set as publicly visible" do
+ file = @storage.copy(@existing_file, @media_path, { content_type: "image/jpeg" })
acl = file.connection.get_object_acl(file.directory.key, file.key).body['AccessControlList']
perms = acl.detect {|grant| grant['Grantee']['URI'] == 'http://acs.amazonaws.com/groups/global/AllUsers' }
- perms["Permission"].should == "READ"
+ perms["Permission"].must_equal "READ"
end
+ it "sets any additional headers passed to the copy method" do
+ file = @storage.copy(@existing_file, @media_path, { content_type: "image/jpeg", content_disposition: "attachment; filename='something.jpg'" })
+ file.content_disposition.must_equal "attachment; filename='something.jpg'"
+ end
end
- context "public urls" do
- setup do
+ describe "public urls" do
+ before do
existing_file = File.expand_path("../../fixtures/images/rose.jpg", __FILE__)
@media_path = %w(0003 0567 rose.jpg)
- @storage.copy(existing_file, @media_path, "image/jpeg")
+ @storage.copy(existing_file, @media_path, { content_type: "image/jpeg" })
end
- should "have the correct base url" do
- @storage.public_url(@media_path).should == "https://media.example.com.s3.amazonaws.com/0003-0567-rose.jpg"
+ it "have the correct base url" do
+ @storage.public_url(@media_path).must_equal "https://media.example.com.s3.amazonaws.com/0003/0567/rose.jpg"
end
- should "use custom urls if configured" do
+ it "use custom urls if configured" do
storage = Spontaneous::Storage::Cloud.new(@aws_credentials.merge({
:public_host => "http://media.example.com",
}), @bucket_name)
- storage.public_url(@media_path).should == "http://media.example.com/0003-0567-rose.jpg"
+ storage.public_url(@media_path).must_equal "http://media.example.com/0003/0567/rose.jpg"
end
end
end
end