rom-http 0.7.0 → 0.8.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 (46) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +26 -2
  3. data/LICENSE.txt +1 -1
  4. data/README.md +12 -15
  5. data/lib/rom-http.rb +2 -0
  6. data/lib/rom/http.rb +2 -0
  7. data/lib/rom/http/attribute.rb +10 -0
  8. data/lib/rom/http/commands.rb +2 -0
  9. data/lib/rom/http/commands/create.rb +2 -0
  10. data/lib/rom/http/commands/delete.rb +2 -0
  11. data/lib/rom/http/commands/update.rb +2 -0
  12. data/lib/rom/http/dataset.rb +152 -101
  13. data/lib/rom/http/error.rb +2 -0
  14. data/lib/rom/http/gateway.rb +44 -3
  15. data/lib/rom/http/handlers.rb +14 -0
  16. data/lib/rom/http/handlers/json.rb +65 -0
  17. data/lib/rom/http/mapper_compiler.rb +11 -0
  18. data/lib/rom/http/relation.rb +19 -64
  19. data/lib/rom/http/schema.rb +20 -0
  20. data/lib/rom/http/schema/dsl.rb +12 -0
  21. data/lib/rom/http/transformer.rb +2 -0
  22. data/lib/rom/http/types.rb +13 -0
  23. data/lib/rom/http/version.rb +3 -1
  24. metadata +32 -59
  25. data/.gitignore +0 -16
  26. data/.rspec +0 -3
  27. data/.rubocop.yml +0 -22
  28. data/.rubocop_todo.yml +0 -12
  29. data/.travis.yml +0 -20
  30. data/Gemfile +0 -24
  31. data/Rakefile +0 -24
  32. data/examples/repository_with_combine.rb +0 -154
  33. data/lib/rom/http/dataset/class_interface.rb +0 -33
  34. data/rakelib/rubocop.rake +0 -18
  35. data/rom-http.gemspec +0 -32
  36. data/spec/integration/abstract/commands/create_spec.rb +0 -119
  37. data/spec/integration/abstract/commands/delete_spec.rb +0 -52
  38. data/spec/integration/abstract/commands/update_spec.rb +0 -119
  39. data/spec/integration/abstract/relation_spec.rb +0 -78
  40. data/spec/shared/setup.rb +0 -18
  41. data/spec/shared/users_and_tasks.rb +0 -30
  42. data/spec/spec_helper.rb +0 -19
  43. data/spec/support/mutant.rb +0 -10
  44. data/spec/unit/rom/http/dataset_spec.rb +0 -824
  45. data/spec/unit/rom/http/gateway_spec.rb +0 -69
  46. data/spec/unit/rom/http/relation_spec.rb +0 -268
