allscripts_unity_client 1.3.4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +66 -66
  3. data/allscripts_unity_client.gemspec +32 -32
  4. data/lib/allscripts_unity_client/client.rb +215 -205
  5. data/lib/allscripts_unity_client/client_driver.rb +15 -42
  6. data/lib/allscripts_unity_client/client_options.rb +68 -0
  7. data/lib/allscripts_unity_client/json_client_driver.rb +46 -50
  8. data/lib/allscripts_unity_client/json_unity_request.rb +20 -20
  9. data/lib/allscripts_unity_client/json_unity_response.rb +1 -1
  10. data/lib/allscripts_unity_client/soap_client_driver.rb +29 -29
  11. data/lib/allscripts_unity_client/timezone.rb +15 -10
  12. data/lib/allscripts_unity_client/unity_request.rb +17 -17
  13. data/lib/allscripts_unity_client/unity_response.rb +3 -3
  14. data/lib/allscripts_unity_client/utilities.rb +5 -5
  15. data/lib/allscripts_unity_client/version.rb +1 -1
  16. data/lib/allscripts_unity_client.rb +21 -25
  17. data/spec/allscripts_unity_client_spec.rb +12 -16
  18. data/spec/client_driver_spec.rb +1 -49
  19. data/spec/client_options_spec.rb +134 -0
  20. data/spec/client_spec.rb +9 -9
  21. data/spec/factories/allscripts_unity_client_parameters_factory.rb +2 -2
  22. data/spec/factories/client_driver_factory.rb +4 -5
  23. data/spec/factories/client_factory.rb +2 -2
  24. data/spec/factories/client_options.rb +13 -0
  25. data/spec/factories/json_client_driver_factory.rb +1 -1
  26. data/spec/factories/json_unity_request_factory.rb +1 -1
  27. data/spec/factories/json_unity_response_factory.rb +1 -1
  28. data/spec/factories/magic_request_factory.rb +4 -4
  29. data/spec/factories/soap_client_driver_factory.rb +1 -1
  30. data/spec/factories/timezone_factory.rb +2 -2
  31. data/spec/factories/unity_request_factory.rb +3 -3
  32. data/spec/factories/unity_response_factory.rb +2 -2
  33. data/spec/json_client_driver_spec.rb +18 -86
  34. data/spec/json_unity_request_spec.rb +7 -7
  35. data/spec/json_unity_response_spec.rb +6 -6
  36. data/spec/soap_client_driver_spec.rb +20 -82
  37. data/spec/spec_helper.rb +5 -9
  38. data/spec/support/shared_examples_for_client_driver.rb +37 -58
  39. data/spec/support/shared_examples_for_unity_request.rb +13 -13
  40. data/spec/support/shared_examples_for_unity_response.rb +4 -4
  41. data/spec/timezone_spec.rb +31 -11
  42. data/spec/unity_request_spec.rb +7 -7
  43. data/spec/unity_response_spec.rb +4 -4
  44. data/spec/utilities_spec.rb +2 -2
  45. metadata +30 -57
@@ -4,21 +4,21 @@ describe 'JSONClientDriver' do
4
4
  it_behaves_like 'a client driver'
5
5
 
6
6
  subject do
7
- client_driver = FactoryGirl.build(:json_client_driver)
7
+ client_driver = build(:json_client_driver)
8
8
  client_driver.security_token = SecureRandom.uuid
9
9
  client_driver
10
10
  end
11
11
 
12
- let(:get_server_info) { FixtureLoader.load_file("get_server_info.json") }
13
- let(:get_security_token) { FixtureLoader.load_file("get_security_token.json") }
14
- let(:retire_security_token) { FixtureLoader.load_file("retire_security_token.json") }
15
- let(:error) { FixtureLoader.load_json("error.json") }
16
- let(:error_string) { "error: Username and Password not valid for any licenses on this server" }
12
+ let(:get_server_info) { FixtureLoader.load_file('get_server_info.json') }
13
+ let(:get_security_token) { FixtureLoader.load_file('get_security_token.json') }
14
+ let(:retire_security_token) { FixtureLoader.load_file('retire_security_token.json') }
15
+ let(:error) { FixtureLoader.load_json('error.json') }
16
+ let(:error_string) { 'error: Username and Password not valid for any licenses on this server' }
17
17
  let(:url) { Faker::Internet.url }
18
18
 
19
19
  let(:hash) do
20
20
  {
21
- "test" => true
21
+ 'test' => true
22
22
  }
