wcc-contentful 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f22654d250bb9d8f8011c38bb10ee5a61ccca2761e5f39f795513dd423b1265e
|
4
|
+
data.tar.gz: 105f2934b5364a5fc64373bd6c34e822628cb7b9a5e80a6da09a093cd8df1340
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 894635b750b72af362dbfaf12f7421b3dced5872634a948c77721c613e9ec8d6f29d17dfadb9ae3497ff2b134f29ca5d74edd989cc42411ca5a05ea49ea17400
|
7
|
+
data.tar.gz: 7a3e9a7aa7ac701a735908bb1cc8074a5625ededf16e4081b04ce34b5464b32e522c0719a5f22c7d7cc67f60ae92e62289cec40e62d7acda1c8b63c598b74064
|
@@ -253,12 +253,22 @@ module WCC::Contentful::Store
|
|
253
253
|
end
|
254
254
|
|
255
255
|
" AND t.data->#{quote_parameter_path(path)}" \
|
256
|
-
"
|
256
|
+
" @> to_jsonb($#{push_param(expected, params)})"
|
257
257
|
end
|
258
258
|
|
259
|
+
PARAM_TYPES = {
|
260
|
+
String => 'text'
|
261
|
+
|
262
|
+
# These can be cast directly to jsonb
|
263
|
+
# Integer => 'jsonb'
|
264
|
+
# Float => 'jsonb'
|
265
|
+
}.freeze
|
266
|
+
|
259
267
|
def push_param(param, params)
|
260
268
|
params << param
|
261
|
-
|
269
|
+
param_type = PARAM_TYPES[param.class] || 'jsonb'
|
270
|
+
|
271
|
+
"#{params.length}::#{param_type}"
|
262
272
|
end
|
263
273
|
|
264
274
|
def quote_parameter_path(path)
|
@@ -546,6 +546,68 @@ RSpec.shared_examples 'basic store' do
|
|
546
546
|
expect(found.dig('sys', 'id')).to eq('idTwo')
|
547
547
|
expect(found.dig('fields', 'system', 'en-US')).to eq('Two')
|
548
548
|
end
|
549
|
+
|
550
|
+
[
|
551
|
+
[Integer, proc { rand(-4_611_686_018_427_387_903..4_611_686_018_427_387_903) }],
|
552
|
+
[Float, proc { rand }]
|
553
|
+
].each do |(type, generator)|
|
554
|
+
context "by #{type} equality" do
|
555
|
+
it 'can apply filter object' do
|
556
|
+
data =
|
557
|
+
1.upto(10).map do |i|
|
558
|
+
{
|
559
|
+
'sys' => { 'id' => "k#{i}", 'contentType' => { 'sys' => { 'id' => 'test1' } } },
|
560
|
+
'fields' => { type.to_s => { 'en-US' => generator.call } }
|
561
|
+
}
|
562
|
+
end
|
563
|
+
|
564
|
+
desired_value = generator.call
|
565
|
+
desired = {
|
566
|
+
'sys' => { 'id' => "k#{rand}", 'contentType' => { 'sys' => { 'id' => 'test1' } } },
|
567
|
+
'fields' => { type.to_s => { 'en-US' => desired_value } }
|
568
|
+
}
|
569
|
+
|
570
|
+
data << desired
|
571
|
+
data.shuffle.each { |d| subject.set(d.dig('sys', 'id'), d) }
|
572
|
+
|
573
|
+
# act
|
574
|
+
found = subject.find_by(content_type: 'test1', filter: { type.to_s => desired_value })
|
575
|
+
|
576
|
+
# assert
|
577
|
+
expect(found).to_not be_nil
|
578
|
+
expect(found).to eq(desired)
|
579
|
+
end
|
580
|
+
|
581
|
+
it 'filter object can find value in array' do
|
582
|
+
data =
|
583
|
+
1.upto(10).map do |i|
|
584
|
+
{
|
585
|
+
'sys' => {
|
586
|
+
'id' => "k#{i}",
|
587
|
+
'contentType' => { 'sys' => { 'id' => 'test1' } }
|
588
|
+
},
|
589
|
+
'fields' => { 'name' => { 'en-US' => [generator.call, generator.call] } }
|
590
|
+
}
|
591
|
+
end
|
592
|
+
|
593
|
+
desired_value = generator.call
|
594
|
+
desired = {
|
595
|
+
'sys' => { 'id' => "k#{rand}", 'contentType' => { 'sys' => { 'id' => 'test1' } } },
|
596
|
+
'fields' => { type.to_s => { 'en-US' => [generator.call, desired_value].shuffle } }
|
597
|
+
}
|
598
|
+
|
599
|
+
data << desired
|
600
|
+
data.shuffle.each { |d| subject.set(d.dig('sys', 'id'), d) }
|
601
|
+
|
602
|
+
# act
|
603
|
+
found = subject.find_by(content_type: 'test1', filter: { type.to_s => { eq: desired_value } })
|
604
|
+
|
605
|
+
# assert
|
606
|
+
expect(found).to_not be_nil
|
607
|
+
expect(found).to eq(desired)
|
608
|
+
end
|
609
|
+
end
|
610
|
+
end
|
549
611
|
end
|
550
612
|
|
551
613
|
describe '#find_all' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wcc-contentful
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Watermark Dev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|