lhs 2.2.2 → 3.0.0

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.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +296 -30
  3. data/lhs.gemspec +3 -3
  4. data/lib/lhs.rb +0 -7
  5. data/lib/lhs/collection.rb +4 -4
  6. data/lib/lhs/concerns/item/destroy.rb +2 -2
  7. data/lib/lhs/concerns/item/save.rb +3 -3
  8. data/lib/lhs/concerns/item/update.rb +2 -2
  9. data/lib/lhs/concerns/item/validation.rb +4 -5
  10. data/lib/lhs/concerns/{service → record}/all.rb +2 -2
  11. data/lib/lhs/concerns/{service → record}/batch.rb +3 -3
  12. data/lib/lhs/concerns/{service → record}/create.rb +4 -3
  13. data/lib/lhs/concerns/{service → record}/endpoints.rb +6 -6
  14. data/lib/lhs/concerns/{service → record}/find.rb +3 -2
  15. data/lib/lhs/concerns/{service → record}/find_by.rb +3 -2
  16. data/lib/lhs/concerns/{service → record}/first.rb +1 -1
  17. data/lib/lhs/concerns/{service → record}/includes.rb +4 -2
  18. data/lib/lhs/concerns/{service → record}/mapping.rb +1 -1
  19. data/lib/lhs/concerns/{service → record}/model.rb +1 -1
  20. data/lib/lhs/concerns/{service → record}/request.rb +12 -12
  21. data/lib/lhs/concerns/{service → record}/where.rb +3 -2
  22. data/lib/lhs/data.rb +25 -53
  23. data/lib/lhs/endpoint.rb +2 -2
  24. data/lib/lhs/item.rb +8 -2
  25. data/lib/lhs/proxy.rb +2 -2
  26. data/lib/lhs/record.rb +42 -0
  27. data/lib/lhs/version.rb +1 -1
  28. data/spec/collection/meta_data_spec.rb +2 -2
  29. data/spec/collection/without_object_items_spec.rb +1 -1
  30. data/spec/data/item_spec.rb +2 -14
  31. data/spec/data/merge_spec.rb +3 -3
  32. data/spec/data/raw_spec.rb +1 -1
  33. data/spec/data/respond_to_spec.rb +3 -3
  34. data/spec/data/root_spec.rb +2 -2
  35. data/spec/data/to_json_spec.rb +2 -2
  36. data/spec/endpoint/for_url_spec.rb +1 -1
  37. data/spec/item/delegate_spec.rb +2 -2
  38. data/spec/item/destroy_spec.rb +4 -4
  39. data/spec/item/errors_spec.rb +4 -4
  40. data/spec/item/getter_spec.rb +2 -2
  41. data/spec/item/internal_data_structure_spec.rb +1 -1
  42. data/spec/item/save_spec.rb +3 -4
  43. data/spec/item/setter_spec.rb +2 -2
  44. data/spec/item/update_spec.rb +2 -2
  45. data/spec/item/validation_spec.rb +47 -75
  46. data/spec/proxy/load_spec.rb +2 -2
  47. data/spec/{service → record}/all_spec.rb +7 -7
  48. data/spec/{service → record}/build_spec.rb +5 -4
  49. data/spec/{service → record}/create_spec.rb +6 -5
  50. data/spec/{service → record}/creation_failed_spec.rb +6 -5
  51. data/spec/record/definitions_spec.rb +29 -0
  52. data/spec/{service → record}/endpoint_misconfiguration_spec.rb +3 -3
  53. data/spec/{service → record}/endpoint_options_spec.rb +4 -4
  54. data/spec/{service → record}/endpoints_spec.rb +15 -15
  55. data/spec/{service → record}/find_by_spec.rb +8 -8
  56. data/spec/{service → record}/find_each_spec.rb +3 -3
  57. data/spec/{service → record}/find_in_batches_spec.rb +6 -6
  58. data/spec/{service → record}/find_spec.rb +10 -9
  59. data/spec/{service → record}/first_spec.rb +7 -6
  60. data/spec/{service → record}/includes_spec.rb +7 -7
  61. data/spec/{service → record}/mapping_spec.rb +27 -16
  62. data/spec/{service → record}/model_name_spec.rb +2 -2
  63. data/spec/{service → record}/new_spec.rb +4 -3
  64. data/spec/{service → record}/request_spec.rb +3 -3
  65. data/spec/record/where_spec.rb +34 -0
  66. data/spec/support/cleanup_endpoints.rb +1 -1
  67. data/spec/support/{cleanup_services.rb → cleanup_records.rb} +2 -2
  68. metadata +60 -67
  69. data/docs/collections.md +0 -28
  70. data/docs/data.md +0 -39
  71. data/docs/items.md +0 -79
  72. data/docs/service.jpg +0 -0
  73. data/docs/service.pdf +2 -650
  74. data/docs/services.md +0 -266
  75. data/lib/lhs/concerns/service/build.rb +0 -19
  76. data/lib/lhs/service.rb +0 -18
  77. data/spec/data/pagination_spec.rb +0 -60
  78. data/spec/dummy/README.rdoc +0 -28
  79. data/spec/service/where_spec.rb +0 -33
