lhs 14.6.5 → 15.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 (84) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/README.md +68 -68
  4. data/lhs.gemspec +1 -1
  5. data/lib/lhs/concerns/record/endpoints.rb +1 -1
  6. data/lib/lhs/concerns/record/request.rb +1 -1
  7. data/lib/lhs/version.rb +1 -1
  8. data/spec/autoloading_spec.rb +2 -2
  9. data/spec/collection/collection_items_spec.rb +1 -1
  10. data/spec/collection/configurable_spec.rb +1 -1
  11. data/spec/collection/meta_data_spec.rb +4 -4
  12. data/spec/collection/without_object_items_spec.rb +1 -1
  13. data/spec/data/collection_spec.rb +1 -1
  14. data/spec/data/inspect_spec.rb +1 -1
  15. data/spec/data/item_spec.rb +2 -2
  16. data/spec/data/merge_spec.rb +2 -2
  17. data/spec/data/raw_spec.rb +3 -3
  18. data/spec/data/root_spec.rb +3 -3
  19. data/spec/data/select_spec.rb +1 -1
  20. data/spec/data/to_json_spec.rb +2 -2
  21. data/spec/dummy/app/models/user.rb +1 -1
  22. data/spec/endpoint/for_url_spec.rb +6 -6
  23. data/spec/item/becomes_spec.rb +2 -2
  24. data/spec/item/delegate_spec.rb +2 -2
  25. data/spec/item/destroy_spec.rb +3 -3
  26. data/spec/item/dig_spec.rb +1 -1
  27. data/spec/item/errors_spec.rb +2 -2
  28. data/spec/item/fetch_spec.rb +1 -1
  29. data/spec/item/getter_spec.rb +2 -2
  30. data/spec/item/internal_data_structure_spec.rb +2 -2
  31. data/spec/item/map_spec.rb +1 -1
  32. data/spec/item/partial_update_spec.rb +4 -4
  33. data/spec/item/save_spec.rb +2 -2
  34. data/spec/item/setter_spec.rb +2 -2
  35. data/spec/item/update_spec.rb +2 -2
  36. data/spec/item/validation_spec.rb +2 -2
  37. data/spec/pagination/pages_left_spec.rb +1 -1
  38. data/spec/proxy/create_sub_resource_spec.rb +2 -2
  39. data/spec/proxy/load_spec.rb +2 -2
  40. data/spec/proxy/record_identification_spec.rb +1 -1
  41. data/spec/record/build_spec.rb +2 -2
  42. data/spec/record/cast_nested_data_spec.rb +6 -6
  43. data/spec/record/create_spec.rb +2 -2
  44. data/spec/record/creation_failed_spec.rb +2 -2
  45. data/spec/record/definitions_spec.rb +2 -2
  46. data/spec/record/destroy_spec.rb +1 -1
  47. data/spec/record/endpoint_inheritance_spec.rb +3 -3
  48. data/spec/record/endpoint_misconfiguration_spec.rb +4 -4
  49. data/spec/record/endpoint_options_spec.rb +1 -1
  50. data/spec/record/endpoints_spec.rb +19 -19
  51. data/spec/record/find_by_spec.rb +4 -4
  52. data/spec/record/find_each_spec.rb +2 -2
  53. data/spec/record/find_in_batches_spec.rb +4 -4
  54. data/spec/record/find_in_parallel_spec.rb +1 -1
  55. data/spec/record/find_spec.rb +4 -4
  56. data/spec/record/first_spec.rb +2 -2
  57. data/spec/record/has_many_spec.rb +1 -1
  58. data/spec/record/ignore_errors_spec.rb +1 -1
  59. data/spec/record/includes_all_spec.rb +7 -7
  60. data/spec/record/includes_spec.rb +28 -28
  61. data/spec/record/includes_warning_spec.rb +1 -1
  62. data/spec/record/item_key_spec.rb +1 -1
  63. data/spec/record/loading_twice_spec.rb +2 -2
  64. data/spec/record/mapping_spec.rb +5 -5
  65. data/spec/record/model_name_spec.rb +1 -1
  66. data/spec/record/new_spec.rb +3 -3
  67. data/spec/record/options_spec.rb +2 -2
  68. data/spec/record/paginatable_collection_spec.rb +4 -4
  69. data/spec/record/pagination_chain_spec.rb +3 -3
  70. data/spec/record/pagination_spec.rb +1 -1
  71. data/spec/record/persisted_spec.rb +1 -1
  72. data/spec/record/references_spec.rb +1 -1
  73. data/spec/record/reload_by_id_spec.rb +2 -2
  74. data/spec/record/reload_spec.rb +2 -2
  75. data/spec/record/request_spec.rb +6 -6
  76. data/spec/record/save_spec.rb +1 -1
  77. data/spec/record/scope_chains_spec.rb +1 -1
  78. data/spec/record/to_json_spec.rb +1 -1
  79. data/spec/record/where_chains_spec.rb +1 -1
  80. data/spec/record/where_spec.rb +2 -2
  81. data/spec/record/where_values_hash_spec.rb +1 -1
  82. data/spec/request_cycle_cache/main_spec.rb +1 -1
  83. data/spec/views/form_for_spec.rb +1 -1
  84. metadata +5 -5
