cuprum-collections 0.5.1 → 0.6.0.rc.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 +4 -4
- data/CHANGELOG.md +47 -0
- data/lib/cuprum/collections/adaptable/collection.rb +18 -0
- data/lib/cuprum/collections/adaptable/command.rb +22 -0
- data/lib/cuprum/collections/adaptable/commands/abstract_assign_one.rb +27 -0
- data/lib/cuprum/collections/adaptable/commands/abstract_build_one.rb +25 -0
- data/lib/cuprum/collections/adaptable/commands/abstract_validate_one.rb +35 -0
- data/lib/cuprum/collections/adaptable/commands.rb +15 -0
- data/lib/cuprum/collections/adaptable/query.rb +64 -0
- data/lib/cuprum/collections/adaptable.rb +13 -0
- data/lib/cuprum/collections/adapter.rb +300 -0
- data/lib/cuprum/collections/adapters/data_adapter.rb +82 -0
- data/lib/cuprum/collections/adapters/entity_adapter.rb +76 -0
- data/lib/cuprum/collections/adapters/hash_adapter.rb +48 -0
- data/lib/cuprum/collections/adapters.rb +14 -0
- data/lib/cuprum/collections/basic/collection.rb +2 -20
- data/lib/cuprum/collections/basic/commands/destroy_one.rb +1 -1
- data/lib/cuprum/collections/basic/commands/find_many.rb +0 -31
- data/lib/cuprum/collections/basic/commands/find_matching.rb +0 -94
- data/lib/cuprum/collections/basic/commands/find_one.rb +0 -18
- data/lib/cuprum/collections/basic/commands/insert_one.rb +1 -1
- data/lib/cuprum/collections/basic/commands/update_one.rb +1 -1
- data/lib/cuprum/collections/basic/scopes/criteria_scope.rb +36 -21
- data/lib/cuprum/collections/basic.rb +6 -5
- data/lib/cuprum/collections/collection.rb +6 -0
- data/lib/cuprum/collections/collection_command.rb +1 -1
- data/lib/cuprum/collections/commands/abstract_find_many.rb +40 -3
- data/lib/cuprum/collections/commands/abstract_find_matching.rb +102 -0
- data/lib/cuprum/collections/commands/abstract_find_one.rb +23 -1
- data/lib/cuprum/collections/commands/associations/find_many.rb +1 -3
- data/lib/cuprum/collections/commands/associations/require_many.rb +1 -1
- data/lib/cuprum/collections/commands/find_one_matching.rb +10 -10
- data/lib/cuprum/collections/commands/query_command.rb +6 -4
- data/lib/cuprum/collections/commands/upsert.rb +0 -2
- data/lib/cuprum/collections/constraints/order/attributes_array.rb +5 -4
- data/lib/cuprum/collections/constraints/order/attributes_hash.rb +5 -4
- data/lib/cuprum/collections/constraints/order/sort_direction.rb +2 -2
- data/lib/cuprum/collections/constraints/ordering.rb +11 -9
- data/lib/cuprum/collections/constraints/query_hash.rb +2 -2
- data/lib/cuprum/collections/errors/abstract_find_error.rb +101 -23
- data/lib/cuprum/collections/errors/extra_attributes.rb +3 -3
- data/lib/cuprum/collections/errors/failed_validation.rb +3 -3
- data/lib/cuprum/collections/errors/missing_default_contract.rb +12 -4
- data/lib/cuprum/collections/queries.rb +4 -0
- data/lib/cuprum/collections/relation.rb +0 -2
- data/lib/cuprum/collections/relations/parameters.rb +120 -68
- data/lib/cuprum/collections/repository.rb +71 -6
- data/lib/cuprum/collections/rspec/contracts/query_contracts.rb +23 -4
- data/lib/cuprum/collections/rspec/contracts/repository_contracts.rb +18 -0
- data/lib/cuprum/collections/rspec/contracts/scope_contracts.rb +51 -0
- data/lib/cuprum/collections/rspec/contracts/scopes/builder_contracts.rb +10 -0
- data/lib/cuprum/collections/rspec/contracts/scopes/composition_contracts.rb +8 -0
- data/lib/cuprum/collections/rspec/contracts/scopes/criteria_contracts.rb +18 -366
- data/lib/cuprum/collections/rspec/contracts/scopes/logical_contracts.rb +30 -0
- data/lib/cuprum/collections/rspec/contracts/scopes.rb +2 -0
- data/lib/cuprum/collections/rspec/contracts.rb +2 -10
- data/lib/cuprum/collections/rspec/deferred/adapter_examples.rb +1077 -0
- data/lib/cuprum/collections/rspec/deferred/collection_examples.rb +27 -7
- data/lib/cuprum/collections/rspec/deferred/commands/assign_one_examples.rb +4 -4
- data/lib/cuprum/collections/rspec/deferred/commands/build_one_examples.rb +2 -2
- data/lib/cuprum/collections/rspec/deferred/commands/destroy_one_examples.rb +2 -2
- data/lib/cuprum/collections/rspec/deferred/commands/find_many_examples.rb +5 -5
- data/lib/cuprum/collections/rspec/deferred/commands/find_matching_examples.rb +45 -12
- data/lib/cuprum/collections/rspec/deferred/commands/find_one_examples.rb +2 -2
- data/lib/cuprum/collections/rspec/deferred/commands/insert_one_examples.rb +1 -1
- data/lib/cuprum/collections/rspec/deferred/commands/update_one_examples.rb +1 -1
- data/lib/cuprum/collections/rspec/deferred/query_examples.rb +930 -0
- data/lib/cuprum/collections/rspec/deferred/relation_examples.rb +48 -17
- data/lib/cuprum/collections/rspec/deferred/repository_examples.rb +961 -0
- data/lib/cuprum/collections/rspec/deferred/scope_examples.rb +598 -0
- data/lib/cuprum/collections/rspec/deferred/scopes/all_examples.rb +391 -0
- data/lib/cuprum/collections/rspec/deferred/scopes/builder_examples.rb +857 -0
- data/lib/cuprum/collections/rspec/deferred/scopes/composition_examples.rb +93 -0
- data/lib/cuprum/collections/rspec/deferred/scopes/conjunction_examples.rb +438 -0
- data/lib/cuprum/collections/rspec/deferred/scopes/criteria_examples.rb +1941 -0
- data/lib/cuprum/collections/rspec/deferred/scopes/disjunction_examples.rb +415 -0
- data/lib/cuprum/collections/rspec/deferred/scopes/none_examples.rb +385 -0
- data/lib/cuprum/collections/rspec/deferred/scopes/parser_examples.rb +740 -0
- data/lib/cuprum/collections/rspec/deferred/scopes.rb +8 -0
- data/lib/cuprum/collections/scope.rb +2 -2
- data/lib/cuprum/collections/scopes/container.rb +5 -4
- data/lib/cuprum/collections/scopes/criteria/parser.rb +24 -48
- data/lib/cuprum/collections/scopes/criteria.rb +7 -6
- data/lib/cuprum/collections/version.rb +4 -4
- data/lib/cuprum/collections.rb +5 -1
- metadata +47 -11
- data/lib/cuprum/collections/rspec/contracts/association_contracts.rb +0 -2127
- data/lib/cuprum/collections/rspec/contracts/basic.rb +0 -11
- data/lib/cuprum/collections/rspec/contracts/collection_contracts.rb +0 -387
- data/lib/cuprum/collections/rspec/contracts/command_contracts.rb +0 -169
- data/lib/cuprum/collections/rspec/contracts/relation_contracts.rb +0 -1264
|
@@ -77,7 +77,11 @@ module Cuprum::Collections::RSpec::Deferred
|
|
|
77
77
|
include_deferred 'should define the command', :validate_one
|
|
78
78
|
|
|
79
79
|
describe '#==' do
|
|
80
|
-
let(:other_options)
|
|
80
|
+
let(:other_options) do
|
|
81
|
+
next super() if defined?(super())
|
|
82
|
+
|
|
83
|
+
{ name: }
|
|
84
|
+
end
|
|
81
85
|
let(:other_collection) { described_class.new(**other_options) }
|
|
82
86
|
|
|
83
87
|
describe 'with nil' do
|
|
@@ -223,7 +227,9 @@ module Cuprum::Collections::RSpec::Deferred
|
|
|
223
227
|
|
|
224
228
|
describe 'with matching entity class as a Class' do
|
|
225
229
|
let(:configured_entity_class) do
|
|
226
|
-
options.fetch(:default_entity_class, Book)
|
|
230
|
+
value = options.fetch(:default_entity_class, Book)
|
|
231
|
+
value = instance_exec(&value) if value.is_a?(Proc)
|
|
232
|
+
value
|
|
227
233
|
end
|
|
228
234
|
let(:other_options) { { entity_class: configured_entity_class } }
|
|
229
235
|
|
|
@@ -232,7 +238,9 @@ module Cuprum::Collections::RSpec::Deferred
|
|
|
232
238
|
|
|
233
239
|
describe 'with matching entity class as a String' do
|
|
234
240
|
let(:configured_entity_class) do
|
|
235
|
-
options.fetch(:default_entity_class, Book)
|
|
241
|
+
value = options.fetch(:default_entity_class, Book)
|
|
242
|
+
value = instance_exec(&value) if value.is_a?(Proc)
|
|
243
|
+
value
|
|
236
244
|
end
|
|
237
245
|
let(:other_options) do
|
|
238
246
|
{ entity_class: configured_entity_class.to_s }
|
|
@@ -241,8 +249,14 @@ module Cuprum::Collections::RSpec::Deferred
|
|
|
241
249
|
it { expect(collection.matches?(**other_options)).to be true }
|
|
242
250
|
end
|
|
243
251
|
|
|
244
|
-
describe 'with matching name' do
|
|
245
|
-
let(:other_options) { { name: } }
|
|
252
|
+
describe 'with matching name as a String' do
|
|
253
|
+
let(:other_options) { { name: name.to_s } }
|
|
254
|
+
|
|
255
|
+
it { expect(collection.matches?(**other_options)).to be true }
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
describe 'with matching name as a Symbol' do
|
|
259
|
+
let(:other_options) { { name: name.intern } }
|
|
246
260
|
|
|
247
261
|
it { expect(collection.matches?(**other_options)).to be true }
|
|
248
262
|
end
|
|
@@ -259,8 +273,14 @@ module Cuprum::Collections::RSpec::Deferred
|
|
|
259
273
|
it { expect(collection.matches?(**other_options)).to be true }
|
|
260
274
|
end
|
|
261
275
|
|
|
262
|
-
describe 'with matching qualified name' do
|
|
263
|
-
let(:other_options) { { qualified_name: name } }
|
|
276
|
+
describe 'with matching qualified name as a String' do
|
|
277
|
+
let(:other_options) { { qualified_name: name.to_s } }
|
|
278
|
+
|
|
279
|
+
it { expect(collection.matches?(**other_options)).to be true }
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
describe 'with matching qualified name as a Symbol' do
|
|
283
|
+
let(:other_options) { { qualified_name: name.intern } }
|
|
264
284
|
|
|
265
285
|
it { expect(collection.matches?(**other_options)).to be true }
|
|
266
286
|
end
|
|
@@ -77,8 +77,8 @@ module Cuprum::Collections::RSpec::Deferred::Commands
|
|
|
77
77
|
describe 'with an attributes hash with extra attributes' do
|
|
78
78
|
let(:attributes) do
|
|
79
79
|
{
|
|
80
|
-
title
|
|
81
|
-
audiobook
|
|
80
|
+
'title' => 'The Book of Lost Tales',
|
|
81
|
+
'audiobook' => true
|
|
82
82
|
}
|
|
83
83
|
end
|
|
84
84
|
|
|
@@ -143,8 +143,8 @@ module Cuprum::Collections::RSpec::Deferred::Commands
|
|
|
143
143
|
describe 'with an attributes hash with extra attributes' do
|
|
144
144
|
let(:attributes) do
|
|
145
145
|
{
|
|
146
|
-
title
|
|
147
|
-
audiobook
|
|
146
|
+
'title' => 'The Book of Lost Tales',
|
|
147
|
+
'audiobook' => true
|
|
148
148
|
}
|
|
149
149
|
end
|
|
150
150
|
|
|
@@ -62,8 +62,8 @@ module Cuprum::Collections::RSpec::Deferred::Commands
|
|
|
62
62
|
describe 'with an attributes hash with extra attributes' do
|
|
63
63
|
let(:attributes) do
|
|
64
64
|
{
|
|
65
|
-
title
|
|
66
|
-
audiobook
|
|
65
|
+
'title' => 'The Book of Lost Tales',
|
|
66
|
+
'audiobook' => true
|
|
67
67
|
}
|
|
68
68
|
end
|
|
69
69
|
|
|
@@ -35,7 +35,7 @@ module Cuprum::Collections::RSpec::Deferred::Commands
|
|
|
35
35
|
Cuprum::Collections::Errors::NotFound.new(
|
|
36
36
|
attribute_name: collection.primary_key_name,
|
|
37
37
|
attribute_value: primary_key,
|
|
38
|
-
|
|
38
|
+
name: collection.name,
|
|
39
39
|
primary_key: true
|
|
40
40
|
)
|
|
41
41
|
end
|
|
@@ -69,7 +69,7 @@ module Cuprum::Collections::RSpec::Deferred::Commands
|
|
|
69
69
|
Cuprum::Collections::Errors::NotFound.new(
|
|
70
70
|
attribute_name: collection.primary_key_name,
|
|
71
71
|
attribute_value: primary_key,
|
|
72
|
-
|
|
72
|
+
name: collection.name,
|
|
73
73
|
primary_key: true
|
|
74
74
|
)
|
|
75
75
|
end
|
|
@@ -67,7 +67,7 @@ module Cuprum::Collections::RSpec::Deferred::Commands
|
|
|
67
67
|
Cuprum::Collections::Errors::NotFound.new(
|
|
68
68
|
attribute_name: collection.primary_key_name,
|
|
69
69
|
attribute_value: primary_key,
|
|
70
|
-
|
|
70
|
+
name: collection.name,
|
|
71
71
|
primary_key: true
|
|
72
72
|
)
|
|
73
73
|
end
|
|
@@ -112,7 +112,7 @@ module Cuprum::Collections::RSpec::Deferred::Commands
|
|
|
112
112
|
Cuprum::Collections::Errors::NotFound.new(
|
|
113
113
|
attribute_name: collection.primary_key_name,
|
|
114
114
|
attribute_value: primary_key,
|
|
115
|
-
|
|
115
|
+
name: collection.name,
|
|
116
116
|
primary_key: true
|
|
117
117
|
)
|
|
118
118
|
end
|
|
@@ -140,7 +140,7 @@ module Cuprum::Collections::RSpec::Deferred::Commands
|
|
|
140
140
|
Cuprum::Collections::Errors::NotFound.new(
|
|
141
141
|
attribute_name: collection.primary_key_name,
|
|
142
142
|
attribute_value: primary_key,
|
|
143
|
-
|
|
143
|
+
name: collection.name,
|
|
144
144
|
primary_key: true
|
|
145
145
|
)
|
|
146
146
|
end
|
|
@@ -183,7 +183,7 @@ module Cuprum::Collections::RSpec::Deferred::Commands
|
|
|
183
183
|
Cuprum::Collections::Errors::NotFound.new(
|
|
184
184
|
attribute_name: collection.primary_key_name,
|
|
185
185
|
attribute_value: primary_key,
|
|
186
|
-
|
|
186
|
+
name: collection.name,
|
|
187
187
|
primary_key: true
|
|
188
188
|
)
|
|
189
189
|
end
|
|
@@ -211,7 +211,7 @@ module Cuprum::Collections::RSpec::Deferred::Commands
|
|
|
211
211
|
Cuprum::Collections::Errors::NotFound.new(
|
|
212
212
|
attribute_name: collection.primary_key_name,
|
|
213
213
|
attribute_value: primary_key,
|
|
214
|
-
|
|
214
|
+
name: collection.name,
|
|
215
215
|
primary_key: true
|
|
216
216
|
)
|
|
217
217
|
end
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'cuprum/collections/rspec/contracts/query_contracts'
|
|
4
3
|
require 'cuprum/collections/rspec/deferred/command_examples'
|
|
5
4
|
require 'cuprum/collections/rspec/deferred/commands'
|
|
5
|
+
require 'cuprum/collections/rspec/deferred/query_examples'
|
|
6
6
|
|
|
7
7
|
module Cuprum::Collections::RSpec::Deferred::Commands
|
|
8
8
|
# Namespace for deferred example groups for validating FindMatching commands.
|
|
@@ -11,8 +11,8 @@ module Cuprum::Collections::RSpec::Deferred::Commands
|
|
|
11
11
|
|
|
12
12
|
deferred_examples 'should implement the FindMatching command' do
|
|
13
13
|
describe '#call' do
|
|
14
|
-
include Cuprum::Collections::RSpec::Contracts::QueryContracts
|
|
15
14
|
include Cuprum::Collections::RSpec::Deferred::CommandExamples
|
|
15
|
+
include Cuprum::Collections::RSpec::Deferred::QueryExamples
|
|
16
16
|
|
|
17
17
|
shared_examples 'should return the matching items' do
|
|
18
18
|
it { expect(result).to be_a_passing_result }
|
|
@@ -59,7 +59,7 @@ module Cuprum::Collections::RSpec::Deferred::Commands
|
|
|
59
59
|
defined?(super()) ? super() : matching_data
|
|
60
60
|
end
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
define_method :call_command do
|
|
63
63
|
command.call(**options, &block)
|
|
64
64
|
end
|
|
65
65
|
|
|
@@ -98,11 +98,21 @@ module Cuprum::Collections::RSpec::Deferred::Commands
|
|
|
98
98
|
end
|
|
99
99
|
|
|
100
100
|
describe 'with an invalid where value' do
|
|
101
|
-
|
|
101
|
+
describe 'with an object' do
|
|
102
|
+
let(:options) { super().merge(where: Object.new.freeze) }
|
|
102
103
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
include_deferred 'should validate the parameter',
|
|
105
|
+
:where,
|
|
106
|
+
message: 'where is not a scope or query hash'
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
describe 'with an Proc with invalid arity' do
|
|
110
|
+
let(:options) { super().merge(where: ->(_a, _b = nil) {}) }
|
|
111
|
+
|
|
112
|
+
include_deferred 'should validate the parameter',
|
|
113
|
+
:where,
|
|
114
|
+
message: 'where is not a scope or query hash'
|
|
115
|
+
end
|
|
106
116
|
end
|
|
107
117
|
|
|
108
118
|
describe 'with an invalid filter block' do
|
|
@@ -127,13 +137,36 @@ module Cuprum::Collections::RSpec::Deferred::Commands
|
|
|
127
137
|
context 'when the collection has many items' do
|
|
128
138
|
let(:data) { fixtures_data }
|
|
129
139
|
|
|
130
|
-
|
|
131
|
-
|
|
140
|
+
context 'when passed a scope as a block' do
|
|
141
|
+
include_deferred 'should query the collection' do
|
|
142
|
+
include_examples 'should return the matching items'
|
|
143
|
+
|
|
144
|
+
describe 'with envelope: true' do
|
|
145
|
+
let(:options) { super().merge(envelope: true) }
|
|
146
|
+
|
|
147
|
+
include_examples 'should return the wrapped items'
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
context 'when passed a scope as a proc' do
|
|
153
|
+
let(:options) do
|
|
154
|
+
opts = super()
|
|
155
|
+
|
|
156
|
+
opts[:where] = filter unless filter.nil?
|
|
157
|
+
|
|
158
|
+
opts
|
|
159
|
+
end
|
|
160
|
+
let(:block) { nil }
|
|
161
|
+
|
|
162
|
+
include_deferred 'should query the collection' do
|
|
163
|
+
include_examples 'should return the matching items'
|
|
132
164
|
|
|
133
|
-
|
|
134
|
-
|
|
165
|
+
describe 'with envelope: true' do
|
|
166
|
+
let(:options) { super().merge(envelope: true) }
|
|
135
167
|
|
|
136
|
-
|
|
168
|
+
include_examples 'should return the wrapped items'
|
|
169
|
+
end
|
|
137
170
|
end
|
|
138
171
|
end
|
|
139
172
|
end
|
|
@@ -46,7 +46,7 @@ module Cuprum::Collections::RSpec::Deferred::Commands
|
|
|
46
46
|
Cuprum::Collections::Errors::NotFound.new(
|
|
47
47
|
attribute_name: collection.primary_key_name,
|
|
48
48
|
attribute_value: primary_key,
|
|
49
|
-
|
|
49
|
+
name: collection.name,
|
|
50
50
|
primary_key: true
|
|
51
51
|
)
|
|
52
52
|
end
|
|
@@ -74,7 +74,7 @@ module Cuprum::Collections::RSpec::Deferred::Commands
|
|
|
74
74
|
Cuprum::Collections::Errors::NotFound.new(
|
|
75
75
|
attribute_name: collection.primary_key_name,
|
|
76
76
|
attribute_value: primary_key,
|
|
77
|
-
|
|
77
|
+
name: collection.name,
|
|
78
78
|
primary_key: true
|
|
79
79
|
)
|
|
80
80
|
end
|