lhs 25.1.0 → 25.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92e9ccdfc62407ecb0d4ba6b6ce18b28628ecaad229586f589eb7167fe8ff0de
4
- data.tar.gz: 26924759db03d133fbfc8dee9be190e8238fa0fc3036f7b79b13636e881f785e
3
+ metadata.gz: 22ba3545c4f37d2becb37fbe7efb328a942af240d6a4d03e64fea4890e766969
4
+ data.tar.gz: 9cd64f9e1222e7f0f4cb041bdf967c257a2f0fd3ef1564618a65650e23a07ec1
5
5
  SHA512:
6
- metadata.gz: 4186ce186f51e95872532c943c93a402b1d23160d35b123f2fa4c01a1e589ffc863b5f6345c8071c606545539e91e789d75bed7efefcef0546677fe852a56d3d
7
- data.tar.gz: b31b7ab8443d71a735397127f389d8dda1f9add35fa318e92ba0172f65172d21928181120a56c953227d0051778646745c8c510c04967e17ba0c24ddd60723ea
6
+ metadata.gz: a9c87bfbc21370b89591c0b7a58bf30a24d8123ccbd41280f418afd69a5ebae47d05e0367fabdc7b7a0441a3cdf9729da8fee97b1c2fd5c39fbc757a7c1a0e6e
7
+ data.tar.gz: 4ef0c1857ba4983df1c567ea3ffee56ef5348e195e000beed34b4d91d7d372effc9c7fcbeb0d59419aebad7477926ece0e8938b9dfab936827603a8488f051a8
@@ -4,24 +4,13 @@ on: push
4
4
 
5
5
  jobs:
6
6
  rubocop:
7
- runs-on: ubuntu-latest
7
+ runs-on: ubuntu-18.04
8
8
 
9
9
  steps:
10
10
  - uses: actions/checkout@v2
11
- - uses: actions/setup-ruby@v1
11
+ - uses: ruby/setup-ruby@v1
12
12
  with:
13
- ruby-version: 2.7.2
14
- - name: Cache Ruby Gems
15
- uses: actions/cache@v2
16
- with:
17
- path: /.tmp/vendor/bundle
18
- key: ${{ runner.os }}-gems-latest-${{ hashFiles('**/Gemfile.lock') }}
19
- restore-keys: |
20
- ${{ runner.os }}-gems-latest-
21
- - name: Bundle Install
22
- run: |
23
- bundle config path /.tmp/vendor/bundle
24
- bundle install --jobs 4 --retry 3
13
+ bundler-cache: true
25
14
  - name: Run Rubocop
26
15
  run: |
27
16
  bundle exec rubocop
@@ -4,24 +4,17 @@ on: push
4
4
 
5
5
  jobs:
6
6
  rspec:
7
- runs-on: ubuntu-latest
7
+ runs-on: ubuntu-18.04
8
8
 
9
9
  steps:
10
10
  - uses: actions/checkout@v2
11
- - uses: actions/setup-ruby@v1
11
+ - uses: ruby/setup-ruby@v1
12
12
  with:
13
- ruby-version: 2.7.2
14
- - name: Cache Ruby Gems
15
- uses: actions/cache@v2
16
- with:
17
- path: /.tmp/vendor/bundle
18
- key: ${{ runner.os }}-gems-v5-${{ hashFiles('**/Gemfile.lock') }}
19
- restore-keys: |
20
- ${{ runner.os }}-gems-v5-
21
- - name: Bundle Install ActiveSupport v5
22
- run: |
23
- bundle config path /.tmp/vendor/bundle
24
- BUNDLE_GEMFILE=Gemfile.activesupport5 bundle install --jobs 4 --retry 3
13
+ bundler-cache: true
14
+ env:
15
+ BUNDLE_GEMFILE: Gemfile.activesupport5
25
16
  - name: Run Tests
17
+ env:
18
+ BUNDLE_GEMFILE: Gemfile.activesupport5
26
19
  run: |
27
- BUNDLE_GEMFILE=Gemfile.activesupport5 bundle exec rspec
20
+ bundle exec rspec
@@ -4,24 +4,13 @@ on: push
4
4
 
5
5
  jobs:
6
6
  rspec:
7
- runs-on: ubuntu-latest
7
+ runs-on: ubuntu-18.04
8
8
 
9
9
  steps:
10
10
  - uses: actions/checkout@v2
11
- - uses: actions/setup-ruby@v1
11
+ - uses: ruby/setup-ruby@v1
12
12
  with:
