where_exists 1.2.2 → 1.2.3

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: 28bde73cd6a1857a0762a1fd489258ad40b44cea344afba4357cbe7fa83cdf41
4
- data.tar.gz: ed7a98cb6a7391cb955c911f0063f9eb901e86305b0b7ddb3e01b9a209371476
3
+ metadata.gz: 397b2a3fc406fb516d6f060ae46b25580a764c668476859737ee07fbd979c15b
4
+ data.tar.gz: 1c23ab279b89ede28edb71e3b951f7587ab2a7b27605bba607888f0b89e03c58
5
5
  SHA512:
6
- metadata.gz: 943e345289ac9f2a2d44a5428a559c8a22adb11713b26ac0e7893fd28ccbb9577a092bbae50fa9eec960c72497ca5d902892209ce7c83d9c2b291fc017e0d5ab
7
- data.tar.gz: 509c56167e4998c662bf21efa637de8495cc5d2974421041d8264f66de16f99a2c223463cfd494b35f64bffb39b8511696822405e2609b649ff876f685ffd4cc
6
+ metadata.gz: 454c6302e62cbc669c8d800bab1305b2e83402f46ed2499a4caf373cfaa23547cbaf261163fc28cd2fe224a31c7f5bb927a5baf09deb04c856de49c481b5fc75
7
+ data.tar.gz: b32e53db604284721d96afd9b1fa7ac204277dda4cc27f4851ac1918760980fa64c17392917ca770a712541f5ab132bedaa2f0f102ac6c20fa50354d16e18ad1
data/lib/where_exists.rb CHANGED
@@ -20,7 +20,11 @@ module WhereExists
20
20
  not_string = "NOT "
21
21
  end
22
22
 
23
- self.where("#{not_string}(#{queries_sql})")
23
+ if queries_sql.empty?
24
+ does_exist ? self.none : self.all
25
+ else
26
+ self.where("#{not_string}(#{queries_sql})")
27
+ end
24
28
  end
25
29
 
26
30
  def build_exists_string(association_name, *where_parameters, &block)
@@ -1,3 +1,3 @@
1
1
  module WhereExists
2
- VERSION = "1.2.2"
2
+ VERSION = "1.2.3"
3
3
  end
@@ -61,6 +61,18 @@ class BelongsToPolymorphicTest < Minitest::Test
61
61
  assert_equal orphaned_child.id, result.first.id
62
62
  end
63
63
 
64
+ def test_no_entities_or_empty_child_relation
65
+ result = BelongsToPolymorphicChild.where_not_exists(:polymorphic_entity)
66
+ assert_equal 0, result.length
67
+
68
+ _first_child = BelongsToPolymorphicChild.create!
69
+ result = BelongsToPolymorphicChild.where_not_exists(:polymorphic_entity)
70
+ assert_equal 1, result.length
71
+
72
+ result = BelongsToPolymorphicChild.where_exists(:polymorphic_entity)
73
+ assert_equal 0, result.length
74
+ end
75
+
64
76
  def test_table_name_based_lookup
65
77
  first_entity = FirstPolymorphicEntity.create!
66
78
  second_entity = SecondPolymorphicEntity.create! id: first_entity.id + 1
data/test/db/test.db CHANGED
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: where_exists
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eugene Zolotarev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-13 00:00:00.000000000 Z
11
+ date: 2021-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -126,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
126
  - !ruby/object:Gem::Version
127
127
  version: '0'
128
128
  requirements: []
129
- rubygems_version: 3.0.6
129
+ rubygems_version: 3.1.2
130
130
  signing_key:
131
131
  specification_version: 4
132
132
  summary: "#where_exists extension of ActiveRecord"