cherby 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cherby"
3
- s.version = "0.0.5"
3
+ s.version = "0.0.6"
4
4
  s.summary = "Cherwell-Ruby bridge"
5
5
  s.description = <<-EOS
6
6
  Cherby is a Ruby wrapper for the Cherwell Web Service.
@@ -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.
@@ -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
 
@@ -32,13 +32,22 @@ describe Cherby::Cherwell do
32
32
  end #initialize
33
33
 
34
34
  describe "#login" do
35
- it "success when Cherwell returns a true status" do
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
- returns(login_response)
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).
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cherby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: