usps-imis-api 1.0.0.pre.rc.3 → 1.0.0.pre.rc.5

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.
@@ -20,7 +20,7 @@ module Usps
20
20
  # @param ordinal [Integer] The ordinal identifier for the desired object
21
21
  #
22
22
  def get(ordinal)
23
- api.get(business_object, url_id: "~#{api.imis_id}|#{ordinal}")
23
+ api.business_object(business_object, url_id: "~#{api.imis_id}|#{ordinal}").get
24
24
  end
25
25
 
26
26
  # Create a new object in the Panel
@@ -28,7 +28,7 @@ module Usps
28
28
  # @param data [Hash] The record data for the desired object
29
29
  #
30
30
  def create(data)
31
- api.post(business_object, payload(data), url_id: '')
31
+ api.business_object(business_object, url_id: '').post(payload(data))
32
32
  end
33
33
 
34
34
  # Update an existing object in the Panel
@@ -37,7 +37,9 @@ module Usps
37
37
  # +ordinal+ identifier
38
38
  #
39
39
  def update(data)
40
- api.put(business_object, payload(data), url_id: "~#{api.imis_id}|#{data[:ordinal]}")
40
+ api
41
+ .business_object(business_object, url_id: "~#{api.imis_id}|#{data[:ordinal]}")
42
+ .put(payload(data))
41
43
  end
42
44
 
43
45
  # Remove a specific object from the Panel
@@ -45,7 +47,7 @@ module Usps
45
47
  # @param ordinal [Integer] The ordinal identifier for the desired object
46
48
  #
47
49
  def destroy(ordinal)
48
- api.delete(business_object, url_id: "~#{api.imis_id}|#{ordinal}")
50
+ api.business_object(business_object, url_id: "~#{api.imis_id}|#{ordinal}").delete
49
51
  end
50
52
 
51
53
  private
@@ -57,6 +59,42 @@ module Usps
57
59
  def payload(_data)
58
60
  raise Error::ApiError, "#{self.class.name} must implement #payload(data)"
59
61
  end
62
+
63
+ def payload_header(data)
64
+ {
65
+ '$type' => 'Asi.Soa.Core.DataContracts.GenericEntityData, Asi.Contracts',
66
+ 'EntityTypeName' => business_object,
67
+ 'PrimaryParentEntityTypeName' => 'Party',
68
+ 'Identity' => identity(data[:ordinal]),
69
+ 'PrimaryParentIdentity' => primary_parent_identity
70
+ }
71
+ end
72
+
73
+ def identity(ordinal = nil)
74
+ {
75
+ '$type' => 'Asi.Soa.Core.DataContracts.IdentityData, Asi.Contracts',
76
+ 'EntityTypeName' => business_object,
77
+ 'IdentityElements' => {
78
+ '$type' => identity_type,
79
+ '$values' => [api.imis_id, ordinal&.to_s].compact
80
+ }
81
+ }
82
+ end
83
+
84
+ def primary_parent_identity
85
+ {
86
+ '$type' => 'Asi.Soa.Core.DataContracts.IdentityData, Asi.Contracts',
87
+ 'EntityTypeName' => 'Party',
88
+ 'IdentityElements' => {
89
+ '$type' => identity_type,
90
+ '$values' => [api.imis_id]
91
+ }
92
+ }
93
+ end
94
+
95
+ def identity_type = 'System.Collections.ObjectModel.Collection`1[[System.String, mscorlib]], mscorlib'
96
+
97
+ def build_payload(data, &) = payload_header(data).merge(PanelProperties.build(&))
60
98
  end
61
99
  end
62
100
  end
@@ -12,101 +12,21 @@ module Usps
12
12
  'ABC_ASC_Educ'
13
13
  end
14
14
 
15
- # rubocop:disable Metrics/MethodLength
16
15
  def payload(data)
