active_record_extended 1.1.0 → 1.2.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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -18
  3. data/lib/active_record_extended.rb +2 -1
  4. data/lib/active_record_extended/active_record.rb +2 -0
  5. data/lib/active_record_extended/active_record/relation_patch.rb +1 -1
  6. data/lib/active_record_extended/arel.rb +1 -0
  7. data/lib/active_record_extended/arel/aggregate_function_name.rb +40 -0
  8. data/lib/active_record_extended/arel/nodes.rb +31 -41
  9. data/lib/active_record_extended/arel/predications.rb +4 -1
  10. data/lib/active_record_extended/arel/visitors/postgresql_decorator.rb +40 -1
  11. data/lib/active_record_extended/patch/5_0/predicate_builder_decorator.rb +4 -4
  12. data/lib/active_record_extended/patch/5_0/regex_match.rb +10 -0
  13. data/lib/active_record_extended/query_methods/any_of.rb +5 -4
  14. data/lib/active_record_extended/query_methods/inet.rb +1 -1
  15. data/lib/active_record_extended/query_methods/json.rb +152 -43
  16. data/lib/active_record_extended/query_methods/select.rb +117 -0
  17. data/lib/active_record_extended/query_methods/unionize.rb +4 -39
  18. data/lib/active_record_extended/query_methods/with_cte.rb +3 -3
  19. data/lib/active_record_extended/utilities/order_by.rb +96 -0
  20. data/lib/active_record_extended/utilities/support.rb +175 -0
  21. data/lib/active_record_extended/version.rb +1 -1
  22. data/spec/query_methods/any_of_spec.rb +40 -40
  23. data/spec/query_methods/array_query_spec.rb +14 -14
  24. data/spec/query_methods/either_spec.rb +14 -14
  25. data/spec/query_methods/hash_query_spec.rb +11 -11
  26. data/spec/query_methods/inet_query_spec.rb +33 -31
  27. data/spec/query_methods/json_spec.rb +40 -25
  28. data/spec/query_methods/select_spec.rb +115 -0
  29. data/spec/query_methods/unionize_spec.rb +54 -54
  30. data/spec/query_methods/with_cte_spec.rb +12 -12
  31. data/spec/sql_inspections/any_of_sql_spec.rb +11 -11
  32. data/spec/sql_inspections/arel/aggregate_function_name_spec.rb +41 -0
  33. data/spec/sql_inspections/arel/array_spec.rb +7 -7
  34. data/spec/sql_inspections/arel/inet_spec.rb +7 -7
  35. data/spec/sql_inspections/contains_sql_queries_spec.rb +14 -14
  36. data/spec/sql_inspections/either_sql_spec.rb +11 -11
  37. data/spec/sql_inspections/json_sql_spec.rb +38 -8
  38. data/spec/sql_inspections/unionize_sql_spec.rb +27 -27
  39. data/spec/sql_inspections/with_cte_sql_spec.rb +22 -22
  40. data/spec/support/models.rb +18 -4
  41. metadata +11 -3
  42. data/lib/active_record_extended/utilities.rb +0 -141
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecordExtended
4
- VERSION = "1.1.0"
4
+ VERSION = "1.2.0"
5
5
  end
@@ -3,65 +3,65 @@
3
3
  require "spec_helper"
4
4
 
5
5
  RSpec.describe "Active Record Any / None of Methods" do
6
- let!(:one) { Person.create!(personal_id: 1) }
7
- let!(:two) { Person.create!(personal_id: 2) }
8
- let!(:three) { Person.create!(personal_id: 3) }
6
+ let!(:one) { User.create!(personal_id: 1) }
7
+ let!(:two) { User.create!(personal_id: 2) }
8
+ let!(:three) { User.create!(personal_id: 3) }
9
9
 
10
- let!(:tag_one) { Tag.create!(person_id: one.id) }
11
- let!(:tag_two) { Tag.create!(person_id: two.id) }
12
- let!(:tag_three) { Tag.create!(person_id: three.id) }
10
+ let!(:tag_one) { Tag.create!(user_id: one.id) }
11
+ let!(:tag_two) { Tag.create!(user_id: two.id) }
12
+ let!(:tag_three) { Tag.create!(user_id: three.id) }
13
13
 
14
14
  describe "where.any_of/1" do
15
15
  it "Should return queries that match any of the outlined queries" do
