savon 2.11.2 → 2.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +112 -73
  3. data/README.md +25 -16
  4. data/lib/savon/block_interface.rb +1 -0
  5. data/lib/savon/builder.rb +100 -30
  6. data/lib/savon/client.rb +1 -0
  7. data/lib/savon/header.rb +2 -6
  8. data/lib/savon/http_error.rb +4 -4
  9. data/lib/savon/log_message.rb +1 -0
  10. data/lib/savon/message.rb +1 -0
  11. data/lib/savon/mock/expectation.rb +1 -0
  12. data/lib/savon/mock/spec_helper.rb +1 -0
  13. data/lib/savon/mock.rb +1 -0
  14. data/lib/savon/model.rb +4 -3
  15. data/lib/savon/operation.rb +20 -18
  16. data/lib/savon/options.rb +71 -2
  17. data/lib/savon/qualified_message.rb +5 -4
  18. data/lib/savon/request.rb +18 -3
  19. data/lib/savon/request_logger.rb +8 -2
  20. data/lib/savon/response.rb +52 -5
  21. data/lib/savon/soap_fault.rb +2 -3
  22. data/lib/savon/string_utils.rb +17 -0
  23. data/lib/savon/version.rb +2 -1
  24. data/lib/savon.rb +2 -0
  25. metadata +62 -97
  26. data/.gitignore +0 -14
  27. data/.travis.yml +0 -19
  28. data/.yardopts +0 -6
  29. data/CONTRIBUTING.md +0 -46
  30. data/Gemfile +0 -13
  31. data/donate.png +0 -0
  32. data/lib/savon/core_ext/string.rb +0 -29
  33. data/savon.gemspec +0 -46
  34. data/spec/fixtures/gzip/message.gz +0 -0
  35. data/spec/fixtures/response/another_soap_fault.xml +0 -14
  36. data/spec/fixtures/response/authentication.xml +0 -14
  37. data/spec/fixtures/response/f5.xml +0 -39
  38. data/spec/fixtures/response/header.xml +0 -13
  39. data/spec/fixtures/response/list.xml +0 -18
  40. data/spec/fixtures/response/multi_ref.xml +0 -39
  41. data/spec/fixtures/response/soap_fault.xml +0 -8
  42. data/spec/fixtures/response/soap_fault12.xml +0 -18
  43. data/spec/fixtures/response/soap_fault_funky.xml +0 -8
  44. data/spec/fixtures/response/taxcloud.xml +0 -1
  45. data/spec/fixtures/ssl/client_cert.pem +0 -16
  46. data/spec/fixtures/ssl/client_encrypted_key.pem +0 -30
  47. data/spec/fixtures/ssl/client_encrypted_key_cert.pem +0 -24
  48. data/spec/fixtures/ssl/client_key.pem +0 -15
  49. data/spec/fixtures/wsdl/authentication.xml +0 -63
  50. data/spec/fixtures/wsdl/betfair.xml +0 -2981
  51. data/spec/fixtures/wsdl/brand.xml +0 -624
  52. data/spec/fixtures/wsdl/edialog.xml +0 -15416
  53. data/spec/fixtures/wsdl/interhome.xml +0 -2137
  54. data/spec/fixtures/wsdl/lower_camel.xml +0 -52
  55. data/spec/fixtures/wsdl/multiple_namespaces.xml +0 -92
  56. data/spec/fixtures/wsdl/multiple_types.xml +0 -60
  57. data/spec/fixtures/wsdl/no_message_tag.xml +0 -1267
  58. data/spec/fixtures/wsdl/taxcloud.xml +0 -934
  59. data/spec/fixtures/wsdl/team_software.xml +0 -1
  60. data/spec/fixtures/wsdl/vies.xml +0 -176
  61. data/spec/fixtures/wsdl/wasmuth.xml +0 -153
  62. data/spec/integration/centra_spec.rb +0 -66
  63. data/spec/integration/email_example_spec.rb +0 -32
  64. data/spec/integration/random_quote_spec.rb +0 -23
  65. data/spec/integration/ratp_example_spec.rb +0 -28
  66. data/spec/integration/stockquote_example_spec.rb +0 -34
  67. data/spec/integration/support/application.rb +0 -82
  68. data/spec/integration/support/server.rb +0 -84
  69. data/spec/integration/temperature_example_spec.rb +0 -46
  70. data/spec/integration/zipcode_example_spec.rb +0 -42
  71. data/spec/savon/builder_spec.rb +0 -137
  72. data/spec/savon/client_spec.rb +0 -271
  73. data/spec/savon/core_ext/string_spec.rb +0 -37
  74. data/spec/savon/features/message_tag_spec.rb +0 -61
  75. data/spec/savon/http_error_spec.rb +0 -49
  76. data/spec/savon/log_message_spec.rb +0 -50
  77. data/spec/savon/message_spec.rb +0 -70
  78. data/spec/savon/mock_spec.rb +0 -174
  79. data/spec/savon/model_spec.rb +0 -182
  80. data/spec/savon/observers_spec.rb +0 -92
  81. data/spec/savon/operation_spec.rb +0 -230
  82. data/spec/savon/options_spec.rb +0 -1075
  83. data/spec/savon/qualified_message_spec.rb +0 -68
  84. data/spec/savon/request_logger_spec.rb +0 -37
  85. data/spec/savon/request_spec.rb +0 -496
  86. data/spec/savon/response_spec.rb +0 -270
  87. data/spec/savon/soap_fault_spec.rb +0 -136
  88. data/spec/savon/softlayer_spec.rb +0 -27
  89. data/spec/spec_helper.rb +0 -30
  90. data/spec/support/adapters.rb +0 -48
  91. data/spec/support/endpoint.rb +0 -25
  92. data/spec/support/fixture.rb +0 -39
  93. data/spec/support/integration.rb +0 -9
  94. data/spec/support/stdout.rb +0 -25
