active_record_extended 2.0.3 → 3.1.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 (51) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +140 -77
  3. data/lib/active_record_extended/arel/nodes.rb +1 -1
  4. data/lib/active_record_extended/arel/{sql_literal.rb → sql_literal_patch.rb} +2 -2
  5. data/lib/active_record_extended/arel/visitors/postgresql_decorator.rb +16 -12
  6. data/lib/active_record_extended/arel.rb +1 -1
  7. data/lib/active_record_extended/patch/array_handler_patch.rb +22 -0
  8. data/lib/active_record_extended/patch/relation_patch.rb +82 -0
  9. data/lib/active_record_extended/patch/where_clause_patch.rb +13 -0
  10. data/lib/active_record_extended/query_methods/any_of.rb +1 -1
  11. data/lib/active_record_extended/query_methods/either.rb +5 -7
  12. data/lib/active_record_extended/query_methods/{select.rb → foster_select.rb} +4 -4
  13. data/lib/active_record_extended/query_methods/json.rb +2 -2
  14. data/lib/active_record_extended/query_methods/unionize.rb +5 -5
  15. data/lib/active_record_extended/query_methods/where_chain.rb +96 -90
  16. data/lib/active_record_extended/query_methods/window.rb +3 -3
  17. data/lib/active_record_extended/query_methods/with_cte.rb +61 -4
  18. data/lib/active_record_extended/utilities/order_by.rb +1 -1
  19. data/lib/active_record_extended/utilities/support.rb +1 -1
  20. data/lib/active_record_extended/version.rb +1 -1
  21. data/lib/active_record_extended.rb +55 -4
  22. metadata +20 -83
  23. data/lib/active_record_extended/active_record/relation_patch.rb +0 -50
  24. data/lib/active_record_extended/active_record.rb +0 -25
  25. data/lib/active_record_extended/patch/5_1/where_clause.rb +0 -11
  26. data/lib/active_record_extended/patch/5_2/where_clause.rb +0 -11
  27. data/lib/active_record_extended/predicate_builder/array_handler_decorator.rb +0 -20
  28. data/spec/active_record_extended_spec.rb +0 -7
  29. data/spec/query_methods/any_of_spec.rb +0 -131
  30. data/spec/query_methods/array_query_spec.rb +0 -64
  31. data/spec/query_methods/either_spec.rb +0 -70
  32. data/spec/query_methods/hash_query_spec.rb +0 -45
  33. data/spec/query_methods/inet_query_spec.rb +0 -112
  34. data/spec/query_methods/json_spec.rb +0 -157
  35. data/spec/query_methods/select_spec.rb +0 -115
  36. data/spec/query_methods/unionize_spec.rb +0 -165
  37. data/spec/query_methods/window_spec.rb +0 -51
  38. data/spec/query_methods/with_cte_spec.rb +0 -50
  39. data/spec/spec_helper.rb +0 -28
  40. data/spec/sql_inspections/any_of_sql_spec.rb +0 -41
  41. data/spec/sql_inspections/arel/aggregate_function_name_spec.rb +0 -41
  42. data/spec/sql_inspections/arel/array_spec.rb +0 -63
  43. data/spec/sql_inspections/arel/inet_spec.rb +0 -66
  44. data/spec/sql_inspections/contains_sql_queries_spec.rb +0 -47
  45. data/spec/sql_inspections/either_sql_spec.rb +0 -71
  46. data/spec/sql_inspections/json_sql_spec.rb +0 -82
  47. data/spec/sql_inspections/unionize_sql_spec.rb +0 -124
  48. data/spec/sql_inspections/window_sql_spec.rb +0 -98
  49. data/spec/sql_inspections/with_cte_sql_spec.rb +0 -95
  50. data/spec/support/database_cleaner.rb +0 -15
  51. data/spec/support/models.rb +0 -80
