Skip to content

Commit

Permalink
Add specs
Browse files Browse the repository at this point in the history
mdouchement committed Aug 13, 2015
1 parent 6a07dd6 commit 4bd0822
Showing 2 changed files with 45 additions and 1 deletion.
4 changes: 3 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -51,8 +51,10 @@ def body(new_body)
def random_length
Random.rand(5000) + 1000
end
end


SwiftStorage.configure do |config|
config.auth_version = '1.0'
end

RSpec::Matchers.define :send_request do |method, path, options={}|
42 changes: 42 additions & 0 deletions spec/swift/object_spec.rb
Original file line number Diff line number Diff line change
@@ -44,4 +44,46 @@
expect(subject.metadata.jon_doe).to eq('a meta')
end

describe '#copy_from' do
subject { swift_service.containers['some_destination_container'].objects['some_copied_object'] }
let(:source) { swift_service.containers['some_source_container'].objects['some_object'] }

it 'adds optional headers to request' do
expect { subject.copy_from(source, 'X-Object-Falcon' => 'Awesome') }.to send_request(
:copy,
'/v1/AUTH_test/some_source_container/some_object',
headers: { h::DESTINATION => 'some_destination_container/some_copied_object', 'X-Object-Falcon' => 'Awesome' }
)
end

context 'when source is a SwiftStorage::Object' do
it 'copies the source' do
expect { subject.copy_from(source) }.to send_request(
:copy,
'/v1/AUTH_test/some_source_container/some_object',
headers: { h::DESTINATION => 'some_destination_container/some_copied_object' }
)
end
end

context 'when source is a string' do
it 'copies the source' do
expect { subject.copy_from(source.relative_path) }.to send_request(
:copy,
'/v1/AUTH_test/some_source_container/some_object',
headers: { h::DESTINATION => 'some_destination_container/some_copied_object' }
)
end
end

context 'when source is an integer' do
it 'raises an error' do
expect { subject.copy_from(42) }.to raise_error(ArgumentError, 'Invalid source type')
end
end

it 'returns destination object' do
expect(subject.copy_from(source).relative_path).to eq('some_destination_container/some_copied_object')
end
end
end

0 comments on commit 4bd0822

Please sign in to comment.