where_exists 0.9.2 → 1.0.0
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 +4 -4
- data/lib/where_exists/version.rb +1 -1
- data/test/belongs_to_polymorphic_test.rb +14 -14
- data/test/belongs_to_test.rb +16 -16
- data/test/db/test.db +0 -0
- data/test/documentation_test.rb +4 -4
- data/test/has_many_polymorphic_test.rb +11 -11
- data/test/has_many_test.rb +5 -5
- data/test/has_many_through_test.rb +6 -6
- metadata +24 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7c13e66fd0af529abc8be142a7f93a19bd711f3
|
4
|
+
data.tar.gz: ade84d5322c10bbac3e23d09eb8db75bfacb4c45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 742c790c391f2ca6ce2104c912bc3ec957f20cc60d58c7342e3075e166012ec7c88de7336d10180e4c9bd67d84e7115a828c05d419c8a2c5cc8a06bc88a34192
|
7
|
+
data.tar.gz: 919c4d93e016f39c49cadf80d123e3301305c186cec36cc0e6f38cf95cbe6f9e03233960a093b5d61c4b579ef8973f9e0351632eb1dcd6806522defd40e3e61d
|
data/lib/where_exists/version.rb
CHANGED
@@ -8,25 +8,25 @@ ActiveRecord::Migration.create_table :second_polymorphic_entities, :force => tru
|
|
8
8
|
t.string :name
|
9
9
|
end
|
10
10
|
|
11
|
-
ActiveRecord::Migration.create_table :
|
11
|
+
ActiveRecord::Migration.create_table :belongs_to_polymorphic_children, :force => true do |t|
|
12
12
|
t.integer :polymorphic_entity_id
|
13
13
|
t.string :polymorphic_entity_type
|
14
14
|
t.string :name
|
15
15
|
end
|
16
16
|
|
17
|
-
class
|
17
|
+
class BelongsToPolymorphicChild < ActiveRecord::Base
|
18
18
|
belongs_to :polymorphic_entity, polymorphic: true
|
19
19
|
end
|
20
20
|
|
21
21
|
class FirstPolymorphicEntity < ActiveRecord::Base
|
22
|
-
has_many :children, as: :polymorphic_entity, class_name:
|
22
|
+
has_many :children, as: :polymorphic_entity, class_name: BelongsToPolymorphicChild
|
23
23
|
end
|
24
24
|
|
25
25
|
class SecondPolymorphicEntity < ActiveRecord::Base
|
26
|
-
has_many :children, as: :polymorphic_entity, class_name:
|
26
|
+
has_many :children, as: :polymorphic_entity, class_name: BelongsToPolymorphicChild
|
27
27
|
end
|
28
28
|
|
29
|
-
class BelongsToPolymorphicTest < Minitest::
|
29
|
+
class BelongsToPolymorphicTest < Minitest::Test
|
30
30
|
def setup
|
31
31
|
ActiveRecord::Base.descendants.each(&:delete_all)
|
32
32
|
end
|
@@ -36,12 +36,12 @@ class BelongsToPolymorphicTest < Minitest::Unit::TestCase
|
|
36
36
|
second_entity = SecondPolymorphicEntity.create!
|
37
37
|
second_entity.update_column(:id, first_entity.id + 1)
|
38
38
|
|
39
|
-
first_child =
|
40
|
-
second_child =
|
41
|
-
|
42
|
-
|
39
|
+
first_child = BelongsToPolymorphicChild.create!(polymorphic_entity: first_entity)
|
40
|
+
second_child = BelongsToPolymorphicChild.create!(polymorphic_entity: second_entity)
|
41
|
+
_really_orphaned_child = BelongsToPolymorphicChild.create!(polymorphic_entity_type: 'FirstPolymorphicEntity', polymorphic_entity_id: second_entity.id)
|
42
|
+
_another_really_orphaned_child = BelongsToPolymorphicChild.create!(polymorphic_entity_type: 'SecondPolymorphicEntity', polymorphic_entity_id: first_entity.id)
|
43
43
|
|
44
|
-
result =
|
44
|
+
result = BelongsToPolymorphicChild.where_exists(:polymorphic_entity)
|
45
45
|
|
46
46
|
assert_equal 2, result.length
|
47
47
|
assert_equal [first_child, second_child].map(&:id).sort, result.map(&:id).sort
|
@@ -52,12 +52,12 @@ class BelongsToPolymorphicTest < Minitest::Unit::TestCase
|
|
52
52
|
second_entity = SecondPolymorphicEntity.create!
|
53
53
|
second_entity.update_column(:id, first_entity.id + 1)
|
54
54
|
|
55
|
-
|
56
|
-
orphaned_child =
|
55
|
+
_first_child = BelongsToPolymorphicChild.create!(polymorphic_entity: first_entity)
|
56
|
+
orphaned_child = BelongsToPolymorphicChild.create!(polymorphic_entity_id: second_entity.id, polymorphic_entity_type: 'FirstPolymorphicEntity')
|
57
57
|
|
58
|
-
result =
|
58
|
+
result = BelongsToPolymorphicChild.where_not_exists(:polymorphic_entity)
|
59
59
|
|
60
60
|
assert_equal 1, result.length
|
61
61
|
assert_equal orphaned_child.id, result.first.id
|
62
62
|
end
|
63
|
-
end
|
63
|
+
end
|
data/test/belongs_to_test.rb
CHANGED
@@ -1,49 +1,49 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
ActiveRecord::Migration.create_table :
|
3
|
+
ActiveRecord::Migration.create_table :belongs_to_simple_entities, :force => true do |t|
|
4
4
|
t.string :name
|
5
5
|
t.integer :my_id
|
6
6
|
end
|
7
7
|
|
8
|
-
ActiveRecord::Migration.create_table :
|
8
|
+
ActiveRecord::Migration.create_table :belongs_to_simple_entity_children, :force => true do |t|
|
9
9
|
t.integer :parent_id
|
10
10
|
t.string :name
|
11
11
|
end
|
12
12
|
|
13
|
-
class
|
14
|
-
has_many :simple_entity_children, primary_key: :my_id, foreign_key: :parent_id
|
13
|
+
class BelongsToSimpleEntity < ActiveRecord::Base
|
14
|
+
has_many :simple_entity_children, primary_key: :my_id, foreign_key: :parent_id, class_name: "BelongsToSimpleEntityChild"
|
15
15
|
end
|
16
16
|
|
17
|
-
class
|
18
|
-
belongs_to :simple_entity, foreign_key: :parent_id, primary_key: :my_id
|
17
|
+
class BelongsToSimpleEntityChild < ActiveRecord::Base
|
18
|
+
belongs_to :simple_entity, foreign_key: :parent_id, primary_key: :my_id, class_name: "BelongsToSimpleEntity"
|
19
19
|
end
|
20
20
|
|
21
|
-
class BelongsToTest < Minitest::
|
21
|
+
class BelongsToTest < Minitest::Test
|
22
22
|
def setup
|
23
23
|
ActiveRecord::Base.descendants.each(&:delete_all)
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_nil_foreign_key
|
27
|
-
|
27
|
+
_entity = BelongsToSimpleEntity.create!(my_id: 999)
|
28
28
|
|
29
|
-
child =
|
30
|
-
|
29
|
+
child = BelongsToSimpleEntityChild.create!(parent_id: 999)
|
30
|
+
_orphaned_child = BelongsToSimpleEntityChild.create!(parent_id: nil)
|
31
31
|
|
32
|
-
result =
|
32
|
+
result = BelongsToSimpleEntityChild.where_exists(:simple_entity)
|
33
33
|
|
34
34
|
assert_equal 1, result.length
|
35
35
|
assert_equal result.first.id, child.id
|
36
36
|
end
|
37
37
|
|
38
38
|
def test_not_existing_foreign_object
|
39
|
-
|
39
|
+
_entity = BelongsToSimpleEntity.create!(my_id: 999)
|
40
40
|
|
41
|
-
child =
|
42
|
-
|
41
|
+
child = BelongsToSimpleEntityChild.create!(parent_id: 999)
|
42
|
+
_orphaned_child = BelongsToSimpleEntityChild.create!(parent_id: 500)
|
43
43
|
|
44
|
-
result =
|
44
|
+
result = BelongsToSimpleEntityChild.where_exists(:simple_entity)
|
45
45
|
|
46
46
|
assert_equal 1, result.length
|
47
47
|
assert_equal result.first.id, child.id
|
48
48
|
end
|
49
|
-
end
|
49
|
+
end
|
data/test/db/test.db
CHANGED
Binary file
|
data/test/documentation_test.rb
CHANGED
@@ -29,7 +29,7 @@ class Connection < ActiveRecord::Base
|
|
29
29
|
belongs_to :group
|
30
30
|
end
|
31
31
|
|
32
|
-
class DocumentationTest < Minitest::
|
32
|
+
class DocumentationTest < Minitest::Test
|
33
33
|
def setup
|
34
34
|
ActiveRecord::Base.descendants.each(&:delete_all)
|
35
35
|
end
|
@@ -37,9 +37,9 @@ class DocumentationTest < Minitest::Unit::TestCase
|
|
37
37
|
def test_readme
|
38
38
|
group1 = Group.create!(name: 'first')
|
39
39
|
group2 = Group.create!(name: 'second')
|
40
|
-
|
40
|
+
_group3 = Group.create!(name: 'third')
|
41
41
|
|
42
|
-
|
42
|
+
_group4 = Group.create!(name: 'fourth')
|
43
43
|
group5 = Group.create!(name: 'fifth')
|
44
44
|
group6 = Group.create!(name: 'sixth')
|
45
45
|
|
@@ -67,4 +67,4 @@ class DocumentationTest < Minitest::Unit::TestCase
|
|
67
67
|
assert_equal 1, result.length
|
68
68
|
assert_equal user4.id, result.first.id
|
69
69
|
end
|
70
|
-
end
|
70
|
+
end
|
@@ -8,37 +8,37 @@ ActiveRecord::Migration.create_table :irrelevant_polymorphic_entities, :force =>
|
|
8
8
|
t.string :name
|
9
9
|
end
|
10
10
|
|
11
|
-
ActiveRecord::Migration.create_table :
|
12
|
-
t.integer :
|
13
|
-
t.string :
|
11
|
+
ActiveRecord::Migration.create_table :has_many_polymorphic_children, :force => true do |t|
|
12
|
+
t.integer :polymorphic_thing_id
|
13
|
+
t.string :polymorphic_thing_type
|
14
14
|
t.string :name
|
15
15
|
end
|
16
16
|
|
17
|
-
class
|
18
|
-
belongs_to :
|
17
|
+
class HasManyPolymorphicChild < ActiveRecord::Base
|
18
|
+
belongs_to :polymorphic_thing, polymorphic: true
|
19
19
|
end
|
20
20
|
|
21
21
|
class RelevantPolymorphicEntity < ActiveRecord::Base
|
22
|
-
has_many :children, as: :
|
22
|
+
has_many :children, as: :polymorphic_thing, class_name: HasManyPolymorphicChild
|
23
23
|
end
|
24
24
|
|
25
25
|
class IrrelevantPolymorphicEntity < ActiveRecord::Base
|
26
|
-
has_many :children, as: :
|
26
|
+
has_many :children, as: :polymorphic_thing, class_name: HasManyPolymorphicChild
|
27
27
|
end
|
28
28
|
|
29
|
-
class HasManyPolymorphicTest < Minitest::
|
29
|
+
class HasManyPolymorphicTest < Minitest::Test
|
30
30
|
def setup
|
31
31
|
ActiveRecord::Base.descendants.each(&:delete_all)
|
32
32
|
end
|
33
33
|
|
34
34
|
def test_polymorphic
|
35
|
-
child =
|
35
|
+
child = HasManyPolymorphicChild.create!
|
36
36
|
|
37
37
|
irrelevant_entity = IrrelevantPolymorphicEntity.create!(children: [child])
|
38
|
-
|
38
|
+
_relevant_entity = RelevantPolymorphicEntity.create!(id: irrelevant_entity.id)
|
39
39
|
|
40
40
|
result = RelevantPolymorphicEntity.where_exists(:children)
|
41
41
|
|
42
42
|
assert_equal 0, result.length
|
43
43
|
end
|
44
|
-
end
|
44
|
+
end
|
data/test/has_many_test.rb
CHANGED
@@ -18,7 +18,7 @@ class SimpleEntityChild < ActiveRecord::Base
|
|
18
18
|
belongs_to :simple_entity, foreign_key: :parent_id
|
19
19
|
end
|
20
20
|
|
21
|
-
class HasManyTest < Minitest::
|
21
|
+
class HasManyTest < Minitest::Test
|
22
22
|
def setup
|
23
23
|
ActiveRecord::Base.descendants.each(&:delete_all)
|
24
24
|
end
|
@@ -26,7 +26,7 @@ class HasManyTest < Minitest::Unit::TestCase
|
|
26
26
|
def test_without_parameters
|
27
27
|
child = SimpleEntityChild.create!
|
28
28
|
|
29
|
-
|
29
|
+
_blank_entity = SimpleEntity.create!(my_id: 999)
|
30
30
|
filled_entity = SimpleEntity.create!(simple_entity_children: [child], my_id: 500)
|
31
31
|
|
32
32
|
result = SimpleEntity.where_exists(:simple_entity_children)
|
@@ -39,8 +39,8 @@ class HasManyTest < Minitest::Unit::TestCase
|
|
39
39
|
wrong_child = SimpleEntityChild.create!(name: 'wrong')
|
40
40
|
child = SimpleEntityChild.create!(name: 'right')
|
41
41
|
|
42
|
-
|
43
|
-
|
42
|
+
_blank_entity = SimpleEntity.create!(my_id: 999)
|
43
|
+
_wrong_entity = SimpleEntity.create!(simple_entity_children: [wrong_child], my_id: 500)
|
44
44
|
entity = SimpleEntity.create!(name: 'this field is irrelevant', simple_entity_children: [child], my_id: 300)
|
45
45
|
|
46
46
|
result = SimpleEntity.where_exists(:simple_entity_children, name: 'right')
|
@@ -63,7 +63,7 @@ class HasManyTest < Minitest::Unit::TestCase
|
|
63
63
|
child = SimpleEntityChild.create!
|
64
64
|
|
65
65
|
blank_entity = SimpleEntity.create!(my_id: 999)
|
66
|
-
|
66
|
+
_filled_entity = SimpleEntity.create!(simple_entity_children: [child], my_id: 500)
|
67
67
|
|
68
68
|
result = SimpleEntity.where_not_exists(:simple_entity_children)
|
69
69
|
|
@@ -44,7 +44,7 @@ end
|
|
44
44
|
|
45
45
|
# Invoices -> LineItems <- Tasks <- Project
|
46
46
|
|
47
|
-
class HasManyThroughTest < Minitest::
|
47
|
+
class HasManyThroughTest < Minitest::Test
|
48
48
|
def setup
|
49
49
|
ActiveRecord::Base.descendants.each(&:delete_all)
|
50
50
|
end
|
@@ -56,8 +56,8 @@ class HasManyThroughTest < Minitest::Unit::TestCase
|
|
56
56
|
task = Task.create!(project: project)
|
57
57
|
irrelevant_task = Task.create!(project: irrelevant_project)
|
58
58
|
|
59
|
-
|
60
|
-
|
59
|
+
_line_item = LineItem.create!(name: 'relevant', task: task)
|
60
|
+
_irrelevant_line_item = LineItem.create!(name: 'irrelevant', task: irrelevant_task)
|
61
61
|
|
62
62
|
result = Project.where_exists(:project_line_items, name: 'relevant')
|
63
63
|
|
@@ -79,8 +79,8 @@ class HasManyThroughTest < Minitest::Unit::TestCase
|
|
79
79
|
invoice = Invoice.create!(name: 'relevant')
|
80
80
|
irrelevant_invoice = Invoice.create!(name: 'irrelevant')
|
81
81
|
|
82
|
-
|
83
|
-
|
82
|
+
_line_item = LineItem.create!(task: task, invoice: invoice)
|
83
|
+
_irrelevant_line_item = LineItem.create!(task: irrelevant_task, invoice: irrelevant_invoice)
|
84
84
|
|
85
85
|
result = Project.where_exists(:invoices, name: 'relevant')
|
86
86
|
|
@@ -92,4 +92,4 @@ class HasManyThroughTest < Minitest::Unit::TestCase
|
|
92
92
|
assert_equal 1, result.length
|
93
93
|
assert_equal irrelevant_project.id, result.first.id
|
94
94
|
end
|
95
|
-
end
|
95
|
+
end
|
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: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eugene Zolotarev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 3.2.22
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '6'
|
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
29
|
version: 3.2.22
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '6'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: sqlite3
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,6 +44,20 @@ dependencies:
|
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '1.3'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: minitest
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
47
61
|
description: Rails way to harness the power of SQL "EXISTS" statement
|
48
62
|
email:
|
49
63
|
- eugzol@gmail.com
|
@@ -83,16 +97,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
97
|
version: '0'
|
84
98
|
requirements: []
|
85
99
|
rubyforge_project:
|
86
|
-
rubygems_version: 2.
|
100
|
+
rubygems_version: 2.5.1
|
87
101
|
signing_key:
|
88
102
|
specification_version: 4
|
89
103
|
summary: "#where_exists extension of ActiveRecord"
|
90
104
|
test_files:
|
91
|
-
- test/belongs_to_polymorphic_test.rb
|
92
|
-
- test/belongs_to_test.rb
|
93
105
|
- test/db/test.db
|
106
|
+
- test/belongs_to_test.rb
|
94
107
|
- test/documentation_test.rb
|
108
|
+
- test/test_helper.rb
|
95
109
|
- test/has_many_polymorphic_test.rb
|
110
|
+
- test/belongs_to_polymorphic_test.rb
|
96
111
|
- test/has_many_test.rb
|
97
112
|
- test/has_many_through_test.rb
|
98
|
-
- test/test_helper.rb
|