@@ -3,7 +3,7 @@ require 'rails_helper'
3
3
  describe LHS::Proxy do
4
4
 
5
5
  before(:each) do
6
- class SomeService < LHS::Service
6
+ class Record < LHS::Record
7
7
  endpoint ':datastore/v2/feedbacks'
8
8
  end
9
9
  end
@@ -13,7 +13,7 @@ describe LHS::Proxy do
13
13
  end
14
14
 
15
15
  let(:data) do
16
- LHS::Data.new(json, nil, SomeService)
16
+ LHS::Data.new(json, nil, Record)
17
17
  end
18
18
 
19
19
  let(:item) do
@@ -6,7 +6,7 @@ describe LHS::Collection do
6
6
 
7
7
  before(:each) do
8
8
  LHC.config.placeholder('datastore', datastore)
9
- class SomeService < LHS::Service
9
+ class Record < LHS::Record
10
10
  endpoint ':datastore/:campaign_id/feedbacks'
11
11
  endpoint ':datastore/feedbacks'
12
12
  end
@@ -21,8 +21,8 @@ describe LHS::Collection do
21
21
  .to_return(status: 200, body: {items: (101..200).to_a, total: 300, limit: 100, offset: 101}.to_json)
22
22
  stub_request(:get, "#{datastore}/feedbacks?limit=100&offset=201")
23
23
  .to_return(status: 200, body: {items: (201..300).to_a, total: 300, limit: 100, offset: 201}.to_json)
24
- all = SomeService.all
25
- expect(all).to be_kind_of LHS::Data
24
+ all = Record.all
25
+ expect(all).to be_kind_of Record
26
26
  expect(all._proxy).to be_kind_of LHS::Collection
27
27
  expect(all.count).to eq 300
28
28
  expect(all.last).to eq 300
@@ -35,8 +35,8 @@ describe LHS::Collection do
35
35
  .to_return(status: 200, body: {items: (101..200).to_a, total: 300, offset: 101}.to_json)
36
36
  stub_request(:get, "#{datastore}/feedbacks?limit=100&offset=201")
37
37
  .to_return(status: 200, body: {items: (201..300).to_a, total: 300, offset: 201}.to_json)
38
- all = SomeService.all
39
- expect(all).to be_kind_of LHS::Data
38
+ all = Record.all
39
+ expect(all).to be_kind_of Record
40
40
  expect(all._proxy).to be_kind_of LHS::Collection
41
41
  expect(all.count).to eq 300
42
42
  expect(all.last).to eq 300
@@ -45,8 +45,8 @@ describe LHS::Collection do
45
45
  it 'also works when there is no item in the first response' do
