wcc-contentful 1.0.0 → 1.0.4

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
- SHA256:
3
- metadata.gz: ad34af3480e2e993b8046826ef3ca65b6f28ccf28e57e19cca79061a17766877
4
- data.tar.gz: e0e214bf19721287af20502260033f595dcf461d2b5d31fd943c838b3ced204e
2
+ SHA1:
3
+ metadata.gz: 5e0a14cd883ecb58fe7d8dd07963eeb83c8f3f7d
4
+ data.tar.gz: 445174542f3d500a9e2872f0887efc98aa2c6554
5
5
  SHA512:
6
- metadata.gz: 1e67eacbb406c6269c0a43b6b7a1284836a357c9b9ff0ffe297ee188aeea6a2c96107b9a6fc127d2e622223f38797528e18e93485575068d7eae4a73a77f9375
7
- data.tar.gz: c16f075caa26c9a9a0f0c22fe725eabf0b0c2900f4c58bac33fcb8ad42a10dee09ae257e2a91d71e06e878d1c7b8165dea28b1a5a791480f5c03e328f8635355
6
+ metadata.gz: f3928e46b2ad722c4bcd003225b3092fac6dd602f5ab79994767e134966fd2592b35c1df1301f65c41a95f270d2ac99255dc9971a0ca3dde818d0918676a0f79
7
+ data.tar.gz: f3d31807796c12b9407b1a6e9dcb6ef92cd8b95ee7dcdddcb6ee6c925c071f6c61bf5b5396807105ebaec1129891f6d7fd0729bfa5604a16d3f4ee1a6efdefa2
@@ -14,7 +14,11 @@ module WCC::Contentful::ActiveRecordShim
14
14
  end
15
15
 
16
16
  def cache_key_with_version
17
- "#{self.class.model_name}/#{id}-#{cache_version}"
17
+ "#{cache_key_without_version}-#{cache_version}"
18
+ end
19
+
20
+ def cache_key_without_version
21
+ "#{self.class.model_name}/#{id}"
18
22
  end
19
23
 
20
24
  def cache_version
@@ -253,12 +253,22 @@ module WCC::Contentful::Store
253
253
  end
254
254
 
255
255
  " AND t.data->#{quote_parameter_path(path)}" \
256
- " ? $#{push_param(expected, params)}::text"
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
- params.length
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module WCC
4
4
  module Contentful
5
- VERSION = '1.0.0'
5
+ VERSION = '1.0.4'
6
6
  end
7
7
  end
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.0
4
+ version: 1.0.4
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-04-16 00:00:00.000000000 Z
11
+ date: 2021-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -519,7 +519,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
519
519
  version: '0'
520
520
  requirements: []
521
521
  rubyforge_project:
522
- rubygems_version: 2.7.6.2
522
+ rubygems_version: 2.6.11
523
523
  signing_key:
524
524
  specification_version: 4
525
525
  summary: '[![Gem Version](https://badge.fury.io/rb/wcc-contentful.svg)](https://rubygems.org/gems/wcc-contentful)