Skip to content

Commit

Permalink
Option to change the service name (#243)
Browse files Browse the repository at this point in the history
* Allow a service_name configuration option with the default as 'service'.

* Renders the service name in the view.

* Adds tests for allowing a custom service name.

* Updates the README file.
  • Loading branch information
jesusabarca authored and inossidabile committed Oct 16, 2018
1 parent 4f2a783 commit f875b9c
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ Available properties are:
* **namespace**: SOAP namespace to use. Default is `urn:WashOut`.
* **snakecase_input**: Determines if WashOut should modify parameters keys to snakecase. Default is `false`.
* **camelize_wsdl**: Determines if WashOut should camelize types within WSDL and responses. Supports `true` for CamelCase and `:lower` for camelCase. Default is `false`.
* **service_name**: Allows to define a custom name for the SOAP service. By default, the name is set as `service`.

### Camelization

Expand Down
2 changes: 1 addition & 1 deletion app/views/wash_out/document/wsdl.builder
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ xml.definitions 'xmlns' => 'http://schemas.xmlsoap.org/wsdl/',
end
end

xml.service :name => "service" do
xml.service :name => @service_name do
xml.port :name => "#{@name}_port", :binding => "tns:#{@name}_binding" do
xml.tag! "soap:address", :location => WashOut::Router.url(request, @name)
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/wash_out/rpc/wsdl.builder
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ xml.definitions 'xmlns' => 'http://schemas.xmlsoap.org/wsdl/',
end
end

xml.service :name => "service" do
xml.service :name => @service_name do
xml.port :name => "#{@name}_port", :binding => "tns:#{@name}_binding" do
xml.tag! "soap:address", :location => WashOut::Router.url(request, @name)
end
Expand Down
7 changes: 4 additions & 3 deletions lib/wash_out/dispatcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ def _load_params(spec, xml_data)

# This action generates the WSDL for defined SOAP methods.
def _generate_wsdl
@map = self.class.soap_actions
@namespace = soap_config.namespace
@name = controller_path
@map = self.class.soap_actions
@namespace = soap_config.namespace
@name = controller_path
@service_name = soap_config.service_name

render :template => "wash_out/#{soap_config.wsdl_style}/wsdl", :layout => false,
:content_type => 'text/xml'
Expand Down
1 change: 1 addition & 0 deletions lib/wash_out/soap_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class SoapConfig
wsse_password: nil,
wsse_auth_callback: nil,
soap_action_routing: true,
service_name: 'service'
}

attr_reader :config
Expand Down
34 changes: 34 additions & 0 deletions spec/lib/wash_out_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,40 @@ def savon!(method, message={}, &block)
end
end

describe 'WSDL' do
let :wsdl do
mock_controller

HTTPI.get('http://app/route/api/wsdl').body
end

let :xml do
nori.parse wsdl
end

it "defines a default service name as 'service'" do
service_name = xml[:definitions][:service][:@name]
expect(service_name).to match 'service'
end
end

describe 'WSDL' do
let :wsdl do
mock_controller service_name: 'CustomServiceName'

HTTPI.get('http://app/route/api/wsdl').body
end

let :xml do
nori.parse wsdl
end

it 'allows to define a custom service name' do
service_name = xml[:definitions][:service][:@name]
expect(service_name).to match 'CustomServiceName'
end
end

describe "Dispatcher" do

context "simple actions" do
Expand Down

0 comments on commit f875b9c

Please sign in to comment.