23
23
  end
24
24
 
@@ -27,49 +27,9 @@ describe 'JSONClientDriver' do
27
27
  end
28
28
 
29
29
  describe '#initialize' do
30
- context 'when nil is given for base_unity_url' do
31
- it { expect { FactoryGirl.build(:json_client_driver, :base_unity_url => nil) }.to raise_error(ArgumentError) }
32
- end
33
-
34
- context 'when nil is given for username' do
35
- it { expect { FactoryGirl.build(:json_client_driver, :username => nil) }.to raise_error(ArgumentError) }
36
- end
37
-
38
- context 'when nil is given for password' do
39
- it { expect { FactoryGirl.build(:json_client_driver, :password => nil) }.to raise_error(ArgumentError) }
40
- end
41
-
42
- context 'when nil is given for appname' do
43
- it { expect { FactoryGirl.build(:json_client_driver, :appname => nil) }.to raise_error(ArgumentError) }
44
- end
45
-
46
- context 'when given a base_unity_url with a trailing /' do
47
- it 'sets @base_unity_url without the trailing /' do
48
- client_driver = FactoryGirl.build(:json_client_driver, :base_unity_url => "http://www.example.com/")
49
- expect(client_driver.base_unity_url).to eq("http://www.example.com")
50
- end
51
- end
52
-
53
- context 'when nil is given for timezone' do
54
- it 'sets @timezone to UTC' do
55
- client_driver = FactoryGirl.build(:json_client_driver, :timezone => nil)
56
- utc_timezone = FactoryGirl.build(:timezone, :zone_identifier => "UTC")
57
- expect(client_driver.timezone.tzinfo).to eq(utc_timezone.tzinfo)
58
- end
59
- end
60
-
61
- context 'when nil is given for logger' do
62
- it 'sets @logger to Logger' do
63
- client_driver = FactoryGirl.build(:json_client_driver, :logger => nil)
64
- expect(client_driver.logger).to be_instance_of(Logger)
65
- end
66
- end
67
-
68
- context 'when logger is set' do
69
- it 'sets @logger to logger' do
70
- logger = double("logger")
71
- client_driver = FactoryGirl.build(:json_client_driver, :logger => logger)
72
- expect(client_driver.logger).to be(logger)
30
+ context 'when given proxy' do
31
+ it 'passes configuration to connection' do
32
+ expect(build(:json_client_driver, proxy: url).connection.proxy.uri.to_s).to eq(url)
73
33
  end
74
34
  end
75
35
  end
@@ -80,7 +40,7 @@ describe 'JSONClientDriver' do
80
40
 
81
41
  describe '#magic' do