17
- identity_type =
18
- 'System.Collections.ObjectModel.Collection`1[[System.String, mscorlib]], mscorlib'
19
-
20
- {
21
- '$type' => 'Asi.Soa.Core.DataContracts.GenericEntityData, Asi.Contracts',
22
- 'EntityTypeName' => 'ABC_ASC_EDUC',
23
- 'PrimaryParentEntityTypeName' => 'Party',
24
- 'Identity' => {
25
- '$type' => 'Asi.Soa.Core.DataContracts.IdentityData, Asi.Contracts',
26
- 'EntityTypeName' => 'ABC_ASC_EDUC',
27
- 'IdentityElements' => {
28
- '$type' => identity_type,
29
- '$values' => [api.imis_id, data[:ordinal]&.to_s].compact
30
- }
31
- },
32
- 'PrimaryParentIdentity' => {
33
- '$type' => 'Asi.Soa.Core.DataContracts.IdentityData, Asi.Contracts',
34
- 'EntityTypeName' => 'Party',
35
- 'IdentityElements' => {
36
- '$type' => identity_type,
37
- '$values' => [api.imis_id]
38
- }
39
- },
40
- 'Properties' => {
41
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyDataCollection, Asi.Contracts',
42
- '$values' => [
43
- {
44
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
45
- 'Name' => 'ID',
46
- 'Value' => api.imis_id
47
- },
48
- (
49
- if data[:ordinal]
50
- {
51
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
52
- 'Name' => 'Ordinal',
53
- 'Value' => {
54
- '$type' => 'System.Int32',
55
- '$value' => data[:ordinal]
56
- }
57
- }
58
- end
59
- ),
60
- {
61
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
62
- 'Name' => 'ABC_EDUC_THRU_DATE',
63
- 'Value' => data[:thru_date] || '0001-01-01T00:00:00'
64
- },
65
- {
66
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
67
- 'Name' => 'ABC_ECertificate',
68
- 'Value' => data[:certificate]
69
- },
70
- {
71
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
72
- 'Name' => 'ABC_Educ_Description',
73
- 'Value' => data[:description]
74
- },
75
- {
76
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
77
- 'Name' => 'ABC_Educ_Effective_Date',
78
- 'Value' => data[:effective_date]
79
- },
80
- {
81
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
82
- 'Name' => 'ABC_Educ_Source_System',
83
- 'Value' => data[:source]
84
- },
85
- {
86
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
87
- 'Name' => 'ABC_Educ_Transaction_Date',
88
- 'Value' => Time.now.strftime('%Y-%m-%dT%H:%I:%S')
89
- },
90
- {
91
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
92
- 'Name' => 'ABC_Other_Code',
93
- 'Value' => data[:code]
94
- },
95
- {
96
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
97
- 'Name' => 'ABC_Product_Code',
98
- 'Value' => data[:type_code]
99
- },
100
- {
101
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
102
- 'Name' => 'ABC_TYPE',
103
- 'Value' => data[:abc_type_code] || 'EDUC'
104
- }
105
- ].compact
106
- }
107
- }
16
+ build_payload(data) do |props|
17
+ props.add 'ID', api.imis_id
18
+ props.add 'Ordinal', data[:ordinal] if data[:ordinal]
19
+ props.add 'ABC_EDUC_THRU_DATE', data[:thru_date] || '0001-01-01T00:00:00'
20
+ props.add 'ABC_ECertificate', data[:certificate]
21
+ props.add 'ABC_Educ_Description', data[:description]
22
+ props.add 'ABC_Educ_Effective_Date', data[:effective_date]
23
+ props.add 'ABC_Educ_Source_System', data[:source]
24
+ props.add 'ABC_Educ_Transaction_Date', Time.now
25
+ props.add 'ABC_Other_Code', data[:code]
26
+ props.add 'ABC_Product_Code', data[:type_code]
27
+ props.add 'ABC_TYPE', data[:abc_type_code] || 'EDUC'
28
+ end
108
29
  end
109
- # rubocop:enable Metrics/MethodLength
110
30
  end
111
31
  end
112
32
  end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Usps
