vend 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +57 -0
- data/README.rdoc +1 -1
- data/Rakefile +1 -1
- data/example.rb +3 -3
- data/lib/vend.rb +2 -1
- data/lib/vend/base.rb +12 -12
- data/lib/vend/base_factory.rb +2 -6
- data/lib/vend/client.rb +5 -5
- data/lib/vend/http_client.rb +30 -31
- data/lib/vend/null_logger.rb +9 -5
- data/lib/vend/oauth2/auth_code.rb +7 -10
- data/lib/vend/oauth2/client.rb +1 -5
- data/lib/vend/pagination_info.rb +2 -1
- data/lib/vend/resource/customer.rb +1 -3
- data/lib/vend/resource/outlet.rb +0 -2
- data/lib/vend/resource/payment_type.rb +0 -2
- data/lib/vend/resource/product.rb +0 -2
- data/lib/vend/resource/register.rb +0 -2
- data/lib/vend/resource/register_sale.rb +2 -5
- data/lib/vend/resource/register_sale_product.rb +1 -1
- data/lib/vend/resource/supplier.rb +23 -0
- data/lib/vend/resource/tax.rb +0 -2
- data/lib/vend/resource/user.rb +0 -2
- data/lib/vend/resource_collection.rb +11 -15
- data/lib/vend/scope.rb +1 -2
- data/lib/vend/version.rb +1 -1
- data/spec/integration/customer_spec.rb +12 -9
- data/spec/integration/outlet_spec.rb +2 -3
- data/spec/integration/payment_types_spec.rb +1 -2
- data/spec/integration/product_spec.rb +26 -29
- data/spec/integration/register_sale_spec.rb +9 -10
- data/spec/integration/register_spec.rb +1 -2
- data/spec/integration/supplier_spec.rb +14 -0
- data/spec/integration/tax_spec.rb +1 -2
- data/spec/integration/user_spec.rb +1 -2
- data/spec/mock_responses/suppliers.json +36 -0
- data/spec/spec_helper.rb +1 -2
- data/spec/support/matchers/have_attributes.rb +3 -3
- data/spec/support/shared_examples/integration.rb +7 -9
- data/spec/support/shared_examples/logger.rb +21 -10
- data/spec/vend/base_factory_spec.rb +11 -12
- data/spec/vend/base_spec.rb +22 -23
- data/spec/vend/client_spec.rb +40 -39
- data/spec/vend/http_client_spec.rb +70 -62
- data/spec/vend/null_logger_spec.rb +1 -1
- data/spec/vend/oauth2/auth_code_spec.rb +18 -17
- data/spec/vend/oauth2/client_spec.rb +21 -21
- data/spec/vend/pagination_info_spec.rb +40 -17
- data/spec/vend/resource/register_sale_product_spec.rb +8 -6
- data/spec/vend/resource/register_sale_spec.rb +7 -8
- data/spec/vend/resource_collection_spec.rb +108 -95
- data/spec/vend/scope_spec.rb +20 -12
- data/vend.gemspec +5 -6
- metadata +10 -20
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Vend::Resource::RegisterSale do
|
4
|
-
|
5
4
|
subject { described_class.new(nil, {}) }
|
6
5
|
|
7
6
|
describe "#register_sale_products" do
|
@@ -9,16 +8,16 @@ describe Vend::Resource::RegisterSale do
|
|
9
8
|
let(:raw_register_sale_product) { double("raw register sale prodcut") }
|
10
9
|
|
11
10
|
before do
|
12
|
-
subject.stub(:attrs)
|
13
|
-
{ "register_sale_products" => [raw_register_sale_product] }
|
14
|
-
|
15
|
-
Vend::Resource::RegisterSaleProduct.stub(:new).with(raw_register_sale_product)
|
16
|
-
register_sale_product
|
17
|
-
|
11
|
+
subject.stub(:attrs) do
|
12
|
+
{ "register_sale_products" => [raw_register_sale_product] }
|
13
|
+
end
|
14
|
+
Vend::Resource::RegisterSaleProduct.stub(:new).with(raw_register_sale_product) do
|
15
|
+
register_sale_product
|
16
|
+
end
|
18
17
|
end
|
19
18
|
|
20
19
|
it "returns all the register sale products" do
|
21
|
-
subject.register_sale_products.
|
20
|
+
expect(subject.register_sale_products).to eq [register_sale_product]
|
22
21
|
end
|
23
22
|
end
|
24
23
|
end
|
@@ -1,66 +1,77 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Vend::ResourceCollection do
|
4
|
-
|
5
4
|
let(:client) { double("client") }
|
6
|
-
let(:target_class)
|
5
|
+
let(:target_class) do
|
7
6
|
double("target_class", default_collection_request_args: {})
|
8
|
-
|
7
|
+
end
|
9
8
|
let(:endpoint) { "endpoint" }
|
10
9
|
let(:request_args) { {} }
|
11
10
|
|
12
11
|
subject { described_class.new(client, target_class, endpoint, request_args) }
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
its(:scopes) { should == [] }
|
13
|
+
specify :client do
|
14
|
+
expect(subject.client).to eq client
|
15
|
+
end
|
18
16
|
|
19
|
-
|
17
|
+
specify :target_class do
|
18
|
+
expect(subject.target_class).to eq target_class
|
19
|
+
end
|
20
|
+
|
21
|
+
specify :endpoint do
|
22
|
+
expect(subject.endpoint).to eq endpoint
|
23
|
+
end
|
24
|
+
|
25
|
+
specify :scopes do
|
26
|
+
expect(subject.scopes).to eq []
|
27
|
+
end
|
20
28
|
|
21
|
-
|
29
|
+
describe "#request_args" do
|
30
|
+
specify :request_args do
|
31
|
+
expect(subject.request_args).to eq request_args
|
32
|
+
end
|
22
33
|
|
23
34
|
context "when not set in initialize" do
|
24
|
-
subject {
|
25
|
-
|
26
|
-
|
27
|
-
|
35
|
+
subject { described_class.new(client, target_class, endpoint) }
|
36
|
+
specify :request_args do
|
37
|
+
expect(subject.request_args).to eq({})
|
38
|
+
end
|
28
39
|
end
|
29
40
|
|
30
41
|
context "when target class has default request args" do
|
31
|
-
subject
|
42
|
+
subject do
|
32
43
|
described_class.new(client, target_class, endpoint)
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
44
|
+
end
|
45
|
+
|
46
|
+
before { target_class.stub(default_collection_request_args: {foo: :bar}) }
|
37
47
|
|
48
|
+
specify :request_args do
|
49
|
+
expect(subject.request_args).to eq({ foo: :bar })
|
50
|
+
end
|
51
|
+
end
|
38
52
|
end
|
39
53
|
|
40
54
|
describe "#each" do
|
41
|
-
|
42
55
|
let(:member_one) { double("member_one") }
|
43
56
|
let(:member_two) { double("member_two") }
|
44
57
|
let(:json) { double("json") }
|
45
58
|
let(:next_page) { double("next_page") }
|
46
59
|
|
47
60
|
before do
|
48
|
-
target_class.
|
61
|
+
expect(target_class).to receive(:build_from_json).with(client, next_page) {
|
49
62
|
[member_one, member_two]
|
50
63
|
}
|
64
|
+
|
51
65
|
client.stub(:request).with(endpoint, request_args) { json }
|
52
66
|
subject.stub(:get_next_page) { next_page }
|
53
67
|
subject.stub(:last_page?).and_return(false, true)
|
54
68
|
end
|
55
69
|
|
56
70
|
it "yields each member and returns self" do
|
57
|
-
member_one.
|
58
|
-
member_two.
|
59
|
-
subject.each
|
60
|
-
member.ping!
|
61
|
-
end.should == subject
|
71
|
+
expect(member_one).to receive(:ping!)
|
72
|
+
expect(member_two).to receive(:ping!)
|
73
|
+
expect(subject.each(&:ping!)).to eq subject
|
62
74
|
end
|
63
|
-
|
64
75
|
end
|
65
76
|
|
66
77
|
describe "#last_page?" do
|
@@ -84,9 +95,9 @@ describe Vend::ResourceCollection do
|
|
84
95
|
describe "#paged?" do
|
85
96
|
context "when pagination is set" do
|
86
97
|
let(:value) { double("value") }
|
87
|
-
let(:pagination) { double("pagination",
|
98
|
+
let(:pagination) { double("pagination", paged?: value) }
|
88
99
|
before do
|
89
|
-
subject.stub(:
|
100
|
+
subject.stub(pagination: pagination)
|
90
101
|
end
|
91
102
|
|
92
103
|
it "delegates to #pagination" do
|
@@ -101,20 +112,18 @@ describe Vend::ResourceCollection do
|
|
101
112
|
end
|
102
113
|
end
|
103
114
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
end
|
117
|
-
=end
|
115
|
+
# [:pages, :page].each do |method|
|
116
|
+
# describe method do
|
117
|
+
# let(:value) { double("value") }
|
118
|
+
# let(:pagination) { double("pagination", method => value) }
|
119
|
+
# before do
|
120
|
+
# subject.stub(pagination: pagination)
|
121
|
+
# end
|
122
|
+
# it "delegates to #pagination" do
|
123
|
+
# expect(subject.send(method)).to eq value
|
124
|
+
# end
|
125
|
+
# end
|
126
|
+
# end
|
118
127
|
|
119
128
|
describe "#scope" do
|
120
129
|
let(:value) { double("value") }
|
@@ -124,12 +133,13 @@ describe Vend::ResourceCollection do
|
|
124
133
|
context "when scope is not already present" do
|
125
134
|
before do
|
126
135
|
subject.stub(:has_scope?).with(:name) { false }
|
127
|
-
subject.stub(:
|
136
|
+
subject.stub(scopes: scopes)
|
128
137
|
Vend::Scope.stub(:new).with(:name, value) { scope }
|
129
|
-
scopes.
|
138
|
+
expect(scopes).to receive(:<<).with(scope)
|
130
139
|
end
|
140
|
+
|
131
141
|
it "returns self" do
|
132
|
-
subject.scope(:name, value).
|
142
|
+
expect(subject.scope(:name, value)).to eq subject
|
133
143
|
end
|
134
144
|
end
|
135
145
|
|
@@ -137,10 +147,11 @@ describe Vend::ResourceCollection do
|
|
137
147
|
before do
|
138
148
|
subject.stub(:has_scope?).with(:name) { true }
|
139
149
|
end
|
150
|
+
|
140
151
|
it "raises and AlreadyScopedError" do
|
141
|
-
|
152
|
+
expect do
|
142
153
|
subject.scope(:name, value)
|
143
|
-
end.
|
154
|
+
end.to raise_exception(Vend::ResourceCollection::AlreadyScopedError)
|
144
155
|
end
|
145
156
|
end
|
146
157
|
end
|
@@ -168,28 +179,27 @@ describe Vend::ResourceCollection do
|
|
168
179
|
before do
|
169
180
|
target_class.stub(:accepts_scope?).with(:name) { value }
|
170
181
|
end
|
182
|
+
|
171
183
|
it "delegates to target_class" do
|
172
|
-
subject.accepts_scope?(:name).
|
184
|
+
expect(subject.accepts_scope?(:name)).to eq value
|
173
185
|
end
|
174
186
|
end
|
175
187
|
|
176
188
|
describe "#method_missing" do
|
177
|
-
|
178
189
|
let(:value) { double("value") }
|
179
|
-
|
180
190
|
context "when the method name is a valid scope name" do
|
181
|
-
|
182
191
|
before do
|
183
192
|
subject.stub(:accepts_scope?).with(:foo) { true }
|
184
193
|
end
|
185
194
|
|
186
|
-
|
195
|
+
specify :responds_to_foo do
|
196
|
+
expect(subject).to respond_to(:foo)
|
197
|
+
end
|
187
198
|
|
188
199
|
it "adds the relevant scope if it accepts a scope for the method name" do
|
189
|
-
subject.
|
190
|
-
subject.foo(value).
|
200
|
+
expect(subject).to receive(:scope).with(:foo, value) { subject }
|
201
|
+
expect(subject.foo(value)).to eq subject
|
191
202
|
end
|
192
|
-
|
193
203
|
end
|
194
204
|
|
195
205
|
context "when the method name is not a valid scope name" do
|
@@ -202,29 +212,31 @@ describe Vend::ResourceCollection do
|
|
202
212
|
end
|
203
213
|
|
204
214
|
it "raises method missing" do
|
205
|
-
|
215
|
+
expect do
|
206
216
|
subject.foo(value)
|
207
|
-
end.
|
217
|
+
end.to raise_exception(NoMethodError)
|
208
218
|
end
|
209
219
|
end
|
210
220
|
end
|
211
221
|
|
212
222
|
describe "#url" do
|
213
|
-
|
214
223
|
let(:endpoint_with_scopes) { "endpoint_with_scopes" }
|
215
224
|
|
216
225
|
before do
|
217
|
-
subject.stub(:
|
218
|
-
subject.
|
226
|
+
subject.stub(endpoint_with_scopes: endpoint_with_scopes)
|
227
|
+
expect(subject).to receive(:increment_page)
|
219
228
|
end
|
220
229
|
|
221
|
-
|
230
|
+
specify :url do
|
231
|
+
expect(subject.url).to eq endpoint_with_scopes
|
232
|
+
end
|
222
233
|
end
|
223
234
|
|
224
235
|
describe "#endpoint_with_scopes" do
|
225
|
-
|
226
236
|
context "when there are no scopes" do
|
227
|
-
|
237
|
+
specify :endpoint_with_scopes do
|
238
|
+
expect(subject.endpoint_with_scopes).to eq endpoint
|
239
|
+
end
|
228
240
|
end
|
229
241
|
|
230
242
|
context "when there are scopes" do
|
@@ -232,95 +244,96 @@ describe Vend::ResourceCollection do
|
|
232
244
|
let(:scope2) { "scope2" }
|
233
245
|
let(:scopes) { [scope1, scope2] }
|
234
246
|
before do
|
235
|
-
subject.stub(:
|
247
|
+
subject.stub(scopes: scopes)
|
236
248
|
end
|
237
249
|
|
238
|
-
|
250
|
+
specify :endpoint_with_scopes do
|
251
|
+
expect(subject.endpoint_with_scopes).to eq endpoint + scopes.join
|
252
|
+
end
|
239
253
|
end
|
240
254
|
end
|
241
255
|
|
242
256
|
describe "#increment_page" do
|
243
|
-
|
244
257
|
context "when not paged" do
|
245
|
-
|
246
258
|
before do
|
247
|
-
subject.stub(
|
259
|
+
subject.stub(paged?: false)
|
248
260
|
end
|
249
261
|
|
250
|
-
|
251
|
-
|
262
|
+
specify :increment_page do
|
263
|
+
expect(subject.increment_page).to be_nil
|
264
|
+
end
|
252
265
|
end
|
253
266
|
|
254
267
|
context "when paged" do
|
255
|
-
|
256
|
-
let(:page_scope) { double("page_scope", :value => 1) }
|
268
|
+
let(:page_scope) { double("page_scope", value: 1) }
|
257
269
|
|
258
270
|
before do
|
259
|
-
subject.stub(
|
260
|
-
subject.stub(:
|
261
|
-
subject.
|
262
|
-
page_scope.
|
271
|
+
subject.stub(paged?: true)
|
272
|
+
subject.stub(page: 1)
|
273
|
+
expect(subject).to receive(:get_or_create_page_scope) { page_scope }
|
274
|
+
expect(page_scope).to receive(:value=).with(2) { 2 }
|
263
275
|
end
|
264
276
|
|
265
|
-
|
266
|
-
|
277
|
+
specify :increment_page do
|
278
|
+
expect(subject.increment_page).to eq 2
|
279
|
+
end
|
267
280
|
end
|
268
|
-
|
269
281
|
end
|
270
282
|
|
271
283
|
describe "#get_or_create_page_scope" do
|
272
|
-
|
273
284
|
let(:page_scope) { double("page_scope") }
|
274
285
|
let(:page) { 1 }
|
275
286
|
|
276
287
|
before do
|
277
|
-
subject.stub(:
|
278
|
-
subject.
|
288
|
+
subject.stub(page: page)
|
289
|
+
expect(subject).to receive(:get_scope).with(:page) { page_scope }
|
279
290
|
end
|
280
291
|
|
281
292
|
context "when scope is not present" do
|
282
293
|
before do
|
283
294
|
subject.stub(:has_scope?).with(:page) { false }
|
284
|
-
subject.
|
295
|
+
expect(subject).to receive(:scope).with(:page, page) { page_scope }
|
296
|
+
end
|
297
|
+
|
298
|
+
specify :get_or_create_page_scope do
|
299
|
+
expect(subject.get_or_create_page_scope).to eq page_scope
|
285
300
|
end
|
286
|
-
its(:get_or_create_page_scope) { should == page_scope }
|
287
301
|
end
|
288
302
|
|
289
303
|
context "when scope is already present" do
|
290
304
|
before do
|
291
305
|
subject.stub(:has_scope?).with(:page) { true }
|
292
306
|
end
|
293
|
-
|
307
|
+
specify :get_or_create_page_scope do
|
308
|
+
expect(subject.get_or_create_page_scope).to eq page_scope
|
309
|
+
end
|
294
310
|
end
|
295
311
|
end
|
296
312
|
|
297
313
|
describe "#get_scope" do
|
298
|
-
|
299
314
|
let(:scope_name) { :scope_name }
|
300
|
-
let(:scope) { double("scope", :
|
315
|
+
let(:scope) { double("scope", name: scope_name) }
|
301
316
|
|
302
317
|
context "when scope is present" do
|
303
|
-
|
304
318
|
before do
|
305
|
-
subject.stub(:
|
319
|
+
subject.stub(scopes: [scope])
|
306
320
|
end
|
307
321
|
|
308
322
|
specify do
|
309
|
-
subject.get_scope(scope_name).
|
323
|
+
expect(subject.get_scope(scope_name)).to eq scope
|
310
324
|
end
|
311
|
-
|
312
325
|
end
|
313
326
|
|
314
327
|
context "when scope is not present" do
|
315
328
|
before do
|
316
|
-
subject.stub(:
|
329
|
+
subject.stub(scopes: [])
|
317
330
|
end
|
331
|
+
|
318
332
|
specify do
|
319
|
-
|
333
|
+
expect do
|
320
334
|
subject.get_scope(scope_name)
|
321
|
-
end.
|
335
|
+
end.to raise_exception(Vend::ResourceCollection::ScopeNotFoundError)
|
322
336
|
end
|
323
337
|
end
|
324
|
-
|
325
338
|
end
|
326
339
|
end
|
data/spec/vend/scope_spec.rb
CHANGED
@@ -1,41 +1,49 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Vend::Scope do
|
4
|
-
|
5
4
|
let(:name) { :name }
|
6
5
|
let(:value) { "value" }
|
7
6
|
|
8
7
|
subject { described_class.new(name, value) }
|
9
8
|
|
10
|
-
|
11
|
-
|
9
|
+
specify :name do
|
10
|
+
expect(subject.name).to eq name
|
11
|
+
end
|
12
12
|
|
13
|
+
specify :value do
|
14
|
+
expect(subject.value).to eq value
|
15
|
+
end
|
13
16
|
|
14
17
|
describe "#to_s" do
|
15
|
-
|
16
18
|
let(:escaped_value) { "escaped_value" }
|
17
19
|
|
18
20
|
before do
|
19
|
-
subject.stub(:
|
21
|
+
subject.stub(escaped_value: escaped_value)
|
20
22
|
end
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
+
specify :to_s do
|
25
|
+
expect(subject.to_s).to eq "/#{name}/#{escaped_value}"
|
26
|
+
end
|
24
27
|
end
|
25
28
|
|
26
29
|
describe "#escaped_value" do
|
27
30
|
let(:value) { "value with spaces" }
|
28
|
-
|
31
|
+
specify :escaped_value do
|
32
|
+
expect(subject.escaped_value).to eq "value+with+spaces"
|
33
|
+
end
|
29
34
|
|
30
35
|
context "when value is a Fixnum" do
|
31
36
|
let(:value) { 42 }
|
32
|
-
|
37
|
+
specify :escaped_value do
|
38
|
+
expect(subject.escaped_value).to eq "42"
|
39
|
+
end
|
33
40
|
end
|
34
41
|
|
35
42
|
context "when value is a timestamp" do
|
36
|
-
let(:value) { Time.new(2012,7,11,10,40,29) }
|
37
|
-
|
43
|
+
let(:value) { Time.new(2012, 7, 11, 10, 40, 29) }
|
44
|
+
specify :escaped_value do
|
45
|
+
expect(subject.escaped_value).to eq "2012-07-11+10%3A40%3A29"
|
46
|
+
end
|
38
47
|
end
|
39
48
|
end
|
40
|
-
|
41
49
|
end
|