rom-http 0.6.0 → 0.7.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
  SHA1:
3
- metadata.gz: ceb0d5ad55a0025e591bbd6d1faa80c61daf1dcc
4
- data.tar.gz: fa8e226b0edc81e712507776b0be4e6b5a107ea0
3
+ metadata.gz: 5fd07f83166373c0e0f2bfe8c83f8f68578818dc
4
+ data.tar.gz: e643299868045661adadfd6ea6881cf59feda4fe
5
5
  SHA512:
6
- metadata.gz: 12cad00ba08382a6f334e872edc03be82ec1e337705324835227ea073d4970288ffb0478119c085eb5e011e82cf3dba859b707c20309eb75b2d7ea8792b6e022
7
- data.tar.gz: 055fb8f3a1543398ba921a459066d852f3eca1df5912afb2dfd3337b18b70f49a57552e9b281c314fc568a7f2fe7d0a8a95c04c119510a4b4cc59a79eed50213
6
+ metadata.gz: 2a2de5a39a3cf600c2464250809a2e292c7abef3a8e1b2e79232ac035b14992a160a56035c5c7a65414ab60b643093ac375e234ffab952c6a262f3517cd146fd
7
+ data.tar.gz: 44315f4744aa86c60fb92c801bd1521e2834dbada29fd53a6cfc4a6f35f27fb09cb335719d9bb4b52be5f1bda9c549539f4e98c96fca2344640c2e7b0a096062
@@ -5,17 +5,12 @@ cache: bundler
5
5
  bundler_args: --without sql benchmarks console tools
6
6
  script: "bundle exec rake ci"
7
7
  rvm:
8
- - 2.2.6
9
- - 2.3.3
10
- - 2.4.0
11
- - rbx-3
12
- - jruby-9.1.6.0
8
+ - 2.3.4
9
+ - 2.4.1
10
+ - jruby-9.1.13.0
13
11
  env:
14
12
  global:
15
13
  - JRUBY_OPTS='--dev -J-Xmx1024M'
16
- matrix:
17
- allow_failures:
18
- - rvm: rbx-3
19
14
  notifications:
20
15
  webhooks:
21
16
  urls:
