vend 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +57 -0
  3. data/README.rdoc +1 -1
  4. data/Rakefile +1 -1
  5. data/example.rb +3 -3
  6. data/lib/vend.rb +2 -1
  7. data/lib/vend/base.rb +12 -12
  8. data/lib/vend/base_factory.rb +2 -6
  9. data/lib/vend/client.rb +5 -5
  10. data/lib/vend/http_client.rb +30 -31
  11. data/lib/vend/null_logger.rb +9 -5
  12. data/lib/vend/oauth2/auth_code.rb +7 -10
  13. data/lib/vend/oauth2/client.rb +1 -5
  14. data/lib/vend/pagination_info.rb +2 -1
  15. data/lib/vend/resource/customer.rb +1 -3
  16. data/lib/vend/resource/outlet.rb +0 -2
  17. data/lib/vend/resource/payment_type.rb +0 -2
  18. data/lib/vend/resource/product.rb +0 -2
  19. data/lib/vend/resource/register.rb +0 -2
  20. data/lib/vend/resource/register_sale.rb +2 -5
  21. data/lib/vend/resource/register_sale_product.rb +1 -1
  22. data/lib/vend/resource/supplier.rb +23 -0
  23. data/lib/vend/resource/tax.rb +0 -2
  24. data/lib/vend/resource/user.rb +0 -2
  25. data/lib/vend/resource_collection.rb +11 -15
  26. data/lib/vend/scope.rb +1 -2
  27. data/lib/vend/version.rb +1 -1
  28. data/spec/integration/customer_spec.rb +12 -9
  29. data/spec/integration/outlet_spec.rb +2 -3
  30. data/spec/integration/payment_types_spec.rb +1 -2
  31. data/spec/integration/product_spec.rb +26 -29
  32. data/spec/integration/register_sale_spec.rb +9 -10
  33. data/spec/integration/register_spec.rb +1 -2
  34. data/spec/integration/supplier_spec.rb +14 -0
  35. data/spec/integration/tax_spec.rb +1 -2
  36. data/spec/integration/user_spec.rb +1 -2
  37. data/spec/mock_responses/suppliers.json +36 -0
  38. data/spec/spec_helper.rb +1 -2
  39. data/spec/support/matchers/have_attributes.rb +3 -3
  40. data/spec/support/shared_examples/integration.rb +7 -9
  41. data/spec/support/shared_examples/logger.rb +21 -10
  42. data/spec/vend/base_factory_spec.rb +11 -12
  43. data/spec/vend/base_spec.rb +22 -23
  44. data/spec/vend/client_spec.rb +40 -39
  45. data/spec/vend/http_client_spec.rb +70 -62
  46. data/spec/vend/null_logger_spec.rb +1 -1
  47. data/spec/vend/oauth2/auth_code_spec.rb +18 -17
  48. data/spec/vend/oauth2/client_spec.rb +21 -21
  49. data/spec/vend/pagination_info_spec.rb +40 -17
  50. data/spec/vend/resource/register_sale_product_spec.rb +8 -6
  51. data/spec/vend/resource/register_sale_spec.rb +7 -8
  52. data/spec/vend/resource_collection_spec.rb +108 -95
  53. data/spec/vend/scope_spec.rb +20 -12
  54. data/vend.gemspec +5 -6
  55. 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.should == [register_sale_product]
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
- its(:client) { should == client }
15
- its(:target_class) { should == target_class }
16
- its(:endpoint) { should == endpoint }
17
- its(:scopes) { should == [] }
13
+ specify :client do
14
+ expect(subject.client).to eq client
15
+ end
18
16
 