4
+ module Imis
5
+ module Panel
6
+ # Constructor for the Properties field for Panel requests
7
+ #
8
+ class PanelProperties
9
+ # Build a new Properties field
10
+ #
11
+ def self.build(&) = new.build(&)
12
+
13
+ # Build the Properties field
14
+ #
15
+ def build
16
+ yield(self)
17
+
18
+ {
19
+ 'Properties' => {
20
+ '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyDataCollection, Asi.Contracts',
21
+ '$values' => @properties
22
+ }
23
+ }
24
+ end
25
+
26
+ # Add an individual property to the field
27
+ #
28
+ def add(name, value)
29
+ @properties ||= []
30
+ @properties << {
31
+ '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
32
+ 'Name' => name,
33
+ 'Value' => property_value(value)
34
+ }
35
+ end
36
+
37
+ private
38
+
39
+ def property_value(value)
40
+ case value
41
+ when String then value
42
+ when Time, DateTime then value.strftime('%Y-%m-%dT%H:%I:%S')
43
+ when Integer then { '$type' => 'System.Int32', '$value' => value }
44
+ when true, false then { '$type' => 'System.Boolean', '$value' => value }
45
+ else
46
+ raise Error::ApiError, "Unexpected property type: #{value.inspect}"
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -12,99 +12,20 @@ module Usps
12
12
  'ABC_ASC_Vessel_Safety_Checks'
13
13
  end
14
14
 
15
- # rubocop:disable Metrics/MethodLength
16
15
  def payload(data)
17
- identity_type =
18
- 'System.Collections.ObjectModel.Collection`1[[System.String, mscorlib]], mscorlib'
19
-
20
- {
21
- '$type' => 'Asi.Soa.Core.DataContracts.GenericEntityData, Asi.Contracts',
22
- 'EntityTypeName' => 'ABC_ASC_Vessel_Safety_Checks',
23
- 'PrimaryParentEntityTypeName' => 'Party',
24
- 'Identity' => {
25
- '$type' => 'Asi.Soa.Core.DataContracts.IdentityData, Asi.Contracts',
26
- 'EntityTypeName' => 'ABC_ASC_Vessel_Safety_Checks',
27
- 'IdentityElements' => {
28
- '$type' => identity_type,
29
- '$values' => [api.imis_id, data[:ordinal]&.to_s].compact
30
- }
31
- },
32
- 'PrimaryParentIdentity' => {
33
- '$type' => 'Asi.Soa.Core.DataContracts.IdentityData, Asi.Contracts',
34
- 'EntityTypeName' => 'Party',
35
- 'IdentityElements' => {
36
- '$type' => identity_type,
37
- '$values' => [api.imis_id]
38
- }
39
- },
40
- 'Properties' => {
41
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyDataCollection, Asi.Contracts',
42
- '$values' => [
43
- {
44
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
45
- 'Name' => 'ID',
46
- 'Value' => api.imis_id
47
- },
48
- (
49
- if data[:ordinal]
50
- {
51
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
52
- 'Name' => 'Ordinal',
53
- 'Value' => {
54
- '$type' => 'System.Int32',
55
- '$value' => data[:ordinal]
56
- }
57
- }
58
- end
59
- ),
60
- {
61
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
62
- 'Name' => 'Source_System',
63
- 'Value' => 'Manual ITCom Entry'
64
- },
65
- {
66
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
67
- 'Name' => 'ABC_ECertificate',
68
- 'Value' => data[:certificate]
69
- },
70
- {
71
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
72
- 'Name' => 'Activity_Type',
73
- 'Value' => 'VSC'
74
- },
75
- {
76
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
77
- 'Name' => 'Description',
78
- 'Value' => 'Vessel Safety Checks'
79
- },
80
- {
81
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
82
- 'Name' => 'Effective_Date',
83
- 'Value' => "#{data[:year]}-12-01T00:00:00"
84
- },
85
- {
86
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
87
- 'Name' => 'Quantity',
88
- 'Value' => {
89
- '$type' => 'System.Int32',
90
- '$value' => data[:count]
91
- }
92
- },
93
- {
94
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
95
- 'Name' => 'Thru_Date',
96
- 'Value' => "#{data[:year]}-12-31T00:00:00"
97
- },
98
- {
99
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
100
- 'Name' => 'Transaction_Date',
101
- 'Value' => Time.now.strftime('%Y-%m-%dT%H:%M:%S')
102
- }
103
- ].compact
104
- }
105
- }
16
+ build_payload(data) do |props|
17
+ props.add 'ID', api.imis_id
18
+ props.add 'Ordinal', data[:ordinal] if data[:ordinal]
19
+ props.add 'Source_System', 'Manual ITCom Entry'
20
+ props.add 'ABC_ECertificate', data[:certificate]
21
+ props.add 'Activity_Type', 'VSC'
22
+ props.add 'Description', 'Vessel Safety Checks'
23
+ props.add 'Effective_Date', "#{data[:year]}-12-01T00:00:00"
24
+ props.add 'Quantity', data[:count]
25
+ props.add 'Thru_Date', "#{data[:year]}-12-31T00:00:00"
26
+ props.add 'Transaction_Date', Time.now
27
+ end
106
28
  end