82
42
  before(:each) {
83
- stub_request(:post, "http://www.example.com/Unity/UnityService.svc/json/MagicJson").to_return(:body => get_server_info)
43
+ stub_request(:post, 'http://www.example.com/Unity/UnityService.svc/json/MagicJson').to_return(body: get_server_info)
84
44
  allow(subject).to receive(:start_timer)
85
45
  allow(subject).to receive(:end_timer)
86
46
  allow(subject).to receive(:log_magic)
@@ -88,7 +48,7 @@ describe 'JSONClientDriver' do
88
48
 
89
49
  it 'should POST to /Unity/UnityService.svc/json/MagicJson' do
90
50
  subject.magic
91
- WebMock.should have_requested(:post, "http://www.example.com/Unity/UnityService.svc/json/MagicJson")
51
+ expect(WebMock).to have_requested(:post, 'http://www.example.com/Unity/UnityService.svc/json/MagicJson').with(body: /\{"Action":(null|"[^"]*"),"AppUserID":(null|"[^"]*"),"Appname":(null|"[^"]*"),"PatientID":(null|"[^"]*"),"Token":(null|"[^"]*"),"Parameter1":(null|"[^"]*"),"Parameter2":(null|"[^"]*"),"Parameter3":(null|"[^"]*"),"Parameter4":(null|"[^"]*"),"Parameter5":(null|"[^"]*"),"Parameter6":(null|"[^"]*"),"Data":(null|"[^"]*")\}/, headers: { 'Content-Type' => 'application/json' })
92
52
  end
93
53
 
94
54
  it 'should call start_timer' do
@@ -109,15 +69,15 @@ describe 'JSONClientDriver' do
109
69
 
110
70
  describe '#get_security_token!' do
111
71
  before(:each) {
112
- stub_request(:post, "http://www.example.com/Unity/UnityService.svc/json/GetToken").to_return(:body => get_security_token)
72
+ stub_request(:post, 'http://www.example.com/Unity/UnityService.svc/json/GetToken').to_return(body: get_security_token)
113
73
  allow(subject).to receive(:start_timer)
114
74
  allow(subject).to receive(:end_timer)
115
75
  allow(subject).to receive(:log_get_security_token)
116
76
  }
117
77
 
118
- it 'should POST to /Unity/UnityService.svc/json/GetToken' do
78
+ it 'should POST to /Unity/UnityService.svc/json/GetToken with username, password, and appname' do
119
79
  subject.get_security_token!
120
- WebMock.should have_requested(:post, "http://www.example.com/Unity/UnityService.svc/json/GetToken")
80
+ expect(WebMock).to have_requested(:post, 'http://www.example.com/Unity/UnityService.svc/json/GetToken').with(body: /\{"Username":"[^"]+","Password":"[^"]+","Appname":"[^"]+"\}/, headers: { 'Content-Type' => 'application/json' })
121
81
  end
122
82
 
123
83
  it 'should call start_timer' do
@@ -138,15 +98,15 @@ describe 'JSONClientDriver' do
138
98
 
139
99
  describe '#retire_security_token!' do
140
100
  before(:each) {
141
- stub_request(:post, "http://www.example.com/Unity/UnityService.svc/json/RetireSecurityToken").to_return(:body => retire_security_token)
101
+ stub_request(:post, 'http://www.example.com/Unity/UnityService.svc/json/RetireSecurityToken').to_return(body: retire_security_token)
142
102
  allow(subject).to receive(:start_timer)
143
103
  allow(subject).to receive(:end_timer)
144
104
  allow(subject).to receive(:log_retire_security_token)
145
105
  }
146
106
 
147
- it 'should POST to /Unity/UnityService.svc/json/RetireSecurityToken' do
107
+ it 'should POST to /Unity/UnityService.svc/json/RetireSecurityToken with token and appname' do
148
108
  subject.retire_security_token!
149
- WebMock.should have_requested(:post, "http://www.example.com/Unity/UnityService.svc/json/RetireSecurityToken")
109
+ expect(WebMock).to have_requested(:post, 'http://www.example.com/Unity/UnityService.svc/json/RetireSecurityToken').with(body: /\{"Token":"[^"]+","Appname":"[^"]+"\}/, headers: { 'Content-Type' => 'application/json' })
150
110
  end
151
111
 
152
112
  it 'should call start_timer' do
@@ -165,34 +125,6 @@ describe 'JSONClientDriver' do
165
125
  end
166
126
  end
167
127
 
168
- describe '#create_httpi_request' do
169
- context 'when given url' do
170
- it 'returns an HTTPI request with that url' do
171
- expect(subject.send(:create_httpi_request, url, hash).url.to_s).to eq(url)
172
- end
173
- end
174
-
175
- context 'when given data' do
176
- it 'returns an HTTPI request with body set to that data' do
177
- expect(subject.send(:create_httpi_request, url, hash).body).to eq(json_hash)
178
- end
179
- end
180
-
181
- context 'when @proxy is nil' do
182
- it 'returns an HTTPI request with proxy set to nil' do
183
- subject.proxy = nil
184
- expect(subject.send(:create_httpi_request, url, hash).proxy).to be_nil
185
- end
186
- end
187
-
188
- context 'when @proxy is set' do
189
- it 'return an HTTPI request with proxy set to @proxy' do
190
- subject.proxy = url
191
- expect(subject.send(:create_httpi_request, url, hash).proxy.to_s).to eq(url)
192
- end
193
- end
194
- end
195
-
196
128
  describe '#raise_if_response_error' do
197
129
  context 'when given nil for response' do
198
130
  it { expect { subject.send(:raise_if_response_error, nil) }.to raise_error(AllscriptsUnityClient::APIError) }
@@ -3,34 +3,34 @@ require 'spec_helper'
3
3
  describe 'JSONUnityRequest' do
4
4
  it_behaves_like 'a unity request'
5
5
 
6
- subject { FactoryGirl.build(:json_unity_request) }
6
+ subject { build(:json_unity_request) }
7
7
 
8
8
  describe '#initialize' do
9
9
  context 'when nil is given for parameters' do
10
- it { expect { FactoryGirl.build(:json_unity_request, :parameters => nil) }.to raise_error(ArgumentError) }
10
+ it { expect { build(:json_unity_request, parameters: nil) }.to raise_error(ArgumentError) }
11
11
  end
12
12
 
13
13
  context 'when nil is given for timezone' do
14
- it { expect { FactoryGirl.build(:json_unity_request, :timezone => nil) }.to raise_error(ArgumentError) }
14
+ it { expect { build(:json_unity_request, timezone: nil) }.to raise_error(ArgumentError) }
15
15
  end
16
16
 
17
17
  context 'when nil is given for appname' do
18
- it { expect { FactoryGirl.build(:json_unity_request, :appname => nil) }.to raise_error(ArgumentError) }
18
+ it { expect { build(:json_unity_request, appname: nil) }.to raise_error(ArgumentError) }
19
19
  end
20
20
 
21
21
  context 'when nil is given for security_token' do
22
- it { expect { FactoryGirl.build(:json_unity_request, :security_token => nil) }.to raise_error(ArgumentError) }
22
+ it { expect { build(:json_unity_request, security_token: nil) }.to raise_error(ArgumentError) }
23
23
  end
24
24
  end
25
25
 
26
26
  describe '#to_hash' do
27
27
  it ':userid maps to AppUserID' do
28
- subject.parameters = FactoryGirl.build(:magic_request, :userid => 'UserID')
28
+ subject.parameters = build(:magic_request, userid: 'UserID')
29
29
  expect(subject.to_hash['AppUserID']).to eq('UserID')
30
30
  end
31
31
 
32
32
  it ':data maps to Base64 encoded Data' do
33
- subject.parameters = FactoryGirl.build(:magic_request, :data => 'data')
33
+ subject.parameters = build(:magic_request, data: 'data')
34
34
  expect(subject.to_hash['Data']).to eq(['data'].pack('m'))
35
35
  end
36
36
  end
@@ -3,18 +3,18 @@ require 'spec_helper'
3
3
  describe 'JSONUnityResponse' do
4
4
  it_behaves_like 'a unity response'
5
5
 
6
- subject { FactoryGirl.build(:json_unity_response, :response => get_server_info) }
6
+ subject { build(:json_unity_response, response: get_server_info) }
7
7
 
8
- let(:get_server_info) { FixtureLoader.load_yaml("get_server_info_json.yml") }
9
- let(:get_providers) { FixtureLoader.load_yaml("get_providers_json.yml") }
8
+ let(:get_server_info) { FixtureLoader.load_yaml('get_server_info_json.yml') }
9
+ let(:get_providers) { FixtureLoader.load_yaml('get_providers_json.yml') }
10
10
 
11
11
  describe '#initialize' do
12
12
  context 'when nil is given for response' do
13
- it { expect { FactoryGirl.build(:json_unity_response, :response => nil) }.to raise_error(ArgumentError) }
13
+ it { expect { build(:json_unity_response, response: nil) }.to raise_error(ArgumentError) }
14
14
  end
15
15
 
16
16
  context 'when nil is given for timezone' do
17
- it { expect { FactoryGirl.build(:json_unity_response, :timezone => nil) }.to raise_error(ArgumentError) }
17
+ it { expect { build(:json_unity_response, timezone: nil) }.to raise_error(ArgumentError) }
18
18
  end
19
19
  end
20
20
 
@@ -28,7 +28,7 @@ describe 'JSONUnityResponse' do
28
28
  context 'when given empty response' do
29
29
  it 'returns []' do
30
30
  magic_response = get_providers
31
- magic_response[0]["getprovidersinfo"] = []
31
+ magic_response[0]['getprovidersinfo'] = []
32
32
  subject.response = magic_response
33
33
  expect(subject.to_hash).to eq([])
34
34
  end
@@ -5,82 +5,20 @@ describe 'SOAPClientDriver' do
5
5
  it_behaves_like 'a client driver'
6
6
 
7
7
  subject do
8
- client_driver = FactoryGirl.build(:soap_client_driver)
8
+ client_driver = build(:soap_client_driver, proxy: 'http://localhost:8888')
9
9
  client_driver.security_token = SecureRandom.uuid
10
10
  client_driver
11
11
  end
12
12
 
13
- let(:get_server_info) { FixtureLoader.load_file("get_server_info.xml") }
14
- let(:get_security_token) { FixtureLoader.load_file("get_security_token.xml") }
15
- let(:retire_security_token) { FixtureLoader.load_file("retire_security_token.xml") }
16
- let(:soap_fault) { FixtureLoader.load_file("soap_fault.xml") }
13
+ let(:get_server_info) { FixtureLoader.load_file('get_server_info.xml') }
14
+ let(:get_security_token) { FixtureLoader.load_file('get_security_token.xml') }
15
+ let(:retire_security_token) { FixtureLoader.load_file('retire_security_token.xml') }
16
+ let(:soap_fault) { FixtureLoader.load_file('soap_fault.xml') }
17
17
  let(:url) { Faker::Internet.url }
18
18
 
19
19
  before(:all) { savon.mock! }
20
20
  after(:all) { savon.unmock! }
21
21
 
22
- describe '#initialize' do
23
- context 'when nil is given for base_unity_url' do
24
- it { expect { FactoryGirl.build(:soap_client_driver, :base_unity_url => nil) }.to raise_error(ArgumentError) }
25
- end
26
-
27
- context 'when nil is given for username' do
28
- it { expect { FactoryGirl.build(:soap_client_driver, :username => nil) }.to raise_error(ArgumentError) }
29
- end
30
-
31
- context 'when nil is given for password' do
32
- it { expect { FactoryGirl.build(:soap_client_driver, :password => nil) }.to raise_error(ArgumentError) }
33
- end
34
-
35
- context 'when nil is given for appname' do
36
- it { expect { FactoryGirl.build(:soap_client_driver, :appname => nil) }.to raise_error(ArgumentError) }
37
- end
38
-
39
- context 'when given a base_unity_url with a trailing /' do
40
- it 'sets @base_unity_url without the trailing /' do
41
- client_driver = FactoryGirl.build(:soap_client_driver, :base_unity_url => "http://www.example.com/")
42
- expect(client_driver.base_unity_url).to eq("http://www.example.com")
43
- end
44
- end
45
-
46
- context 'when nil is given for timezone' do
47
- it 'sets @timezone to UTC' do
48
- client_driver = FactoryGirl.build(:soap_client_driver, :timezone => nil)
49
- utc_timezone = FactoryGirl.build(:timezone, :zone_identifier => "UTC")
50
- expect(client_driver.timezone.tzinfo).to eq(utc_timezone.tzinfo)
51
- end
52
- end
53
-
54
- context 'when nil is given for proxy' do
55
- it 'sets Savon proxy option to nil' do
56
- client_driver = FactoryGirl.build(:soap_client_driver, :proxy => nil)
57
- expect(client_driver.savon_client.globals.instance_variable_get("@options")[:proxy]).to be_nil
58
- end
59
- end
60
-
61
- context 'when proxy is given' do
62
- it 'sets Savon proxy option to the given url' do
63
- client_driver = FactoryGirl.build(:soap_client_driver, :proxy => url)
64
- expect(client_driver.savon_client.globals.instance_variable_get("@options")[:proxy]).to eq(url)
65
- end
66
- end
67
-
68
- context 'when nil is given for logger' do
69
- it 'sets @logger to Logger' do
70
- client_driver = FactoryGirl.build(:soap_client_driver, :logger => nil)
71
- expect(client_driver.logger).to be_instance_of(Logger)
72
- end
73
- end
74
-
75
- context 'when logger is set' do
76
- it 'sets @logger to logger' do
77
- logger = double("logger")
78
- client_driver = FactoryGirl.build(:soap_client_driver, :logger => logger)
79
- expect(client_driver.logger).to be(logger)
80
- end
81
- end
82
- end
83
-
84
22
  describe '#client_type' do
85
23
  it { expect(subject.client_type).to be(:soap) }
86
24
  end
@@ -93,31 +31,31 @@ describe 'SOAPClientDriver' do
93
31
  }
94
32
 
95
33
  it 'should send a SOAP request to Magic endpoint' do
96
- savon.expects("Magic").with(:message => :any).returns(get_server_info)
34
+ savon.expects('Magic').with(message: :any).returns(get_server_info)
97
35
  subject.magic
98
36
  end
99
37
 
100
38
  context 'when a Savon::SOAPFault is raised' do
101
39
  it 'should raise an APIError' do
102
- savon.expects("Magic").with(:message => :any).returns({ code: 500, headers: {}, body: soap_fault })
40
+ savon.expects('Magic').with(message: :any).returns({ code: 500, headers: {}, body: soap_fault })
103
41
  expect { subject.magic }.to raise_error(AllscriptsUnityClient::APIError)
104
42
  end
105
43
  end
106
44
 
107
45
  it 'should call start_timer' do
108
- savon.expects("Magic").with(:message => :any).returns(get_server_info)
46
+ savon.expects('Magic').with(message: :any).returns(get_server_info)
109
47
  subject.magic
110
48
  expect(subject).to have_received(:start_timer)
111
49
  end
112
50
 
113
51
  it 'should call end_timer' do
114
- savon.expects("Magic").with(:message => :any).returns(get_server_info)
52
+ savon.expects('Magic').with(message: :any).returns(get_server_info)
115
53
  subject.magic
116
54
  expect(subject).to have_received(:start_timer)
117
55
  end
118
56
 
119
57
  it 'should call log_magic' do
120
- savon.expects("Magic").with(:message => :any).returns(get_server_info)
58
+ savon.expects('Magic').with(message: :any).returns(get_server_info)
121
59
  subject.magic
122
60
  expect(subject).to have_received(:log_magic)
123
61
  end
@@ -131,31 +69,31 @@ describe 'SOAPClientDriver' do
131
69
  }