13
- ruby-version: 2.7.2
14
- - name: Cache Ruby Gems
15
- uses: actions/cache@v2
16
- with:
17
- path: /.tmp/vendor/bundle
18
- key: ${{ runner.os }}-gems-latest-${{ hashFiles('**/Gemfile.lock') }}
19
- restore-keys: |
20
- ${{ runner.os }}-gems-latest-
21
- - name: Bundle Install
22
- run: |
23
- bundle config path /.tmp/vendor/bundle
24
- bundle install --jobs 4 --retry 3
13
+ bundler-cache: true
25
14
  - name: Run Tests
26
15
  run: |
27
16
  bundle exec rspec
data/README.md CHANGED
@@ -80,7 +80,6 @@ record.review # "Lunch was great
80
80
  * [Pagination strategy](#pagination-strategy)
81
81
  * [Pagination strategy: offset (default)](#pagination-strategy-offset-default)
82
82
  * [Pagination strategy: page](#pagination-strategy-page)
83
- * [Pagination strategy: total_pages](#pagination-strategy-total-pages)
84
83
  * [Pagination strategy: start](#pagination-strategy-start)
85
84
  * [Pagination strategy: link](#pagination-strategy-link)
86
85
  * [Pagination keys](#pagination-keys)
@@ -1254,41 +1253,6 @@ In parallel:
1254
1253
  GET https://service.example.com/records?limit=100&page=3
1255
1254
  ```
1256
1255
 
1257
- ##### Pagination strategy: total_pages
1258
-
1259
- The `total_pages` strategy is based on the `page` strategy with the only difference
1260
- that the responding api provides `total_pages` over `total_items`.
1261
-
1262
- ```ruby
1263
- # app/models/transaction.rb
1264
-
1265
- class Transaction < LHS::Record
1266
- configuration pagination_strategy: 'total_pages', pagination_key: 'page', total_key: 'total_pages'
1267
-
1268
- endpoint '{+service}/transactions'
1269
- end
1270
- ```
1271
-
1272
- ```ruby
1273
- # app/controllers/some_controller.rb
1274
-
1275
- Record.all
1276
-
1277
- ```
1278
- ```
1279
- GET https://service.example.com/transactions?limit=100
1280
- {
1281
- items: [{...}, ...],
1282
- total_pages: 3,
1283
- limit: 100,
1284
- page: 1
1285
- }
1286
- In parallel:
1287
- GET https://service.example.com/records?limit=100&page=2
1288
- GET https://service.example.com/records?limit=100&page=3
1289
- ```
1290
-
1291
-
1292
1256
  ##### Pagination strategy: start
1293
1257
 
1294
1258
  In comparison to the `offset` strategy, the `start` strategy indicates with which item the current page starts.
data/lib/lhs.rb CHANGED
@@ -58,8 +58,6 @@ module LHS
58
58
  'lhs/pagination/offset'
59
59
  autoload :Page,
60
60
  'lhs/pagination/page'
61
- autoload :TotalPages,
62
- 'lhs/pagination/total_pages'
63
61
  autoload :Start,
64
62
  'lhs/pagination/start'
65
63
  autoload :Link,
@@ -45,7 +45,7 @@ class LHS::Item < LHS::Proxy
45
45
  _data.merge_raw!(response_data.unwrap(:item_created_key))
46
46
  response_headers = response_data._request.response.headers
47
47
  end
48
- if response_headers && response_headers['Location']
48
+ if options.fetch(:followlocation, true) && response_headers && response_headers['Location']
49
49
  location_data = record.request(options.merge(url: response_headers['Location'], method: :get, body: nil))
50
50
  _data.merge_raw!(location_data.unwrap(:item_created_key))
51
51
  end
@@ -22,8 +22,6 @@ class LHS::Record
22
22
  case pagination_strategy.to_sym
23
23
  when :page
24
24
  LHS::Pagination::Page
25
- when :total_pages
26
- LHS::Pagination::TotalPages
27
25
  when :start
28
26
  LHS::Pagination::Start
29
27
  when :link
data/lib/lhs/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LHS
4
- VERSION = '25.1.0'
4
+ VERSION = '25.2.0'
5
5
  end
@@ -3,7 +3,7 @@
3
3
  class RequestCycleCacheController < ApplicationController
4
4
  def simple
5
5
  User.find(1) # first request
6
- user = User.find(1) # second request that should be serverd from request cycle cache
6
+ user = User.find(1) # second request that should be served from request cycle cache
7
7
  render json: user.to_json
8
8
  end
9
9
 
@@ -15,13 +15,13 @@ class RequestCycleCacheController < ApplicationController
15
15
 
16
16
  def parallel
17
17
  User.find(1, 2) # first request
18
- users = User.find(1, 2) # second request that should be serverd from request cycle cache
18
+ users = User.find(1, 2) # second request that should be served from request cycle cache
19
19
  render json: users.to_json
20
20
  end
21
21
 
22
- def headers
22
+ def different_headers
23
23
  User.find(1) # first request
24
- user = User.options(headers: { 'Authentication' => 'Bearer 123' }).find(1) # second request that should NOT be serverd from request cycle cache as the headers are different
24
+ user = User.options(headers: { 'Authentication' => 'Bearer 123' }).find(1) # second request that should NOT be served from request cycle cache as the headers are different
25
25
  render json: user.to_json
26
26
  end
27
27
  end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ LHS.configure do |config|
4
+ config.auto_oauth = -> { access_token }
5
+ end
@@ -12,7 +12,7 @@ Rails.application.routes.draw do
12
12
  get 'request_cycle_cache/simple' => 'request_cycle_cache#simple'
13
13
  get 'request_cycle_cache/no_caching_interceptor' => 'request_cycle_cache#no_caching_interceptor'
14
14
  get 'request_cycle_cache/parallel' => 'request_cycle_cache#parallel'
15
- get 'request_cycle_cache/headers' => 'request_cycle_cache#headers'
15
+ get 'request_cycle_cache/different_headers' => 'request_cycle_cache#different_headers'
16
16
 
17
17
  # Error handling with chains
18
18
  get 'error_handling_with_chains/fetch_in_controller' => 'error_handling_with_chains#fetch_in_controller'
@@ -135,25 +135,65 @@ describe LHS::Record do
135
135
  end
136
136
 
137
137
  context 'location header' do
138
- before do
139
- class ContactPerson < LHS::Record
140
- endpoint 'http://datastore/contact_persons'
141
- end
142
- end
143
-
144
- let(:location) { 'http://datastore/contact_persons/1' }
145
138
  let(:created_at) { '2017-12-21' }
139
+ let(:location) { 'http://datastore/contact_persons/1' }
146
140
  let(:name) { 'Sebastian' }
147
-
148
- it 'Loads the data from the "Location" header after creation' do
141
+ let!(:create_contact_person_request) do
149
142
  stub_request(:post, "http://datastore/contact_persons")
150
143
  .to_return(status: 204, headers: { Location: location })
144
+ end
145
+ let!(:fetch_contact_person_request) do
151
146
  stub_request(:get, "http://datastore/contact_persons/1")
152
147
  .to_return(body: { href: location, name: name, created_at: created_at }.to_json)
153
- contact_person = ContactPerson.create!(name: name)
154
- expect(contact_person.href).to eq location
155
- expect(contact_person.created_at).to eq Date.parse(created_at)
156
- expect(contact_person.name).to eq name
148
+ end
149
+
150
+ context 'without `followlocation` option' do
151
+ before do
152
+ class ContactPerson < LHS::Record
153
+ endpoint 'http://datastore/contact_persons'
154
+ end
155
+ end
156
+
157
+ it 'loads the data from the "Location" header after creation' do
158
+ contact_person = ContactPerson.create!(name: name)
159
+ expect(create_contact_person_request).to have_been_made.once
160
+ expect(fetch_contact_person_request).to have_been_made.once
161
+ expect(contact_person.href).to eq location
162
+ expect(contact_person.created_at).to eq Date.parse(created_at)
163
+ expect(contact_person.name).to eq name
164
+ end
165
+ end
166
+
167
+ context 'when `followlocation` is set to `true`' do
168
+ before do
169
+ class ContactPerson < LHS::Record
170
+ endpoint 'http://datastore/contact_persons', followlocation: true
171
+ end
172
+ end
173
+
174
+ it 'loads the data from the "Location" header after creation' do
175
+ contact_person = ContactPerson.create!(name: name)
176
+ expect(create_contact_person_request).to have_been_made.once
177
+ expect(fetch_contact_person_request).to have_been_made.once
178
+ expect(contact_person.href).to eq location
179
+ expect(contact_person.created_at).to eq Date.parse(created_at)
180
+ expect(contact_person.name).to eq name
181
+ end
182
+ end
183
+
184
+ context 'when `followlocation` is set to `false`' do
185
+ before do
186
+ class ContactPerson < LHS::Record
187
+ endpoint 'http://datastore/contact_persons', followlocation: false
188
+ end
189
+ end
190
+
191
+ it 'does not load the data from the "Location" header after creation' do
192
+ contact_person = ContactPerson.create!(name: name)
193
+ expect(create_contact_person_request).to have_been_made.once
194
+ expect(fetch_contact_person_request).not_to have_been_made
195
+ expect(contact_person.name).to eq name
196
+ end
157
197
  end
158
198
  end
159
199
  end
@@ -85,7 +85,7 @@ describe 'Request Cycle Cache', type: :request do
85
85
  context 'headers' do
86
86
  it 'considers the request headers when setting the cache key',
87
87
  dummy_models: true, request_cycle_cache: true do
88
- get '/request_cycle_cache/headers'
88
+ get '/request_cycle_cache/different_headers'
89
89
  expect(request).to have_been_made.times(2)
90
90
  end
91
91
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhs
3
3
  version: !ruby/object:Gem::Version
4
- version: 25.1.0
4
+ version: 25.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - https://github.com/local-ch/lhs/graphs/contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-25 00:00:00.000000000 Z
11
+ date: 2021-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -321,7 +321,6 @@ files:
321
321
  - lib/lhs/pagination/offset.rb
322
322
  - lib/lhs/pagination/page.rb
323
323
  - lib/lhs/pagination/start.rb
324
- - lib/lhs/pagination/total_pages.rb
325
324
  - lib/lhs/problems/base.rb
326
325
  - lib/lhs/problems/errors.rb
327
326
  - lib/lhs/problems/nested/base.rb
@@ -410,6 +409,7 @@ files:
410
409
  - spec/dummy/config/initializers/cookies_serializer.rb
411
410
  - spec/dummy/config/initializers/filter_parameter_logging.rb
412
411
  - spec/dummy/config/initializers/inflections.rb
412
+ - spec/dummy/config/initializers/lhs.rb
413
413
  - spec/dummy/config/initializers/mime_types.rb
414
414
  - spec/dummy/config/initializers/rollbar.rb
415
415
  - spec/dummy/config/initializers/session_store.rb
@@ -457,7 +457,6 @@ files:
457
457
  - spec/pagination/link/total_spec.rb
458
458
  - spec/pagination/offset/pages_left_spec.rb
459
459
  - spec/pagination/parameters_spec.rb
460
- - spec/pagination/total_pages_spec.rb
461
460
  - spec/proxy/create_sub_resource_spec.rb
462
461
  - spec/proxy/load_spec.rb
463
462
  - spec/proxy/record_identification_spec.rb
@@ -644,6 +643,7 @@ test_files:
644
643
  - spec/dummy/config/initializers/cookies_serializer.rb
645
644
  - spec/dummy/config/initializers/filter_parameter_logging.rb
646
645
  - spec/dummy/config/initializers/inflections.rb
646
+ - spec/dummy/config/initializers/lhs.rb
647
647
  - spec/dummy/config/initializers/mime_types.rb
648
648
  - spec/dummy/config/initializers/rollbar.rb
649
649
  - spec/dummy/config/initializers/session_store.rb
@@ -691,7 +691,6 @@ test_files:
691
691
  - spec/pagination/link/total_spec.rb
692
692
  - spec/pagination/offset/pages_left_spec.rb
693
693
  - spec/pagination/parameters_spec.rb
694
- - spec/pagination/total_pages_spec.rb
695
694
  - spec/proxy/create_sub_resource_spec.rb
696
695
  - spec/proxy/load_spec.rb
697
696
  - spec/proxy/record_identification_spec.rb
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class LHS::Pagination::TotalPages < LHS::Pagination::Page
4
-
5
- def total
6
- (data._raw.dig(*_record.total_key) || 0) * limit
7
- end
8
- alias count total
9
- end
@@ -1,52 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- describe LHS::Record do
6
- context 'pagination' do
7
-
8
- let(:page_1_json) do
9
- {
10
- items: [1, 2],
11
- total_pages: 3,
12
- page: 1,
13
- limit: 2
14
- }.to_json
15
- end
16
-
17
- let(:page_2_json) do
18
- {
19
- items: [3, 4],
20
- total_pages: 3,
21
- page: 2,
22
- limit: 2
23
- }.to_json
24
- end
25
-
26
- let(:page_3_json) do
27
- {
28
- items: [5, 6],
29
- total_pages: 3,
30
- page: 3,
31
- limit: 2
32
- }.to_json
33
- end
34
-
35
- before do
36
- class Feedback < LHS::Record
37
- configuration pagination_strategy: :total_pages, total_key: :total_pages, pagination_key: :page
38
- endpoint 'http://local.ch/v2/feedbacks'
39
- end
40
- stub_request(:get, 'http://local.ch/v2/feedbacks?limit=100').to_return(body: page_1_json)
41
- stub_request(:get, 'http://local.ch/v2/feedbacks?limit=2&page=2').to_return(body: page_2_json)
42
- stub_request(:get, 'http://local.ch/v2/feedbacks?limit=2&page=3').to_return(body: page_3_json)
43
- end
44
-
45
- it 'responds to limit_value' do
46
- feedbacks = Feedback.all.fetch
47
- expect(feedbacks.length).to eq 6
48
- expect(feedbacks.count).to eq 6
49
- expect(feedbacks.items.as_json).to eq [1, 2, 3, 4, 5, 6]
50
- end
51
- end
52
- end