107
- # rubocop:enable Metrics/MethodLength
108
29
  end
109
30
  end
110
31
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Usps
4
+ module Imis
5
+ # @private
6
+ #
7
+ module Requests
8
+ private
9
+
10
+ def client(uri)
11
+ Net::HTTP.new(uri.host, uri.port).tap do |http|
12
+ http.use_ssl = true
13
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
14
+ end
15
+ end
16
+
17
+ # Authorize a request prior to submitting
18
+ #
19
+ # If the current token is missing/expired, request a new one
20
+ #
21
+ def authorize(request)
22
+ authenticate if token_expiration < Time.now
23
+ request.tap { |r| r.add_field('Authorization', "Bearer #{token}") }
24
+ end
25
+
26
+ def submit(uri, request)
27
+ client(uri).request(request).tap do |result|
28
+ raise Error::ResponseError.from(result) unless result.is_a?(Net::HTTPSuccess)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Usps
4
4
  module Imis
5
- VERSION = '1.0.0-rc.3'
5
+ VERSION = '1.0.0-rc.5'
6
6
  end
7
7
  end
data/lib/usps/imis.rb CHANGED
@@ -6,6 +6,8 @@ require 'json'
6
6
  require 'time'
7
7
  require 'cgi'
8
8
 
9
+ require 'active_support/string_inquirer'
10
+
9
11
  # Extensions
10
12
  # :nocov:
11
13
  require 'ext/hash' unless defined?(Rails)
@@ -16,9 +18,12 @@ require_relative 'imis/config'
16
18
  require_relative 'imis/error/api_error'
17
19
  require_relative 'imis/error/mapper_error'
18
20
  require_relative 'imis/error/response_error'
21
+ require_relative 'imis/requests'
22
+ require_relative 'imis/business_object'
19
23
  require_relative 'imis/api'
20
24
  require_relative 'imis/mapper'
21
25
  require_relative 'imis/panel/base_panel'
26
+ require_relative 'imis/panel/panel_properties'
22
27
  require_relative 'imis/panel/vsc'
23
28
  require_relative 'imis/panel/education'
24
29
 
@@ -41,7 +41,9 @@ describe Usps::Imis::Api do
41
41
  before { api.imis_id = 31092 }
42
42
 
43
43
  it 'sends an update' do
44
- expect(api.put_fields('ABC_ASC_Individual_Demog', { 'TotMMS' => 15 })).to be_a(Hash)
44
+ expect(api.business_object('ABC_ASC_Individual_Demog').put_fields('TotMMS' => 15)).to(
45
+ be_a(Hash)
46
+ )
45
47
  end
46
48
 
47
49
  context 'when receiving a response error' do
@@ -61,8 +63,8 @@ describe Usps::Imis::Api do
61
63
  end
62
64
 
63
65
  it 'wraps the error' do