132
70
 
133
71
  it 'should send a SOAP request to GetSecurityToken endpoint' do
134
- savon.expects("GetSecurityToken").with(:message => :any).returns(get_security_token)
72
+ savon.expects('GetSecurityToken').with(message: :any).returns(get_security_token)
135
73
  subject.get_security_token!
136
74
  end
137
75
 
138
76
  context 'when a Savon::SOAPFault is raised' do
139
77
  it 'should raise an APIError' do
140
- savon.expects("GetSecurityToken").with(:message => :any).returns({ code: 500, headers: {}, body: soap_fault })
78
+ savon.expects('GetSecurityToken').with(message: :any).returns({ code: 500, headers: {}, body: soap_fault })
141
79
  expect { subject.get_security_token! }.to raise_error(AllscriptsUnityClient::APIError)
142
80
  end
143
81
  end
144
82
 
145
83
  it 'should call start_timer' do
146
- savon.expects("GetSecurityToken").with(:message => :any).returns(get_security_token)
84
+ savon.expects('GetSecurityToken').with(message: :any).returns(get_security_token)
147
85
  subject.get_security_token!
148
86
  expect(subject).to have_received(:start_timer)
149
87
  end
150
88
 
151
89
  it 'should call end_timer' do
152
- savon.expects("GetSecurityToken").with(:message => :any).returns(get_security_token)
90
+ savon.expects('GetSecurityToken').with(message: :any).returns(get_security_token)
153
91
  subject.get_security_token!
