Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

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

rob-anderson opened this issue Sep 18, 2012 · 3 comments
Assignees
Milestone

Comments

@rob-anderson
Copy link

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?

@ghost ghost assigned rubiii Sep 18, 2012
@rubiii
Copy link
Contributor

rubiii commented Sep 18, 2012

thanks for reporting. i'll look into it.

@rubiii rubiii closed this as completed in 0179e5a Sep 18, 2012
@rob-anderson
Copy link
Author

Wow, that was quick. Thanks!

@rubiii
Copy link
Contributor

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
Labels
None yet
Development

No branches or pull requests

2 participants