rom-http 0.5.0 → 0.6.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,31 +1,279 @@
1
1
  RSpec.describe ROM::HTTP::Relation do
2
+ let(:relation_klass) do
3
+ Class.new(ROM::HTTP::Relation) do
4
+ schema do
5
+ attribute :id, ROM::Types::Strict::Int
6
+ attribute :name, ROM::Types::Strict::String
7
+ end
8
+ end
9
+ end
10
+ let(:relation) { relation_klass.new(dataset) }
11
+ let(:dataset) { ROM::HTTP::Dataset.new({ name: 'test' }, {}) }
12
+ let(:data) do
13
+ [
14
+ {
15
+ id: 1,
16
+ name: 'John'
17
+ },
18
+ {
19
+ id: 2,
20
+ name: 'Jill'
21
+ }
22
+ ]
23
+ end
24
+
25
+ before do
26
+ allow(dataset).to receive(:response).and_return(data)
27
+ end
28
+
2
29
  describe '#initialize' do
3
- let(:relation) { relation_klass.new(dataset) }
4
- let(:dataset) { ROM::HTTP::Dataset.new(nil, {}) }
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
+ describe '#primary_key' do
42
+ subject { relation.primary_key }
43
+
44
+ context 'with no primary key defined in schema' do
45
+ it 'defaults to :id' do
46
+ is_expected.to eq(:id)
47
+ end
48
+ end
49
+
50
+ context 'with primary key defined in schema' do
51
+ context 'without alias' do
52
+ let(:relation_klass) do
53
+ Class.new(ROM::HTTP::Relation) do
54
+ schema do
55
+ attribute :id, ROM::Types::Strict::Int
56
+ attribute :name, ROM::Types::Strict::String.meta(primary_key: true)
57
+ end
58
+ end
59
+ end
60
+
61
+ it 'returns the attribute name of the primary key' do
62
+ is_expected.to eq(:name)
63
+ end
64
+ end
65
+
66
+ context 'with alias' do
67
+ let(:relation_klass) do
68
+ Class.new(ROM::HTTP::Relation) do
69
+ schema do
70
+ attribute :id, ROM::Types::Strict::Int.meta(primary_key: true, alias: :ident)
71
+ attribute :name, ROM::Types::Strict::String
72
+ end
73
+ end
74
+ end
75
+
76
+ it 'returns the attribute name of the primary key' do
77
+ is_expected.to eq(:ident)
78
+ end
79
+ end
80
+ end
81
+ end
82
+
83
+ describe '#project' do
84
+ subject { relation.project(:id).to_a }
85
+
86
+ it 'returns the projected data' do
87
+ is_expected.to match_array([
88
+ { id: 1 },
89
+ { id: 2 }
90
+ ])
91
+ end
92
+ end
93
+
94
+ describe '#exclude' do
95
+ subject { relation.exclude(:id).to_a }
96
+
97
+ it 'returns the data with specified keys excluded' do
98
+ is_expected.to match_array([
99
+ { name: 'John' },
100
+ { name: 'Jill' }
101
+ ])
102
+ end
103
+ end
104
+
105
+ describe '#rename' do
106
+ subject { relation.rename(id: :identity).to_a }
107
+
108
+ it 'returns the data with keys renamed according to mapping' do
109
+ is_expected.to match_array([
110
+ { name: 'John', identity: 1 },
111
+ { name: 'Jill', identity: 2 }
112
+ ])
113
+ end
114
+ end
115
+
116
+ describe '#prefix' do
117
+ subject { relation.prefix('user').to_a }
118
+
119
+ it 'returns the data with prefixed keys' do
120
+ is_expected.to match_array([
121
+ { user_id: 1, user_name: 'John' },
122
+ { user_id: 2, user_name: 'Jill' }
123
+ ])
124
+ end
125
+ end
126
+
127
+ describe '#wrap' do
128
+ context 'when called without a prefix' do
129
+ subject { relation.wrap.to_a }
130
+
131
+ it 'returns the data with keys prefixed by dataset name' do
132
+ is_expected.to match_array([
133
+ { test_id: 1, test_name: 'John' },
134
+ { test_id: 2, test_name: 'Jill' }
135
+ ])
136
+ end
137
+ end
138
+
139
+ context 'when called with a prefix' do
140
+ subject { relation.wrap('user').to_a }
5
141
 
6
- context 'when relation has schema' do
142
+ it 'returns the data with keys prefixed by the given prefix' do
143
+ is_expected.to match_array([
144
+ { user_id: 1, user_name: 'John' },
145
+ { user_id: 2, user_name: 'Jill' }
146
+ ])
147
+ end
148
+ end
149
+ end
150
+
151
+ describe '#to_a' do
152
+ subject { relation.to_a }
153
+
154
+ context 'with standard schema' do
7
155
  let(:relation_klass) do