46
46
  stub_request(:get, "#{datastore}/feedbacks?limit=100")
47
47
  .to_return(status: 200, body: {items: [], total: 300, offset: 0}.to_json)
48
- all = SomeService.all
49
- expect(all).to be_kind_of LHS::Data
48
+ all = Record.all
49
+ expect(all).to be_kind_of Record
50
50
  expect(all._proxy).to be_kind_of LHS::Collection
51
51
  expect(all.count).to eq 0
52
52
  end
@@ -1,6 +1,6 @@
1
1
  require 'rails_helper'
2
2
 
3
- describe LHS::Service do
3
+ describe LHS::Record do
4
4
 
5
5
  context 'build' do
6
6
 
@@ -8,7 +8,7 @@ describe LHS::Service do
8
8
 
9
9
  before(:each) do
10
10
  LHC.config.placeholder('datastore', datastore)
11
- class Feedback < LHS::Service
11
+ class Feedback < LHS::Record
12
12
  endpoint ':datastore/content-ads/:campaign_id/feedbacks'
13
13
  endpoint ':datastore/feedbacks'
14
14
  end
@@ -16,9 +16,10 @@ describe LHS::Service do
16
16
 
17
17
  it 'builds a new item from scratch' do
18
18
  feedback = Feedback.build recommended: true
19
+ expect(feedback).to be_kind_of Feedback
19
20
  expect(feedback.recommended).to eq true
20
- stub_request(:post, "http://local.ch/v2/feedbacks")
21
- .with(body: "{\"recommended\":true}")
21
+ stub_request(:post, 'http://local.ch/v2/feedbacks')
22
+ .with(body: "{\"recommended\":true}")
22
23
  feedback.save
23
24
  end
24
25
  end
@@ -1,6 +1,6 @@
1
1
  require 'rails_helper'
2
2
 
3
- describe LHS::Service do
3
+ describe LHS::Record do
4
4
 
5
5
  context 'create' do
6
6
 
@@ -8,7 +8,7 @@ describe LHS::Service do
8
8
 
9
9
  before(:each) do
10
10
  LHC.config.placeholder('datastore', datastore)
11
- class Feedback < LHS::Service
11
+ class Feedback < LHS::Record
12
12
  endpoint ':datastore/content-ads/:campaign_id/feedbacks'
13
13
  endpoint ':datastore/feedbacks'
14
14
  end
@@ -23,9 +23,10 @@ describe LHS::Service do
23
23
 
24
24
  it 'creates new record on the backend' do
25
25
  stub_request(:post, "#{datastore}/feedbacks")
26
- .with(body: object.to_json)
27
- .to_return(status: 200, body: object.to_json)
26
+ .with(body: object.to_json)
27
+ .to_return(status: 200, body: object.to_json)
28
28
  record = Feedback.create(object)
29
+ expect(record).to be_kind_of Feedback
29
30
  expect(record.recommended).to eq true
30
31
  expect(record.errors).to eq nil
31
32
  end
@@ -64,7 +65,7 @@ describe LHS::Service do
64
65
 
65
66
  it 'provides errors accessor on the record when creation failed using create' do
66
67
  stub_request(:post, "#{datastore}/content-ads/12345/feedbacks")
67
- .to_return(status: 400, body: creation_error.to_json)
68
+ .to_return(status: 400, body: creation_error.to_json)
68
69
  feedback = Feedback.create(object.merge(campaign_id: '12345'))
69
70
  expect(feedback.errors).to be_kind_of LHS::Errors
70
71
  end
@@ -1,6 +1,6 @@
1
1
  require 'rails_helper'
2
2
 
3
- describe LHS::Service do
3
+ describe LHS::Record do
4
4
 
5
5
  context 'creation failed' do
6
6
 
@@ -8,7 +8,7 @@ describe LHS::Service do
8
8
 
9
9
  before(:each) do
10
10
  LHC.config.placeholder(:datastore, datastore)
