Skip to content

Optional final xml element in a soap.body block #322

Closed
rob-anderson opened this Issue Sep 18, 2012 · 3 comments

2 participants

@rob-anderson

When constructing request xml via a block like this

client.request(:wsdl, 'SomeService') do

  soap.body do |xml|
    xml.foo 'bar'
  end
end

it all works fine.

But if we want to make the final element optional, and it happens to return false, the request body will be empty:

client.request(:wsdl, 'SomeService') do

  soap.body do |xml|
    xml.foo 'bar'
    xml.baz 'bat' if some_test # which evaluates to false
  end
end

This is because savon relies on the return value of the last statement in the block to determine the xml string. I think this is a bug as it produces problems in the scenario above.

The only way round it afaik is clunky code like this:

client.request(:wsdl, 'SomeService') do

  soap.body do |xml|
    xml.foo 'bar'
    if some_test
      xml.baz 'bat'
    else
      xml.target!
    end
  end
end

Should savon not be relying on the modified state of the xml object after the yield, rather than the value returned from the block?

@rubiii rubiii was assigned Sep 18, 2012
@rubiii
savonrb member
rubiii commented Sep 18, 2012

thanks for reporting. i'll look into it.

@rubiii rubiii added a commit that closed this issue Sep 18, 2012
@rubiii rubiii use the builder instead of a block's return value
currently, when passing a block to both soap#body and soap#xml to use builder to
create the xml, savon uses the block's return value instead of the builder's state.

this fixes #322.
0179e5a
@rubiii rubiii closed this in 0179e5a Sep 18, 2012
@rob-anderson

Wow, that was quick. Thanks!

@rubiii
savonrb member
rubiii commented Sep 18, 2012

a quick fix, but since this is not a regression, you still have to wait for the next release ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.