@@ -1,3 +1,18 @@
1
+ # v0.7.0 2018-01-11
2
+
3
+ ### Added
4
+ - Add Dataset#add_params(AMHOL)
5
+
6
+ ### Changed
7
+ - Updated error messages (AMHOL)
8
+ - updated to depend on ROM 4.0 (maximderbin)
9
+ - Removed ruby 2.1 support (maximderbin)
10
+ - Removed rbx-3 support (maximderbin)
11
+
12
+
13
+
14
+ [Compare v0.5.0...v0.6.0](https://github.com/rom-rb/rom-http/compare/v0.6.0...v0.7.0)
15
+
1
16
  # v0.6.0 2017-02-06
2
17
  ### Changed
3
18
  - Make schemas mandatory and use schema API from ROM core (AMHOL)
data/Gemfile CHANGED
@@ -2,10 +2,10 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'rom-repository', github: 'rom-rb/rom-repository', branch: 'master'
5
+ gem 'rom-repository', '~> 2.0'
6
6
 
7
7
  group :test do
8
- gem 'rom', github: 'rom-rb/rom', branch: 'master'
8
+ gem 'rom', '~> 4.0'
9
9
  gem 'faraday'
10
10
  gem 'inflecto'
11
11
  end
data/README.md CHANGED
@@ -52,10 +52,7 @@ require 'net/http'
52
52
 
53
53
  class RequestHandler
54
54
  def call(dataset)
55
- uri = URI(dataset.uri)
56
- uri.path = dataset.absolute_path
57
- uri.query = URI.encode_www_form(dataset.params)
58
-
55
+ uri = dataset.uri
59
56
  http = Net::HTTP.new(uri.host, uri.port)
60
57
  request_klass = Net::HTTP.const_get(Inflecto.classify(dataset.request_method))
61
58
 
@@ -119,27 +116,27 @@ require 'net/http'
119
116
  module ROM
120
117
  module MyAdapter
121
118
  class Dataset < ROM::HTTP::Dataset
122
- default_request_handler ->(dataset) do
123
- uri = URI(dataset.uri)
124
- uri.path = dataset.absolute_path
125
- uri.query = URI.encode_www_form(dataset.params)
119
+ configure do |config|
120
+ config.default_request_handler = ->(dataset) do
121
+ uri = dataset.uri
126
122
 
127
- http = Net::HTTP.new(uri.host, uri.port)
128
- request_klass = Net::HTTP.const_get(Inflecto.classify(dataset.request_method))
123
+ http = Net::HTTP.new(uri.host, uri.port)
124
+ request_klass = Net::HTTP.const_get(Inflecto.classify(dataset.request_method))
129
125
 
130
- request = request_klass.new(uri.request_uri)
131
- dataset.headers.each_with_object(request) do |(header, value), request|
132
- request[header.to_s] = value
133
- end
126
+ request = request_klass.new(uri.request_uri)
127
+ dataset.headers.each_with_object(request) do |(header, value), request|
128
+ request[header.to_s] = value
129
+ end
134
130
 
135
- response = http.request(request)
136
- end
131
+ response = http.request(request)
132
+ end
137
133
 
138
- default_response_handler ->(response, dataset) do
139
- if %i(post put patch).include?(dataset.request_method)
140
- JSON.parse(response.body, symbolize_names: true)
141
- else
142
- Array([JSON.parse(response.body, symbolize_names: true)]).flatten
134
+ config.default_response_handler = ->(response, dataset) do
135
+ if %i(post put patch).include?(dataset.request_method)
136
+ JSON.parse(response.body, symbolize_names: true)
137
+ else
138
+ Array([JSON.parse(response.body, symbolize_names: true)]).flatten
139
+ end
143
140
  end
144
141
  end
145
142
  end
@@ -1,4 +1,8 @@
1
+ require 'uri'
2
+ require 'dry-configurable'
3
+ require 'dry/core/deprecations'
1
4
  require 'rom/initializer'
5
+ require 'rom/http/dataset/class_interface'
2
6
 
3
7
  module ROM
4
8
  module HTTP
@@ -9,32 +13,25 @@ module ROM
9
13
  # @api public
10
14
  class Dataset
11
15
  PATH_SEPARATOR = '/'.freeze
12
- STRIP_PATH = ->(path) { path.sub(%r{\A/}, '') }.freeze
13
16
 
14
- include Enumerable
15
- include Dry::Equalizer(:config, :options)
16
17
  extend ::ROM::Initializer
18
+ extend ::Dry::Configurable
19
+ extend ::ROM::HTTP::Dataset::ClassInterface
20
+ include ::Enumerable
21
+ include ::Dry::Equalizer(:config, :options)
22
+
23
+ setting :default_request_handler
24
+ setting :default_response_handler
25
+ setting :param_encoder, ->(params) { URI.encode_www_form(params) }
17
26
 
18
27
  param :config
19
28
 
20
29
  option :request_method, type: Types::Symbol, default: proc { :get }, reader: true
21
30
  option :base_path, type: Types::String, default: proc { name }
22
- option :path, type: Types::String, default: proc { '' }
31
+ option :path, type: Types::String, default: proc { '' }, reader: false
23
32
  option :params, type: Types::Hash, default: proc { {} }, reader: true
24
33
  option :headers, type: Types::Hash, default: proc { {} }
25
34
 
26
- class << self
27
- def default_request_handler(handler = Undefined)
28
- return @default_request_handler if Undefined === handler
29
- @default_request_handler = handler
30
- end
31
-
32
- def default_response_handler(handler = Undefined)
33
- return @default_response_handler if Undefined === handler
34
- @default_response_handler = handler
35
- end
36
- end
37
-
38
35
  # Return the gateway's URI
39
36
  #
40
37
  # @return [String]
@@ -43,7 +40,13 @@ module ROM
43
40
  #
44
41
  # @api public
45
42
  def uri
46
- config.fetch(:uri) { fail Error, ':uri configuration missing' }
43
+ uri = config.fetch(:uri) { fail Error, '+uri+ configuration missing' }
44
+ uri = URI(join_path(uri, path))
45
+ if request_method == :get && params.any?
46
+ uri.query = self.class.config.param_encoder.call(params)
47
+ end
48
+
49
+ uri
47
50
  end
48
51
 
49
52
  # Return request headers
@@ -83,7 +86,7 @@ module ROM
83
86
  #
84
87
  # @api public
85
88
  def base_path
86
- STRIP_PATH.call(super)
89
+ strip_path(super)
87
90
  end
88
91
 
89
92
  # Return the dataset path
@@ -96,7 +99,7 @@ module ROM
96
99
  #
97
100
  # @api public
98
101
  def path
99
- STRIP_PATH.call(join_path(base_path, super))
102
+ join_path(base_path, strip_path(options[:path].to_s))
100
103
  end
101
104
 
102
105
  # Return the dataset path
@@ -234,6 +237,25 @@ module ROM
234
237
  with_options(params: params)
235
238
  end
236
239
 
240
+ # Return a new dataset with merged request parameters
241
+ #
242
+ # @param [Hash] params the new request parameters to add
243
+ #
244
+ # @example
245
+ # users = Dataset.new(config, params: { uid: 33 })
246
+ # users.add_params(login: 'jdoe').params
247
+ # # => { uid: 33, :login => 'jdoe' }
248
+ #
249
+ # @return [Dataset]
250
+ #
251
+ # @api public
252
+ def add_params(new_params)
253
+ # TODO: Should we merge arrays?
254
+ with_options(
255
+ params: ::ROM::HTTP::Transformer[:deep_merge][params, new_params]
256
+ )
257
+ end
258
+
237
259
  # Iterate over each response value
238
260
  #
239
261
  # @yield [Hash] a dataset tuple
@@ -299,14 +321,20 @@ module ROM
299
321
  private
300
322
 
301
323
  def response_handler
302
- response_handler = config.fetch(:response_handler, self.class.default_response_handler)
303
- fail Error, ':response_handler configuration missing' if response_handler.nil?
324
+ response_handler = config.fetch(
325
+ :response_handler,
326
+ self.class.config.default_response_handler
327
+ )
328
+ fail Error, '+default_response_handler+ configuration missing' if response_handler.nil?
304
329
  response_handler
305
330
  end
306
331
 
307
332
  def request_handler
308
- request_handler = config.fetch(:request_handler, self.class.default_request_handler)
309
- fail Error, ':response_handler configuration missing' if request_handler.nil?
333
+ request_handler = config.fetch(
334
+ :request_handler,
335
+ self.class.config.default_request_handler
336
+ )
337
+ fail Error, '+default_response_handler+ configuration missing' if request_handler.nil?
310
338
  request_handler
311
339
  end
312
340
 
@@ -317,6 +345,10 @@ module ROM
317
345
  def join_path(*paths)
318
346
  paths.reject(&:empty?).join(PATH_SEPARATOR)
319
347
  end
348
+
349
+ def strip_path(path)
350
+ path.sub(%r{\A/}, '')
351
+ end
320
352
  end
321
353
  end
322
354
  end
@@ -0,0 +1,33 @@
1
+ module ROM
2
+ module HTTP
3
+ # HTTP Dataset
4
+ #
5
+ # Represents a specific HTTP collection resource
6
+ #
7
+ # @api public
8
+ class Dataset
9
+ # @api private
10
+ module ClassInterface
11
+ # TODO: Remove in favour of configuration
12
+ def default_request_handler(handler = Undefined)
13
+ ::Dry::Core::Deprecations.announce(
14
+ __method__,
15
+ 'use configuration instead'
16
+ )
17
+ return config.default_request_handler if Undefined === handler
18
+ config.default_request_handler = handler
19
+ end
20
+
21
+ # TODO: Remove in favour of configuration
22
+ def default_response_handler(handler = Undefined)
23
+ ::Dry::Core::Deprecations.announce(
24
+ __method__,
25
+ 'use configuration instead'
26
+ )
27
+ return config.default_response_handler if Undefined === handler
28
+ config.default_response_handler = handler
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,6 +1,5 @@
1
1
  module ROM
2
2
  module HTTP
3
3
  Error = Class.new(StandardError)
4
- SchemaNotDefinedError = Class.new(Error)
5
4
  end
6
5
  end
@@ -16,6 +16,8 @@ module ROM
16
16
  #
17
17
  # @api public
18
18
  class Gateway < ROM::Gateway
19
+ adapter :http
20
+
19
21
  attr_reader :datasets, :config
20
22
  private :datasets, :config
21
23
 
@@ -1,6 +1,5 @@
1
1
  require 'dry/core/cache'
2
2
  require 'rom/initializer'
3
- require 'rom/plugins/relation/key_inference'
4
3
  require 'rom/http/transformer'
5
4
 
6
5
  module ROM
@@ -14,22 +13,11 @@ module ROM
14
13
 
15
14
  adapter :http
16
15
 
17
- use :key_inference
18
-
19
16
  option :transformer, reader: true, default: proc { ::ROM::HTTP::Transformer }
20
17
 
21
- forward :with_request_method, :with_path, :append_path, :with_options,
22
- :with_params, :clear_params
23
-
24
-
25
- def initialize(*)
26
- super
27
-
28
- raise(
29
- SchemaNotDefinedError,
30
- "You must define a schema for #{self.class.register_as} relation"
31
- ) unless schema?
32
- end
18
+ forward :with_headers, :add_header, :with_options,
19
+ :with_base_path, :with_path, :append_path,
20
+ :with_request_method, :with_params, :add_params
33
21
 
34
22
  def primary_key
35
23
  attribute = schema.find(&:primary_key?)
@@ -83,8 +71,8 @@ module ROM
83
71
 
84
72
  private
85
73
 
86
- def with_transformation(&block)
87
- tuples = block.call
74
+ def with_transformation
75
+ tuples = yield
88
76
 
89
77
  transformed = with_schema_proc do |proc|
90
78
  transformer_proc[Array([tuples]).flatten(1).map(&proc.method(:call))]
@@ -93,12 +81,12 @@ module ROM
93
81
  tuples.kind_of?(Array) ? transformed : transformed.first
94
82
  end
95
83
 
96
- def with_schema_proc(&block)
84
+ def with_schema_proc
97
85
  schema_proc = fetch_or_store(schema) do
98
86
  Types::Coercible::Hash.schema(schema.to_h)
99
87
  end
100
88
 
101
- block.call(schema_proc)
89
+ yield(schema_proc)
102
90
  end
103
91
 
104
92
  def transformer_proc
@@ -11,6 +11,7 @@ module ROM
11
11
  import :identity, from: ::Transproc::Coercions
12
12
  import :map_array, from: ::Transproc::ArrayTransformations
13
13
  import :rename_keys, from: ::Transproc::HashTransformations
14
+ import :deep_merge, from: ::Transproc::HashTransformations
14
15
  end
15
16
  end
16
17
  end
@@ -1,5 +1,5 @@
1
1
  module ROM
2
2
  module HTTP
3
- VERSION = '0.6.0'.freeze
3
+ VERSION = '0.7.0'.freeze
4
4
  end
5
5
  end
@@ -19,9 +19,11 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_runtime_dependency 'concurrent-ruby'
22
- spec.add_runtime_dependency 'rom', '~> 3.0.0'
22
+ spec.add_runtime_dependency 'addressable'
23
+ spec.add_runtime_dependency 'rom', '~> 4.0'
23
24
  spec.add_runtime_dependency 'dry-core', '~> 0.2', '>= 0.2.3'
24
25
  spec.add_runtime_dependency 'dry-equalizer', '~> 0.2'
26
+ spec.add_runtime_dependency 'dry-configurable', '~> 0.6'
25
27
 
26
28
  spec.add_development_dependency 'bundler'
27
29
  spec.add_development_dependency 'rspec', '~> 3.1'
@@ -47,7 +47,7 @@ RSpec.describe ROM::HTTP::Commands::Create do
47
47
  allow(response_handler).to receive(:call).and_return(tuple)
48
48
  end
49
49
 
50
- subject! { container.command(:users).create.call(attributes) }
50
+ subject! { container.commands[:users].create.call(attributes) }
51
51
 
52
52
  it do
53
53
  expect(request_handler).to have_received(:call).with(dataset)
@@ -106,7 +106,7 @@ RSpec.describe ROM::HTTP::Commands::Create do
106
106
  allow(response_handler).to receive(:call).and_return(tuple_1, tuple_2)
107
107
  end
108
108
 
109
- subject! { container.command(:users).create.call(attributes) }
109
+ subject! { container.commands[:users].create.call(attributes) }
110
110
 
111
111
  it do
112
112
  expect(request_handler).to have_received(:call).with(dataset_1)
@@ -42,7 +42,7 @@ RSpec.describe ROM::HTTP::Commands::Delete do
42
42
  allow(response_handler).to receive(:call).and_return(tuples)
43
43
  end
44
44
 
45
- subject! { container.command(:users).delete.call }
45
+ subject! { container.commands[:users].delete.call }
46
46
 
47
47
  it do
48
48
  expect(request_handler).to have_received(:call).with(dataset)
@@ -47,7 +47,7 @@ RSpec.describe ROM::HTTP::Commands::Update do
47
47
  allow(response_handler).to receive(:call).and_return(tuple)
48
48
  end
49
49
 
50
- subject! { container.command(:users).update.call(attributes) }
50
+ subject! { container.commands[:users].update.call(attributes) }
51
51
 
52
52
  it do
53
53
  expect(request_handler).to have_received(:call).with(dataset)
@@ -106,7 +106,7 @@ RSpec.describe ROM::HTTP::Commands::Update do
106
106
  allow(response_handler).to receive(:call).and_return(tuple_1, tuple_2)
107
107
  end
108
108
 
109
- subject! { container.command(:users).update.call(attributes) }
109
+ subject! { container.commands[:users].update.call(attributes) }
110
110
 
111
111
  it do
112
112
  expect(request_handler).to have_received(:call).with(dataset_1)
@@ -2,7 +2,7 @@ require 'json'
2
2
  require 'rom-repository'
3
3
 
4
4
  RSpec.describe ROM::HTTP::Relation do
5
- subject(:users) { container.relation(:users).by_id(id).filter(params) }
5
+ subject(:users) { container.relations[:users].by_id(id).filter(params) }
6
6
 
7
7
  include_context 'setup'
8
8
 
@@ -58,11 +58,15 @@ RSpec.describe ROM::HTTP::Relation do
58
58
 
59
59
  context 'using a repo' do
60
60
  let(:repo) do
61
- Class.new(ROM::Repository) { relations :users }.new(container)
61
+ Class.new(ROM::Repository) do
62
+ def self.to_s
63
+ 'UserRepo'
64
+ end
65
+ end.new(container)
62
66
  end
63
67
 
64
68
  it 'returns structs' do
65
- user = repo.users.by_id(1337).filter(params).one
69
+ user = repo.users.by_id(1337).filter(params).first
66
70
 
67
71
  expect(user.id).to be(1337)
68
72
  expect(user.name).to eql('John')
@@ -5,6 +5,9 @@ Bundler.setup
5
5
 
6
6
  require 'rom-http'
7
7
  require 'rspec/its'
8
+ require 'dry/configurable/test_interface'
9
+
10
+ ROM::HTTP::Dataset.enable_test_interface
8
11
 
9
12
  begin
10
13
  require 'byebug'
@@ -13,7 +13,22 @@ RSpec.describe ROM::HTTP::Dataset do
13
13
  let(:request_handler) { double(Proc) }
14
14
  let(:response_handler) { double(Proc) }
15
15
 
16
- it { expect(dataset).to be_kind_of(Enumerable) }
16
+ it { expect(klass).to be_kind_of(::Dry::Configurable) }
17
+ it { expect(dataset).to be_kind_of(::Enumerable) }
18
+
19
+ describe 'settings' do
20
+ describe 'default_request_handler' do
21
+ it 'defaults to nil' do
22
+ expect(klass.config.default_request_handler).to be nil
23
+ end
24
+ end
25
+
26
+ describe 'default_response_handler' do
27
+ it 'defaults to nil' do
28
+ expect(klass.config.default_response_handler).to be nil
29
+ end
30
+ end
31
+ end
17
32
 
18
33
  describe 'defaults' do
19
34
  describe '#config' do
@@ -57,11 +72,21 @@ RSpec.describe ROM::HTTP::Dataset do
57
72
  module Test
58
73
  class Dataset < ROM::HTTP::Dataset; end
59
74
  end
75
+
76
+ allow(Dry::Core::Deprecations).to receive(:announce)
60
77
  end
61
78
 
79
+ after { Test::Dataset.reset_config }
80
+
62
81
  context 'when no default_request_handler set' do
82
+ subject! { Test::Dataset.default_request_handler }
83
+
63
84
  it 'returns nil' do
64
- expect(klass.default_request_handler).to be nil
85
+ expect(Dry::Core::Deprecations).to have_received(:announce).with(
86
+ :default_request_handler,
87
+ 'use configuration instead'
88
+ )
89
+ is_expected.to be nil
65
90
  end
66
91
  end
67
92
 
@@ -70,8 +95,14 @@ RSpec.describe ROM::HTTP::Dataset do
70
95
  Test::Dataset.default_request_handler(request_handler)
71
96
  end
72
97
 
98
+ subject! { Test::Dataset.default_request_handler }
99
+
73
100
  it 'returns the default request handler' do
74
- expect(Test::Dataset.default_request_handler).to eq request_handler
101
+ expect(Dry::Core::Deprecations).to have_received(:announce).with(
102
+ :default_request_handler,
103
+ 'use configuration instead'
104
+ ).twice
105
+ is_expected.to eq request_handler
75
106
  end
76
107
  end
77
108
  end
@@ -81,11 +112,21 @@ RSpec.describe ROM::HTTP::Dataset do
81
112
  module Test
82
113
  class Dataset < ROM::HTTP::Dataset; end
83
114
  end
115
+
116
+ allow(Dry::Core::Deprecations).to receive(:announce)
84
117
  end
85
118
 
119
+ after { Test::Dataset.reset_config }
120
+
86
121
  context 'when no default_response_handler set' do
122
+ subject! { Test::Dataset.default_response_handler }
123
+
87
124
  it 'returns nil' do
88
- expect(klass.default_response_handler).to be nil
125
+ expect(Dry::Core::Deprecations).to have_received(:announce).with(
126
+ :default_response_handler,
127
+ 'use configuration instead'
128
+ )
129
+ is_expected.to be nil
89
130
  end
90
131
  end
91
132
 
@@ -94,8 +135,14 @@ RSpec.describe ROM::HTTP::Dataset do
94
135
  Test::Dataset.default_response_handler(response_handler)
95
136
  end
96
137
 
138
+ subject! { Test::Dataset.default_response_handler }
139
+
97
140
  it 'returns the default response handler' do
98
- expect(Test::Dataset.default_response_handler).to eq response_handler
141
+ expect(Dry::Core::Deprecations).to have_received(:announce).with(
142
+ :default_response_handler,
143
+ 'use configuration instead'
144
+ ).twice
145
+ is_expected.to eq response_handler
99
146
  end
100
147
  end
101
148
  end
@@ -110,7 +157,107 @@ RSpec.describe ROM::HTTP::Dataset do
110
157
  end
111
158
 
112
159
  context 'when uri configured' do
113
- it { expect(dataset.uri).to eq(uri) }
160
+ subject! { dataset.uri }
161
+
162
+ context 'when request method is GET' do
163
+ context 'with params' do
164
+ let(:options) do
165
+ {
166
+ params: {
167
+ username: 'John',
168
+ role: 'admin'
169
+ }
170
+ }
171
+ end
172
+ let(:expected_uri) { URI("#{uri}?username=John&role=admin") }
173
+
174
+ it { is_expected.to eq(expected_uri) }
175
+ end
176
+ end
177
+
178
+ context 'when request method is not GET' do
179
+ context 'with params' do
180
+ let(:options) do
181
+ {
182
+ request_method: :post,
183
+ params: {
184
+ username: 'John',
185
+ role: 'admin'
186
+ }
187
+ }
188
+ end
189
+ let(:expected_uri) { URI(uri) }
190
+
191
+ it { is_expected.to eq(expected_uri) }
192
+ end
193
+ end
194
+
195
+ context 'without dataset name' do
196
+ context 'with no path' do
197
+ let(:expected_uri) { URI(uri) }
198
+
199
+ it { is_expected.to eq(expected_uri) }
200
+ end
201
+
202
+ context 'with path' do
203
+ context 'without custom base_path' do
204
+ let(:options) { { path: '/users' } }
205
+ let(:expected_uri) { URI("#{uri}/users") }
206
+
207
+ it { is_expected.to eq(expected_uri) }
208
+ end
209
+
210
+ context 'with custom base_path' do
211
+ let(:options) { { base_path: '/blog', path: '/users' } }
212
+ let(:expected_uri) { URI("#{uri}/blog/users") }
213
+
214
+ it { is_expected.to eq(expected_uri) }
215
+ end
216
+ end
217
+ end
218
+
219
+ context 'with dataset name' do
220
+ let(:config) { super().merge(name: :blog) }
221
+
222
+ context 'with no path' do
223
+ let(:expected_uri) { URI("#{uri}/blog") }
224
+
225
+ it { is_expected.to eq(expected_uri) }
226
+ end
227
+
228
+ context 'with path' do
229
+ context 'without custom base_path' do
230
+ let(:options) { { path: '/users' } }
231
+ let(:expected_uri) { URI("#{uri}/blog/users") }
232
+
233
+ it { is_expected.to eq(expected_uri) }
234
+ end
235
+
236
+ context 'with custom base_path' do
237
+ let(:options) { { base_path: '/bloggers', path: '/users' } }
238
+ let(:expected_uri) { URI("#{uri}/bloggers/users") }
239
+
240
+ it { is_expected.to eq(expected_uri) }
241
+ end
242
+ end
243
+ end
244
+
245
+ context 'with custom base_path' do
246
+ let(:config) { super().merge(name: :blog) }
247
+
248
+ context 'with no path' do
249
+ let(:expected_uri) { URI("#{uri}/blog") }
250
+
251
+ it { is_expected.to eq(expected_uri) }
252
+ end
253
+
254
+ context 'with path' do
255
+ let(:options) { { path: '/users' } }
256
+ let(:expected_uri) { URI("#{uri}/blog/users") }
257
+
258
+ it { is_expected.to eq(expected_uri) }
259
+ end
260
+ end
114
261
  end
115
262
  end
116
263
 
@@ -224,24 +371,68 @@ RSpec.describe ROM::HTTP::Dataset do
224
371
  subject { dataset.path }
225
372
 
226
373
  context 'with no path option' do
227
- it { is_expected.to eq('') }
374
+ context 'without dataset name' do
375
+ it { is_expected.to eq('') }
376
+ end
377
+
378
+ context 'with dataset name' do
379
+ let(:config) { super().merge(name: :users) }
380
+ it { is_expected.to eq('users') }
381
+ end
382
+
383
+ context 'with base path' do
384
+ let(:options) { { base_path: '/users' } }
385
+ it { is_expected.to eq('users') }
386
+ end
228
387
  end
229
388
 
230
389
  context 'with path option' do
231
390
  context 'when path is absolute' do
232
391
  let(:path) { '/users' }
233
- let(:options) { { path: path } }
234
392
 
235
- it 'removes the leading /' do
236
- is_expected.to eq('users')
393
+ context 'without dataset name' do
394
+ let(:options) { { path: path } }
395
+
396
+ it 'removes the leading /' do
397
+ is_expected.to eq('users')
398
+ end
399
+ end
400
+
401
+ context 'with dataset name' do
402
+ let(:config) { super().merge(name: :blog) }
403
+ let(:options) { { path: path } }
404
+
405
+ it { is_expected.to eq('blog/users') }
406
+ end
407
+
408
+ context 'with base path' do
409
+ let(:options) { { base_path: '/blog', path: path } }
410
+
411
+ it { is_expected.to eq('blog/users') }
237
412
  end
238
413
  end
239
414
 
240
415
  context 'when path is not absolute' do
241
416
  let(:path) { 'users' }
242
- let(:options) { { path: path } }
243
417
 
244
- it { is_expected.to eq(path) }
418
+ context 'without dataset name' do
419
+ let(:options) { { path: path } }
420
+
421
+ it { is_expected.to eq(path) }
422
+ end
423
+
424
+ context 'with dataset name' do
425
+ let(:config) { super().merge(name: :blog) }
426
+ let(:options) { { path: path } }
427
+
428
+ it { is_expected.to eq('blog/users') }
429
+ end
430
+
431
+ context 'with base path' do
432
+ let(:options) { { base_path: '/blog', path: path } }
433
+
434
+ it { is_expected.to eq('blog/users') }
435
+ end
245
436
  end
246
437
  end
247
438
  end
@@ -449,6 +640,36 @@ RSpec.describe ROM::HTTP::Dataset do
449
640
  it { is_expected.to eq(new_dataset) }
450
641
  end
451
642
 
643
+ describe '#add_params' do
644
+ let(:options) do
645
+ {
646
+ params: {
647
+ user: {
648
+ uid: 3
649
+ }
650
+ }
651
+ }
652
+ end
653
+ let(:params) { { user: { name: 'Jack' } } }
654
+ let(:new_dataset) { double(ROM::HTTP::Dataset) }
655
+
656
+ before do
657
+ allow(dataset).to receive(:with_options).and_return(new_dataset)
658
+ end
659
+
660
+ subject! { dataset.add_params(params) }
661
+
662
+ it do
663
+ expect(dataset).to have_received(:with_options).with(params: {
664
+ user: {
665
+ uid: 3,
666
+ name: 'Jack'
667
+ }
668
+ })
669
+ end
670
+ it { is_expected.to eq(new_dataset) }
671
+ end
672
+
452
673
  describe '#each' do
453
674
  let(:response) { double(Array) }
454
675
  let(:block) { proc {} }
@@ -560,7 +781,7 @@ RSpec.describe ROM::HTTP::Dataset do
560
781
  end
561
782
 
562
783
  context 'when request_handler and response_handler configured' do
563
- let(:klass) { Test::Dataset }
784
+ let(:dataset) { Test::Dataset.new(config, options) }
564
785
  let(:config) { {} }
565
786
 
566
787
  before do
@@ -575,6 +796,8 @@ RSpec.describe ROM::HTTP::Dataset do
575
796
  allow(response_handler).to receive(:call).and_return(result)
576
797
  end
577
798
 
799
+ after { Test::Dataset.reset_config }
800
+
578
801
  subject! { dataset.response }
579
802
 
580
803
  it { expect(request_handler).to have_received(:call).with(dataset) }
@@ -26,18 +26,6 @@ RSpec.describe ROM::HTTP::Relation do
26
26
  allow(dataset).to receive(:response).and_return(data)
27
27
  end
28
28
 
29
- describe '#initialize' do
30
- context 'when initialized without a schema defined' do
31
- let(:relation_klass) do
32
- Class.new(ROM::HTTP::Relation)
33
- end
34
-
35
- it do
36
- expect { relation }.to raise_error(::ROM::HTTP::SchemaNotDefinedError)
37
- end
38
- end
39
- end
40
-
41
29
  describe '#primary_key' do
42
30
  subject { relation.primary_key }
43
31
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rom-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-02-07 00:00:00.000000000 Z
13
+ date: 2018-01-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: concurrent-ruby
@@ -26,20 +26,34 @@ dependencies:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
28
  version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: addressable
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
29
43
  - !ruby/object:Gem::Dependency
30
44
  name: rom
31
45
  requirement: !ruby/object:Gem::Requirement
32
46
  requirements:
33
47
  - - "~>"
34
48
  - !ruby/object:Gem::Version
35
- version: 3.0.0
49
+ version: '4.0'
36
50
  type: :runtime
37
51
  prerelease: false
38
52
  version_requirements: !ruby/object:Gem::Requirement
39
53
  requirements:
40
54
  - - "~>"
41
55
  - !ruby/object:Gem::Version
42
- version: 3.0.0
56
+ version: '4.0'
43
57
  - !ruby/object:Gem::Dependency
44
58
  name: dry-core
45
59
  requirement: !ruby/object:Gem::Requirement
@@ -74,6 +88,20 @@ dependencies:
74
88
  - - "~>"
75
89
  - !ruby/object:Gem::Version
76
90
  version: '0.2'
91
+ - !ruby/object:Gem::Dependency
92
+ name: dry-configurable
93
+ requirement: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '0.6'
98
+ type: :runtime
99
+ prerelease: false
100
+ version_requirements: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '0.6'
77
105
  - !ruby/object:Gem::Dependency
78
106
  name: bundler
79
107
  requirement: !ruby/object:Gem::Requirement
@@ -157,6 +185,7 @@ files:
157
185
  - lib/rom/http/commands/delete.rb
158
186
  - lib/rom/http/commands/update.rb
159
187
  - lib/rom/http/dataset.rb
188
+ - lib/rom/http/dataset/class_interface.rb
160
189
  - lib/rom/http/error.rb
161
190
  - lib/rom/http/gateway.rb
162
191
  - lib/rom/http/relation.rb
@@ -195,7 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
224
  version: '0'
196
225
  requirements: []
197
226
  rubyforge_project:
198
- rubygems_version: 2.5.1
227
+ rubygems_version: 2.6.13
199
228
  signing_key:
200
229
  specification_version: 4
201
230
  summary: HTTP support for ROM