11
- class SomeService < LHS::Service
11
+ class Record < LHS::Record
12
12
  endpoint ':datastore/:campaign_id/feedbacks'
13
13
  endpoint ':datastore/feedbacks'
14
14
  end
@@ -34,8 +34,9 @@ describe LHS::Service do
34
34
 
35
35
  it 'provides errors when creation failed' do
36
36
  stub_request(:post, "#{datastore}/feedbacks")
37
- .to_return(status: 400, body: creation_error.to_json)
38
- record = SomeService.create(name: 'Steve')
37
+ .to_return(status: 400, body: creation_error.to_json)
38
+ record = Record.create(name: 'Steve')
39
+ expect(record).to be_kind_of Record
39
40
  expect(record.errors).to be
40
41
  expect(record.name).to eq 'Steve'
41
42
  expect(record.errors.include?(:ratings)).to eq true
@@ -48,7 +49,7 @@ describe LHS::Service do
48
49
  it 'doesnt fail when no fields are provided by the backend' do
49
50
  stub_request(:post, "#{datastore}/feedbacks")
50
51
  .to_return(status: 400, body: {}.to_json)
51
- SomeService.create(name: 'Steve')
52
+ Record.create(name: 'Steve')
52
53
  end
53
54
  end
54
55
  end
@@ -0,0 +1,29 @@
1
+ require 'rails_helper'
2
+
3
+ describe LHS::Record do
4
+
5
+ context 'definitions' do
6
+
7
+ let(:datastore) { 'http://local.ch/v2' }
8
+
9
+ before(:each) do
10
+ LHC.config.placeholder('datastore', datastore)
11
+ class LocalEntry < LHS::Record
12
+ endpoint ':datastore/local-entries'
13
+ endpoint ':datastore/local-entries/:id'
14
+ end
15
+ end
16
+
17
+ it 'allows mappings in all functions/defitions' do
18
+ class LocalEntry < LHS::Record
19
+ def name
20
+ addresses.first.business.identities.first.name
21
+ end
22
+ end
23
+ stub_request(:get, "#{datastore}/local-entries/1")
24
+ .to_return(status: 200, body: {addresses: [{business: {identities: [{name: 'Löwenzorn'}]}}]}.to_json)
25
+ entry = LocalEntry.find(1)
26
+ expect(entry.name).to eq 'Löwenzorn'
27
+ end
28
+ end
29
+ end
@@ -1,13 +1,13 @@
1
1
  require 'rails_helper'
2
2
 
3
- describe LHS::Service do
3
+ describe LHS::Record do
4
4
 
5
5
  context 'misconfiguration of endpoints' do
6
6
 
7
7
  it 'fails trying to add clashing endpoints' do