154
92
  expect(subject).to have_received(:start_timer)
155
93
  end
156
94
 
157
95
  it 'should call log_get_security_token' do
158
- savon.expects("GetSecurityToken").with(:message => :any).returns(get_security_token)
96
+ savon.expects('GetSecurityToken').with(message: :any).returns(get_security_token)
159
97
  subject.get_security_token!
160
98
  expect(subject).to have_received(:log_get_security_token)
161
99
  end
@@ -169,31 +107,31 @@ describe 'SOAPClientDriver' do
169
107
  }
170
108
 
171
109
  it 'should send a SOAP request to RetireSecurityToken endpoint' do
172
- savon.expects("RetireSecurityToken").with(:message => :any).returns(retire_security_token)
110
+ savon.expects('RetireSecurityToken').with(message: :any).returns(retire_security_token)
173
111
  subject.retire_security_token!
174
112
  end
175
113
 
176
114
  context 'when a Savon::SOAPFault is raised' do
177
115
  it 'should raise an APIError' do
178
- savon.expects("RetireSecurityToken").with(:message => :any).returns({ code: 500, headers: {}, body: soap_fault })
116
+ savon.expects('RetireSecurityToken').with(message: :any).returns({ code: 500, headers: {}, body: soap_fault })
179
117
  expect { subject.retire_security_token! }.to raise_error(AllscriptsUnityClient::APIError)