@@ -1,69 +0,0 @@
1
- require 'rom/lint/spec'
2
-
3
- RSpec.describe ROM::HTTP::Gateway do
4
- include_context 'users and tasks'
5
-
6
- it_behaves_like 'a rom gateway' do
7
- let(:identifier) { :http }
8
- let(:gateway) { ROM::HTTP::Gateway }
9
- let(:options) do
10
- {
11
- uri: 'http://localhost:3000',
12
- request_handler: request_handler,
13
- response_handler: response_handler
14
- }
15
- end
16
- # H4xz0rz
17
- let(:uri) { options }
18
- end
19
-
20
- describe '#dataset?' do
21
- it 'returns true if a table exists' do
22
- expect(gateway.dataset?(:users)).to be(true)
23
- end
24
-
25
- it 'returns false if a table does not exist' do
26
- expect(gateway.dataset?(:not_here)).to be(false)
27
- end
28
- end
29
-
30
- describe '#dataset' do
31
- subject { gateway.dataset(:name) }
32
-
33
- context 'when extended' do
34
- let(:gateway) { Test::Gateway.new({}) }
35
-
36
- before do
37
- module Test
38
- class Gateway < ROM::HTTP::Gateway; end
39
- end
40
- end
41
-
42
- context 'when no Dataset defined in the same namespace' do
43
- it 'returns ROM::HTTP::Dataset' do
44
- is_expected.to be_kind_of(ROM::HTTP::Dataset)
45
- end
46
- end
47
-
48
- context 'when Dataset defined in the same namespace' do
49
- before do
50
- module Test
51
- class Dataset < ROM::HTTP::Dataset; end
52
- end
53
- end
54
-
55
- it 'returns ROM::HTTP::Dataset' do
56
- is_expected.to be_kind_of(Test::Dataset)
57
- end
58
- end
59
- end
60
-
61
- context 'when not extended' do
62
- let(:gateway) { ROM::HTTP::Gateway.new({}) }
63
-
64
- it 'returns ROM::HTTP::Dataset' do
65
- is_expected.to be_kind_of(ROM::HTTP::Dataset)
66
- end
67
- end
68
- end
69
- end
@@ -1,268 +0,0 @@
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
-
29
- describe '#primary_key' do
30
- subject { relation.primary_key }
31
-
32
- context 'with no primary key defined in schema' do
33
- it 'defaults to :id' do
34
- is_expected.to eq(:id)
35
- end
36
- end
37
-
38
- context 'with primary key defined in schema' do
39
- context 'without alias' do
40
- let(:relation_klass) do
41
- Class.new(ROM::HTTP::Relation) do
42
- schema do
43
- attribute :id, ROM::Types::Strict::Int
44
- attribute :name, ROM::Types::Strict::String.meta(primary_key: true)
45
- end
46
- end
47
- end
48
-
49
- it 'returns the attribute name of the primary key' do
50
- is_expected.to eq(:name)
51
- end
52
- end
53
-
54
- context 'with alias' do
55
- let(:relation_klass) do
56
- Class.new(ROM::HTTP::Relation) do
57
- schema do
58
- attribute :id, ROM::Types::Strict::Int.meta(primary_key: true, alias: :ident)
59
- attribute :name, ROM::Types::Strict::String
60
- end
61
- end
62
- end
63
-
64
- it 'returns the attribute name of the primary key' do
65
- is_expected.to eq(:ident)
66
- end
67
- end
68
- end
69
- end
70
-
71
- describe '#project' do
72
- subject { relation.project(:id).to_a }
73
-
74
- it 'returns the projected data' do
75
- is_expected.to match_array([
76
- { id: 1 },
77
- { id: 2 }
78
- ])
79
- end
80
- end
81
-
82
- describe '#exclude' do
83
- subject { relation.exclude(:id).to_a }
84
-
85
- it 'returns the data with specified keys excluded' do
86
- is_expected.to match_array([
87
- { name: 'John' },
88
- { name: 'Jill' }
89
- ])
90
- end
91
- end
92
-
93
- describe '#rename' do
94
- subject { relation.rename(id: :identity).to_a }
95
-
96
- it 'returns the data with keys renamed according to mapping' do
97
- is_expected.to match_array([
98
- { name: 'John', identity: 1 },
99
- { name: 'Jill', identity: 2 }
100
- ])
101
- end
102
- end
103
-
104
- describe '#prefix' do
105
- subject { relation.prefix('user').to_a }
106
-
107
- it 'returns the data with prefixed keys' do
108
- is_expected.to match_array([
109
- { user_id: 1, user_name: 'John' },
110
- { user_id: 2, user_name: 'Jill' }
111
- ])
112
- end
113
- end
114
-
115
- describe '#wrap' do
116
- context 'when called without a prefix' do
117
- subject { relation.wrap.to_a }
118
-
119
- it 'returns the data with keys prefixed by dataset name' do
120
- is_expected.to match_array([
121
- { test_id: 1, test_name: 'John' },
122
- { test_id: 2, test_name: 'Jill' }
123
- ])
124
- end
125
- end
126
-
127
- context 'when called with a prefix' do
128
- subject { relation.wrap('user').to_a }
129
-
130
- it 'returns the data with keys prefixed by the given prefix' do
131
- is_expected.to match_array([
132
- { user_id: 1, user_name: 'John' },
133
- { user_id: 2, user_name: 'Jill' }
134
- ])
135
- end
136
- end
137
- end
138
-
139
- describe '#to_a' do
140
- subject { relation.to_a }
141
-
142
- context 'with standard schema' do
143
- let(:relation_klass) do
144
- Class.new(ROM::HTTP::Relation) do
145
- schema do
146
- attribute :id, ROM::Types::Strict::Int
147
- end
148
- end
149
- end
150
-
151
- it 'applies the schema and returns the materialized results' do
152
- is_expected.to match_array([
153
- { id: 1 },
154
- { id: 2 }
155
- ])
156
- end
157
- end
158
-
159
- context 'with aliased schema' do
160
- let(:relation_klass) do
161
- Class.new(ROM::HTTP::Relation) do
162
- schema do
163
- attribute :id, ROM::Types::Strict::Int
164
- attribute :name, ROM::Types::Strict::String.meta(alias: :username)
165
- end
166
- end
167
- end
168
-
169
- it 'applies the schema and returns the materialized results' do
170
- is_expected.to match_array([
171
- { id: 1, username: 'John' },
172
- { id: 2, username: 'Jill' }
173
- ])
174
- end
175
- end
176
- end
177
-
178
- %i[insert update].each do |method_name|
179
- describe "##{method_name}" do
180
- subject { relation.send(method_name, name: 'John') }
181
-
182
- before do
183
- allow(dataset).to receive(method_name).and_return(data)
184
- end
185
-
186
- context 'with standard schema' do
187
- let(:relation_klass) do
188
- Class.new(ROM::HTTP::Relation) do
189
- schema do
190
- attribute :id, ROM::Types::Strict::Int
191
- end
192
- end
193
- end
194
-
195
- context 'when respond with single tuple' do
196
- let(:data) { { id: 1, name: 'John' } }
197
-
198
- it 'applies the schema and returns the materialized results' do
199
- is_expected.to eq(id: 1)
200
- end
201
- end
202
-
203
- context 'when respond with multiple tuples' do
204
- let(:data) do
205
- [
206
- {
207
- id: 1,
208
- name: 'John'
209
- },
210
- {
211
- id: 2,
212
- name: 'Jill'
213
- }
214
- ]
215
- end
216
-
217
- it 'applies the schema and returns the materialized results' do
218
- is_expected.to match_array([
219
- { id: 1 },
220
- { id: 2 }
221
- ])
222
- end
223
- end
224
- end
225
-
226
- context 'with aliased schema' do
227
- let(:relation_klass) do
228
- Class.new(ROM::HTTP::Relation) do
229
- schema do
230
- attribute :id, ROM::Types::Strict::Int
231
- attribute :name, ROM::Types::Strict::String.meta(alias: :username)
232
- end
233
- end
234
- end
235
-
236
- context 'when respond with single tuple' do
237
- let(:data) { { id: 1, name: 'John' } }
238
-
239
- it 'applies the schema and returns the materialized results' do
240
- is_expected.to eq(id: 1, username: 'John')
241
- end
242
- end
243
-
244
- context 'when respond with multiple tuples' do
245
- let(:data) do
246
- [
247
- {
248
- id: 1,
249
- name: 'John'
250
- },
251
- {
252
- id: 2,
253
- name: 'Jill'
254
- }
255
- ]
256
- end
257
-
258
- it 'applies the schema and returns the materialized results' do
259
- is_expected.to match_array([
260
- { id: 1, username: 'John' },
261
- { id: 2, username: 'Jill' }
262
- ])
263
- end
264
- end
265
- end
266
- end
267
- end
268
- end