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

Allow strings as response without a wrapping tag. #241

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ appraise "rails-4.2.0" do
end


appraise "rails-5.0.0" do
gem "rails", "5.0.0"
appraise "rails-5.0.3" do
Copy link
Contributor Author

@jesusabarca jesusabarca Aug 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bumps up version of rails from 5.0.0 to 5.0.3 to include a bug fix in the minitest plugin rails/rails#29022. This only prevents the test suit from crashing. This PR will fix this #238, so it's just a temporal fix.

gem "rails", "5.0.3"
end
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ class RumbasController < ApplicationController
render :soap => params[:value].to_s
end

soap_action 'single_string_response',
args: { a: :string }
return: :string
def single_string_response
render soap: params[:a].to_s, wrap_response: false
end

soap_action "concat",
:args => { :a => :string, :b => :string },
:return => :string
Expand Down
4 changes: 3 additions & 1 deletion app/helpers/wash_out_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ def wsdl_data_attrs(param)
end
end

def wsdl_data(xml, params)
def wsdl_data(xml, params, wrap_response = true)
params.each do |param|
next if param.attribute?

return xml.text! param.value.to_s unless wrap_response == true

tag_name = param.name
param_options = wsdl_data_options(param)
param_options.merge! wsdl_data_attrs(param)
Expand Down
2 changes: 1 addition & 1 deletion app/views/wash_out/document/response.builder
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ xml.tag! "soap:Envelope", "xmlns:soap" => 'http://schemas.xmlsoap.org/soap/envel
end
xml.tag! "soap:Body" do
xml.tag! "tns:#{@action_spec[:response_tag]}" do
wsdl_data xml, result
wsdl_data xml, result, wrap_response
end
end
end
2 changes: 1 addition & 1 deletion app/views/wash_out/rpc/response.builder
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ xml.tag! "soap:Envelope", "xmlns:soap" => 'http://schemas.xmlsoap.org/soap/envel
end
xml.tag! "soap:Body" do
xml.tag! "tns:#{@action_spec[:response_tag]}" do
wsdl_data xml, result
wsdl_data xml, result, wrap_response
end
end
end
21 changes: 0 additions & 21 deletions gemfiles/rails_3.2.13.gemfile

This file was deleted.

2 changes: 1 addition & 1 deletion gemfiles/rails_4.0.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ gem "simplecov-summary"
gem "rails", "4.0.0"
gem "listen", "< 3.1.0"

gemspec :path => "../"
gemspec path: "../"
2 changes: 1 addition & 1 deletion gemfiles/rails_4.1.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ gem "simplecov-summary"
gem "rails", "4.1.0"
gem "listen", "< 3.1.0"

gemspec :path => "../"
gemspec path: "../"
2 changes: 1 addition & 1 deletion gemfiles/rails_4.2.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ gem "simplecov-summary"
gem "rails", "4.2.0"
gem "listen", "< 3.1.0"

gemspec :path => "../"
gemspec path: "../"
19 changes: 0 additions & 19 deletions gemfiles/rails_5.0.0.beta2.gemfile

This file was deleted.

4 changes: 2 additions & 2 deletions gemfiles/rails_5.0.0.gemfile → gemfiles/rails_5.0.3.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ gem "tzinfo"
gem "pry"
gem "simplecov"
gem "simplecov-summary"
gem "rails", "5.0.0"
gem "rails", "5.0.3"

gemspec :path => "../"
gemspec path: "../"
5 changes: 4 additions & 1 deletion lib/wash_out/dispatcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,15 @@ def _render_soap(result, options)
header = HashWithIndifferentAccess.new(header)
end

wrap_response = options.fetch :wrap_response, true

render :template => "wash_out/#{soap_config.wsdl_style}/response",
:layout => false,
:locals => {
:header => header.present? ? inject.call(header, @action_spec[:header_out])
: nil,
:result => inject.call(result, @action_spec[:out])
:result => inject.call(result, @action_spec[:out]),
:wrap_response => wrap_response
},
:content_type => 'text/xml'
end
Expand Down
12 changes: 12 additions & 0 deletions spec/lib/wash_out_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,18 @@ def funky

expect(savon(:funky, :a => 42, :b => 'k')[:funky_response][:value]).to eq '420k'
end

it 'responds with single strings without wraping the response' do
mock_controller do
soap_action 'single_string', args: { a: :string }, return: :string
def single_string
render soap: params[:a], wrap_response: false
end
end

response = savon(:single_string, a: 'single string')[:single_string_response]
expect(response).to match 'single string'
end
end

context "complex actions" do
Expand Down