16
- query = Person.where.any_of({ personal_id: 1 }, { personal_id: 2 })
16
+ query = User.where.any_of({ personal_id: 1 }, { personal_id: 2 })
17
17
  expect(query).to include(one, two)
18
18
  expect(query).to_not include(three)
19
19
  end
20
20
 
21
21
  it "Should accept where query predicates" do
22
- personal_one = Person.where(personal_id: 1)
23
- personal_two = Person.where(personal_id: 2)
24
- query = Person.where.any_of(personal_one, personal_two)
22
+ personal_one = User.where(personal_id: 1)
23
+ personal_two = User.where(personal_id: 2)
24
+ query = User.where.any_of(personal_one, personal_two)
25
25
 
26
26
  expect(query).to include(one, two)
27
27
  expect(query).to_not include(three)
28
28
  end
29
29
 
30
30
  it "Should accept query strings" do
31
- personal_one = Person.where(personal_id: 1)
31
+ personal_one = User.where(personal_id: 1)
32
32
 
33
- query = Person.where.any_of(personal_one, "personal_id > 2")
33
+ query = User.where.any_of(personal_one, "personal_id > 2")
34
34
  expect(query).to include(one, three)
35
35
  expect(query).to_not include(two)
36
36
 
37
- query = Person.where.any_of(["personal_id >= ?", 2])
37
+ query = User.where.any_of(["personal_id >= ?", 2])
38
38
  expect(query).to include(two, three)
39
39
  expect(query).to_not include(one)
40
40
  end
41
41
 
42
42
  context "Relationship queries" do
43
43
  it "Finds records that are queried from two or more has_many associations" do
44
- person_one_tag = Tag.create!(person_id: one.id)
45
- person_two_tag = Tag.create!(person_id: two.id)
46
- query = Tag.where.any_of(one.hm_tags, two.hm_tags)
44
+ user_one_tag = Tag.create!(user_id: one.id)
45
+ user_two_tag = Tag.create!(user_id: two.id)
46
+ query = Tag.where.any_of(one.hm_tags, two.hm_tags)
47
47
 
48
- expect(query).to include(tag_one, tag_two, person_one_tag, person_two_tag)
48
+ expect(query).to include(tag_one, tag_two, user_one_tag, user_two_tag)
49
49
  expect(query).to_not include(tag_three)
50
50
  end
51
51
 
52
52
  it "Finds records that are dynamically joined" do
53
- person_one_tag = Tag.where(people: { id: one.id }).includes(:person).references(:person)
54
- person_two_tag = Tag.where(people: { id: two.id }).joins(:person)
55
- query = Tag.where.any_of(person_one_tag, person_two_tag)
53
+ user_one_tag = Tag.where(users: { id: one.id }).includes(:user).references(:user)
54
+ user_two_tag = Tag.where(users: { id: two.id }).joins(:user)
55
+ query = Tag.where.any_of(user_one_tag, user_two_tag)
56
56
 
57
57
  expect(query).to include(tag_one, tag_two)
58
58
  expect(query).to_not include(tag_three)
59
59
  end
60
60
 
61
61
  it "Return matched records of a joined table on the parent level" do
