simple-sql 0.5.26 → 0.5.27

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: fab09e2181d6826802076b03cf71b0c742862ab1bf58e730403eee0eed1bb1c6
4
- data.tar.gz: 4f64d6025f76fec82d72f83cc936072cb092fa51f5fa0ad4ea37da1e70b045a3
3
+ metadata.gz: fd927c6b8b525593892421de3ce43fefa20d036c3d3eaf3ee3f0bbb863108deb
4
+ data.tar.gz: 2765ce9e6f3e86801074b014f142a607673f04692c6b0d8d3424c024066f25c9
5
5
  SHA512:
6
- metadata.gz: e8d383d973a2564e5e841e3820c24dc8aa9438c1ce3629f9508538e53c9775ef9ec16e8b7979933d1fed09bdc9389c71b2ce31122347f096f0e604bba2b20184
7
- data.tar.gz: 8a8caf53d1e973c8d762e725e7a7f91ea2fc5295d092c024db4227bda1c92976b0600f1f62d80d1d98794b5f35dc0eea3639ef887dbb2506b1cfdf20b8d7a055
6
+ metadata.gz: b4737e323e981525a17129dfdfd1e5a8076e99350ae0f758d6e5d53386ecd57e8d1c66766dbf8ded98b6fdf14ca25ee5a2a616b6c3ae04b844917d71f2ad720a
7
+ data.tar.gz: 8a86b32006f6bf1713c71550ea4a32bf4c393558ec8d76738d9905cae114bb470404c5168c10b352b5394b2ea7230277b931089cea9f15110e04522cb279cd5c
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.26
1
+ 0.5.27
@@ -75,6 +75,12 @@ module Simple::SQL::Connection::Scope::Search
75
75
 
76
76
  # -- apply dynamic filters --------------------------------------------------
77
77
 
78
+ def empty_filter?(_key, value)
79
+ return true if value.nil?
80
+ return true if value.is_a?(Enumerable) && value.empty? # i.e. Hash, Array
81
+ false
82
+ end
83
+
78
84
  def apply_dynamic_filters(scope, filters, dynamic_column:)
79
85
  # we translate a condition of "foo => []" into a SQL fragment like this:
80
86
  #
@@ -82,7 +88,7 @@ module Simple::SQL::Connection::Scope::Search
82
88
  #
83
89
  # i.e. we check for non-existing columns and columns that exist but have a
84
90
  # value of null (i.e. column->'key' IS NULL).
85
- empty_filters, filters = filters.partition { |_key, value| value.nil? || value.empty? }
91
+ empty_filters, filters = filters.partition { |key, value| empty_filter?(key, value) }
86
92
  empty_filters.each do |key, _|
87
93
  scope = scope.where("(NOT #{dynamic_column} ? '#{key}' OR #{dynamic_column} @> '#{::JSON.generate(key => nil)}'::jsonb)")
88
94
  end
@@ -20,10 +20,14 @@ describe "Simple::SQL.search" do
20
20
  scope.search(*args).all
21
21
  end
22
22
 
23
- it "filters by one dynamic attribute and one match" do
23
+ it "filters by one dynamic attribute matching a String" do
24
24
  expect(search(even_str: "yes").map(&:id)).to contain_exactly(2,4,6,8,10)
25
25
  end
26
26
 
27
+ it "filters by one dynamic attribute matching an Integer" do
28
+ expect(search(user_id_squared: 4).map(&:id)).to contain_exactly(2)
29
+ end
30
+
27
31
  it "filters by one dynamic attribute and multiple matches" do
28
32
  expect(search(user_id_squared: [1, 3, 9]).map(&:id)).to contain_exactly(1,3)
29
33
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-sql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.26
4
+ version: 0.5.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - radiospiel
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-01-21 00:00:00.000000000 Z
12
+ date: 2020-01-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pg_array_parser