@@ -82,7 +82,7 @@ class LHS::Record
82
82
  # The best endpoint is the one where all placeholders are interpolated.
83
83
  def find_best_endpoint(params)
84
84
  sorted_endpoints.find do |endpoint|
85
- endpoint.placeholders.all? { |match| endpoint.find_value(match, params) }
85
+ endpoint.placeholders.all? { |match| endpoint.find_value(match, params).present? }
86
86
  end
87
87
  end
88
88
 
@@ -77,7 +77,7 @@ class LHS::Record
77
77
 
78
78
  def parse_uri(url, options)
79
79
  URI.parse(
80
- if url.match(LHC::Endpoint::PLACEHOLDER)
80
+ if url.match(Addressable::Template::EXPRESSION)
81
81
  compute_url(options[:params], url)
82
82
  else
83
83
  url
@@ -1,3 +1,3 @@
1
1
  module LHS
2
- VERSION = '14.6.5'
2
+ VERSION = '15.0.0'
3
3
  end
@@ -7,12 +7,12 @@ describe LHS, type: :request do
7
7
  cleanup_before: false do
8
8
  all_endpoints = LHS::Record::Endpoints.all
9
9
  expect(all_endpoints['http://datastore/v2/users']).to be
10
- expect(all_endpoints['http://datastore/v2/users/:id']).to be
10
+ expect(all_endpoints['http://datastore/v2/users/{id}']).to be
11
11
  expect(
12
12
  User.endpoints.detect { |endpoint| endpoint.url == 'http://datastore/v2/users' }
13
13
  ).to be
14
14
  expect(
15
- User.endpoints.detect { |endpoint| endpoint.url == 'http://datastore/v2/users/:id' }
15
+ User.endpoints.detect { |endpoint| endpoint.url == 'http://datastore/v2/users/{id}' }
16
16
  ).to be
17
17
  end
18
18
  end
@@ -8,7 +8,7 @@ describe LHS::Collection do
8
8
  before(:each) do
9
9
  LHC.config.placeholder('datastore', datastore)
10
10
  class Account < LHS::Record
11
- endpoint ':datastore/accounts'
11
+ endpoint '{+datastore}/accounts'
12
12
  end
13
13
  stub_request(:get, "http://local.ch/v2/accounts")
14
14
  .to_return(body: response_data.to_json)
@@ -9,7 +9,7 @@ describe LHS::Collection do
9
9
  LHC.config.placeholder('search', search)
10
10
  class Search < LHS::Record
11
11
  configuration items_key: :docs, limit_key: :size, pagination_key: :start, pagination_strategy: :start, total_key: :totalResults
12
- endpoint ':search/:type'
12
+ endpoint '{+search}/{type}'
13
13
  end
14
14
  stub_request(:get, "http://local.ch/search/phonebook?size=10").to_return(
15
15
  body: {
@@ -29,12 +29,12 @@ describe LHS::Collection do
29
29
  before(:each) do
30
30
  LHC.config.placeholder('datastore', datastore)
31
31
  class Feedback < LHS::Record
32
- endpoint ':datastore/feedbacks'
33
- endpoint ':datastore/feedbacks/:id'
32
+ endpoint '{+datastore}/feedbacks'
33
+ endpoint '{+datastore}/feedbacks/{id}'
34
34
  end
35
35
  class User < LHS::Record
36
- endpoint ':datastore/users'
37
- endpoint ':datastore/users/:id'
36
+ endpoint '{+datastore}/users'
37
+ endpoint '{+datastore}/users/{id}'
38
38
  end
39
39
  end
40
40
 
@@ -6,7 +6,7 @@ describe LHS::Collection do
6
6
  before(:each) do
7
7
  LHC.config.placeholder('datastore', datastore)
8
8
  class Account < LHS::Record
9
- endpoint ':datastore/accounts/:id'
9
+ endpoint '{+datastore}/accounts/{id}'
10
10
  end
11
11
  end
12
12
 
@@ -11,7 +11,7 @@ describe LHS::Data do
11
11
 
12
12
  before(:each) do
13
13
  class Record < LHS::Record
14
- endpoint ':datastore/v2/data'
14
+ endpoint '{+datastore}/v2/data'
15
15
  end
16
16
  end
17
17
 
@@ -9,7 +9,7 @@ describe LHS::Data do
9
9
  before(:each) do
10
10
  class Record < LHS::Record
11
11
  endpoint 'http://local.ch/records'
12
- endpoint 'http://local.ch/records/:id'
12
+ endpoint 'http://local.ch/records/{id}'
13
13
  end
14
14
  end
15
15
 
@@ -3,8 +3,8 @@ require 'rails_helper'
3
3
  describe LHS::Data do
4
4
  before(:each) do
5
5
  class Record < LHS::Record
6
- endpoint ':datastore/v2/:campaign_id/feedbacks'
7
- endpoint ':datastore/v2/feedbacks'
6
+ endpoint '{+datastore}/v2/{campaign_id}/feedbacks'
7
+ endpoint '{+datastore}/v2/feedbacks'
8
8
  end
9
9
  end
10
10
 
@@ -3,8 +3,8 @@ require 'rails_helper'
3
3
  describe LHS::Data do
4
4
  before(:each) do
5
5
  class Record < LHS::Record
6
- endpoint ':datastore/v2/:campaign_id/feedbacks'
7
- endpoint ':datastore/v2/feedbacks'
6
+ endpoint '{+datastore}/v2/{campaign_id}/feedbacks'
7
+ endpoint '{+datastore}/v2/feedbacks'
8
8
  end
9
9
  end
10
10
 
@@ -3,9 +3,9 @@ require 'rails_helper'
3
3
  describe LHS::Data do
4
4
  before(:each) do
5
5
  class Record < LHS::Record
6
- endpoint ':datastore/v2/entries/:entry_id/content-ads/:campaign_id/feedbacks'
7
- endpoint ':datastore/v2/:campaign_id/feedbacks'
8
- endpoint ':datastore/v2/feedbacks'
6
+ endpoint '{+datastore}/v2/entries/{entry_id}/content-ads/{campaign_id}/feedbacks'
7
+ endpoint '{+datastore}/v2/{campaign_id}/feedbacks'
8
+ endpoint '{+datastore}/v2/feedbacks'
9
9
  end
10
10
  end
11
11
 
@@ -3,9 +3,9 @@ require 'rails_helper'
3
3
  describe LHS::Data do
4
4
  before(:each) do
5
5
  class Record < LHS::Record
6
- endpoint ':datastore/v2/entries/:entry_id/content-ads/:campaign_id/feedbacks'
7
- endpoint ':datastore/v2/:campaign_id/feedbacks'
8
- endpoint ':datastore/v2/feedbacks'
6
+ endpoint '{+datastore}/v2/entries/{entry_id}/content-ads/{campaign_id}/feedbacks'
7
+ endpoint '{+datastore}/v2/{campaign_id}/feedbacks'
8
+ endpoint '{+datastore}/v2/feedbacks'
9
9
  end
10
10
  end
11
11
 
@@ -11,7 +11,7 @@ describe LHS::Data do
11
11
 
12
12
  before(:each) do
13
13
  class Record < LHS::Record
14
- endpoint ':datastore/v2/data'
14
+ endpoint '{+datastore}/v2/data'
15
15
  end
16
16
  end
17
17
 
@@ -3,8 +3,8 @@ require 'rails_helper'
3
3
  describe LHS::Data do
4
4
  before(:each) do
5
5
  class Record < LHS::Record
6
- endpoint ':datastore/v2/:campaign_id/feedbacks'
7
- endpoint ':datastore/v2/feedbacks'
6
+ endpoint '{+datastore}/v2/{campaign_id}/feedbacks'
7
+ endpoint '{+datastore}/v2/feedbacks'
8
8
  end
9
9
  end
10
10
 
@@ -1,4 +1,4 @@
1
1
  class User < LHS::Record
2
2
  endpoint 'http://datastore/v2/users'
3
- endpoint 'http://datastore/v2/users/:id'
3
+ endpoint 'http://datastore/v2/users/{id}'
4
4
  end
@@ -4,22 +4,22 @@ describe LHS::Endpoint do
4
4
  context 'for url' do
5
5
  before(:each) do
6
6
  class Record < LHS::Record
7
- endpoint ':datastore/entries/:entry_id/content-ads/:campaign_id/feedbacks'
8
- endpoint ':datastore/:campaign_id/feedbacks'
9
- endpoint ':datastore/feedbacks'
7
+ endpoint '{+datastore}/entries/{entry_id}/content-ads/{campaign_id}/feedbacks'
8
+ endpoint '{+datastore}/{campaign_id}/feedbacks'
9
+ endpoint '{+datastore}/feedbacks'
10
10
  end
11
11
  end
12
12
 
13
13
  it 'provides the endpoint for a given url' do
14
14
  expect(
15
15
  LHS::Endpoint.for_url('http://local.ch/v2/entries/123/content-ads/456/feedbacks').url
16
- ).to eq ':datastore/entries/:entry_id/content-ads/:campaign_id/feedbacks'
16
+ ).to eq '{+datastore}/entries/{entry_id}/content-ads/{campaign_id}/feedbacks'
17
17
  expect(
18
18
  LHS::Endpoint.for_url('http://local.ch/123/feedbacks').url
19
- ).to eq ':datastore/:campaign_id/feedbacks'
19
+ ).to eq '{+datastore}/{campaign_id}/feedbacks'
20
20
  expect(
21
21
  LHS::Endpoint.for_url('http://local.ch/feedbacks').url
22
- ).to eq ':datastore/feedbacks'
22
+ ).to eq '{+datastore}/feedbacks'
23
23
  end