180
118
  end
181
119
  end
182
120
 
183
121
  it 'should call start_timer' do
184
- savon.expects("RetireSecurityToken").with(:message => :any).returns(retire_security_token)
122
+ savon.expects('RetireSecurityToken').with(message: :any).returns(retire_security_token)
185
123
  subject.retire_security_token!
186
124
  expect(subject).to have_received(:start_timer)
187
125
  end
188
126
 
189
127
  it 'should call end_timer' do
190
- savon.expects("RetireSecurityToken").with(:message => :any).returns(retire_security_token)
128
+ savon.expects('RetireSecurityToken').with(message: :any).returns(retire_security_token)
191
129
  subject.retire_security_token!
192
130
  expect(subject).to have_received(:start_timer)
193
131
  end
194
132
 
195
133
  it 'should call log_retire_security_token' do
196
- savon.expects("RetireSecurityToken").with(:message => :any).returns(retire_security_token)
134
+ savon.expects('RetireSecurityToken').with(message: :any).returns(retire_security_token)
197
135
  subject.retire_security_token!
198
136
  expect(subject).to have_received(:log_retire_security_token)
199
137
  end
data/spec/spec_helper.rb CHANGED
@@ -10,14 +10,9 @@ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
10
10
  SimpleCov.start do
11
11
  add_filter do |source_file|