@@ -1,95 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- RSpec.describe "Active Record WITH CTE tables" do
6
- let(:with_personal_query) { /WITH.+personal_id_one.+AS \(SELECT.+users.+FROM.+WHERE.+users.+personal_id.+ = 1\)/ }
7
-
8
- it "should contain WITH statement that creates the CTE table" do
9
- query = User.with(personal_id_one: User.where(personal_id: 1))
10
- .joins("JOIN personal_id_one ON personal_id_one.id = users.id")
11
- .to_sql
12
- expect(query).to match_regex(with_personal_query)
13
- end
14
-
15
- it "will maintain the CTE table when merging" do
16
- query = User.all
17
- .merge(User.with(personal_id_one: User.where(personal_id: 1)))
18
- .joins("JOIN personal_id_one ON personal_id_one.id = users.id")
19
- .to_sql
20
-
21
- expect(query).to match_regex(with_personal_query)
22
- end
23
-
24
- it "will pipe Children CTE's into the Parent relation" do
25
- personal_id_one_query = User.where(personal_id: 1)
26
- personal_id_two_query = User.where(personal_id: 2)
27
-
28
- sub_query = personal_id_two_query.with(personal_id_one: personal_id_one_query)
29
- query = User.all.with(personal_id_two: sub_query)
30
- expected_order = User.with(
31
- personal_id_one: personal_id_one_query,
32
- personal_id_two: personal_id_two_query
33
- )
34
-
35
- expect(query.to_sql).to eq(expected_order.to_sql)
36
- end
37
-
38
- context "when multiple CTE's" do
39
- let(:chained_with) do
40
- User.with(personal_id_one: User.where(personal_id: 1))
41
- .with(personal_id_two: User.where(personal_id: 2))
42
- .joins("JOIN personal_id_one ON personal_id_one.id = users.id")
43
- .joins("JOIN personal_id_two ON personal_id_two.id = users.id")
44
- .to_sql
45
- end
46
-
47
- let(:with_arguments) do
48
- User.with(personal_id_one: User.where(personal_id: 1), personal_id_two: User.where(personal_id: 2))
49
- .joins("JOIN personal_id_one ON personal_id_one.id = users.id")
50
- .joins("JOIN personal_id_two ON personal_id_two.id = users.id")
51
- .to_sql
52
- end
53
-
54
- it "Should only contain a single WITH statement" do
55
- expect(with_arguments.scan(/WITH/).count).to eq(1)
56
- expect(with_arguments.scan(/AS/).count).to eq(2)
57
- end
58
-
59
- it "Should only contain a single WITH statement when chaining" do
60
- expect(chained_with.scan(/WITH/).count).to eq(1)
61
- expect(chained_with.scan(/AS/).count).to eq(2)
62
- end
63
- end
64
-
65
- context "when chaining the recursive method" do
66
- let(:with_recursive_personal_query) do
67
- /WITH.+RECURSIVE.+personal_id_one.+AS \(SELECT.+users.+FROM.+WHERE.+users.+personal_id.+ = 1\)/
68
- end
69
-
70
- let(:with_recursive) do
71
- User.with
72
- .recursive(personal_id_one: User.where(personal_id: 1))
73
- .joins("JOIN personal_id_one ON personal_id_one.id = users.id")
74
- .to_sql
75
- end
76
-
77
- it "generates an expression with recursive" do
78
- query = User.with
79
- .recursive(personal_id_one: User.where(personal_id: 1))
80
- .joins("JOIN personal_id_one ON personal_id_one.id = users.id")
81
- .to_sql
82
-
83
- expect(query).to match_regex(with_recursive_personal_query)
84
- end
85
-
86
- it "will maintain the CTE table when merging" do
87
- sub_query = User.with.recursive(personal_id_one: User.where(personal_id: 1))
88
- query = User.merge(sub_query)
89
- .joins("JOIN personal_id_one ON personal_id_one.id = users.id")
90
- .to_sql
91
-
92
- expect(query).to match_regex(with_recursive_personal_query)
93
- end
94
- end
95
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "database_cleaner"
4
-
5
- DatabaseCleaner.strategy = :truncation
6
-
7
- RSpec.configure do |config|
8
- config.before do
9
- DatabaseCleaner.start
10
- end
11
-
12
- config.after do
13
- DatabaseCleaner.clean
14
- end
15
- end
@@ -1,80 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class ApplicationRecord < ActiveRecord::Base
4
- self.abstract_class = true
5
- end
6
-
7
- class User < ApplicationRecord
8
- has_many :groups_users, class_name: "GroupsUser"
9
- has_many :groups, through: :groups_users, dependent: :destroy
10
- has_many :hm_tags, class_name: "Tag"
11
- has_one :profile_l, class_name: "ProfileL"
12
- has_one :profile_r, class_name: "ProfileR"
13
- # attributes
14
- # t.string "tags", array: true
15
- # t.integer "number", default: 0
16
- # t.string "name"
17
- # t.integer "personal_id"
18
- # t.hstore "data"
19
- # t.jsonb "jsonb_data"
20
- # t.inet "ip"
21
- # t.cidr "subnet"
22
- #
23
- end
24
-
25
- class StiRecord < ApplicationRecord
26
- # t.string "type"
27
- end
28
-
29
- class AdminSti < StiRecord; end
30
-
31
- module Namespaced
32
- def self.table_name_prefix
33
- "namespaced_"
34
- end
35
-
36
- class Record < ApplicationRecord
37
- # attributes
38
- # t.inet :ip
39
- # t.cidr :subnet
40
- #
41
- end
42
- end
43
-
44
- class Tag < ApplicationRecord
45
- belongs_to :user
46
- # attributes: tag_number
47
- end
48
-
49
- class ProfileL < ApplicationRecord
50
- belongs_to :user
51
- has_one :version, as: :versionable, class_name: "VersionControl"
52
- # attributes
53
- # t.integer :likes
54
- #
55
- end
56
-
57
- class ProfileR < ApplicationRecord
58
- belongs_to :user
59
- has_one :version, as: :versionable, class_name: "VersionControl"
60
- # attributes
61
- # t.integer :dislikes
62
- #
63
- end
64
-
65
- class VersionControl < ApplicationRecord
66
- belongs_to :versionable, polymorphic: true, optional: false
67
- # attributes
68
- # t.jsonb :source, default: {}, null: false
69
- #
70
- end
71
-
72
- class Group < ApplicationRecord
73
- has_many :groups_users, class_name: "GroupsUser"
74
- has_many :users, through: :groups_users, dependent: :destroy
75
- end
76
-
77
- class GroupsUser < ApplicationRecord
78
- belongs_to :user
79
- belongs_to :group
80
- end