24
24
  end
25
25
  end
@@ -4,11 +4,11 @@ describe LHS::Item do
4
4
  before(:each) do
5
5
  class Location < LHS::Record
6
6
  endpoint 'http://sync/locations'
7
- endpoint 'http://sync/locations/:id'
7
+ endpoint 'http://sync/locations/{id}'
8
8
  end
9
9
 
10
10
  class Synchronization < LHS::Record
11
- endpoint 'http://sync/locations/:id/sync'
11
+ endpoint 'http://sync/locations/{id}/sync'
12
12
  end
13
13
 
14
14
  stub_request(:get, "http://sync/locations/1")
@@ -3,8 +3,8 @@ require 'rails_helper'
3
3
  describe LHS::Item do
4
4
  before(:each) do
5
5
  class Record < LHS::Record
6
- endpoint ':datastore/v2/:campaign_id/feedbacks'
7
- endpoint ':datastore/v2/feedbacks'
6
+ endpoint '{+datastore}/v2/{campaign_id}/feedbacks'
7
+ endpoint '{+datastore}/v2/feedbacks'
8
8
  end
9
9
  end
10
10
 
@@ -4,8 +4,8 @@ describe LHS::Item do
4
4
  before(:each) do
5
5
  LHC.config.placeholder('datastore', datastore)
