where_exists 1.2.2 → 2.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: 28bde73cd6a1857a0762a1fd489258ad40b44cea344afba4357cbe7fa83cdf41
4
- data.tar.gz: ed7a98cb6a7391cb955c911f0063f9eb901e86305b0b7ddb3e01b9a209371476
3
+ metadata.gz: 70bb8d0cc4affb99051fe748c883841abd8635f78faab07572208dd495ae9e0e
4
+ data.tar.gz: 56be70dc7847f0beddf4a19284485e8e50c38709e2b0db4f64a0250c967b0a33
5
5
  SHA512:
6
- metadata.gz: 943e345289ac9f2a2d44a5428a559c8a22adb11713b26ac0e7893fd28ccbb9577a092bbae50fa9eec960c72497ca5d902892209ce7c83d9c2b291fc017e0d5ab
7
- data.tar.gz: 509c56167e4998c662bf21efa637de8495cc5d2974421041d8264f66de16f99a2c223463cfd494b35f64bffb39b8511696822405e2609b649ff876f685ffd4cc
6
+ metadata.gz: e86824a1c85aa3a4006bc20035444fe36d1895c7cb17fd3019e5da5431753ba45fd735bbd41ae903f807bc7e45e36d415c887390d2fab8805d44e8afdcd37f2c
7
+ data.tar.gz: 5a4814a20b678da5ee28b9cdbccd99ef653f4ea6284fd42f5203d0074301d35b3627524e00e89623000595fdb7f9c110873224f163edc2b0a112ae0deeba18b9
data/README.markdown CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  ## Description
6
6
 
7
- <img src="http://i.imgur.com/psLfPoW.gif" alt="Exists" align="right" width="100" height="200">
7
+ <img src="exists.png" alt="Exists" align="right" width="100" height="200">
8
8
 
9
9
  This gem does exactly two things:
10
10
 
@@ -29,7 +29,7 @@ Syntax:
29
29
  Model.where_exists(association, additional_finder_parameters)
30
30
  ```
31
31
 
32
- Supported Rails versions: >= 4.2.
32
+ Supported Rails versions: >= 5.2.
33
33
 
34
34
  ## Example of usage
35
35
 
@@ -155,7 +155,13 @@ Also,
155
155
  * Submit pull request with new features or bug fixes
156
156
  * Enhance or clarify the documentation that you are reading
157
157
 
158
- To run tests: `bundle exec rake test`
158
+ **Please ping me in addition to creating PR/issue** (just add "@EugZol" to the PR/issue text). Thank you!
159
+
160
+ To run tests:
161
+ ```
162
+ > bundle exec appraisal install
163
+ > bundle exec appraisal rake test
164
+ ```
159
165
 
160
166
  ## License
161
167
 
@@ -1,3 +1,3 @@
1
1
  module WhereExists
2
- VERSION = "1.2.2"
2
+ VERSION = "2.0.1"
3
3
  end
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)
@@ -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,35 +1,35 @@
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: 2.0.1
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: 2022-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.2'
19
+ version: '5.2'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '6.2'
22
+ version: '7.1'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '4.2'
29
+ version: '5.2'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '6.2'
32
+ version: '7.1'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: sqlite3
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -86,6 +86,20 @@ dependencies:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
88
  version: '6.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: appraisal
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
89
103
  description: Rails way to harness the power of SQL "EXISTS" statement
90
104
  email:
91
105
  - eugzol@gmail.com
@@ -126,17 +140,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
140
  - !ruby/object:Gem::Version
127
141
  version: '0'
128
142
  requirements: []
129
- rubygems_version: 3.0.6
143
+ rubygems_version: 3.1.6
130
144
  signing_key:
131
145
  specification_version: 4
132
146
  summary: "#where_exists extension of ActiveRecord"
133
147
  test_files:
134
- - test/has_and_belongs_to_many.rb
148
+ - test/documentation_test.rb
135
149
  - test/belongs_to_polymorphic_test.rb
136
- - test/has_many_through_test.rb
150
+ - test/belongs_to_test.rb
151
+ - test/has_many_polymorphic_test.rb
137
152
  - test/db/test.db
153
+ - test/has_many_through_test.rb
138
154
  - test/test_helper.rb
139
- - test/has_many_polymorphic_test.rb
155
+ - test/has_and_belongs_to_many.rb
140
156
  - test/has_many_test.rb
141
- - test/documentation_test.rb
142
- - test/belongs_to_test.rb