8
8
  expect(
9
9
  ->{
10
- class SomeService < LHS::Service
10
+ class Record < LHS::Record
11
11
  endpoint ':datastore/v2/feedbacks'
12
12
  endpoint ':datastore/v2/reviews'
13
13
  end
@@ -15,7 +15,7 @@ describe LHS::Service do
15
15
  ).to raise_error('Clashing endpoints.')
16
16
  expect(
17
17
  ->{
18
- class SomeService < LHS::Service
18
+ class Record < LHS::Record
19
19
  endpoint ':datastore/v2/:campaign_id/feedbacks'
20
20
  endpoint ':datastore/v2/:campaign_id/reviews'
21
21
  end
@@ -1,23 +1,23 @@
1
1
  require 'rails_helper'
2
2
 
3
- describe LHS::Service do
3
+ describe LHS::Record do
4
4
 
5
5
  context 'set options for an endpoint' do
6
6
 
7
7
  before(:each) do
8
- class SomeService < LHS::Service
8
+ class Record < LHS::Record
9
9
  endpoint 'backend/v2/feedbacks/:id', cache_expires_in: 1.day, retry: 2, cache: true
10
10
  end
11
11
  end
12
12
 
13
13
  it 'stores endpoints with options' do
14
- expect(SomeService.endpoints[0].options).to eq(cache_expires_in: 86400, retry: 2, cache: true)
14
+ expect(Record.endpoints[0].options).to eq(cache_expires_in: 86400, retry: 2, cache: true)
15
15
  end
16
16
 
17
17
  it 'uses the options that are configured for an endpoint' do
18
18
  expect(LHC).to receive(:request).with(cache_expires_in: 1.day, retry: 2, cache: true, url: 'backend/v2/feedbacks/1').and_call_original
19
19
  stub_request(:get, "http://backend/v2/feedbacks/1").to_return(status: 200)
20
- SomeService.find(1)
20
+ Record.find(1)
21
21
  end
22
22
  end
23
23
  end
@@ -1,6 +1,6 @@
1
1
  require 'rails_helper'
2
2
 
3
- describe LHS::Service do
3
+ describe LHS::Record do
4
4
 
5
5
  context 'endpoints' do
6
6
 
@@ -8,7 +8,7 @@ describe LHS::Service do
8
8
 
9
9
  before(:each) do
10
10
  LHC.config.placeholder(:datastore, datastore)
11
- class SomeService < LHS::Service
11
+ class Record < LHS::Record
12
12
  endpoint ':datastore/entries/:entry_id/content-ads/:campaign_id/feedbacks'
13
13
  endpoint ':datastore/:campaign_id/feedbacks'
14
14
  endpoint ':datastore/feedbacks'
@@ -16,37 +16,37 @@ describe LHS::Service do
16
16
  end
17
17
 
18
18
  it 'stores all the endpoints by url' do
19
- expect(LHS::Service::Endpoints.all[':datastore/entries/:entry_id/content-ads/:campaign_id/feedbacks']).to be
20
- expect(LHS::Service::Endpoints.all[':datastore/:campaign_id/feedbacks']).to be
21
- expect(LHS::Service::Endpoints.all[':datastore/feedbacks']).to be
19
+ expect(LHS::Record::Endpoints.all[':datastore/entries/:entry_id/content-ads/:campaign_id/feedbacks']).to be
20
+ expect(LHS::Record::Endpoints.all[':datastore/:campaign_id/feedbacks']).to be
21
+ expect(LHS::Record::Endpoints.all[':datastore/feedbacks']).to be
22
22
  end
23
23
 
24
24
  it 'stores the endpoints of the service' do
25
- expect(SomeService.endpoints.count).to eq 3
26
- expect(SomeService.endpoints[0].url).to eq ':datastore/entries/:entry_id/content-ads/:campaign_id/feedbacks'
27
- expect(SomeService.endpoints[1].url).to eq ':datastore/:campaign_id/feedbacks'
28
- expect(SomeService.endpoints[2].url).to eq ':datastore/feedbacks'
25
+ expect(Record.endpoints.count).to eq 3
26
+ expect(Record.endpoints[0].url).to eq ':datastore/entries/:entry_id/content-ads/:campaign_id/feedbacks'
27
+ expect(Record.endpoints[1].url).to eq ':datastore/:campaign_id/feedbacks'
28
+ expect(Record.endpoints[2].url).to eq ':datastore/feedbacks'
29
29
  end
30
30
 
31
31
  it 'finds the endpoint by the one with the most route param hits' do
32
32
  expect(
33
- SomeService.find_endpoint(campaign_id: '12345').url
33
+ Record.find_endpoint(campaign_id: '12345').url
34
34
  ).to eq ':datastore/:campaign_id/feedbacks'
35
35
  expect(
36
- SomeService.find_endpoint(campaign_id: '12345', entry_id: '123').url
36
+ Record.find_endpoint(campaign_id: '12345', entry_id: '123').url
37
37
  ).to eq ':datastore/entries/:entry_id/content-ads/:campaign_id/feedbacks'
38
38
  end
39
39
 
40
40
  it 'finds the base endpoint (endpoint with least amount of route params)' do
41
41
  expect(
42
- SomeService.find_endpoint.url
42
+ Record.find_endpoint.url
43
43
  ).to eq ':datastore/feedbacks'
44
44
  end
45
45
 
46
46
  context 'compute url from endpoint' do
47
47
 
48
48
  before(:each) do
49
- class Feedback < LHS::Service
49
+ class Feedback < LHS::Record
50
50
  endpoint ':datastore/feedbacks'
51
51
  endpoint ':datastore/feedbacks/:id'
52
52
  end
@@ -61,7 +61,7 @@ describe LHS::Service do
61
61
  context 'unsorted endpoints' do
62
62
 
63
63
  before(:each) do
64
- class AnotherService < LHS::Service
64
+ class AnotherRecord < LHS::Record
65
65
  endpoint ':datastore/feedbacks'
66
66
  endpoint ':datastore/:campaign_id/feedbacks'
67
67
  endpoint ':datastore/entries/:entry_id/content-ads/:campaign_id/feedbacks'
@@ -70,7 +70,7 @@ describe LHS::Service do
70
70
 
71
71
  it 'sorts endpoints before trying to find the best endpoint' do
72
72
  stub_request(:get, "#{datastore}/entries/123/content-ads/123/feedbacks").to_return(status: 200)
73
- AnotherService.where(campaign_id: 123, entry_id: 123)
73
+ AnotherRecord.where(campaign_id: 123, entry_id: 123)
74
74
  end
75
75
 
76
76
  end
@@ -1,11 +1,11 @@
1
1
  require 'rails_helper'
2
2
 
3
- describe LHS::Service do
3
+ describe LHS::Record do
4
4
  let(:datastore) { 'http://local.ch/v2' }
5
5
 
6
6
  before(:each) do
7
7
  LHC.config.placeholder(:datastore, datastore)
8
- class SomeService < LHS::Service
8
+ class Record < LHS::Record
9
9
  endpoint ':datastore/content-ads/:campaign_id/feedbacks'
10
10
  endpoint ':datastore/content-ads/:campaign_id/feedbacks/:id'
11
11
  endpoint ':datastore/feedbacks'
@@ -17,16 +17,16 @@ describe LHS::Service do
17
17
  it 'finds a single record' do
18
18
  stub_request(:get, "#{datastore}/feedbacks/z12f-3asm3ngals?limit=1")
19
19
  .to_return(status: 200, body: load_json(:feedback))
20
- expect(
21
- SomeService.find_by(id: 'z12f-3asm3ngals').source_id
22
- ).to be_kind_of String
20
+ record = Record.find_by(id: 'z12f-3asm3ngals')
21
+ expect(record.source_id).to be_kind_of String
22
+ expect(record).to be_kind_of Record
23
23
  end
24
24
 
25
25
  it 'returns nil if no record was found' do
26
26
  stub_request(:get, "#{datastore}/feedbacks/something-inexistent?limit=1")
27
27
  .to_return(status: 404)
28
28
  expect(
29
- SomeService.find_by(id: 'something-inexistent')
29
+ Record.find_by(id: 'something-inexistent')
30
30
  ).to eq nil
31
31
  end
32
32
 
@@ -35,7 +35,7 @@ describe LHS::Service do
35
35
  stub_request(:get, "#{datastore}/feedbacks?has_reviews=true&limit=1")
36
36
  .to_return(status: 200, body: json)
37
37
  expect(
38
- SomeService.find_by(has_reviews: true).id
38
+ Record.find_by(has_reviews: true).id
39
39
  ).to eq json['items'].first['id']
40
40
  end
41
41
  end
@@ -44,7 +44,7 @@ describe LHS::Service do
44
44
  it 'raises if nothing was found with parameters' do
45
45
  stub_request(:get, "#{datastore}/feedbacks?has_reviews=true&limit=1")
46
46
  .to_return(status: 200, body: { items: [] }.to_json)
47
- expect { SomeService.find_by!(has_reviews: true) }
47
+ expect { Record.find_by!(has_reviews: true) }
48
48
  .to raise_error LHC::NotFound
49
49
  end
50
50
  end
@@ -20,7 +20,7 @@ describe LHS::Collection do
20
20
 
21
21
  before(:each) do
22
22
  LHC.config.placeholder('datastore', datastore)
23
- class SomeService < LHS::Service
23
+ class Record < LHS::Record
24
24
  endpoint ':datastore/:campaign_id/feedbacks'
25
25
  endpoint ':datastore/feedbacks'
26
26
  end
@@ -35,10 +35,10 @@ describe LHS::Collection do
35
35
  stub_request(:get, "#{datastore}/feedbacks?limit=100&offset=301").to_return(status: 200, body: api_response((301..400).to_a, 301))
36
36
  stub_request(:get, "#{datastore}/feedbacks?limit=100&offset=401").to_return(status: 200, body: api_response((401..total).to_a, 401))
37
37
  count = 0
38
- SomeService.find_each do |record|
38
+ Record.find_each do |record|
39
39
  count += 1
40
40
  expect(record.id).to eq(count)
41
- expect(record).to be_kind_of LHS::Data
41
+ expect(record).to be_kind_of Record
42
42
  expect(record._proxy).to be_kind_of LHS::Item
43
43
  end
44
44
  expect(count).to eq total
@@ -20,7 +20,7 @@ describe LHS::Collection do
20
20
 
21
21
  before(:each) do
22
22
  LHC.config.placeholder('datastore', datastore)
23
- class SomeService < LHS::Service
23
+ class Record < LHS::Record
24
24
  endpoint ':datastore/:campaign_id/feedbacks'
25
25
  endpoint ':datastore/feedbacks'
26
26
  end
@@ -35,9 +35,9 @@ describe LHS::Collection do
35
35
  stub_request(:get, "#{datastore}/feedbacks?limit=100&offset=301").to_return(status: 200, body: api_response((301..400).to_a, 301))
36
36
  stub_request(:get, "#{datastore}/feedbacks?limit=100&offset=401").to_return(status: 200, body: api_response((401..total).to_a, 401))
37
37
  count = 0
38
- SomeService.find_in_batches do |records|
38
+ Record.find_in_batches do |records|
39
39
  count += records.count
40
- expect(records).to be_kind_of LHS::Data
40
+ expect(records).to be_kind_of Record
41
41
  expect(records._proxy).to be_kind_of LHS::Collection
42
42
  end
43
43
  expect(count).to eq total
@@ -50,9 +50,9 @@ describe LHS::Collection do
50
50
  stub_request(:get, "#{datastore}/feedbacks?limit=100&offset=301").to_return(status: 200, body: api_response((301..400).to_a, 301))
51
51
  stub_request(:get, "#{datastore}/feedbacks?limit=100&offset=401").to_return(status: 200, body: api_response((401..total).to_a, 401))
52
52
  count = 0
53
- SomeService.find_in_batches(batch_size: 230) do |records|
53
+ Record.find_in_batches(batch_size: 230) do |records|
54
54
  count += records.count
55
- expect(records).to be_kind_of LHS::Data
55
+ expect(records).to be_kind_of Record
56
56
  expect(records._proxy).to be_kind_of LHS::Collection
57
57
  end
58
58
  expect(count).to eq total
@@ -60,7 +60,7 @@ describe LHS::Collection do
60
60
 
61
61
  it 'forwards offset' do
62
62
  stub_request(:get, "#{datastore}/feedbacks?limit=100&offset=401").to_return(status: 200, body: api_response((401..total).to_a, 401))
63
- SomeService.find_in_batches(start: 401) do |records|
63
+ Record.find_in_batches(start: 401) do |records|
64
64
  expect(records.count).to eq(total-400)
65
65
  end
66
66
  end
@@ -1,12 +1,12 @@
1
1
  require 'rails_helper'
2
2
 
3
- describe LHS::Service do
3
+ describe LHS::Record do
4
4
 
5
5
  let(:datastore) { 'http://local.ch/v2' }
6
6
 
7
7
  before(:each) do
8
8
  LHC.config.placeholder(:datastore, datastore)
9
- class SomeService < LHS::Service
9
+ class Record < LHS::Record
10
10
  endpoint ':datastore/content-ads/:campaign_id/feedbacks'
11
11
  endpoint ':datastore/content-ads/:campaign_id/feedbacks/:id'
12
12
  endpoint ':datastore/feedbacks'
@@ -19,20 +19,21 @@ describe LHS::Service do
19
19
  it 'finds a single unique record' do
20
20
  stub_request(:get, "#{datastore}/feedbacks/z12f-3asm3ngals").
21
21
  to_return(status: 200, body: load_json(:feedback))
22
- record = SomeService.find('z12f-3asm3ngals')
22
+ record = Record.find('z12f-3asm3ngals')
23
+ expect(record).to be_kind_of Record
23
24
  expect(record.source_id).to be_kind_of String
24
25
  end
25
26
 
26
27
  it 'raises if nothing was found' do
27
28
  stub_request(:get, "#{datastore}/feedbacks/not-existing").
28
29
  to_return(status: 404)
29
- expect { SomeService.find('not-existing') }.to raise_error LHC::NotFound
30
+ expect { Record.find('not-existing') }.to raise_error LHC::NotFound
30
31
  end
31
32
 
32
33
  it 'finds unique item by providing parameters' do
33
34
  stub_request(:get, "#{datastore}/content-ads/123/feedbacks/123")
34
35
  .to_return(body: "{}")
35
- data = SomeService.find(campaign_id: '123', id: '123')
36
+ data = Record.find(campaign_id: '123', id: '123')
36
37
  expect(data._proxy).to be_kind_of LHS::Item
37
38
  end
38
39
 
@@ -41,7 +42,7 @@ describe LHS::Service do
41
42
  data['items'] = [data['items'].first]
42
43
  stub_request(:get, "#{datastore}/content-ads/123/feedbacks/123")
43
44
  .to_return(body: data.to_json)
44
- data = SomeService.find(campaign_id: '123', id: '123')
45
+ data = Record.find(campaign_id: '123', id: '123')
45
46
  expect(data._proxy).to be_kind_of LHS::Item
46
47
  end
47
48
 
@@ -49,7 +50,7 @@ describe LHS::Service do
49
50
  stub_request(:get, "#{datastore}/content-ads/123/feedbacks/123")
50
51
  .to_return(body: load_json(:feedbacks))
51
52
  expect(->{
52
- SomeService.find(campaign_id: '123', id: '123')
53
+ Record.find(campaign_id: '123', id: '123')
53
54
  }).to raise_error LHC::NotFound
54
55
  end
55
56
 
@@ -59,14 +60,14 @@ describe LHS::Service do
59
60
  stub_request(:get, "#{datastore}/content-ads/123/feedbacks/123")
60
61
  .to_return(body: data.to_json)
61
62
  expect(->{
62
- SomeService.find(campaign_id: '123', id: '123')
63
+ Record.find(campaign_id: '123', id: '123')
63
64
  }).to raise_error LHC::NotFound
64
65
  end
65
66
 
66
67
  it 'raises if nothing was found with parameters' do
67
68
  stub_request(:get, "#{datastore}/content-ads/123/feedbacks/123")
68
69
  .to_return(status: 404)
69
- expect { SomeService.find(campaign_id: '123', id: '123') }.to raise_error LHC::NotFound
70
+ expect { Record.find(campaign_id: '123', id: '123') }.to raise_error LHC::NotFound
70
71
  end
71
72
 
72
73
  end