12
12
  filename = Pathname.new(source_file.filename).basename
13
- ignored_files = [
14
- "version.rb",
15
- "allscripts_unity_client.gemspec",
16
- "Gemfile",
17
- "Rakefile"
18
- ]
19
-
20
- ignored_files.include?(filename) || source_file.filename.include?("spec/")
13
+ ignored_files = %w(version.rb allscripts_unity_client.gemspec Gemfile Rakefile)
14
+
15
+ ignored_files.include?(filename) || source_file.filename.include?('spec/')
21
16
  end
22
17
  end
23
18
 
@@ -35,10 +30,11 @@ require 'factory_girl'
35
30
  require 'json'
36
31
 
37
32
  # Include all support files
38
- Dir["./spec/support/**/*.rb"].sort.each { |f| require f }
33
+ Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
39
34
 
40
35
  # Include all factories
41
36
  FactoryGirl.find_definitions
42
37
 
43
38
  RSpec.configure do |config|
39
+ config.include FactoryGirl::Syntax::Methods
44
40
  end
@@ -3,35 +3,19 @@ shared_examples 'a client driver' do
3
3
  context 'when @security_token is nil' do
4
4
  it do
5
5
  subject.security_token = nil
6
- expect(subject.security_token?).to be_false
6
+ expect(subject.security_token?).to be_falsey
7
7
  end
8
8
  end
9
9
 
10
10
  context 'when @security_token is not nil' do
11
11
  it do
12
- subject.security_token = "security token"
13
- expect(subject.security_token?).to be_true
12
+ subject.security_token = 'security token'
13
+ expect(subject.security_token?).to be_truthy
14
14
  end
15
15
  end
16
16
  end
17
17
 
18
- describe "#log?" do
19
- context 'when log is false' do
20
- it 'return false' do
21
- subject.log = false
22
- expect(subject.log).to be_false
23
- end
24
- end
25
-
26
- context 'when log is true' do
27
- it 'return false' do
28
- subject.log = true
29
- expect(subject.log).to be_true
30
- end
31
- end
32
- end
33
-
34
- describe "#log_get_security_token" do
18
+ describe '#log_get_security_token' do
35
19
  it 'should call log_info' do
36
20
  allow(subject).to receive(:log_info)
37
21
  subject.send(:log_get_security_token)
@@ -39,7 +23,7 @@ shared_examples 'a client driver' do
39
23
  end
40
24
  end
41
25
 
42
- describe "#log_retire_security_token" do
26
+ describe '#log_retire_security_token' do
43
27
  it 'should call log_info' do
44
28
  allow(subject).to receive(:log_info)
45
29
  subject.send(:log_retire_security_token)
@@ -47,10 +31,10 @@ shared_examples 'a client driver' do
47
31
  end
48
32
  end
49
33
 
50
- describe "#log_magic" do
34
+ describe '#log_magic' do
51
35
  it 'should call log_info' do
52
36
  allow(subject).to receive(:log_info)
53
- subject.send(:log_magic, double(:parameters => { :action => "action" }))
37
+ subject.send(:log_magic, double(parameters: { action: 'action'}))
54
38
  expect(subject).to have_received(:log_info)
55
39
  end
56
40
 
@@ -60,58 +44,53 @@ shared_examples 'a client driver' do
60
44
  end
61
45
 
62
46
  describe '#log_info' do
63
- context 'when log? is true' do
64
- it 'should call @logger.info' do
65
- subject.log = true
66
- allow(subject.logger).to receive(:info)
67
- subject.send(:log_info, "test")
68
- expect(subject.logger).to have_received(:info)
47
+ context 'when @options.logger? is true' do
48
+ it 'should call @options.logger.info' do
49
+ subject.options.logger = double('logger', info: true)
50
+ subject.send(:log_info, 'test')
51
+ expect(subject.options.logger).to have_received(:info)
69
52
  end
