bigcommerce 1.0.0.beta → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +115 -39
  3. data/bigcommerce.gemspec +12 -13
  4. data/lib/bigcommerce.rb +5 -34
  5. data/lib/bigcommerce/config.rb +14 -0
  6. data/lib/bigcommerce/connection.rb +26 -0
  7. data/lib/bigcommerce/exception.rb +25 -18
  8. data/lib/bigcommerce/request.rb +8 -9
  9. data/lib/bigcommerce/resource_actions.rb +11 -11
  10. data/lib/bigcommerce/resources/content/blog_post.rb +3 -5
  11. data/lib/bigcommerce/resources/content/blog_tag.rb +2 -3
  12. data/lib/bigcommerce/resources/content/redirect.rb +2 -2
  13. data/lib/bigcommerce/resources/customers/customer.rb +22 -2
  14. data/lib/bigcommerce/resources/customers/customer_address.rb +5 -5
  15. data/lib/bigcommerce/resources/customers/customer_group.rb +2 -2
  16. data/lib/bigcommerce/resources/geography/country.rb +4 -3
  17. data/lib/bigcommerce/resources/geography/state.rb +6 -5
  18. data/lib/bigcommerce/resources/marketing/banner.rb +21 -0
  19. data/lib/bigcommerce/resources/marketing/coupon.rb +2 -2
  20. data/lib/bigcommerce/resources/marketing/gift_certificates.rb +25 -0
  21. data/lib/bigcommerce/resources/orders/order.rb +46 -44
  22. data/lib/bigcommerce/resources/orders/order_coupon.rb +5 -5
  23. data/lib/bigcommerce/resources/orders/order_message.rb +8 -7
  24. data/lib/bigcommerce/resources/orders/order_product.rb +37 -36
  25. data/lib/bigcommerce/resources/orders/order_shipping_address.rb +24 -23
  26. data/lib/bigcommerce/resources/orders/order_status.rb +2 -1
  27. data/lib/bigcommerce/resources/orders/order_tax.rb +8 -7
  28. data/lib/bigcommerce/resources/orders/shipment.rb +11 -10
  29. data/lib/bigcommerce/resources/products/brand.rb +2 -2
  30. data/lib/bigcommerce/resources/products/bulk_pricing_rule.rb +6 -5
  31. data/lib/bigcommerce/resources/products/category.rb +2 -2
  32. data/lib/bigcommerce/resources/products/configurable_field.rb +6 -5
  33. data/lib/bigcommerce/resources/products/custom_field.rb +6 -5
  34. data/lib/bigcommerce/resources/products/google_product_search_mapping.rb +9 -8
  35. data/lib/bigcommerce/resources/products/option.rb +2 -2
  36. data/lib/bigcommerce/resources/products/option_set.rb +2 -2
  37. data/lib/bigcommerce/resources/products/option_set_option.rb +2 -1
  38. data/lib/bigcommerce/resources/products/option_value.rb +1 -0
  39. data/lib/bigcommerce/resources/products/product.rb +61 -61
  40. data/lib/bigcommerce/resources/products/product_image.rb +4 -4
  41. data/lib/bigcommerce/resources/products/product_option.rb +2 -1
  42. data/lib/bigcommerce/resources/products/product_review.rb +1 -5
  43. data/lib/bigcommerce/resources/products/product_rule.rb +4 -4
  44. data/lib/bigcommerce/resources/products/product_video.rb +4 -4
  45. data/lib/bigcommerce/resources/products/sku.rb +15 -9
  46. data/lib/bigcommerce/resources/shipping/shipping_method.rb +2 -1
  47. data/lib/bigcommerce/resources/store/store_information.rb +18 -14
  48. data/lib/bigcommerce/resources/system/time.rb +2 -2
  49. data/lib/bigcommerce/resources/tax/tax_class.rb +2 -1
  50. data/lib/bigcommerce/resources/webhooks/webhook.rb +2 -1
  51. data/lib/bigcommerce/subresource_actions.rb +14 -14
  52. data/lib/bigcommerce/version.rb +1 -1
  53. metadata +47 -166
  54. data/.gitignore +0 -17
  55. data/.rspec +0 -2
  56. data/.rubocop.yml +0 -620
  57. data/.travis.yml +0 -15
  58. data/CHANGELOG.md +0 -11
  59. data/CONTRIBUTING.md +0 -119
  60. data/DEPENDENCIES.md +0 -7
  61. data/Gemfile +0 -15
  62. data/Guardfile +0 -22
  63. data/LICENSE +0 -20
  64. data/RELEASING.md +0 -64
  65. data/Rakefile +0 -13
  66. data/examples/README.md +0 -148
  67. data/examples/configuration/legacy_auth.rb +0 -12
  68. data/examples/configuration/oauth.rb +0 -9
  69. data/examples/content/blog_post.rb +0 -39
  70. data/examples/content/blog_tag.rb +0 -10
  71. data/examples/content/redirect.rb +0 -43
  72. data/examples/customers/customer.rb +0 -36
  73. data/examples/customers/customer_address.rb +0 -50
  74. data/examples/customers/customer_group.rb +0 -35
  75. data/examples/exception_handling.rb +0 -50
  76. data/examples/geography/country.rb +0 -16
  77. data/examples/geography/state.rb +0 -19
  78. data/examples/marketing/coupon.rb +0 -44
  79. data/examples/orders/order.rb +0 -53
  80. data/examples/orders/order_coupon.rb +0 -17
  81. data/examples/orders/order_message.rb +0 -17
  82. data/examples/orders/order_product.rb +0 -23
  83. data/examples/orders/order_shipping_address.rb +0 -23
  84. data/examples/orders/order_status.rb +0 -15
  85. data/examples/orders/order_tax.rb +0 -17
  86. data/examples/orders/shipment.rb +0 -57
  87. data/examples/payments/payment_method.rb +0 -10
  88. data/examples/products/brand.rb +0 -36
  89. data/examples/products/bulk_pricing_rule.rb +0 -47
  90. data/examples/products/category.rb +0 -37
  91. data/examples/products/configurable_field.rb +0 -29
  92. data/examples/products/custom_field.rb +0 -44
  93. data/examples/products/google_product_search_mapping.rb +0 -12
  94. data/examples/products/option.rb +0 -37
  95. data/examples/products/option_set.rb +0 -35
  96. data/examples/products/option_set_option.rb +0 -50
  97. data/examples/products/option_value.rb +0 -43
  98. data/examples/products/product.rb +0 -44
  99. data/examples/products/product_image.rb +0 -42
  100. data/examples/products/product_option.rb +0 -17
  101. data/examples/products/product_review.rb +0 -12
  102. data/examples/products/product_rule.rb +0 -54
  103. data/examples/products/product_video.rb +0 -45
  104. data/examples/products/sku.rb +0 -48
  105. data/examples/shipping/shipping_method.rb +0 -13
  106. data/examples/store/store_info.rb +0 -10
  107. data/examples/system/time.rb +0 -10
  108. data/examples/tax/tax_class.rb +0 -13
  109. data/examples/webhooks/webhook.rb +0 -29
  110. data/spec/bigcommerce/bigcommerce_spec.rb +0 -76
  111. data/spec/bigcommerce/unit/actions_spec.rb +0 -151
  112. data/spec/bigcommerce/unit/exception_spec.rb +0 -53
  113. data/spec/bigcommerce/unit/middleware/auth_spec.rb +0 -18
  114. data/spec/bigcommerce/unit/middleware/http_exception_spec.rb +0 -40
  115. data/spec/bigcommerce/unit/request_spec.rb +0 -180
  116. data/spec/bigcommerce/unit/resources/content/blog_post_spec.rb +0 -12
  117. data/spec/bigcommerce/unit/resources/content/blog_tag_spec.rb +0 -12
  118. data/spec/bigcommerce/unit/resources/content/redirect_spec.rb +0 -12
  119. data/spec/bigcommerce/unit/resources/customers/customer_address_spec.rb +0 -21
  120. data/spec/bigcommerce/unit/resources/customers/customer_group_spec.rb +0 -12
  121. data/spec/bigcommerce/unit/resources/customers/customer_spec.rb +0 -12
  122. data/spec/bigcommerce/unit/resources/geography/country_spec.rb +0 -12
  123. data/spec/bigcommerce/unit/resources/geography/state_spec.rb +0 -21
  124. data/spec/bigcommerce/unit/resources/marketing/coupon_spec.rb +0 -12
  125. data/spec/bigcommerce/unit/resources/orders/order_product_spec.rb +0 -21
  126. data/spec/bigcommerce/unit/resources/orders/order_shipping_address_spec.rb +0 -21
  127. data/spec/bigcommerce/unit/resources/orders/order_spec.rb +0 -13
  128. data/spec/bigcommerce/unit/resources/orders/shipment_spec.rb +0 -21
  129. data/spec/bigcommerce/unit/resources/payments/payment_method_spec.rb +0 -23
  130. data/spec/bigcommerce/unit/resources/products/brand_spec.rb +0 -12
  131. data/spec/bigcommerce/unit/resources/products/bulk_pricing_rule_spec.rb +0 -21
  132. data/spec/bigcommerce/unit/resources/products/category_spec.rb +0 -12
  133. data/spec/bigcommerce/unit/resources/products/configurable_field_spec.rb +0 -21
  134. data/spec/bigcommerce/unit/resources/products/custom_field_spec.rb +0 -21
  135. data/spec/bigcommerce/unit/resources/products/google_product_search_mapping_spec.rb +0 -14
  136. data/spec/bigcommerce/unit/resources/products/option_set_spec.rb +0 -12
  137. data/spec/bigcommerce/unit/resources/products/option_spec.rb +0 -12
  138. data/spec/bigcommerce/unit/resources/products/product_image_spec.rb +0 -21
  139. data/spec/bigcommerce/unit/resources/products/product_review_spec.rb +0 -14
  140. data/spec/bigcommerce/unit/resources/products/product_rule_spec.rb +0 -21
  141. data/spec/bigcommerce/unit/resources/products/product_spec.rb +0 -13
  142. data/spec/bigcommerce/unit/resources/products/product_video_spec.rb +0 -21
  143. data/spec/bigcommerce/unit/resources/products/sku_spec.rb +0 -21
  144. data/spec/bigcommerce/unit/resources/resource_spec.rb +0 -4
  145. data/spec/bigcommerce/unit/resources/store_info/store_information_spec.rb +0 -12
  146. data/spec/bigcommerce/unit/resources/system/time_spec.rb +0 -12
  147. data/spec/bigcommerce/unit/version_spec.rb +0 -7
  148. data/spec/spec_helper.rb +0 -11