64
- expect { api.put_fields('ABC_ASC_Individual_Demog', { 'TotMMS' => 15 }) }.to raise_error(
65
- Usps::Imis::Error::ApiError, warning_text
66
+ expect { api.business_object('ABC_ASC_Individual_Demog').put_fields('TotMMS' => 15) }.to(
67
+ raise_error(Usps::Imis::Error::ApiError, warning_text)
66
68
  )
67
69
  end
68
70
  end
@@ -71,7 +73,7 @@ describe Usps::Imis::Api do
71
73
  describe '#with' do
72
74
  it 'sends an update from put' do
73
75
  expect(
74
- api.with(31092) { put_fields('ABC_ASC_Individual_Demog', { 'TotMMS' => 15 }) }
76
+ api.with(31092) { business_object('ABC_ASC_Individual_Demog').put_fields('TotMMS' => 15) }
75
77
  ).to be_a(Hash)
76
78
  end
77
79
 
@@ -96,6 +98,39 @@ describe Usps::Imis::Api do
96
98
  end
97
99
  end
98
100
 
101
+ describe '#on' do
102
+ it 'returns a BusinessObject without a block' do
103
+ expect(api.on('ABC_ASC_Individual_Demog')).to be_a(Usps::Imis::BusinessObject)
104
+ end
105
+
106
+ it 'sends an update from put', :aggregate_failures do
107
+ result = api.with(31092) do
108
+ on('ABC_ASC_Individual_Demog') { put_fields({ 'TotMMS' => 15 }) }
109
+ end
110
+
111
+ expect(result).to be_a(Hash)
112
+ expect(api.imis_id).to be_nil
113
+ end
114
+
115
+ it 'chains .with().on() to a single block', :aggregate_failures do
116
+ result = api.with(31092).on('ABC_ASC_Individual_Demog') do
117
+ put_fields({ 'TotMMS' => 15 })
118
+ end
119
+
120
+ expect(result).to be_a(Hash)
121
+ expect(api.imis_id).to eq('31092')
122
+ end
123
+
124
+ it 'nests on and with', :aggregate_failures do
125
+ result = api.on('ABC_ASC_Individual_Demog') do |object|
126
+ api.with(31092) { object.put_fields({ 'TotMMS' => 15 }) }
127
+ end
128
+
129
+ expect(result).to be_a(Hash)
130
+ expect(api.imis_id).to be_nil
131
+ end
132
+ end
133
+
99
134
  describe '#inspect' do
100
135
  it 'is configured to exclude the token instance variable' do
101
136
  expect(api.instance_variables_to_inspect).not_to include(:@token)
@@ -120,36 +155,4 @@ describe Usps::Imis::Api do
120
155
  expect(api).to have_received(:authenticate)
121
156
  end
122
157
  end
123
-
124
- describe '#filter_fields' do
125
- let(:expected) do
126
- {
127
- 'Properties' => {
128
- '$values' => [
129
- { 'Name' => 'Stub iMIS ID', 'Value' => { '$value' => '31092' } },
130
- { 'Name' => 'Stub Integer', 'Value' => { '$value' => 43 } },
131
- { 'Name' => 'Stub String', 'Value' => 'other' }
132
- ]
133
- }
134
- }
135
- end
136
-
137
- before do
138
- allow(api).to receive(:get).and_return({
139
- 'Properties' => {
140
- '$values' => [
141
- { 'Name' => 'Stub iMIS ID', 'Value' => { '$value' => '31092' } },
142
- { 'Name' => 'Stub Integer', 'Value' => { '$value' => 42 } },
143
- { 'Name' => 'Stub String', 'Value' => 'something' }
144
- ]
145
- }
146
- })
147
- end
148
-
149
- it 'formats fields correctly' do
150
- updated = api.send(:filter_fields, 'Stub', { 'Stub Integer' => 43, 'Stub String' => 'other' })
151
-
152
- expect(updated).to eq(expected)
153
- end
154
- end
155
158
  end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Usps::Imis::BusinessObject do
6
+ let(:business_object) { described_class.new(api, 'Stub') }
7
+ let(:api) { Usps::Imis::Api.new }
8
+
9
+ let(:expected) do
10
+ {
11
+ 'Properties' => {
12
+ '$values' => [
13
+ { 'Name' => 'Stub iMIS ID', 'Value' => { '$value' => '31092' } },
14
+ { 'Name' => 'Stub Integer', 'Value' => { '$value' => 43 } },
15
+ { 'Name' => 'Stub String', 'Value' => 'other' }
16
+ ]
17
+ }
18
+ }
19
+ end
20
+
21
+ before do
22
+ allow(business_object).to receive(:get).and_return({
23
+ 'Properties' => {
24
+ '$values' => [
25
+ { 'Name' => 'Stub iMIS ID', 'Value' => { '$value' => '31092' } },
26
+ { 'Name' => 'Stub Integer', 'Value' => { '$value' => 42 } },
27
+ { 'Name' => 'Stub String', 'Value' => 'something' }
28
+ ]
29
+ }
30
+ })
31
+ end
32
+
33
+ describe '#get_field' do
34
+ it 'returns a string value' do
35
+ expect(business_object.get_field('Stub String')).to eq('something')
36
+ end
37
+
38
+ it 'returns an integer value' do
39
+ expect(business_object.get_field('Stub Integer')).to eq(42)
40
+ end
41
+ end
42
+
43
+ describe '#filter_fields' do
44
+ it 'formats fields correctly' do
45
+ updated = business_object.send(:filter_fields, 'Stub Integer' => 43, 'Stub String' => 'other')
46
+
47
+ expect(updated).to eq(expected)
48
+ end
49
+ end
50
+ end
@@ -5,10 +5,36 @@ require 'spec_helper'
5
5
  describe Usps::Imis::Config do
6
6
  let(:config) { described_class.new }
7
7
 
8
- it 'sets values on initialize' do
9
- config = described_class.new { |c| c.environment = 'test' }
8
+ describe 'environment' do
9
+ subject { config.environment }
10
10
 
11
- expect(config.environment).to eq('test')
11
+ let(:config) { described_class.new }
12
+
13
+ context 'when not specified' do
14
+ it { is_expected.to be_development }
15
+ end
16
+
17
+ context 'when specified' do
18
+ before { config.environment = 'something' }
19
+
20
+ it { is_expected.to be_something }
21
+ end
22
+
23
+ context 'when specified on initialize' do
24
+ subject { config.environment }
25
+
26
+ let(:config) do
27
+ described_class.new { |c| c.environment = 'test' }
28
+ end
29
+
30
+ it { is_expected.to be_test }
31
+ end
32
+
33
+ context 'when in Rails' do
34
+ before { stub_const('Rails', Struct.new(:env).new(ActiveSupport::StringInquirer.new('qa'))) }
35
+
36
+ it { is_expected.to be_qa }
37
+ end
12
38
  end
13
39
 
14
40
  describe '#hostname' do
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Usps::Imis::Panel::PanelProperties do
6
+ let(:builder) { described_class.new }
7
+
8
+ it 'handles boolean property values' do
9
+ expect(builder.send(:property_value, true)).to eq(
10
+ '$type' => 'System.Boolean', '$value' => true
11
+ )
12
+ end
13
+
14
+ it 'raises an error for unexpected property types' do
15
+ expect { builder.send(:property_value, {}) }.to raise_error(
16
+ Usps::Imis::Error::ApiError, 'Unexpected property type: {}'
17
+ )
18
+ end
19
+ end
data/spec/spec_helper.rb CHANGED
@@ -7,6 +7,7 @@ SimpleCov.minimum_coverage(line: 100, branch: 100)
7
7
 
8
8
  require 'dotenv/load'
9
9
  require 'usps/imis'
10
+ require 'active_support/string_inquirer'
10
11
 
11
12
  ENV['TESTING'] = 'true'
12
13
 
@@ -15,4 +15,6 @@ Gem::Specification.new do |s|
15
15
  s.metadata['rubygems_mfa_required'] = 'true'
16
16
 
17
17
  s.required_ruby_version = '>= 3.4'
18
+
19
+ s.add_dependency 'activesupport', '~> 8.0'
18
20
  end