@@ -1,37 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe String do
4
-
5
- describe "snakecase" do
6
- it "lowercases one word CamelCase" do
7
- expect("Merb".snakecase).to eq("merb")
8
- end
9
-
10
- it "makes one underscore snakecase two word CamelCase" do
11
- expect("MerbCore".snakecase).to eq("merb_core")
12
- end
13
-
14
- it "handles CamelCase with more than 2 words" do
15
- expect("SoYouWantContributeToMerbCore".snakecase).to eq("so_you_want_contribute_to_merb_core")
16
- end
17
-
18
- it "handles CamelCase with more than 2 capital letter in a row" do
19
- expect("CNN".snakecase).to eq("cnn")
20
- expect("CNNNews".snakecase).to eq("cnn_news")
21
- expect("HeadlineCNNNews".snakecase).to eq("headline_cnn_news")
22
- end
23
-
24
- it "does NOT change one word lowercase" do
25
- expect("merb".snakecase).to eq("merb")
26
- end
27
-
28
- it "leaves snake_case as is" do
29
- expect("merb_core".snakecase).to eq("merb_core")
30
- end
31
-
32
- it "converts period characters to underscores" do
33
- expect("User.GetEmail".snakecase).to eq("user_get_email")
34
- end
35
- end
36
-
37
- end
@@ -1,61 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Savon do
4
-
5
- it 'knows the message tag for :authentication' do
6
- message_tag = message_tag_for(:authentication, :authenticate)
7
- expect(message_tag).to eq(['http://v1_0.ws.auth.order.example.com/', 'authenticate'])
8
- end
9
-
10
- it 'knows the message tag for :taxcloud' do
11
- message_tag = message_tag_for(:taxcloud, :verify_address)
12
- expect(message_tag).to eq(['http://taxcloud.net', 'VerifyAddress'])
13
- end
14
-
15
- it 'knows the message tag for :team_software' do
16
- message_tag = message_tag_for(:team_software, :login)
17
- expect(message_tag).to eq(['http://tempuri.org/', 'Login'])
18
- end
19
-
20
- it 'knows the message tag for :interhome' do
21
- message_tag = message_tag_for(:interhome, :price_list)
22
- expect(message_tag).to eq(['http://www.interhome.com/webservice', 'PriceList'])
23
- end
24
-
25
- it 'knows the message tag for :betfair' do
26
- message_tag = message_tag_for(:betfair, :get_bet)
27
- expect(message_tag).to eq(['http://www.betfair.com/publicapi/v5/BFExchangeService/', 'getBet'])
28
- end
29
-
30
- it 'knows the message tag for :vies' do
31
- message_tag = message_tag_for(:vies, :check_vat)
32
- expect(message_tag).to eq(['urn:ec.europa.eu:taxud:vies:services:checkVat:types', 'checkVat'])
33
- end
34
-
35
- it 'knows the message tag for :wasmuth' do
36
- message_tag = message_tag_for(:wasmuth, :get_st_tables)
37
- expect(message_tag).to eq(['http://ws.online.msw/', 'getStTables'])
38
- end
39
-
40
- def message_tag_for(fixture, operation_name)
41
- globals = Savon::GlobalOptions.new(:log => false)
42
- wsdl = Wasabi::Document.new Fixture.wsdl(fixture)
43
- operation = Savon::Operation.create(operation_name, wsdl, globals)
44
- request_xml = operation.build.to_s
45
-
46
- nsid, local = extract_message_tag_from_request(request_xml)
47
- namespace = extract_namespace_from_request(nsid, request_xml)
48
-
49
- [namespace, local]
50
- end
51
-
52
- def extract_message_tag_from_request(xml)
53
- match = xml.match(/<\w+?:Body><(.+?):(.+?)>/)
54
- [ match[1], match[2] ]
55
- end
56
-
57
- def extract_namespace_from_request(nsid, xml)
58
- xml.match(/xmlns:#{nsid}="(.+?)"/)[1]
59
- end
60
-
61
- end
@@ -1,49 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Savon::HTTPError do
4
- let(:http_error) { Savon::HTTPError.new new_response(:code => 404, :body => "Not Found") }
5
- let(:no_error) { Savon::HTTPError.new new_response }
6
-
7
- it "inherits from Savon::Error" do
8
- expect(Savon::HTTPError.ancestors).to include(Savon::Error)
9
- end
10
-
11
- describe ".present?" do
12
- it "returns true if there was an HTTP error" do
13
- http = new_response(:code => 404, :body => "Not Found")
14
- expect(Savon::HTTPError.present? http).to be_truthy
15
- end
16
-
17
- it "returns false unless there was an HTTP error" do
18
- expect(Savon::HTTPError.present? new_response).to be_falsey
19
- end
20
- end
21
-
22
- describe "#http" do
23
- it "returns the HTTPI::Response" do
24
- expect(http_error.http).to be_a(HTTPI::Response)
25
- end
26
- end
27
-
28
- [:message, :to_s].each do |method|
29
- describe "##{method}" do
30
- it "returns the HTTP error message" do
31
- expect(http_error.send method).to eq("HTTP error (404): Not Found")
32
- end
33
- end
34
- end
35
-
36
- describe "#to_hash" do
37
- it "returns the HTTP response details as a Hash" do
38
- expect(http_error.to_hash).to eq(:code => 404, :headers => {}, :body => "Not Found")
39
- end
40
- end
41
-
42
- def new_response(options = {})
43
- defaults = { :code => 200, :headers => {}, :body => Fixture.response(:authentication) }
44
- response = defaults.merge options
45
-
46
- HTTPI::Response.new response[:code], response[:headers], response[:body]
47
- end
48
-
49
- end
@@ -1,50 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Savon::LogMessage do
4
-
5
- it "returns the message if it's not XML" do
6
- message = log_message("hello", [:password], :pretty_print).to_s
7
- expect(message).to eq("hello")
8
- end
9
-
10
- it "returns the message if it shouldn't be filtered or pretty printed" do
11
- Nokogiri.expects(:XML).never
12
-
13
- message = log_message("<hello/>", [], false).to_s
14
- expect(message).to eq("<hello/>")
15
- end
16
-
17
- it "pretty prints a given message" do
18
- message = log_message("<envelope><body>hello</body></envelope>", [], :pretty_print).to_s
19
-
20
- expect(message).to include("\n<envelope>")
21
- expect(message).to include("\n <body>")
22
- end
23
-
24
- it "filters tags in a given message without pretty printing" do
25
- message = log_message("<root><password>secret</password></root>", [:password], false).to_s
26
- expect(message).to include("<password>***FILTERED***</password>")
27
- expect(message).to_not include("\n <password>***FILTERED***</password>") # no pretty printing
28
- end
29
-
30
- it "filters tags in a given message with pretty printing" do
31
- message = log_message("<root><password>secret</password></root>", [:password], true).to_s
32
- expect(message).to include("\n <password>***FILTERED***</password>")
33
- end
34
-
35
- it "properly applies Proc filter" do
36
- filter = Proc.new do |document|
37
- document.xpath('//password').each do |node|
38
- node.content = "FILTERED"
39
- end
40
- end
41
-
42
- message = log_message("<root><password>secret</password></root>", [filter], false).to_s
43
- expect(message).to include("<password>FILTERED</password>")
44
- end
45
-
46
- def log_message(*args)
47
- Savon::LogMessage.new(*args)
48
- end
49
-
50
- end
@@ -1,70 +0,0 @@
1
- require "spec_helper"
2
- require "integration/support/server"
3
-
4
- describe Savon::Message do
5
-
6
- before do
7
- @server = IntegrationServer.run
8
- end
9
-
10
- after do
11
- @server.stop
12
- end
13
-
14
- let(:client_config) {
15
- {
16
- :endpoint => @server.url(:repeat),
17
- :namespace => 'http://example.com',
18
- :log => false,
19
-
20
- :element_form_default => :qualified,
21
- :convert_request_keys_to => :camelcase,
22
-
23
- :convert_response_tags_to => nil
24
- }
25
- }
26
-
27
- let(:client) { Savon.client(client_config) }
28
-
29
- context "with a qualified message" do
30
- let(:message) {
31
- {
32
- :email_count => 3,
33
- :user_name => 'josh',
34
- :order! => [:user_name, :email_count]
35
- }
36
- }
37
-
38
- let(:converted_keys) {
39
- '<wsdl:UserName>josh</wsdl:UserName><wsdl:EmailCount>3</wsdl:EmailCount>'
40
- }
41
- it "converts request Hash keys for which there is not namespace" do
42
- response = client.call(:something, :message => message)
43
- expect(response.xml).to include(converted_keys)
44
- end
45
- end
46
-
47
- context 'use_wsa_headers' do
48
- let(:client_config) { super().merge(use_wsa_headers: true) }
49
-
50
- context 'headers' do
51
- [ 'wsa:Action', 'wsa:To', 'wsa:MessageID' ].each do |header|
52
- it "should include #{header} header" do
53
- response = client.call(:something, message: {})
54
- expect(response.xml).to include(header)
55
- end
56
- end
57
- end
58
-
59
- context 'wsa:MessageID' do
60
- let(:message_id_tag) {
61
- '<wsa:MessageID xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">'
62
- }
63
- it 'should include xmlns:wsa attribute' do
64
- response = client.call(:something, message: {})
65
- expect(response.xml).to include(message_id_tag)
66
- end
67
- end
68
- end
69
-
70
- end
@@ -1,174 +0,0 @@
1
- require "spec_helper"
2
- require "savon/mock/spec_helper"
3
-
4
- describe "Savon's mock interface" do
5
- include Savon::SpecHelper
6
-
7
- before :all do
8
- savon.mock!
9
- end
10
-
11
- after :all do
12
- savon.unmock!
13
- end
14
-
15
- it "can verify a request and return a fixture response" do
16
- message = { :username => "luke", :password => "secret" }
17
- savon.expects(:authenticate).with(:message => message).returns("<fixture/>")
18
-
19
- response = new_client.call(:authenticate) do
20
- message(:username => "luke", :password => "secret")
21
- end
22
-
23
- expect(response.http.body).to eq("<fixture/>")
24
- end
25
-
26
- it "can verify a request with any parameters and return a fixture response" do
27
- message = { :username => "luke", :password => :any }
28
- savon.expects(:authenticate).with(:message => message).returns("<fixture/>")
29
-
30
- response = new_client.call(:authenticate) do
31
- message(:username => "luke", :password => "secret")
32
- end
33
-
34
- expect(response.http.body).to eq("<fixture/>")
35
- end
36
-
37
- it "accepts a Hash to specify the response code, headers and body" do
38
- soap_fault = Fixture.response(:soap_fault)
39
- response = { :code => 500, :headers => { "X-Result" => "invalid" }, :body => soap_fault }
40
-
41
- savon.expects(:authenticate).returns(response)
42
- response = new_client(:raise_errors => false).call(:authenticate)
43
-
44
- expect(response).to_not be_successful
45
- expect(response).to be_a_soap_fault
46
-
47
- expect(response.http.code).to eq(500)
48
- expect(response.http.headers).to eq("X-Result" => "invalid")
49
- expect(response.http.body).to eq(soap_fault)
50
- end
51
-
52
- it "works with multiple requests" do
53
- authentication_message = { :username => "luke", :password => "secret" }
54
- savon.expects(:authenticate).with(:message => authentication_message).returns("")
55
-
56
- find_user_message = { :by_username => "lea" }
57
- savon.expects(:find_user).with(:message => find_user_message).returns("")
58
-
59
- new_client.call(:authenticate, :message => authentication_message)
60
- new_client.call(:find_user, :message => find_user_message)
61
- end
62
-
63
- it "fails when the expected operation was not called" do
64
- # TODO: find out how to test this! [dh, 2012-12-17]
65
- #savon.expects(:authenticate)
66
- end
67
-
68
- it "fails when the return value for an expectation was not specified" do
69
- savon.expects(:authenticate)
70
-
71
- expect { new_client.call(:authenticate) }.
72
- to raise_error(Savon::ExpectationError, "This expectation was not set up with a response.")
73
- end
74
-
75
- it "fails with an unexpected request" do
76
- expect { new_client.call(:authenticate) }.
77
- to raise_error(Savon::ExpectationError, "Unexpected request to the :authenticate operation.")
78
- end
79
-
80
- it "fails with multiple requests" do
81
- authentication_message = { :username => "luke", :password => "secret" }
82
- savon.expects(:authenticate).with(:message => authentication_message).returns("")
83
-
84
- create_user_message = { :username => "lea" }
85
- savon.expects(:create_user).with(:message => create_user_message).returns("")
86
-
87
- find_user_message = { :by_username => "lea" }
88
- savon.expects(:find_user).with(:message => find_user_message).returns("")
89
-
90
- # reversed order from previous spec
91
- new_client.call(:authenticate, :message => authentication_message)
92
-
93
- expect { new_client.call(:find_user, :message => find_user_message) }.
94
- to raise_error(Savon::ExpectationError, "Expected a request to the :create_user operation.\n" \
95
- "Received a request to the :find_user operation instead.")
96
- end
97
-
98
- it "fails when the expected SOAP operation does not match the actual one" do
99
- savon.expects(:logout).returns("<fixture/>")
100
-
101
- expect { new_client.call(:authenticate) }.
102
- to raise_error(Savon::ExpectationError, "Expected a request to the :logout operation.\n" \
103
- "Received a request to the :authenticate operation instead.")
104
- end
105
-
106
- it "fails when there is no actual message to match" do
107
- message = { :username => "luke" }
108
- savon.expects(:find_user).with(:message => message).returns("<fixture/>")
109
-
110
- expect { new_client.call(:find_user) }.
111
- to raise_error(Savon::ExpectationError, "Expected a request to the :find_user operation\n" \
112
- " with this message: #{message.inspect}\n" \
113
- "Received a request to the :find_user operation\n" \
114
- " with no message.")
115
- end
116
-
117
- it "fails when there is no expect but an actual message" do
118
- savon.expects(:find_user).returns("<fixture/>")
119
- message = { :username => "luke" }
120
-
121
- expect { new_client.call(:find_user, :message => message) }.
122
- to raise_error(Savon::ExpectationError, "Expected a request to the :find_user operation\n" \
123
- " with no message.\n" \
124
- "Received a request to the :find_user operation\n" \
125
- " with this message: #{message.inspect}")
126
- end
127
-
128
- it "does not fail when any message is expected and an actual message" do
129
- savon.expects(:find_user).with(:message => :any).returns("<fixture/>")
130
- message = { :username => "luke" }
131
-
132
- expect { new_client.call(:find_user, :message => message) }.to_not raise_error
133
- end
134
-
135
- it "does not fail when any message is expected and no actual message" do
136
- savon.expects(:find_user).with(:message => :any).returns("<fixture/>")
137
-
138
- expect { new_client.call(:find_user) }.to_not raise_error
139
- end
140
-
141
- it "matchers can be used to specify the message" do
142
- savon.expects(:find_user).with(:message => include(:username)).returns("<fixture/>")
143
- message = { :username => "Han Solo", password: "querty"}
144
-
145
- expect { new_client.call(:find_user, :message => message) }.to_not raise_error
146
- end
147
-
148
- it "allows code to rescue Savon::Error and still report test failures" do
149
- message = { :username => "luke" }
150
- savon.expects(:find_user).with(:message => message).returns("<fixture/>")
151
-
152
- expect {
153
- begin
154
- new_client.call(:find_user)
155
- rescue Savon::Error => e
156
- puts "any real error (e.g. SOAP fault or HTTP error) is OK in the big picture, move on"
157
- end
158
- }.to raise_error(Savon::ExpectationError, "Expected a request to the :find_user operation\n" \
159
- " with this message: #{message.inspect}\n" \
160
- "Received a request to the :find_user operation\n" \
161
- " with no message.")
162
- end
163
-
164
- def new_client(globals = {})
165
- defaults = {
166
- :endpoint => "http://example.com",
167
- :namespace => "http://v1.example.com",
168
- :log => false
169
- }
170
-
171
- Savon.client defaults.merge(globals)
172
- end
173
-
174
- end
@@ -1,182 +0,0 @@
1
- require "spec_helper"
2
- require "integration/support/server"
3
-
4
- describe Savon::Model do
5
-
6
- before :all do
7
- @server = IntegrationServer.run
8
- end
9
-
10
- after :all do
11
- @server.stop
12
- end
13
-
14
- describe ".client" do
15
- it "returns the memoized client" do
16
- model = Class.new {
17
- extend Savon::Model
18
- client :wsdl => Fixture.wsdl(:authentication)
19
- }
20
-
21
- expect(model.client).to be_a(Savon::Client)
22
- expect(model.client).to equal(model.client)
23
- end
24
-
25
- it "raises if the client was not initialized properly" do
26
- model = Class.new { extend Savon::Model }
27
-
28
- expect { model.client }.
29
- to raise_error(Savon::InitializationError, /^Expected the model to be initialized/)
30
- end
31
- end
32
-
33
- describe ".global" do
34
- it "sets global options" do
35
- model = Class.new {
36
- extend Savon::Model
37
-
38
- client :wsdl => Fixture.wsdl(:authentication)
39
-
40
- global :soap_version, 2
41
- global :open_timeout, 71
42
- global :wsse_auth, "luke", "secret", :digest
43
- }
44
-
45
- expect(model.client.globals[:soap_version]).to eq(2)
46
- expect(model.client.globals[:open_timeout]).to eq(71)
47
- expect(model.client.globals[:wsse_auth]).to eq(["luke", "secret", :digest])
48
- end
49
- end
50
-
51
- describe ".operations" do
52
- it "defines class methods for each operation" do
53
- model = Class.new {
54
- extend Savon::Model
55
-
56
- client :wsdl => Fixture.wsdl(:authentication)
57
- operations :authenticate
58
- }
59
-
60
- expect(model).to respond_to(:authenticate)
61
- end
62
-
63
- it "executes class-level SOAP operations" do
64
- repeat_url = @server.url(:repeat)
65
-
66
- model = Class.new {
67
- extend Savon::Model
68
-
69
- client :endpoint => repeat_url, :namespace => "http://v1.example.com"
70
- global :log, false
71
-
72
- operations :authenticate
73
- }
74
-
75
- response = model.authenticate(:xml => Fixture.response(:authentication))
76
- expect(response.body[:authenticate_response][:return]).to include(:authentication_value)
77
- end
78
-
79
- it "defines instance methods for each operation" do
80
- model = Class.new {
81
- extend Savon::Model
82
-
83
- client :wsdl => Fixture.wsdl(:authentication)
84
- operations :authenticate
85
- }
86
-
87
- model_instance = model.new
88
- expect(model_instance).to respond_to(:authenticate)
89
- end
90
-
91
- it "executes instance-level SOAP operations" do
92
- repeat_url = @server.url(:repeat)
93
-
94
- model = Class.new {
95
- extend Savon::Model
96
-
97
- client :endpoint => repeat_url, :namespace => "http://v1.example.com"
98
- global :log, false
99
-
100
- operations :authenticate
101
- }
102
-
103
- model_instance = model.new
104
- response = model_instance.authenticate(:xml => Fixture.response(:authentication))
105
- expect(response.body[:authenticate_response][:return]).to include(:authentication_value)
106
- end
107
- end
108
-
109
- it "allows to overwrite class operations" do
110
- repeat_url = @server.url(:repeat)
111
-
112
- model = Class.new {
113
- extend Savon::Model
114
- client :endpoint => repeat_url, :namespace => "http://v1.example.com"
115
- }
116
-
117
- supermodel = model.dup
118
- supermodel.operations :authenticate
119
-
120
- def supermodel.authenticate(locals = {})
121
- p "super"
122
- super
123
- end
124
-
125
- supermodel.client.expects(:call).with(:authenticate, :message => { :username => "luke", :password => "secret" })
126
- supermodel.expects(:p).with("super") # stupid, but works
127
-
128
- supermodel.authenticate(:message => { :username => "luke", :password => "secret" })
129
- end
130
-
131
- it "allows to overwrite instance operations" do
132
- repeat_url = @server.url(:repeat)
133
-
134
- model = Class.new {
135
- extend Savon::Model
136
- client :endpoint => repeat_url, :namespace => "http://v1.example.com"
137
- }
138
-
139
- supermodel = model.dup
140
- supermodel.operations :authenticate
141
- supermodel = supermodel.new
142
-
143
- def supermodel.authenticate(lcoals = {})
144
- p "super"
145
- super
146
- end
147
-
148
- supermodel.client.expects(:call).with(:authenticate, :message => { :username => "luke", :password => "secret" })
149
- supermodel.expects(:p).with("super") # stupid, but works
150
-
151
- supermodel.authenticate(:message => { :username => "luke", :password => "secret" })
152
- end
153
-
154
- describe ".all_operations" do
155
- it "should call operations with all available client operations" do
156
- model = Class.new {
157
- extend Savon::Model
158
-
159
- client :wsdl => Fixture.wsdl(:taxcloud)
160
- all_operations
161
- }
162
-
163
- [:verify_address,
164
- :lookup_for_date,
165
- :lookup,
166
- :authorized,
167
- :authorized_with_capture,
168
- :captured,
169
- :returned,
170
- :get_tic_groups,
171
- :get_ti_cs,
172
- :get_ti_cs_by_group,
173
- :add_exempt_certificate,
174
- :delete_exempt_certificate,
175
- :get_exempt_certificates].each do |method|
176
- expect(model).to respond_to(method)
177
- end
178
- end
179
-
180
- end
181
-
182
- end