where_exists 0.1 → 0.9
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/db/test.db +0 -0
- data/test/documentation_test.rb +70 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c0011ebbfa83fbd7bec538f131b3cbd1840a461
|
4
|
+
data.tar.gz: be15ecc2aa3b857edeb0c7f577b3d2a23b73cb3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f287f7afb2c78828f04306abd07f2329af3184f3e618cf701e385aa2ae42ba1aa42a4223201b874d89fba1cf1180b968e3e82f24c80fd3bef6fd121024cfa330
|
7
|
+
data.tar.gz: c1d91193439fd382019cd7952698b3db625ef8ac1c96b836d7ab7382f417eb53951713882b958f496383f488b807069a1d1e9f81a017cd24165d4ede5b9a9716
|
data/lib/where_exists/version.rb
CHANGED
data/test/db/test.db
CHANGED
Binary file
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
ActiveRecord::Migration.create_table :users, :force => true do |t|
|
4
|
+
t.string :name
|
5
|
+
end
|
6
|
+
|
7
|
+
ActiveRecord::Migration.create_table :groups, :force => true do |t|
|
8
|
+
t.string :name
|
9
|
+
end
|
10
|
+
|
11
|
+
ActiveRecord::Migration.create_table :connections, :force => true do |t|
|
12
|
+
t.integer :user_id
|
13
|
+
t.integer :group_id
|
14
|
+
t.string :name
|
15
|
+
end
|
16
|
+
|
17
|
+
class User < ActiveRecord::Base
|
18
|
+
has_many :connections
|
19
|
+
has_many :groups, through: :connections
|
20
|
+
end
|
21
|
+
|
22
|
+
class Group < ActiveRecord::Base
|
23
|
+
has_many :connections
|
24
|
+
has_many :users, through: :connections
|
25
|
+
end
|
26
|
+
|
27
|
+
class Connection < ActiveRecord::Base
|
28
|
+
belongs_to :user
|
29
|
+
belongs_to :group
|
30
|
+
end
|
31
|
+
|
32
|
+
class DocumentationTest < Minitest::Unit::TestCase
|
33
|
+
def setup
|
34
|
+
ActiveRecord::Base.descendants.each(&:delete_all)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_readme
|
38
|
+
group1 = Group.create!(name: 'first')
|
39
|
+
group2 = Group.create!(name: 'second')
|
40
|
+
group3 = Group.create!(name: 'third')
|
41
|
+
|
42
|
+
group4 = Group.create!(name: 'fourth')
|
43
|
+
group5 = Group.create!(name: 'fifth')
|
44
|
+
group6 = Group.create!(name: 'sixth')
|
45
|
+
|
46
|
+
user1 = User.create!
|
47
|
+
Connection.create!(user: user1, group: group1)
|
48
|
+
|
49
|
+
user2 = User.create!
|
50
|
+
Connection.create!(user: user2, group: group2)
|
51
|
+
Connection.create!(user: user2, group: group6)
|
52
|
+
|
53
|
+
user3 = User.create!
|
54
|
+
Connection.create!(user: user3, group: group5)
|
55
|
+
|
56
|
+
user4 = User.create!
|
57
|
+
|
58
|
+
result = User.where_exists(:groups, id: [1,2,3])
|
59
|
+
assert_equal 2, result.length
|
60
|
+
assert_equal [user1, user2].map(&:id).sort, result.map(&:id).sort
|
61
|
+
|
62
|
+
result = User.where_exists(:groups, id: [1,2,3]).where_not_exists(:groups, name: %w(fourth fifth sixth))
|
63
|
+
assert_equal 1, result.length
|
64
|
+
assert_equal user1.id, result.first.id
|
65
|
+
|
66
|
+
result = User.where_not_exists(:groups)
|
67
|
+
assert_equal 1, result.length
|
68
|
+
assert_equal user4.id, result.first.id
|
69
|
+
end
|
70
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: where_exists
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.9'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eugene Zolotarev
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- test/belongs_to_polymorphic_test.rb
|
59
59
|
- test/belongs_to_test.rb
|
60
60
|
- test/db/test.db
|
61
|
+
- test/documentation_test.rb
|
61
62
|
- test/has_many_polymorphic_test.rb
|
62
63
|
- test/has_many_test.rb
|
63
64
|
- test/has_many_through_test.rb
|
@@ -90,6 +91,7 @@ test_files:
|
|
90
91
|
- test/belongs_to_polymorphic_test.rb
|
91
92
|
- test/belongs_to_test.rb
|
92
93
|
- test/db/test.db
|
94
|
+
- test/documentation_test.rb
|
93
95
|
- test/has_many_polymorphic_test.rb
|
94
96
|
- test/has_many_test.rb
|
95
97
|
- test/has_many_through_test.rb
|