19
- describe "#request_args" do
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
- its(:request_args) { should == request_args }
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
- described_class.new(client, target_class, endpoint)
26
- }
27
- its(:request_args) { should == {} }
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
- before { target_class.stub(:default_collection_request_args => {:foo => :bar}) }
35
- its(:request_args) { should == {:foo => :bar}}
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.should_receive(:build_from_json).with(client, next_page) {
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.should_receive(:ping!)
58
- member_two.should_receive(:ping!)
59
- subject.each do |member|
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", :paged? => value) }
98
+ let(:pagination) { double("pagination", paged?: value) }
88
99
  before do
89
- subject.stub(:pagination => pagination)
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
- =begin
105
- [:pages, :page].each do |method|
106
- describe method do
107
- let(:value) { double("value") }
108
- let(:pagination) { double("pagination", method => value) }
109
- before do
110
- subject.stub(:pagination => pagination)
111
- end
112
- it "delegates to #pagination" do
113
- subject.send(method).should == value
114
- end
115
- end
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(:scopes => scopes)
136
+ subject.stub(scopes: scopes)
128
137
  Vend::Scope.stub(:new).with(:name, value) { scope }
129
- scopes.should_receive(:<<).with(scope)
138
+ expect(scopes).to receive(:<<).with(scope)
130
139
  end
140
+
131
141
  it "returns self" do
132
- subject.scope(:name, value).should == subject
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
- lambda do
152
+ expect do
142
153
  subject.scope(:name, value)
143
- end.should raise_exception(Vend::ResourceCollection::AlreadyScopedError)
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).should == value
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
- it { should respond_to(:foo) }
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.should_receive(:scope).with(:foo, value) { subject }
190
- subject.foo(value).should == subject
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
- lambda do
215
+ expect do
206
216
  subject.foo(value)
207
- end.should raise_exception(NoMethodError)
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(:endpoint_with_scopes => endpoint_with_scopes)
218
- subject.should_receive(:increment_page)
226
+ subject.stub(endpoint_with_scopes: endpoint_with_scopes)
227
+ expect(subject).to receive(:increment_page)
219
228
  end
220
229
 
221
- its(:url) { should == endpoint_with_scopes }
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
- its(:endpoint_with_scopes) { should == endpoint }
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(:scopes => scopes)
247
+ subject.stub(scopes: scopes)
236
248
  end
237
249
 
238
- its(:endpoint_with_scopes) { should == endpoint + scopes.join}
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(:paged? => false)
259
+ subject.stub(paged?: false)
248
260
  end
249
261
 
250
- its(:increment_page) { should be_nil }
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(:paged? => true)
260
- subject.stub(:page => 1)
261
- subject.should_receive(:get_or_create_page_scope) { page_scope }
262
- page_scope.should_receive(:value=).with(2) { 2 }
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
- its(:increment_page) { should == 2 }
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(:page => page)
278
- subject.should_receive(:get_scope).with(:page) { page_scope }
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.should_receive(:scope).with(:page, page) { page_scope }
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
- its(:get_or_create_page_scope) { should == page_scope }
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", :name => scope_name) }
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(:scopes => [scope])
319
+ subject.stub(scopes: [scope])
306
320
  end
307
321
 
308
322
  specify do
309
- subject.get_scope(scope_name).should == scope
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(:scopes => [])
329
+ subject.stub(scopes: [])
317
330
  end
331
+
318
332
  specify do
319
- lambda do
333
+ expect do
320
334
  subject.get_scope(scope_name)
321
- end.should raise_exception(Vend::ResourceCollection::ScopeNotFoundError)
335
+ end.to raise_exception(Vend::ResourceCollection::ScopeNotFoundError)
322
336
  end
323
337
  end
324
-
325
338
  end
326
339
  end
@@ -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
- its(:name) { should == name }
11
- its(:value) { should == value }
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(:escaped_value => escaped_value)
21
+ subject.stub(escaped_value: escaped_value)
20
22
  end
21
23
 
22
- its(:to_s) { should == "/#{name}/#{escaped_value}" }
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
- its(:escaped_value) { should == "value+with+spaces" }
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
- its(:escaped_value) { should == "42" }
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
- its(:escaped_value) { should == "2012-07-11+10%3A40%3A29" }
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