Skip to content

Commit

Permalink
Merge branch 'release/0.15.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdanRada committed Aug 12, 2015
2 parents 3b89ca3 + 8b0ad2c commit 0065ec8
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 20 deletions.
2 changes: 1 addition & 1 deletion lib/washout_builder/version.rb
Expand Up @@ -6,7 +6,7 @@ def self.gem_version
module VERSION
MAJOR = 0
MINOR = 15
TINY = 7
TINY = 8
PRE = nil

STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
Expand Down
43 changes: 24 additions & 19 deletions spec/lib/washout_builder_spec.rb
Expand Up @@ -164,7 +164,7 @@ def answer
render soap: { a: params[:a] }
end
end
expect(savon(:answer, a: '')[:answer_response][:a]).to eq("@xsi:type": 'xsd:string')
expect(savon(:answer, a: '')[:answer_response][:a][:'@xsi:type']).to eq('xsd:string')
end

it 'accept one parameter' do
Expand Down Expand Up @@ -301,8 +301,9 @@ def gogogo
end
end

expect(savon(:gogogo)[:gogogo_response]
).to eq(zoo: 'zoo', boo: { moo: 'moo', doo: 'doo', "@xsi:type": 'tns:Boo' })
expect(savon(:gogogo)[:gogogo_response].deep_include?(zoo: 'zoo', boo: { moo: 'moo', doo: 'doo' })).to eq true

expect(savon(:gogogo)[:gogogo_response][:boo][:'@xsi:type']).to eq('tns:Boo')
end

it 'respond with arrays' do
Expand Down Expand Up @@ -334,10 +335,13 @@ def rumba
end
end

expect(savon(:rumba)[:rumba_response]).to eq(rumbas: [
{ zombies: 'suck1', puppies: 'rock1', "@xsi:type": 'tns:Rumbas' },
{ zombies: 'suck2', puppies: 'rock2', "@xsi:type": 'tns:Rumbas' }
])
expect(savon(:rumba)[:rumba_response].deep_include?(rumbas: [
{ zombies: 'suck1', puppies: 'rock1' },
{ zombies: 'suck2', puppies: 'rock2' }
])).to eq(true)

expect(savon(:rumba)[:rumba_response][:rumbas][0][:'@xsi:type']).to eq('tns:Rumbas')
expect(savon(:rumba)[:rumba_response][:rumbas][1][:'@xsi:type']).to eq('tns:Rumbas')
end

it 'respond with structs in structs in arrays' do
Expand All @@ -351,22 +355,24 @@ def rumba
end
end

expect(savon(:rumba)[:rumba_response]).to eq(value: [
expect(savon(:rumba)[:rumba_response].deep_include?(value: [
{
rumbas: {
zombies: '100000',
"@xsi:type": 'tns:Rumbas'
},
"@xsi:type": 'tns:Value'
zombies: '100000'
}
},
{
rumbas: {
zombies: '2',
"@xsi:type": 'tns:Rumbas'
},
"@xsi:type": 'tns:Value'
zombies: '2'
}
}
])
])).to eq(true)

expect(savon(:rumba)[:rumba_response][:value][0][:'@xsi:type']).to eq('tns:Value')
expect(savon(:rumba)[:rumba_response][:value][1][:'@xsi:type']).to eq('tns:Value')

expect(savon(:rumba)[:rumba_response][:value][0][:rumbas][:'@xsi:type']).to eq('tns:Rumbas')
expect(savon(:rumba)[:rumba_response][:value][1][:rumbas][:'@xsi:type']).to eq('tns:Rumbas')
end

context 'with arrays missing' do
Expand Down Expand Up @@ -403,8 +409,7 @@ def rocknroll
end
end

expect(savon(:rocknroll)[:rocknroll_response][:my_value]
).to eq("@xsi:type": 'tns:MyValue')
expect(savon(:rocknroll)[:rocknroll_response][:my_value][:'@xsi:type']).to eq('tns:MyValue')
end

it 'handles incomplete array response' do
Expand Down
28 changes: 28 additions & 0 deletions spec/spec_helper.rb
Expand Up @@ -116,3 +116,31 @@ def get_wash_out_param(class_name_or_structure, soap_config = OpenStruct.new(
))
WashOut::Param.parse_builder_def(soap_config, class_name_or_structure)[0]
end

class Hash
def deep_include?(sub_hash)
sub_hash.keys.all? do |key|
if check_key_type(key, Hash)
sub_hash[key].is_a?(Hash) && self[key].deep_include?(sub_hash[key])
elsif check_key_type(key, Array)
sub_hash[key].is_a?(Array) && deep_include_array(key, sub_hash)
else
self[key] == sub_hash[key]
end
end
end

def check_key_type(key, type)
self.key?(key) && self[key].is_a?(type)
end

def deep_include_array(key, sub_hash)
self[key].each_with_index do |value, index|
if value.is_a?(Hash)
value.deep_include?(sub_hash[key][index])
else
value == sub_hash[key][index]
end
end
end
end

0 comments on commit 0065ec8

Please sign in to comment.