8
156
  Class.new(ROM::HTTP::Relation) do
9
157
  schema do
10
- attribute 'id', ROM::Types::Strict::Int
158
+ attribute :id, ROM::Types::Strict::Int
11
159
  end
12
160
  end
13
161
  end
14
162
 
15
- it 'sets the dataset response transformer' do
16
- expect(relation.dataset.response_transformer)
17
- .to be_a(ROM::HTTP::Dataset::ResponseTransformers::Schemad)
163
+ it 'applies the schema and returns the materialized results' do
164
+ is_expected.to match_array([
165
+ { id: 1 },
166
+ { id: 2 }
167
+ ])
18
168
  end
19
169
  end
20
170
 
21
- context 'when relation does not have schema' do
171
+ context 'with aliased schema' do
22
172
  let(:relation_klass) do
23
- Class.new(ROM::HTTP::Relation)
173
+ Class.new(ROM::HTTP::Relation) do
174
+ schema do
175
+ attribute :id, ROM::Types::Strict::Int
176
+ attribute :name, ROM::Types::Strict::String.meta(alias: :username)
177
+ end
178
+ end
179
+ end
180
+
181
+ it 'applies the schema and returns the materialized results' do
182
+ is_expected.to match_array([
183
+ { id: 1, username: 'John' },
184
+ { id: 2, username: 'Jill' }
185
+ ])
24
186
  end
187
+ end
188
+ end
189
+
190
+ %i[insert update].each do |method_name|
191
+ describe "##{method_name}" do
192
+ subject { relation.send(method_name, name: 'John') }
25
193
 
26
- it 'keeps the default (schemaless) transformer' do
27
- expect(relation.dataset.response_transformer)
28
- .to be_a(ROM::HTTP::Dataset::ResponseTransformers::Schemaless)
194
+ before do
195
+ allow(dataset).to receive(method_name).and_return(data)
196
+ end
197
+
198
+ context 'with standard schema' do
199
+ let(:relation_klass) do
200
+ Class.new(ROM::HTTP::Relation) do
201
+ schema do
202
+ attribute :id, ROM::Types::Strict::Int
203
+ end
204
+ end
205
+ end
206
+
207
+ context 'when respond with single tuple' do
208
+ let(:data) { { id: 1, name: 'John' } }
209
+
210
+ it 'applies the schema and returns the materialized results' do
211
+ is_expected.to eq(id: 1)
212
+ end
213
+ end
214
+
215
+ context 'when respond with multiple tuples' do
216
+ let(:data) do
217
+ [
218
+ {
219
+ id: 1,
220
+ name: 'John'
221
+ },
222
+ {
223
+ id: 2,
224
+ name: 'Jill'
225
+ }
226
+ ]
227
+ end
228
+
229
+ it 'applies the schema and returns the materialized results' do
230
+ is_expected.to match_array([
231
+ { id: 1 },
232
+ { id: 2 }
233
+ ])
234
+ end
235
+ end
236
+ end
237
+
238
+ context 'with aliased schema' do
239
+ let(:relation_klass) do
240
+ Class.new(ROM::HTTP::Relation) do
241
+ schema do
242
+ attribute :id, ROM::Types::Strict::Int
243
+ attribute :name, ROM::Types::Strict::String.meta(alias: :username)
244
+ end
245
+ end
246
+ end
247
+
248
+ context 'when respond with single tuple' do
249
+ let(:data) { { id: 1, name: 'John' } }
250
+
251
+ it 'applies the schema and returns the materialized results' do
252
+ is_expected.to eq(id: 1, username: 'John')
253
+ end
254
+ end
255
+
256
+ context 'when respond with multiple tuples' do
257
+ let(:data) do
258
+ [
259
+ {
260
+ id: 1,
261
+ name: 'John'
262
+ },
263
+ {
264
+ id: 2,
265
+ name: 'Jill'
266
+ }
267
+ ]
268
+ end
269
+
270
+ it 'applies the schema and returns the materialized results' do
271
+ is_expected.to match_array([
272
+ { id: 1, username: 'John' },
273
+ { id: 2, username: 'Jill' }
274
+ ])
275
+ end
276
+ end
29
277
  end
30
278
  end
31
279
  end
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.5.0
4
+ version: 0.6.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
@@ -10,10 +10,10 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-08-08 00:00:00.000000000 Z
13
+ date: 2017-01-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: thread_safe
16
+ name: concurrent-ruby
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
19
  - - ">="
@@ -27,47 +27,53 @@ dependencies:
27
27
  - !ruby/object:Gem::Version
28
28
  version: '0'
29
29
  - !ruby/object:Gem::Dependency
30
- name: dry-types
30
+ name: rom
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - ">="
33
+ - - "~>"
34
34
  - !ruby/object:Gem::Version
