1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Adding put_conditional support and spec. Fixes error no Const

Module::YAML when running single simpledb specs.
This commit is contained in:
Jeremy Deininger 2010-06-02 14:40:25 -07:00 committed by geemus
parent 4b736a3979
commit 9d42221815
4 changed files with 59 additions and 2 deletions

View file

@ -29,6 +29,15 @@ module Fog
)
end
def put_conditional(domain_name, item_name, attributes, expected_attributes = {})
request({
'Action' => 'PutAttributes',
'DomainName' => domain_name,
:parser => Fog::Parsers::AWS::SimpleDB::Basic.new(@nil_string),
'ItemName' => item_name
}.merge!(encode_attributes(attributes, {}, expected_attributes)))
end
end
class Mock
@ -41,6 +50,28 @@ module Fog
)
end
def put_conditional(domain_name, item_name, attributes, expected_attributes = {})
response = Excon::Response.new
if @data[:domains][domain_name]
expected_attributes.each do |ck, cv|
if @data[:domains][domain_name][item_name][ck] != cv
response.status = 409
raise(Excon::Errors.status_error({:expects => 200}, response))
end
end
attributes.each do |key, value|
@data[:domains][domain_name][item_name] ||= {}
@data[:domains][domain_name][item_name][key.to_s] = value
end
response.status = 200
response.body = {
'BoxUsage' => Fog::AWS::Mock.box_usage,
'RequestId' => Fog::AWS::Mock.request_id
}
response
end
end
end
end
end

View file

@ -73,9 +73,17 @@ module Fog
private
def encode_attributes(attributes, replace_attributes = [])
def encode_attributes(attributes, replace_attributes = {}, expected_attributes = {})
encoded_attributes = {}
if attributes
expected_attributes.keys.each_with_index do |exkey, index|
for value in Array(expected_attributes[exkey])
encoded_attributes["Expected.#{index}.Name"] = exkey.to_s
encoded_attributes["Expected.#{index}.Value"] = sdb_encode(value)
end
end
index = 0
for key in attributes.keys
for value in Array(attributes[key])
@ -132,7 +140,7 @@ module Fog
:aws_access_key_id => @aws_access_key_id,
:hmac => @hmac,
:host => @host,
:version => '2007-11-07'
:version => '2009-04-15'
}
)

View file

@ -1,3 +1,4 @@
require 'yaml'
module Fog
class << self

View file

@ -18,6 +18,23 @@ describe 'SimpleDB.put_attributes' do
actual.body['BoxUsage'].should be_a(Float)
end
it 'conditional put should succeed' do
actual = AWS[:sdb].put_conditional(@domain_name, 'foo', { 'version' => '1' }, { 'version' => nil })
actual = AWS[:sdb].put_conditional(@domain_name, 'foo', { 'version' => '2' }, { 'version' => '1' })
actual.body['RequestId'].should be_a(String)
actual.body['BoxUsage'].should be_a(Float)
end
it 'conditional put should raise Conflict error' do
actual = AWS[:sdb].put_conditional(@domain_name, 'foo', { 'version' => '2' })
actual.body['RequestId'].should be_a(String)
actual.body['BoxUsage'].should be_a(Float)
lambda {
actual = AWS[:sdb].put_conditional(@domain_name, 'foo', { 'version' => '2' }, { 'version' => '1' })
}.should raise_error(Excon::Errors::Conflict)
end
end
describe 'failure' do