cherby 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/cherby.gemspec +1 -1
- data/lib/cherby/cherwell.rb +15 -14
- data/lib/cherby/client.rb +4 -1
- data/spec/cherwell_spec.rb +12 -3
- metadata +1 -1
data/cherby.gemspec
CHANGED
data/lib/cherby/cherwell.rb
CHANGED
@@ -54,21 +54,22 @@ module Cherby
|
|
54
54
|
rescue => e
|
55
55
|
# This can happen if a bad URL is given
|
56
56
|
raise Cherby::LoginFailed, e.message
|
57
|
-
else
|
58
|
-
if response.body[:login_response][:login_result] == true
|
59
|
-
# FIXME: Using the workaround described in this issue:
|
60
|
-
# https://github.com/savonrb/savon/issues/363
|
61
|
-
# because the version recommended in the documentation:
|
62
|
-
# auth_cookies = response.http.cookies
|
63
|
-
# does not work, giving:
|
64
|
-
# NoMethodError: undefined method `cookies' for #<HTTPI::Response:0x...>
|
65
|
-
@client.globals[:headers] = {"Cookie" => response.http.headers["Set-Cookie"]}
|
66
|
-
return true
|
67
|
-
# This can happen if invalid credentials are given
|
68
|
-
else
|
69
|
-
raise Cherby::LoginFailed, "Cherwell returned false status"
|
70
|
-
end
|
71
57
|
end
|
58
|
+
|
59
|
+
# This can happen if invalid credentials are given
|
60
|
+
if response.body[:login_response][:login_result] == false
|
61
|
+
raise Cherby::LoginFailed, "Cherwell returned false status"
|
62
|
+
end
|
63
|
+
|
64
|
+
# Store cookies so subsequent requests will be authorized
|
65
|
+
@client.cookies = response.http.cookies
|
66
|
+
|
67
|
+
# Double-check that login worked
|
68
|
+
if self.last_error
|
69
|
+
raise Cherby::LoginFailed, "Cherwell returned error: '#{self.last_error}'"
|
70
|
+
end
|
71
|
+
|
72
|
+
return true
|
72
73
|
end
|
73
74
|
|
74
75
|
# Log out of Cherwell.
|
data/lib/cherby/client.rb
CHANGED
@@ -26,6 +26,9 @@ module Cherby
|
|
26
26
|
super(:wsdl => wsdl_url, :log => verbose_logging)
|
27
27
|
end
|
28
28
|
|
29
|
+
# Allow setting cookies
|
30
|
+
attr_accessor :cookies
|
31
|
+
|
29
32
|
# Call a given SOAP method with an optional body.
|
30
33
|
#
|
31
34
|
# @example
|
@@ -52,7 +55,7 @@ module Cherby
|
|
52
55
|
response_field = (method.to_s + '_response').to_sym
|
53
56
|
result_field = (method.to_s + '_result').to_sym
|
54
57
|
# Submit the request
|
55
|
-
response = self.call(method, :message => body)
|
58
|
+
response = self.call(method, :message => body, :cookies => self.cookies)
|
56
59
|
return response.to_hash[response_field][result_field]
|
57
60
|
end
|
58
61
|
|
data/spec/cherwell_spec.rb
CHANGED
@@ -32,13 +32,22 @@ describe Cherby::Cherwell do
|
|
32
32
|
end #initialize
|
33
33
|
|
34
34
|
describe "#login" do
|
35
|
-
it "
|
35
|
+
it "returns true when Cherwell returns true with nil last_error" do
|
36
36
|
login_response = savon_response('Login', 'true')
|
37
|
-
savon.expects(:login).with(:message => :any).
|
38
|
-
|
37
|
+
savon.expects(:login).with(:message => :any).returns(login_response)
|
38
|
+
@cherwell.stub(:last_error => nil)
|
39
39
|
@cherwell.login.should be_true
|
40
40
|
end
|
41
41
|
|
42
|
+
it "raises Cherby::LoginFailed when Cherwell returns true, but last_error is non-nil" do
|
43
|
+
login_response = savon_response('Login', 'true')
|
44
|
+
savon.expects(:login).with(:message => :any).returns(login_response)
|
45
|
+
@cherwell.stub(:last_error => "Kaboom")
|
46
|
+
lambda do
|
47
|
+
@cherwell.login
|
48
|
+
end.should raise_error(Cherby::LoginFailed, /Cherwell returned error/)
|
49
|
+
end
|
50
|
+
|
42
51
|
it "raises Cherby::LoginFailed when client.login raises any exception" do
|
43
52
|
error = "Arbitrary exception message"
|
44
53
|
@cherwell.client.stub(:call).with(:login, :message => anything).
|