35
- version: '0'
35
+ version: 3.0.0.rc
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - ">="
40
+ - - "~>"
41
41
  - !ruby/object:Gem::Version
42
- version: '0'
42
+ version: 3.0.0.rc
43
43
  - !ruby/object:Gem::Dependency
44
- name: rom
44
+ name: dry-core
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - "~>"
48
48
  - !ruby/object:Gem::Version
49
- version: '2.0'
49
+ version: '0.2'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 0.2.3
50
53
  type: :runtime
51
54
  prerelease: false
52
55
  version_requirements: !ruby/object:Gem::Requirement
53
56
  requirements:
54
57
  - - "~>"
55
58
  - !ruby/object:Gem::Version
56
- version: '2.0'
59
+ version: '0.2'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 0.2.3
57
63
  - !ruby/object:Gem::Dependency
58
64
  name: dry-equalizer
59
65
  requirement: !ruby/object:Gem::Requirement
60
66
  requirements:
61
- - - ">="
67
+ - - "~>"
62
68
  - !ruby/object:Gem::Version
63
- version: '0'
69
+ version: '0.2'
64
70
  type: :runtime
65
71
  prerelease: false
66
72
  version_requirements: !ruby/object:Gem::Requirement
67
73
  requirements:
68
- - - ">="
74
+ - - "~>"
69
75
  - !ruby/object:Gem::Version
70
- version: '0'
76
+ version: '0.2'
71
77
  - !ruby/object:Gem::Dependency
72
78
  name: bundler
73
79
  requirement: !ruby/object:Gem::Requirement
@@ -96,6 +102,20 @@ dependencies:
96
102
  - - "~>"
97
103
  - !ruby/object:Gem::Version
98
104
  version: '3.1'
105
+ - !ruby/object:Gem::Dependency
106
+ name: rspec-its
107
+ requirement: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ type: :development
113
+ prerelease: false
114
+ version_requirements: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
99
119
  - !ruby/object:Gem::Dependency
100
120
  name: rake
101
121
  requirement: !ruby/object:Gem::Requirement
@@ -129,6 +149,7 @@ files:
129
149
  - LICENSE.txt
130
150
  - README.md
131
151
  - Rakefile
152
+ - examples/repository_with_combine.rb
132
153
  - lib/rom-http.rb
133
154
  - lib/rom/http.rb
134
155
  - lib/rom/http/commands.rb
@@ -136,12 +157,10 @@ files:
136
157
  - lib/rom/http/commands/delete.rb
137
158
  - lib/rom/http/commands/update.rb
138
159
  - lib/rom/http/dataset.rb
139
- - lib/rom/http/dataset/response_transformers/schemad.rb
140
- - lib/rom/http/dataset/response_transformers/schemaless.rb
141
160
  - lib/rom/http/error.rb
142
161
  - lib/rom/http/gateway.rb
143
162
  - lib/rom/http/relation.rb
144
- - lib/rom/http/support/transformations.rb
163
+ - lib/rom/http/transformer.rb
145
164
  - lib/rom/http/version.rb
146
165
  - rakelib/rubocop.rake
147
166
  - rom-http.gemspec
@@ -153,8 +172,6 @@ files:
153
172
  - spec/shared/users_and_tasks.rb
154
173
  - spec/spec_helper.rb
155
174
  - spec/support/mutant.rb
156
- - spec/unit/rom/http/dataset/response_transformers/schemad_spec.rb
157
- - spec/unit/rom/http/dataset/response_transformers/schemaless_spec.rb
158
175
  - spec/unit/rom/http/dataset_spec.rb
159
176
  - spec/unit/rom/http/gateway_spec.rb
160
177
  - spec/unit/rom/http/relation_spec.rb
@@ -173,12 +190,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
173
190
  version: '0'
174
191
  required_rubygems_version: !ruby/object:Gem::Requirement
175
192
  requirements:
176
- - - ">="
193
+ - - ">"
177
194
  - !ruby/object:Gem::Version
178
- version: '0'
195
+ version: 1.3.1
179
196
  requirements: []
180
197
  rubyforge_project:
181
- rubygems_version: 2.6.3
198
+ rubygems_version: 2.5.1
182
199
  signing_key:
183
200
  specification_version: 4
184
201
  summary: HTTP support for ROM
@@ -191,8 +208,6 @@ test_files:
191
208
  - spec/shared/users_and_tasks.rb
192
209
  - spec/spec_helper.rb
193
210
  - spec/support/mutant.rb
194
- - spec/unit/rom/http/dataset/response_transformers/schemad_spec.rb
195
- - spec/unit/rom/http/dataset/response_transformers/schemaless_spec.rb
196
211
  - spec/unit/rom/http/dataset_spec.rb
197
212
  - spec/unit/rom/http/gateway_spec.rb
198
213
  - spec/unit/rom/http/relation_spec.rb