70
53
  end
71
54
 
72
- context 'when log? is false' do
73
- it 'should not call @logger.info' do
74
- subject.log = false
75
- allow(subject.logger).to receive(:info)
76
- subject.send(:log_info, "test")
77
- expect(subject.logger).to_not have_received(:info)
55
+ context 'when @options.logger? is false' do
56
+ it 'should not call @options.logger.info' do
57
+ allow_message_expectations_on_nil
58
+ subject.options.logger = nil
59
+ allow(subject.options.logger).to receive(:info)
60
+ subject.send(:log_info, 'test')
61
+ expect(subject.options.logger).not_to have_received(:info)
78
62
  end
79
63
  end
80
64
 
81
65
  context 'when given nil for message' do
82
- it 'should not call @logger.info' do
83
- subject.log = true
84
- allow(subject.logger).to receive(:info)
66
+ it 'should not call @options.logger.info' do
67
+ subject.options.logger = double('logger', info: true)
85
68
  subject.send(:log_info, nil)
86
- expect(subject.logger).to_not have_received(:info)
69
+ expect(subject.options.logger).not_to have_received(:info)
87
70
  end
88
71
  end
89
72
 
90
- context 'when @logger is nil and log is true' do
73
+ context 'when @options.logger? is false' do
91
74
  it 'should not call @logger.info' do
92
- subject.log = true
93
- subject.logger = nil
94
- expect { subject.send(:log_info, "test") }.to_not raise_error
75
+ expect { subject.send(:log_info, 'test') }.not_to raise_error
95
76
  end
96
77
  end
97
78
 
98
- context 'when @timer is nil and log is true' do
79
+ context 'when @timer is nil and @options.logger is true' do
99
80
  it 'should not include seconds in the log' do
100
- subject.log = true
101
- subject.instance_variable_set("@timer", nil)
102
- allow(subject.logger).to receive(:info)
103
- subject.send(:log_info, "test")
104
- expect(subject.logger).to_not have_received(:info).with(match(/seconds/))
81
+ subject.options.logger = double('logger', info: true)
82
+ subject.instance_variable_set('@timer', nil)
83
+ subject.send(:log_info, 'test')
84
+ expect(subject.options.logger).not_to have_received(:info).with(match(/seconds/))
105
85
  end
106
86
  end
107
87
 
108
- context 'when @timer is not nil and log is true' do
88
+ context 'when @timer is not nil and @options.logger? is true' do
109
89
  it 'should include seconds in log' do
110
- subject.log = true
111
- subject.instance_variable_set("@timer", 1.2)
112
- allow(subject.logger).to receive(:info)
113
- subject.send(:log_info, "test")
114
- expect(subject.logger).to have_received(:info).with(match(/seconds/))
90
+ subject.options.logger = double('logger', info: true)
91
+ subject.instance_variable_set('@timer', 1.2)
92
+ subject.send(:log_info, 'test')
93
+ expect(subject.options.logger).to have_received(:info).with(match(/seconds/))
115
94
  end
116
95
  end
117
96
  end
@@ -119,7 +98,7 @@ shared_examples 'a client driver' do
119
98
  describe '#start_timer' do
120
99
  it 'sets @start_time' do
121
100
  subject.send(:start_timer)
122
- expect(subject.instance_variable_get("@start_time")).to_not be_nil
101
+ expect(subject.instance_variable_get('@start_time')).not_to be_nil
123
102
  end
124
103
  end
125
104
 
@@ -127,13 +106,13 @@ shared_examples 'a client driver' do
127
106
  it 'sets @end_time' do
128
107
  subject.send(:start_timer)
129
108
  subject.send(:end_timer)
130
- expect(subject.instance_variable_get("@end_time")).to_not be_nil
109
+ expect(subject.instance_variable_get('@end_time')).not_to be_nil
131
110
  end
132
111
 
133
112
  it 'sets @timer to @end_time - @start_time' do
134
113
  subject.send(:start_timer)
135
114
  subject.send(:end_timer)
136
- expect(subject.instance_variable_get("@timer")).to eq(subject.instance_variable_get("@end_time") - subject.instance_variable_get("@start_time"))
115
+ expect(subject.instance_variable_get('@timer')).to eq(subject.instance_variable_get('@end_time') - subject.instance_variable_get('@start_time'))
137
116
  end
138
117
  end
139
118
  end