6
6
  class Record < LHS::Record
7
- endpoint ':datastore/v2/:campaign_id/feedbacks'
8
- endpoint ':datastore/v2/feedbacks'
7
+ endpoint '{+datastore}/v2/{campaign_id}/feedbacks'
8
+ endpoint '{+datastore}/v2/feedbacks'
9
9
  end
10
10
  end
11
11
 
@@ -42,7 +42,7 @@ describe LHS::Item do
42
42
  context 'includes and empty response' do
43
43
  before(:each) do
44
44
  class AnotherRecord < LHS::Record
45
- endpoint ':datastore/v2/:campaign_id/restaurants'
45
+ endpoint '{+datastore}/v2/:campaign_id/restaurants'
46
46
  end
47
47
  end
48
48
 
@@ -3,7 +3,7 @@ require 'rails_helper'
3
3
  describe LHS::Item do
4
4
  before(:each) do
5
5
  class Record < LHS::Record
6
- endpoint ':datastore/records'
6
+ endpoint '{+datastore}/records'
7
7
  end
8
8
  end
9
9
 
@@ -55,8 +55,8 @@ describe LHS::Item do
55
55
  I18n.backend.store_translations(:en, {}) if defined? translations
56
56
  LHC.config.placeholder(:datastore, datastore)