62
- query = Tag.joins(:person).where.any_of(
63
- { people: { personal_id: 1 } },
64
- { people: { personal_id: 3 } },
62
+ query = Tag.joins(:user).where.any_of(
63
+ { users: { personal_id: 1 } },
64
+ { users: { personal_id: 3 } },
65
65
  )
66
66
 
67
67
  expect(query).to include(tag_one, tag_three)
@@ -72,55 +72,55 @@ RSpec.describe "Active Record Any / None of Methods" do
72
72
 
73
73
  describe "where.none_of/1" do
74
74
  it "Should return queries that match none of the outlined queries" do
75
- query = Person.where.none_of({ personal_id: 1 }, { personal_id: 2 })
75
+ query = User.where.none_of({ personal_id: 1 }, { personal_id: 2 })
76
76
  expect(query).to include(three)
77
77
  expect(query).to_not include(one, two)
78
78
  end
79
79
 
80
80
  it "Should accept where query predicates" do
81
- personal_one = Person.where(personal_id: 1)
82
- personal_two = Person.where(personal_id: 2)
83
- query = Person.where.none_of(personal_one, personal_two)
81
+ personal_one = User.where(personal_id: 1)
82
+ personal_two = User.where(personal_id: 2)
83
+ query = User.where.none_of(personal_one, personal_two)
84
84
 
85
85
  expect(query).to include(three)
86
86
  expect(query).to_not include(one, two)
87
87
  end
88
88
 
89
89
  it "Should accept query strings" do
90
- personal_one = Person.where(personal_id: 1)
90
+ personal_one = User.where(personal_id: 1)
91
91
 
92
- query = Person.where.none_of(personal_one, "personal_id > 2")
92
+ query = User.where.none_of(personal_one, "personal_id > 2")
93
93
  expect(query).to include(two)
94
94
  expect(query).to_not include(one, three)
95
95
 
96
- query = Person.where.none_of(["personal_id >= ?", 2])
96
+ query = User.where.none_of(["personal_id >= ?", 2])
97
97
  expect(query).to include(one)
98
98
  expect(query).to_not include(two, three)
99
99
  end
100
100
 
101
101
  context "Relationship queries" do
102
102
  it "Finds records that are queried from two or more has_many associations" do
103
- person_one_tag = Tag.create!(person_id: one.id)
104
- person_two_tag = Tag.create!(person_id: two.id)
105
- query = Tag.where.none_of(one.hm_tags, two.hm_tags)
103
+ user_one_tag = Tag.create!(user_id: one.id)
104
+ user_two_tag = Tag.create!(user_id: two.id)
105
+ query = Tag.where.none_of(one.hm_tags, two.hm_tags)
106
106
 
107
107
  expect(query).to include(tag_three)
108
- expect(query).to_not include(tag_one, tag_two, person_one_tag, person_two_tag)
108
+ expect(query).to_not include(tag_one, tag_two, user_one_tag, user_two_tag)
109
109
  end
110
110
 
111
111
  it "Finds records that are dynamically joined" do
112
- person_one_tag = Tag.where(people: { id: one.id }).includes(:person).references(:person)
113
- person_two_tag = Tag.where(people: { id: two.id }).joins(:person)
114
- query = Tag.where.none_of(person_one_tag, person_two_tag)
112
+ user_one_tag = Tag.where(users: { id: one.id }).includes(:user).references(:user)
113
+ user_two_tag = Tag.where(users: { id: two.id }).joins(:user)
114
+ query = Tag.where.none_of(user_one_tag, user_two_tag)
115
115
 
116
116
  expect(query).to include(tag_three)
117
117
  expect(query).to_not include(tag_one, tag_two)
118
118
  end
119
119
 
120
120
  it "Return matched records of a joined table on the parent level" do
121
- query = Tag.joins(:person).where.none_of(
122
- { people: { personal_id: 1 } },
123
- { people: { personal_id: 3 } },
121
+ query = Tag.joins(:user).where.none_of(
122
+ { users: { personal_id: 1 } },
123
+ { users: { personal_id: 3 } },
124
124
  )
125
125
 
126
126
  expect(query).to include(tag_two)
@@ -3,28 +3,28 @@
3
3
  require "spec_helper"
4
4
 
5
5
  RSpec.describe "Active Record Array Query Methods" do
6
- let!(:one) { Person.create!(tags: [1, 2, 3], personal_id: 33) }
7
- let!(:two) { Person.create!(tags: [3, 1, 5], personal_id: 88) }
8
- let!(:three) { Person.create!(tags: [2, 8, 20], personal_id: 33) }
6
+ let!(:one) { User.create!(tags: [1, 2, 3], personal_id: 33) }
7
+ let!(:two) { User.create!(tags: [3, 1, 5], personal_id: 88) }
8
+ let!(:three) { User.create!(tags: [2, 8, 20], personal_id: 33) }
9
9
 
10
10
  describe "#overlap" do
11
11
  it "Should return matched records" do
12
- query = Person.where.overlap(tags: [1])
12
+ query = User.where.overlap(tags: [1])
13
13
  expect(query).to include(one, two)
14
14
  expect(query).to_not include(three)
15
15
 
16
- query = Person.where.overlap(tags: [2, 3])
16
+ query = User.where.overlap(tags: [2, 3])
17
17
  expect(query).to include(one, two, three)
18
18
  end
19
19
  end
20
20
 
21
21
  describe "#contains" do
22
22
  it "returns records that contain elements in an array" do
23
- query = Person.where.contains(tags: [1, 3])
23
+ query = User.where.contains(tags: [1, 3])
24
24
  expect(query).to include(one, two)
25
25
  expect(query).to_not include(three)
26
26
 
27
- query = Person.where.contains(tags: [8, 2])
27
+ query = User.where.contains(tags: [8, 2])
28
28
  expect(query).to include(three)
29
29
  expect(query).to_not include(one, two)
30
30
  end
@@ -32,31 +32,31 @@ RSpec.describe "Active Record Array Query Methods" do
32
32
 
33
33
  describe "#any" do
34
34
  it "should return any records that match" do
35
- query = Person.where.any(tags: 3)
35
+ query = User.where.any(tags: 3)
36
36
  expect(query).to include(one, two)
37
37
  expect(query).to_not include(three)
38
38
  end
39
39
 
40
40
  it "allows chaining" do
41
- query = Person.where.any(tags: 3).where(personal_id: 33)
41
+ query = User.where.any(tags: 3).where(personal_id: 33)
42
42
  expect(query).to include(one)
43
43
  expect(query).to_not include(two, three)
44
44
  end
45
45
  end
46
46
 
47
47
  describe "#all" do
48
- let!(:contains_all) { Person.create!(tags: [1], personal_id: 1) }
49
- let!(:contains_all_two) { Person.create!(tags: [1], personal_id: 2) }
50
- let!(:contains_some) { Person.create!(tags: [1, 2], personal_id: 2) }
48
+ let!(:contains_all) { User.create!(tags: [1], personal_id: 1) }
49
+ let!(:contains_all_two) { User.create!(tags: [1], personal_id: 2) }
50
+ let!(:contains_some) { User.create!(tags: [1, 2], personal_id: 2) }
51
51
 
52
52
  it "should return any records that match" do
53
- query = Person.where.all(tags: 1)
53
+ query = User.where.all(tags: 1)
54
54
  expect(query).to include(contains_all, contains_all_two)
55
55
  expect(query).to_not include(contains_some)
56
56
  end
57
57
 
58
58
  it "allows chaining" do
59
- query = Person.where.all(tags: 1).where(personal_id: 1)
59
+ query = User.where.all(tags: 1).where(personal_id: 1)
60
60
  expect(query).to include(contains_all)
61
61
  expect(query).to_not include(contains_all_two, contains_some)
62
62
  end
@@ -3,22 +3,22 @@
3
3
  require "spec_helper"
4
4
 
5
5
  RSpec.describe "Active Record Either Methods" do
6
- let!(:one) { Person.create! }
7
- let!(:two) { Person.create! }
8
- let!(:three) { Person.create! }
9
- let!(:profile_l) { ProfileL.create!(person_id: one.id, likes: 100) }
10
- let!(:profile_r) { ProfileR.create!(person_id: two.id, dislikes: 50) }
6
+ let!(:one) { User.create! }
7
+ let!(:two) { User.create! }
8
+ let!(:three) { User.create! }
9
+ let!(:profile_l) { ProfileL.create!(user_id: one.id, likes: 100) }
10
+ let!(:profile_r) { ProfileR.create!(user_id: two.id, dislikes: 50) }
11
11
 
12
12
  describe ".either_join/2" do
13
13
  it "Should only only return records that belong to profile L or profile R" do
14
- query = Person.either_join(:profile_l, :profile_r)
14
+ query = User.either_join(:profile_l, :profile_r)
15
15
  expect(query).to include(one, two)
16
16
  expect(query).to_not include(three)
17
17
  end
18
18
 
19
19
  context "Alias .either_joins/2" do
20
20
  it "Should only only return records that belong to profile L or profile R" do
21
- query = Person.either_joins(:profile_l, :profile_r)
21
+ query = User.either_joins(:profile_l, :profile_r)
22
22
  expect(query).to include(one, two)
23
23
  expect(query).to_not include(three)
24
24
  end
@@ -27,29 +27,29 @@ RSpec.describe "Active Record Either Methods" do
27
27
 
28
28
  describe ".either_order/2" do
29
29
  it "Should not exclude anyone who does not have a relationship" do
30
- query = Person.either_order(:asc, profile_l: :likes, profile_r: :dislikes)
30
+ query = User.either_order(:asc, profile_l: :likes, profile_r: :dislikes)
31
31
  expect(query.count).to eq(3)
32
32
  expect(query[0]).to eq(two)
33
33
  expect(query[1]).to eq(one)
34
34
  expect(query[2]).to eq(three)
35
35
  end
36
36
 
37
- it "Should order people based on their likes and dislikes in ascended order" do
38
- query = Person.either_order(:asc, profile_l: :likes, profile_r: :dislikes).where(id: [one.id, two.id])
37
+ it "Should order users based on their likes and dislikes in ascended order" do
38
+ query = User.either_order(:asc, profile_l: :likes, profile_r: :dislikes).where(id: [one.id, two.id])
39
39
  expect(query.count).to eq(2)
40
40
  expect(query.first).to eq(two)
41
41
  expect(query.last).to eq(one)
42
42
  end
43
43
 
44
- it "Should order people based on their likes and dislikes in descending order" do
45
- query = Person.either_order(:desc, profile_l: :likes, profile_r: :dislikes).where(id: [one.id, two.id])
44
+ it "Should order users based on their likes and dislikes in descending order" do
45
+ query = User.either_order(:desc, profile_l: :likes, profile_r: :dislikes).where(id: [one.id, two.id])
46
46
  expect(query.first).to eq(one)
47
47
  expect(query.last).to eq(two)
48
48
  end
49
49
 
50
50
  context "Alias .either_order/2" do
51
- it "Should order people based on their likes and dislikes in ascended order" do
52
- query = Person.either_orders(:asc, profile_l: :likes, profile_r: :dislikes).where(id: [one.id, two.id])
51
+ it "Should order users based on their likes and dislikes in ascended order" do
52
+ query = User.either_orders(:asc, profile_l: :likes, profile_r: :dislikes).where(id: [one.id, two.id])
53
53
  expect(query.count).to eq(2)
54
54
  expect(query.first).to eq(two)
55
55
  expect(query.last).to eq(one)
@@ -3,23 +3,23 @@
3
3
  require "spec_helper"
4
4
 
5
5
  RSpec.describe "Active Record Hash Related Query Methods" do
6
- let!(:one) { Person.create!(data: { nickname: "george" }, jsonb_data: { payment: "zip" }) }
7
- let!(:two) { Person.create!(data: { nickname: "dan" }, jsonb_data: { payment: "zipper" }) }
8
- let!(:three) { Person.create!(data: { nickname: "georgey" }) }
6
+ let!(:one) { User.create!(data: { nickname: "george" }, jsonb_data: { payment: "zip" }) }
7
+ let!(:two) { User.create!(data: { nickname: "dan" }, jsonb_data: { payment: "zipper" }) }
8
+ let!(:three) { User.create!(data: { nickname: "georgey" }) }
9
9
 
10
10
  describe "#contains" do
11
11
  context "HStore Column Type" do
12
12
  it "returns records that contain hash elements in joined tables" do
13
- tag_one = Tag.create!(person_id: one.id)
14
- tag_two = Tag.create!(person_id: two.id)
13
+ tag_one = Tag.create!(user_id: one.id)
14
+ tag_two = Tag.create!(user_id: two.id)
15
15
 
16
- query = Tag.joins(:person).where.contains(people: { data: { nickname: "george" } })
16
+ query = Tag.joins(:user).where.contains(users: { data: { nickname: "george" } })
17
17
  expect(query).to include(tag_one)
18
18
  expect(query).to_not include(tag_two)
19
19
  end
20
20
 
21
21
  it "returns records that contain hash value" do
22
- query = Person.where.contains(data: { nickname: "george" })
22
+ query = User.where.contains(data: { nickname: "george" })
23
23
  expect(query).to include(one)
24
24
  expect(query).to_not include(two, three)
25
25
  end
@@ -27,16 +27,16 @@ RSpec.describe "Active Record Hash Related Query Methods" do
27
27
 
28
28
  context "JSONB Column Type" do
29
29
  it "returns records that contains a json hashed value" do
30
- query = Person.where.contains(jsonb_data: { payment: "zip" })
30
+ query = User.where.contains(jsonb_data: { payment: "zip" })
31
31
  expect(query).to include(one)
32
32
  expect(query).to_not include(two, three)
33
33
  end
34
34
 
35
35
  it "returns records that contain jsonb elements in joined tables" do
36
- tag_one = Tag.create!(person_id: one.id)
37
- tag_two = Tag.create!(person_id: two.id)
36
+ tag_one = Tag.create!(user_id: one.id)
37
+ tag_two = Tag.create!(user_id: two.id)
38
38
 
39
- query = Tag.joins(:person).where.contains(people: { jsonb_data: { payment: "zip" } })
39
+ query = Tag.joins(:user).where.contains(users: { jsonb_data: { payment: "zip" } })
40
40
  expect(query).to include(tag_one)
41
41
  expect(query).to_not include(tag_two)
42
42
  end
@@ -3,107 +3,109 @@
3
3
  require "spec_helper"
4
4
 
5
5
  RSpec.describe "Active Record Inet Query Methods" do
6
+ before { stub_const("User", Namespaced::Record) }
7
+
6
8
  describe "#inet_contained_within" do
7
- let!(:local_1) { Person.create!(ip: "127.0.0.1") }
8
- let!(:local_44) { Person.create!(ip: "127.0.0.44") }
9
- let!(:local_99_1) { Person.create!(ip: "127.0.99.1") }
10
- let!(:local_range) { Person.create!(ip: "127.0.0.1/10") }
9
+ let!(:local_1) { User.create!(ip: "127.0.0.1") }
10
+ let!(:local_44) { User.create!(ip: "127.0.0.44") }
11
+ let!(:local_99_1) { User.create!(ip: "127.0.99.1") }
12
+ let!(:local_range) { User.create!(ip: "127.0.0.1/10") }
11
13
 
12
- it "Should return people who have an IP within the 127.0.0.1/24 range" do
13
- query = Person.where.inet_contained_within(ip: "127.0.0.1/24")
14
+ it "Should return users who have an IP within the 127.0.0.1/24 range" do
15
+ query = User.where.inet_contained_within(ip: "127.0.0.1/24")
14
16
  expect(query).to include(local_1, local_44)
15
17
  expect(query).to_not include(local_99_1, local_range)
16
18
  end
17
19
 
18
20
  it "Should return all users who have an IP within the 127.0.0.1/16 range" do
19
- query = Person.where.inet_contained_within(ip: "127.0.0.1/16")
21
+ query = User.where.inet_contained_within(ip: "127.0.0.1/16")
20
22
  expect(query).to include(local_1, local_44, local_99_1)
21
23
  expect(query).to_not include(local_range)
22
24
  end
23
25
  end
24
26
 
25
27
  describe "inet_contained_within_or_equals" do
26
- let!(:local_1) { Person.create!(ip: "127.0.0.1/10") }
27
- let!(:local_44) { Person.create!(ip: "127.0.0.44/32") }
28
- let!(:local_99_1) { Person.create!(ip: "127.0.99.1") }
28
+ let!(:local_1) { User.create!(ip: "127.0.0.1/10") }
29
+ let!(:local_44) { User.create!(ip: "127.0.0.44/32") }
30
+ let!(:local_99_1) { User.create!(ip: "127.0.99.1") }
29
31
 
30
32
  it "Should find records that contain a matching submask" do
31
- query = Person.where.inet_contained_within_or_equals(ip: "127.0.0.44/32")
33
+ query = User.where.inet_contained_within_or_equals(ip: "127.0.0.44/32")
32
34
  expect(query).to include(local_44)
33
35
  expect(query).to_not include(local_1, local_99_1)
34
36
  end
35
37
 
36
38
  it "Should find records that are within range of a given submask" do
37
- query = Person.where.inet_contained_within_or_equals(ip: "127.0.0.1/16")
39
+ query = User.where.inet_contained_within_or_equals(ip: "127.0.0.1/16")
38
40
  expect(query).to include(local_44, local_99_1)
39
41
  expect(query).to_not include(local_1)
40
42
 
41
- query = Person.where.inet_contained_within_or_equals(ip: "127.0.0.1/8")
43
+ query = User.where.inet_contained_within_or_equals(ip: "127.0.0.1/8")
42
44
  expect(query).to include(local_1, local_44, local_99_1)
43
45
  end
44
46
  end
45
47
 
46
48
  describe "#inet_contains_or_equals" do
47
- let!(:local_1) { Person.create!(ip: "127.0.0.1/10") }
48
- let!(:local_44) { Person.create!(ip: "127.0.0.44/24") }
49
- let!(:local_99_1) { Person.create!(ip: "127.0.99.1") }
49
+ let!(:local_1) { User.create!(ip: "127.0.0.1/10") }
50
+ let!(:local_44) { User.create!(ip: "127.0.0.44/24") }
51
+ let!(:local_99_1) { User.create!(ip: "127.0.99.1") }
50
52
 
51
53
  it "Should find records with submask ranges that contain a given IP" do
52
- query = Person.where.inet_contains_or_equals(ip: "127.0.255.255")
54
+ query = User.where.inet_contains_or_equals(ip: "127.0.255.255")
53
55
  expect(query).to include(local_1)
54
56
  expect(query).to_not include(local_44, local_99_1)
55
57
 
56
- query = Person.where.inet_contains_or_equals(ip: "127.0.0.255")
58
+ query = User.where.inet_contains_or_equals(ip: "127.0.0.255")
57
59
  expect(query).to include(local_1, local_44)
58
60
  expect(query).to_not include(local_99_1)
59
61
  end
60
62
 
61
63
  it "Finds records when querying with a submasked value" do
62
- query = Person.where.inet_contains_or_equals(ip: "127.0.0.1/10")
64
+ query = User.where.inet_contains_or_equals(ip: "127.0.0.1/10")
63
65
  expect(query).to include(local_1)
64
66
  expect(query).to_not include(local_44, local_99_1)
65
67
 
66
- query = Person.where.inet_contains_or_equals(ip: "127.0.0.1/32")
68
+ query = User.where.inet_contains_or_equals(ip: "127.0.0.1/32")
67
69
  expect(query).to include(local_1, local_44)
68
70
  expect(query).to_not include(local_99_1)
69
71
  end
70
72
  end
71
73
 
72
74
  describe "#inet_contains" do
73
- let!(:local_1) { Person.create!(ip: "127.0.0.1/10") }
74
- let!(:local_44) { Person.create!(ip: "127.0.0.44/24") }
75
+ let!(:local_1) { User.create!(ip: "127.0.0.1/10") }
76
+ let!(:local_44) { User.create!(ip: "127.0.0.44/24") }
75
77
 
76
78
  it "Should find records that the given IP falls within" do
77
- query = Person.where.inet_contains(ip: "127.0.0.1")
79
+ query = User.where.inet_contains(ip: "127.0.0.1")
78
80
  expect(query).to include(local_1, local_44)
79
81
  end
80
82
 
81
83
  it "Should not find records when querying with a submasked value" do
82
- query = Person.where.inet_contains(ip: "127.0.0.0/8")
84
+ query = User.where.inet_contains(ip: "127.0.0.0/8")
83
85
  expect(query).to be_empty
84
86
  end
85
87
  end
86
88
 
87
89
  describe "#inet_contains_or_is_contained_within" do
88
- let!(:local_1) { Person.create!(ip: "127.0.0.1/24") }
89
- let!(:local_44) { Person.create!(ip: "127.0.22.44/8") }
90
- let!(:local_99_1) { Person.create!(ip: "127.0.99.1") }
90
+ let!(:local_1) { User.create!(ip: "127.0.0.1/24") }
91
+ let!(:local_44) { User.create!(ip: "127.0.22.44/8") }
92
+ let!(:local_99_1) { User.create!(ip: "127.0.99.1") }
91
93
 
92
94
  it "should find records where the records contain the given IP" do
93
- query = Person.where.inet_contains_or_is_contained_within(ip: "127.0.255.80")
95
+ query = User.where.inet_contains_or_is_contained_within(ip: "127.0.255.80")
94
96
  expect(query).to include(local_44)
95
97
  expect(query).to_not include(local_1, local_99_1)
96
98
 
97
- query = Person.where.inet_contains_or_is_contained_within(ip: "127.0.0.80")
99
+ query = User.where.inet_contains_or_is_contained_within(ip: "127.0.0.80")
98
100
  expect(query).to include(local_1, local_44)
99
101
  expect(query).to_not include(local_99_1)
100
102
  end
101
103
 
102
104
  it "Should find records that the where query contains a valid range" do
103
- query = Person.where.inet_contains_or_is_contained_within(ip: "127.0.0.80/8")
105
+ query = User.where.inet_contains_or_is_contained_within(ip: "127.0.0.80/8")
104
106
  expect(query).to include(local_1, local_44, local_99_1)
105
107
 
106
- query = Person.where.inet_contains_or_is_contained_within(ip: "127.0.0.80/16")
108
+ query = User.where.inet_contains_or_is_contained_within(ip: "127.0.0.80/16")
107
109
  expect(query).to include(local_1, local_44, local_99_1)
108
110
  end
109
111
  end