#url_for supports :query for custom query params

AWS::S3::S3Object#url(:query => {})
AWS::S3::S3Object.url_for(name, bucket, :query => {})
AWS::S3::S3Object.path!(bucket, name, :query => {})
This commit is contained in:
technoweenie 2013-01-04 15:18:26 -07:00
Родитель c6b35e9300
Коммит 7a18d8b81e
3 изменённых файлов: 38 добавлений и 3 удалений

Просмотреть файл

@ -297,7 +297,11 @@ module AWS
options.replace(bucket)
bucket = nil
end
'/' << File.join(bucket_name(bucket), name)
path = '/' << File.join(bucket_name(bucket), name)
if (query = options[:query]).respond_to?(:to_query_string)
path << query.to_query_string
end
path
end
private

Просмотреть файл

@ -102,6 +102,12 @@ class ConnectionTest < Test::Unit::TestCase
assert authenticated[connection.url_for('/foo', :authenticated => true)]
assert !authenticated[connection.url_for('/foo', :authenticated => false)]
end
def test_url_for_with_canonical_query_params
connection = Connection.new(:access_key_id => '123', :secret_access_key => 'abc', :server => 'example.org')
dispositioned = lambda {|url| url['?response-content-disposition=a']}
assert dispositioned[connection.url_for("/foo?response-content-disposition=a")]
end
def test_connecting_through_a_proxy
connection = nil

Просмотреть файл

@ -5,7 +5,7 @@ class ObjectTest < Test::Unit::TestCase
bucket = Bucket.new(Parsing::XmlParser.new(Fixtures::Buckets.bucket_with_one_key))
@object = bucket.objects.first
end
def test_header_settings_reader_and_writer
headers = {'content-type' => 'text/plain'}
mock_connection_for(S3Object, :returns => {:headers => headers})
@ -57,6 +57,31 @@ class ObjectTest < Test::Unit::TestCase
def test_object_has_owner
assert_kind_of Owner, @object.owner
end
def test_url_is_authenticated
conn = Connection.new :access_key_id => '123', :secret_access_key => 'abc'
begin
AWS::S3::Base.connections['AWS::S3::Base'] = conn
authenticated = lambda {|url| url['?AWSAccessKeyId']}
assert authenticated[@object.url]
ensure
AWS::S3::Base.connections.clear
end
end
def test_url_with_custom_query
conn = Connection.new :access_key_id => '123', :secret_access_key => 'abc'
begin
AWS::S3::Base.connections['AWS::S3::Base'] = conn
assert_match 'response-content-disposition=attachment;%20filename%3Dfoo.txt',
@object.url(:query => {
'response-content-disposition' => 'attachment; filename=foo.txt'})
ensure
AWS::S3::Base.connections.clear
end
end
def test_owner_attributes_are_accessible
owner = @object.owner
@ -217,4 +242,4 @@ class ValueTest < Test::Unit::TestCase
def test_response_is_accessible_from_value_object
assert_equal @response, @value.response
end
end
end