57
57
  class Record < LHS::Record
58
- endpoint ':datastore/:campaign_id/feedbacks'
59
- endpoint ':datastore/feedbacks'
58
+ endpoint '{+datastore}/{campaign_id}/feedbacks'
59
+ endpoint '{+datastore}/feedbacks'
60
60
  end
61
61
  end
62
62
 
@@ -3,7 +3,7 @@ require 'rails_helper'
3
3
  describe LHS::Item do
4
4
  before(:each) do
5
5
  class Record < LHS::Record
6
- endpoint ':datastore/records'
6
+ endpoint '{+datastore}/records'
7
7
  end
8
8
  end
9
9
 
@@ -3,8 +3,8 @@ require 'rails_helper'
3
3
  describe LHS::Item do
4
4
  before(:each) do
5
5
  class Record < LHS::Record
6
- endpoint ':datastore/v2/:campaign_id/feedbacks'
7
- endpoint ':datastore/v2/feedbacks'
6
+ endpoint '{+datastore}/v2/{campaign_id}/feedbacks'
7
+ endpoint '{+datastore}/v2/feedbacks'
8
8
  end
9
9
  end
10
10
 
@@ -3,8 +3,8 @@ require 'rails_helper'
3
3
  describe LHS::Item do
4
4
  before(:each) do
5
5
  class Feedback < LHS::Record
6
- endpoint ':datastore/v2/feedbacks'
7
- endpoint ':datastore/v2/feedbacks/:id'
6
+ endpoint '{+datastore}/v2/feedbacks'
7
+ endpoint '{+datastore}/v2/feedbacks/{id}'
8
8
  end
9
9
  end
10
10
 
@@ -3,7 +3,7 @@ require 'rails_helper'
3
3
  describe LHS::Item do
4
4
  before(:each) do
5
5
  class Record < LHS::Record
6
- endpoint ':datastore/records'
6
+ endpoint '{+datastore}/records'
7
7
  end
8
8
  end
9
9
 
@@ -3,8 +3,8 @@ require 'rails_helper'
3
3
  describe LHS::Item do
4
4
  before(:each) do
5
5
  class Record < LHS::Record
6
- endpoint ':datastore/v2/:campaign_id/feedbacks'
7
- endpoint ':datastore/v2/feedbacks'
6
+ endpoint '{+datastore}/v2/{campaign_id}/feedbacks'
7
+ endpoint '{+datastore}/v2/feedbacks'
8
8
  end
9
9
  end
10
10
 
@@ -65,7 +65,7 @@ describe LHS::Item do
65
65
  before(:each) do
66
66
  class Location < LHS::Record
67
67
  endpoint 'http://uberall/locations'
68
- endpoint 'http://uberall/locations/:id'
68
+ endpoint 'http://uberall/locations/{id}'
69
69
  end
70
70
  end
71
71
 
@@ -83,7 +83,7 @@ describe LHS::Item do
83
83
  before(:each) do
84
84
  class Location < LHS::Record
85
85
  endpoint 'http://uberall/locations'