@@ -1,76 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Bigcommerce do
4
- let(:middleware) do
5
- api.instance_variable_get('@builder').instance_variable_get('@handlers')
6
- end
7
-
8
- it 'should return a faraday object when configured' do
9
- Bigcommerce.configure do |config|
10
- config.url = 'http://foobar.com'
11
- config.auth = 'legacy'
12
- config.api_key = '214789175'
13
- config.username = 'admin'
14
- end
15
- expect(Bigcommerce.api).to be_a_kind_of(Faraday::Connection)
16
- end
17
-
18
- describe '.build_connection' do
19
- context 'when using legacy' do
20
- let(:api) do
21
- Bigcommerce.configure do |config|
22
- config.url = 'http://foobar.com'
23
- config.auth = 'legacy'
24
- config.api_key = '214789175'
25
- config.username = 'admin'
26
- end
27
- end
28
-
29
- it 'should have the correct auth middleware' do
30
- expect(middleware).to include(Faraday::Request::BasicAuthentication)
31
- end
32
- end
33
-
34
- context 'when not using legacy' do
35
- let(:api) do
36
- Bigcommerce.configure do |config|
37
- config.access_token = 'jksdgkjbhksjdb'
38
- config.client_id = 'negskjgdjkbg'
39
- end
40
- end
41
-
42
- it 'should have the correct auth middleware' do
43
- expect(middleware).to include(Bigcommerce::Middleware::Auth)
44
- end
45
- end
46
- end
47
-
48
- describe 'multiple configurations' do
49
- it 'should use the configuration for the most recently defined' do
50
- Bigcommerce.configure do |config|
51
- config.access_token = 'jksdgkjbhksjdb'
52
- config.client_id = 'negskjgdjkbg'
53
- end
54
-
55
- Bigcommerce.configure do |config|
56
- config.url = 'http://foobar.com'
57
- config.auth = 'legacy'
58
- config.api_key = '214789175'
59
- config.username = 'admin'
60
- end
61
-
62
- expect(Bigcommerce.api.instance_variable_get('@builder')
63
- .instance_variable_get('@handlers'))
64
- .to include(Faraday::Request::BasicAuthentication)
65
-
66
- Bigcommerce.configure do |config|
67
- config.access_token = 'jksdgkjbhksjdb'
68
- config.client_id = 'negskjgdjkbg'
69
- end
70
-
71
- expect(Bigcommerce.api.instance_variable_get('@builder')
72
- .instance_variable_get('@handlers'))
73
- .to include(Bigcommerce::Middleware::Auth)
74
- end
75
- end
76
- end
@@ -1,151 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Bigcommerce::ResourceActions do
4
- before do
5
- module Bigcommerce
6
- class DummyClass
7
- include ResourceActions.new(uri: 'http://foo.bar/%d')
8
- end
9
- end
10
- @klass = Bigcommerce::DummyClass
11
- end
12
-
13
- let(:params) do
14
- { page: 1 }
15
- end
16
-
17
- it 'should have options' do
18
- mod = Bigcommerce::ResourceActions.new(
19
- uri: 'http://foo.bar',
20
- disable: [:find,:all]
21
- )
22
- options = {
23
- uri: 'http://foo.bar',
24
- disable: [:find,:all]
25
- }
26
- expect(mod._options).to eq options
27
- end
28
-
29
- describe '.all' do
30
- it 'should make a get request to the correct route with query params' do
31
- expect(@klass).to receive(:get).with('http://foo.bar', page: 1)
32
- @klass.all(params)
33
- end
34
-
35
- it 'should make a get request to the correct route' do
36
- expect(@klass).to receive(:get).with('http://foo.bar', {})
37
- params.delete(:params)
38
- @klass.all
39
- end
40
- end
41
-
42
- describe '.find' do
43
- it 'should make a get request to the correct route' do
44
- expect(@klass).to receive(:get).with('http://foo.bar/1')
45
- @klass.find(1)
46
- end
47
- end
48
-
49
- describe '.create' do
50
- it 'should make a post request to the correct route with params' do
51
- expect(@klass).to receive(:post).with('http://foo.bar', page: 1)
52
- @klass.create(params)
53
- end
54
- end
55
-
56
- describe '.update' do
57
- it 'should make a put request to the correct route with params' do
58
- expect(@klass).to receive(:put).with('http://foo.bar/1', page: 1)
59
- @klass.update(1, params)
60
- end
61
- end
62
-
63
- describe '.destroy' do
64
- it 'should make a delete request to the correct route with params' do
65
- expect(@klass).to receive(:delete).with('http://foo.bar/1')
66
- @klass.destroy(1)
67
- end
68
- end
69
-
70
- describe '.destroy_all' do
71
- it 'should make a delete request to the correct route with params' do
72
- expect(@klass).to receive(:delete).with('http://foo.bar')
73
- @klass.destroy_all
74
- end
75
- end
76
- end
77
-
78
- describe Bigcommerce::SubresourceActions do
79
- before do
80
- module Bigcommerce
81
- class DummyClass
82
- include SubresourceActions.new(uri: 'http://foo.bar/%d/%d')
83
- end
84
- end
85
- @klass = Bigcommerce::DummyClass
86
- end
87
-
88
- let(:params) do
89
- { page: 1 }
90
- end
91
-
92
- it 'should have options' do
93
- mod = Bigcommerce::SubresourceActions.new(
94
- uri: 'http://foo.bar',
95
- disable: [:find,:all]
96
- )
97
- options = {
98
- uri: 'http://foo.bar',
99
- disable: [:find,:all]
100
- }
101
- expect(mod._options).to eq options
102
- end
103
-
104
- describe '.all' do
105
- it 'should make a get request to the correct route with query params' do
106
- expect(@klass).to receive(:get).with('http://foo.bar/1', page: 1)
107
- @klass.all(1, params)
108
- end
109
-
110
- it 'should make a get request to the correct route' do
111
- expect(@klass).to receive(:get).with('http://foo.bar/1', {})
112
- params.delete(:params)
113
- @klass.all(1)
114
- end
115
- end
116
-
117
- describe '.find' do
118
- it 'should make a get request to the correct route' do
119
- expect(@klass).to receive(:get).with('http://foo.bar/1/2')
120
- @klass.find(1,2)
121
- end
122
- end
123
-
124
- describe '.create' do
125
- it 'should make a post request to the correct route with params' do
126
- expect(@klass).to receive(:post).with('http://foo.bar/1', page: 1)
127
- @klass.create(1, params)
128
- end
129
- end
130
-
131
- describe '.update' do
132
- it 'should make a put request to the correct route with params' do
133
- expect(@klass).to receive(:put).with('http://foo.bar/1/2', page: 1)
134
- @klass.update(1, 2, params)
135
- end
136
- end
137
-
138
- describe '.destroy' do
139
- it 'should make a delete request to the correct route with params' do
140
- expect(@klass).to receive(:delete).with('http://foo.bar/1/2')
141
- @klass.destroy(1, 2)
142
- end
143
- end
144
-
145
- describe '.destroy_all' do
146
- it 'should make a delete request to the correct route with params' do
147
- expect(@klass).to receive(:delete).with('http://foo.bar/1')
148
- @klass.destroy_all(1)
149
- end
150
- end
151
- end
@@ -1,53 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Bigcommerce::HttpErrors do
4
- let(:dummy_class) { Class.new { extend Bigcommerce::HttpErrors } }
5
-
6
- it '::ERRORS is not nil' do
7
- expect(Bigcommerce::HttpErrors::ERRORS).not_to be_nil
8
- end
9
-
10
- context 'invalid response status' do
11
- it 'should throw an exception' do
12
- code = 404
13
- expect { dummy_class.throw_http_exception!(code) }.to raise_exception
14
- end
15
-
16
- it 'should have a valid error' do
17
- codes = Bigcommerce::HttpErrors::ERRORS.keys
18
- codes.each do |code|
19
- expect { dummy_class.throw_http_exception!(code) }.to raise_exception
20
- end
21
- end
22
-
23
- it 'should allow you to pass in an error message when throwing exception' do
24
- code = 404
25
- env = double
26
- allow(env).to receive(:body) { {} }
27
- allow(env).to receive(:[]) { {} }
28
- expect do
29
- dummy_class.throw_http_exception!(code, env)
30
- end.to raise_exception(Bigcommerce::HttpErrors::ERRORS[code])
31
- end
32
-
33
- it 'should parse out a retry-after header if present' do
34
- code = 429
35
- env = double
36
- allow(env).to receive(:body) { "{\"time\":1426184190}" }
37
- allow(env).to receive(:[]).with(:response_headers).and_return('X-Retry-After' => 1)
38
- begin
39
- dummy_class.throw_http_exception!(code, env)
40
- rescue Bigcommerce::TooManyRequests => e
41
- expect(e.response_headers[:retry_after]).to eq 1
42
- end
43
- end
44
- end
45
-
46
- context 'valid response status' do
47
- it 'should not throw an exception' do
48
- code = 200
49
- env = double
50
- expect { dummy_class.throw_http_exception!(code, env) }.to_not raise_exception
51
- end
52
- end
53
- end
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Bigcommerce::Middleware::Auth do
4
- it 'should set the correct headers' do
5
- app = double
6
- options = {
7
- client_id: 'client_id',
8
- access_token: 'access_token'
9
- }
10
- @api = Bigcommerce::Middleware::Auth.new(app, options)
11
- expect(app).to receive(:call).with(
12
- request_headers: {
13
- 'X-Auth-Client' => 'client_id',
14
- 'X-Auth-Token' => 'access_token'
15
- })
16
- @api.call(request_headers: {})
17
- end
18
- end
@@ -1,40 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Bigcommerce::Middleware::HttpException do
4
- before(:each) { @e = Bigcommerce::Middleware::HttpException.new }
5
-
6
- it 'should check for an error on all responses' do
7
- env = {
8
- status: '200',
9
- body: 'Valid'
10
- }
11
- expect(@e).to receive(:throw_http_exception!).with(200, env)
12
- @e.on_complete env
13
- end
14
-
15
- context 'when valid response' do
16
- let(:env) do
17
- {
18
- status: '200',
19
- body: 'Valid'
20
- }
21
- end
22
-
23
- it 'should return its argument if no errors' do
24
- expect(@e.on_complete(env)).to eq env
25
- end
26
- end
27
-
28
- context 'when invalid response' do
29
- let(:env) do
30
- {
31
- status: '404',
32
- body: 'Error'
33
- }
34
- end
35
-
36
- it 'should throw an exception' do
37
- expect { @e.on_complete(env) }.to raise_exception
38
- end
39
- end
40
- end
@@ -1,180 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Bigcommerce::Request do
4
- before do
5
- module Bigcommerce
6
- class DummyClass
7
- include Request.new 'foo/%d'
8
- end
9
- end
10
- @klass = Bigcommerce::DummyClass
11
- end
12
-
13
- describe '.path' do
14
- it 'should have a path method to expose the path_builder' do
15
- expect(@klass.path).to be_kind_of Bigcommerce::PathBuilder
16
- end
17
- end
18
-
19
- describe 'ClassMethods' do
20
- before do
21
- double Bigcommerce.api
22
- end
23
-
24
- let(:json) { "{\"body\":[{\"time\":1426184190},{\"time\":1426184190}]}" }
25
-
26
- describe '.get' do
27
- it 'should call raw_request and build_response_object' do
28
- allow(@klass).to receive(:raw_request) { json }
29
- expect(@klass).to receive(:raw_request).with(:get, @klass.path, {})
30
- expect(@klass).to receive(:build_response_object).with(json)
31
- @klass.get(@klass.path, {})
32
- end
33
- end
34
-
35
- describe '.delete' do
36
- it 'should call raw_request' do
37
- response = double
38
- allow(response).to receive(:body) { '' }
39
- allow(@klass).to receive(:raw_request) { response }
40
- expect(@klass).to receive(:raw_request).with(:delete, @klass.path)
41
- @klass.delete(@klass.path)
42
- end
43
- end
44
-
45
- describe '.post' do
46
- it 'should call raw_request and build_response_object' do
47
- allow(@klass).to receive(:raw_request) { json }
48
- expect(@klass).to receive(:raw_request).with(:post, @klass.path, {})
49
- expect(@klass).to receive(:build_response_object).with(json)
50
- @klass.post(@klass.path, {})
51
- end
52
- end
53
-
54
- describe '.put' do
55
- it 'should call raw_request and build_response_object' do
56
- allow(@klass).to receive(:raw_request) { json }
57
- expect(@klass).to receive(:raw_request).with(:put, @klass.path, {})
58
- expect(@klass).to receive(:build_response_object).with(json)
59
- @klass.put(@klass.path, {})
60
- end
61
- end
62
-
63
- describe '.raw_request' do
64
- before do
65
- Bigcommerce.configure do |config|
66
- config.client_id = 'sdbgksjbg4'
67
- config.access_token = 'jkdgbdsgbg'
68
- config.store_hash = 'sdgjnsdjg'
69
- end
70
- @api = Bigcommerce.api
71
- end
72
-
73
- it 'send its method to Bigcommerce.api' do
74
- response = double
75
- allow(@api).to receive(:get) { response }
76
- allow(response).to receive(:headers) { '' }
77
- expect(@api).to receive(:get).with('path/1', nil)
78
- expect(response).to receive(:headers)
79
- @klass.raw_request(:get, 'path/1')
80
- end
81
- end
82
-
83
- describe 'private methods' do
84
- describe '.build_response_object' do
85
- before do
86
- module Bigcommerce
87
- class DummyClass
88
- include Request.new 'foo/%d'
89
- def initialize(params)
90
- @params = params
91
- end
92
- end
93
- end
94
- @klass_with_init = Bigcommerce::DummyClass
95
- end
96
-
97
- describe 'json array' do
98
- let(:json) { "[{\"time\":1426184190},{\"time\":1426184190}]" }
99
-
100
- it 'should build an array of objects' do
101
- response = double
102
- allow(response).to receive(:body) { json }
103
- objs = @klass_with_init.send(:build_response_object, response)
104
- expect(objs).to be_kind_of Array
105
- objs.each do |obj|
106
- expect(obj).to be_kind_of Bigcommerce::DummyClass
107
- end
108
- end
109
- end
110
- describe 'json object' do
111
- let(:json) { "{\"time\":1426184190}" }
112
- it 'should build an object' do
113
- response = double
114
- allow(response).to receive(:body) { json }
115
- objs = @klass_with_init.send(:build_response_object, response)
116
- expect(objs).to be_kind_of Bigcommerce::DummyClass
117
- end
118
- end
119
- end
120
-
121
- describe '.parse' do
122
- describe 'empty string' do
123
- let(:json) { "" }
124
-
125
- it 'should return an array' do
126
- expect(@klass.send(:parse, json)).to be_kind_of Array
127
- end
128
- end
129
-
130
- describe 'valid json' do
131
- let(:json) { "{\"time\":1426184190}" }
132
-
133
- it 'should symbolize keys' do
134
- expect(@klass.send(:parse, json)).to eq({time:1426184190})
135
- end
136
-
137
- it 'should return a hash' do
138
- expect(@klass.send(:parse, json)).to be_kind_of Hash
139
- end
140
- end
141
- end
142
- end
143
- end
144
- end
145
-
146
- describe Bigcommerce::PathBuilder do
147
- let(:uri) { 'bar/%d' }
148
- before do
149
- @path_builder = Bigcommerce::PathBuilder.new uri
150
- end
151
-
152
- describe '.to_s' do
153
- it 'should return uri' do
154
- expect(@path_builder.to_s).to eq uri
155
- end
156
- end
157
-
158
- describe '.build' do
159
- context 'hash of keys' do
160
- let(:keys) { 1 }
161
- it 'should build a formed path' do
162
- expect(@path_builder.build keys).to eq 'bar/1'
163
- end
164
- end
165
-
166
- context 'integer keys' do
167
- let(:keys) { 1 }
168
- it 'should build a formed path' do
169
- expect(@path_builder.build keys).to eq 'bar/1'
170
- end
171
- end
172
-
173
- context 'integer keys' do
174
- let(:keys) { nil }
175
- it 'should build a formed path' do
176
- expect(@path_builder.build keys).to eq 'bar'
177
- end
178
- end
179
- end
180
- end