86
- endpoint 'http://uberall/locations/:id'
86
+ endpoint 'http://uberall/locations/{id}'
87
87
  configuration item_created_key: [:response, :location], item_key: [:response, :location]
88
88
  end
89
89
  end
@@ -3,8 +3,8 @@ require 'rails_helper'
3
3
  describe LHS::Item do
4
4
  before(:each) do
5
5
  class Record < LHS::Record
6
- endpoint ':datastore/v2/:campaign_id/feedbacks'
7
- endpoint ':datastore/v2/feedbacks'
6
+ endpoint '{+datastore}/v2/{campaign_id}/feedbacks'
7
+ endpoint '{+datastore}/v2/feedbacks'
8
8
  end
9
9
  end
10
10
 
@@ -3,8 +3,8 @@ require 'rails_helper'
3
3
  describe LHS::Item do
4
4
  before(:each) do
5
5
  class Record < LHS::Record
6
- endpoint ':datastore/v2/:campaign_id/feedbacks'
7
- endpoint ':datastore/v2/feedbacks'
6
+ endpoint '{+datastore}/v2/{campaign_id}/feedbacks'
7
+ endpoint '{+datastore}/v2/feedbacks'
8
8
  end
9
9
  end
10
10
 
@@ -3,8 +3,8 @@ require 'rails_helper'
3
3
  describe LHS::Item do
4
4
  before(:each) do
5
5
  class Record < LHS::Record
6
- endpoint ':datastore/v2/:campaign_id/feedbacks'
7
- endpoint ':datastore/v2/feedbacks'
6
+ endpoint '{+datastore}/v2/{campaign_id}/feedbacks'
7
+ endpoint '{+datastore}/v2/feedbacks'
8
8
  end
9
9
  end
10
10
 
@@ -100,7 +100,7 @@ describe LHS::Item do
100
100
  context 'endpoint does not support validations' do
101
101
  before(:each) do
102
102
  class Favorite < LHS::Record
103
- endpoint ':datastore/v2/favorites'
103
+ endpoint '{+datastore}/v2/favorites'
104
104
  end
105
105
  end
106
106
 
@@ -114,7 +114,7 @@ describe LHS::Item do
114
114
  context 'generate validation url from locally passed params' do
115
115
  before(:each) do
116
116
  class User < LHS::Record
117
- endpoint 'http://datastore/v2/users/:user_id', validates: { params: { persist: false } }
117
+ endpoint 'http://datastore/v2/users/{user_id}', validates: { params: { persist: false } }
118
118
  end
119
119
  end
120
120
 
@@ -12,7 +12,7 @@ describe LHS::Record do
12
12
 
13
13
  before(:each) do
14
14
  class Record < LHS::Record
15
- endpoint ':datastore/v2/data'
15
+ endpoint '{+datastore}/v2/data'
16
16
  end
17
17
  end
18
18
 
@@ -3,11 +3,11 @@ require 'rails_helper'
3
3
  describe LHS::Item do
4
4
  before(:each) do
5
5
  class Feedback < LHS::Record
6
- endpoint 'http://datastore/v2/feedbacks/:id'
6
+ endpoint 'http://datastore/v2/feedbacks/{id}'
7
7
  end
8
8
 
9
9
  class Review < LHS::Record
10
- endpoint 'http://datastore/v2/feedbacks/:feedback_id/reviews'
10
+ endpoint 'http://datastore/v2/feedbacks/{feedback_id}/reviews'
11
11
  end
12
12
  end
13
13
 
@@ -3,7 +3,7 @@ require 'rails_helper'
3
3
  describe LHS::Proxy do
4
4
  before(:each) do
5
5
  class Record < LHS::Record
6
- endpoint ':datastore/v2/feedbacks'
6
+ endpoint '{+datastore}/v2/feedbacks'
7
7
  end
8
8
  end
9
9
 
@@ -46,7 +46,7 @@ describe LHS::Proxy do
46
46
  context 'endpoint options' do
47
47
  before(:each) do
48
48
  class AnotherRecord < LHS::Record
49
- endpoint ':datastore/v2/feedbacks', params: { color: :blue }
49
+ endpoint '{+datastore}/v2/feedbacks', params: { color: :blue }
50
50
  end
51
51
  end
52
52