ransack 2.3.0 → 2.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +3 -0
  3. data/.github/SECURITY.md +12 -0
  4. data/.github/workflows/cronjob.yml +105 -0
  5. data/.github/workflows/rubocop.yml +20 -0
  6. data/.github/workflows/test.yml +154 -0
  7. data/.rubocop.yml +44 -0
  8. data/CHANGELOG.md +31 -1
  9. data/CONTRIBUTING.md +13 -11
  10. data/Gemfile +19 -5
  11. data/README.md +119 -54
  12. data/bug_report_templates/test-ransack-scope-and-column-same-name.rb +78 -0
  13. data/bug_report_templates/test-ransacker-arel-present-predicate.rb +71 -0
  14. data/docs/img/create_release.png +0 -0
  15. data/docs/release_process.md +20 -0
  16. data/{polyamorous/lib/polyamorous/activerecord_5.2.1_ruby_2 → lib/polyamorous/activerecord_5.2_ruby_2}/join_association.rb +4 -2
  17. data/{polyamorous/lib/polyamorous/activerecord_5.2.1_ruby_2 → lib/polyamorous/activerecord_5.2_ruby_2}/join_dependency.rb +0 -2
  18. data/lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb +11 -0
  19. data/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb +1 -0
  20. data/{polyamorous/lib → lib}/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb +0 -1
  21. data/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb +1 -0
  22. data/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb +74 -0
  23. data/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb +93 -0
  24. data/{polyamorous/lib → lib}/polyamorous/activerecord_6.1_ruby_2/reflection.rb +0 -1
  25. data/lib/polyamorous/activerecord_6.2_ruby_2/join_association.rb +1 -0
  26. data/lib/polyamorous/activerecord_6.2_ruby_2/join_dependency.rb +1 -0
  27. data/lib/polyamorous/activerecord_6.2_ruby_2/reflection.rb +1 -0
  28. data/{polyamorous/lib → lib}/polyamorous/join.rb +0 -0
  29. data/{polyamorous/lib → lib/polyamorous}/polyamorous.rb +3 -8
  30. data/{polyamorous/lib → lib}/polyamorous/swapping_reflection_class.rb +0 -0
  31. data/{polyamorous/lib → lib}/polyamorous/tree_node.rb +0 -0
  32. data/lib/ransack.rb +3 -4
  33. data/lib/ransack/adapters/active_record/base.rb +4 -0
  34. data/lib/ransack/adapters/active_record/context.rb +51 -80
  35. data/lib/ransack/adapters/active_record/ransack/constants.rb +13 -1
  36. data/lib/ransack/adapters/active_record/ransack/context.rb +2 -6
  37. data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +11 -4
  38. data/lib/ransack/configuration.rb +17 -1
  39. data/lib/ransack/constants.rb +2 -5
  40. data/lib/ransack/helpers.rb +1 -1
  41. data/lib/ransack/helpers/form_builder.rb +8 -14
  42. data/lib/ransack/locale/sk.yml +70 -0
  43. data/lib/ransack/nodes/attribute.rb +1 -1
  44. data/lib/ransack/nodes/condition.rb +7 -1
  45. data/lib/ransack/nodes/grouping.rb +1 -1
  46. data/lib/ransack/nodes/sort.rb +1 -1
  47. data/lib/ransack/nodes/value.rb +1 -1
  48. data/lib/ransack/predicate.rb +2 -1
  49. data/lib/ransack/search.rb +3 -1
  50. data/lib/ransack/translate.rb +3 -3
  51. data/lib/ransack/version.rb +1 -1
  52. data/ransack.gemspec +8 -23
  53. data/spec/blueprints/articles.rb +1 -1
  54. data/spec/blueprints/comments.rb +1 -1
  55. data/spec/blueprints/notes.rb +1 -1
  56. data/spec/blueprints/tags.rb +1 -1
  57. data/spec/console.rb +5 -5
  58. data/spec/helpers/polyamorous_helper.rb +1 -10
  59. data/spec/helpers/ransack_helper.rb +1 -1
  60. data/spec/{ransack → polyamorous}/join_association_spec.rb +7 -0
  61. data/spec/{ransack → polyamorous}/join_dependency_spec.rb +0 -0
  62. data/spec/{ransack → polyamorous}/join_spec.rb +0 -0
  63. data/spec/ransack/adapters/active_record/base_spec.rb +9 -6
  64. data/spec/ransack/adapters/active_record/context_spec.rb +19 -18
  65. data/spec/ransack/configuration_spec.rb +10 -0
  66. data/spec/ransack/helpers/form_helper_spec.rb +16 -16
  67. data/spec/ransack/nodes/grouping_spec.rb +2 -2
  68. data/spec/ransack/predicate_spec.rb +39 -1
  69. data/spec/ransack/search_spec.rb +105 -17
  70. data/spec/spec_helper.rb +9 -5
  71. data/spec/support/schema.rb +8 -3
  72. metadata +41 -177
  73. data/.travis.yml +0 -49
  74. data/polyamorous/lib/polyamorous/activerecord_5.0_ruby_2/join_association.rb +0 -2
  75. data/polyamorous/lib/polyamorous/activerecord_5.0_ruby_2/join_dependency.rb +0 -2
  76. data/polyamorous/lib/polyamorous/activerecord_5.1_ruby_2/join_association.rb +0 -31
  77. data/polyamorous/lib/polyamorous/activerecord_5.1_ruby_2/join_dependency.rb +0 -112
  78. data/polyamorous/lib/polyamorous/activerecord_5.2.0_ruby_2/join_association.rb +0 -31
  79. data/polyamorous/lib/polyamorous/activerecord_5.2.0_ruby_2/join_dependency.rb +0 -112
  80. data/polyamorous/lib/polyamorous/activerecord_5.2.0_ruby_2/reflection.rb +0 -12
  81. data/polyamorous/lib/polyamorous/activerecord_5.2.1_ruby_2/reflection.rb +0 -2
  82. data/polyamorous/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb +0 -2
  83. data/polyamorous/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb +0 -2
  84. data/polyamorous/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb +0 -2
  85. data/polyamorous/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb +0 -2
  86. data/polyamorous/lib/polyamorous/version.rb +0 -3
  87. data/polyamorous/polyamorous.gemspec +0 -35
@@ -1,2 +0,0 @@
1
- # active_record_5.0_ruby_2/join_association.rb
2
- require 'polyamorous/activerecord_5.1_ruby_2/join_association'
@@ -1,2 +0,0 @@
1
- # active_record_5.0_ruby_2/join_dependency.rb
2
- require 'polyamorous/activerecord_5.1_ruby_2/join_dependency'
@@ -1,31 +0,0 @@
1
- # active_record_5.1_ruby_2/join_association.rb
2
-
3
- module Polyamorous
4
- module JoinAssociationExtensions
5
- include SwappingReflectionClass
6
- def self.prepended(base)
7
- base.class_eval { attr_reader :join_type }
8
- end
9
-
10
- def initialize(reflection, children, polymorphic_class = nil, join_type = Arel::Nodes::InnerJoin)
11
- @join_type = join_type
12
- if polymorphic_class && ::ActiveRecord::Base > polymorphic_class
13
- swapping_reflection_klass(reflection, polymorphic_class) do |reflection|
14
- super(reflection, children)
15
- self.reflection.options[:polymorphic] = true
16
- end
17
- else
18
- super(reflection, children)
19
- end
20
- end
21
-
22
- def build_constraint(klass, table, key, foreign_table, foreign_key)
23
- if reflection.polymorphic?
24
- super(klass, table, key, foreign_table, foreign_key)
25
- .and(foreign_table[reflection.foreign_type].eq(reflection.klass.name))
26
- else
27
- super(klass, table, key, foreign_table, foreign_key)
28
- end
29
- end
30
- end
31
- end
@@ -1,112 +0,0 @@
1
- # active_record_5.1_ruby_2/join_dependency.rb
2
-
3
- module Polyamorous
4
- module JoinDependencyExtensions
5
- # Replaces ActiveRecord::Associations::JoinDependency#build
6
- #
7
- def build(associations, base_klass)
8
- associations.map do |name, right|
9
- if name.is_a? Join
10
- reflection = find_reflection base_klass, name.name
11
- reflection.check_validity!
12
- reflection.check_eager_loadable!
13
-
14
- klass = if reflection.polymorphic?
15
- name.klass || base_klass
16
- else
17
- reflection.klass
18
- end
19
- JoinAssociation.new(reflection, build(right, klass), name.klass, name.type)
20
- else
21
- reflection = find_reflection base_klass, name
22
- reflection.check_validity!
23
- reflection.check_eager_loadable!
24
-
25
- if reflection.polymorphic?
26
- raise ActiveRecord::EagerLoadPolymorphicError.new(reflection)
27
- end
28
- JoinAssociation.new reflection, build(right, reflection.klass)
29
- end
30
- end
31
- end
32
-
33
- # Replaces ActiveRecord::Associations::JoinDependency#join_constraints
34
- #
35
- # This internal method was changed in Rails 5.0 by commit
36
- # https://github.com/rails/rails/commit/e038975 which added
37
- # left_outer_joins (see #make_polyamorous_left_outer_joins below) and added
38
- # passing an additional argument, `join_type`, to #join_constraints.
39
- #
40
- def join_constraints(outer_joins, join_type)
41
- joins = join_root.children.flat_map { |child|
42
- if join_type == Arel::Nodes::OuterJoin
43
- make_polyamorous_left_outer_joins join_root, child
44
- else
45
- make_polyamorous_inner_joins join_root, child
46
- end
47
- }
48
-
49
- joins.concat outer_joins.flat_map { |oj|
50
- if join_root.match? oj.join_root
51
- walk(join_root, oj.join_root)
52
- else
53
- oj.join_root.children.flat_map { |child|
54
- make_outer_joins(oj.join_root, child)
55
- }
56
- end
57
- }
58
- end
59
-
60
- # Replaces ActiveRecord::Associations::JoinDependency#make_left_outer_joins,
61
- # a new method that was added in Rails 5.0 with the following commit:
62
- # https://github.com/rails/rails/commit/e038975
63
- #
64
- def make_polyamorous_left_outer_joins(parent, child)
65
- tables = child.tables
66
- join_type = Arel::Nodes::OuterJoin
67
- info = make_constraints parent, child, tables, join_type
68
-
69
- [info] + child.children.flat_map { |c|
70
- make_polyamorous_left_outer_joins(child, c)
71
- }
72
- end
73
-
74
- # Replaces ActiveRecord::Associations::JoinDependency#make_inner_joins
75
- #
76
- def make_polyamorous_inner_joins(parent, child)
77
- tables = child.tables
78
- join_type = child.join_type || Arel::Nodes::InnerJoin
79
- info = make_constraints parent, child, tables, join_type
80
-
81
- [info] + child.children.flat_map { |c|
82
- make_polyamorous_inner_joins(child, c)
83
- }
84
- end
85
-
86
- private :make_polyamorous_inner_joins, :make_polyamorous_left_outer_joins
87
-
88
- module ClassMethods
89
- # Prepended before ActiveRecord::Associations::JoinDependency#walk_tree
90
- #
91
- def walk_tree(associations, hash)
92
- case associations
93
- when TreeNode
94
- associations.add_to_tree(hash)
95
- when Hash
96
- associations.each do |k, v|
97
- cache =
98
- if TreeNode === k
99
- k.add_to_tree(hash)
100
- else
101
- hash[k] ||= {}
102
- end
103
- walk_tree(v, cache)
104
- end
105
- else
106
- super(associations, hash)
107
- end
108
- end
109
- end
110
-
111
- end
112
- end
@@ -1,31 +0,0 @@
1
- # active_record_5.2_ruby_2/join_association.rb
2
-
3
- module Polyamorous
4
- module JoinAssociationExtensions
5
- include SwappingReflectionClass
6
- def self.prepended(base)
7
- base.class_eval { attr_reader :join_type }
8
- end
9
-
10
- def initialize(reflection, children, alias_tracker, polymorphic_class = nil, join_type = Arel::Nodes::InnerJoin)
11
- @join_type = join_type
12
- if polymorphic_class && ::ActiveRecord::Base > polymorphic_class
13
- swapping_reflection_klass(reflection, polymorphic_class) do |reflection|
14
- super(reflection, children, alias_tracker)
15
- self.reflection.options[:polymorphic] = true
16
- end
17
- else
18
- super(reflection, children, alias_tracker)
19
- end
20
- end
21
-
22
- def build_constraint(klass, table, key, foreign_table, foreign_key)
23
- if reflection.polymorphic?
24
- super(klass, table, key, foreign_table, foreign_key)
25
- .and(foreign_table[reflection.foreign_type].eq(reflection.klass.name))
26
- else
27
- super(klass, table, key, foreign_table, foreign_key)
28
- end
29
- end
30
- end
31
- end
@@ -1,112 +0,0 @@
1
- # active_record_5.2_ruby_2/join_dependency.rb
2
-
3
- module Polyamorous
4
- module JoinDependencyExtensions
5
- # Replaces ActiveRecord::Associations::JoinDependency#build
6
- #
7
- def build(associations, base_klass)
8
- associations.map do |name, right|
9
- if name.is_a? Join
10
- reflection = find_reflection base_klass, name.name
11
- reflection.check_validity!
12
- reflection.check_eager_loadable!
13
-
14
- klass = if reflection.polymorphic?
15
- name.klass || base_klass
16
- else
17
- reflection.klass
18
- end
19
- JoinAssociation.new(reflection, build(right, klass), alias_tracker, name.klass, name.type)
20
- else
21
- reflection = find_reflection base_klass, name
22
- reflection.check_validity!
23
- reflection.check_eager_loadable!
24
-
25
- if reflection.polymorphic?
26
- raise ActiveRecord::EagerLoadPolymorphicError.new(reflection)
27
- end
28
- JoinAssociation.new(reflection, build(right, reflection.klass), alias_tracker)
29
- end
30
- end
31
- end
32
-
33
- # Replaces ActiveRecord::Associations::JoinDependency#join_constraints
34
- #
35
- # This internal method was changed in Rails 5.0 by commit
36
- # https://github.com/rails/rails/commit/e038975 which added
37
- # left_outer_joins (see #make_polyamorous_left_outer_joins below) and added
38
- # passing an additional argument, `join_type`, to #join_constraints.
39
- #
40
- def join_constraints(outer_joins, join_type)
41
- joins = join_root.children.flat_map { |child|
42
- if join_type == Arel::Nodes::OuterJoin
43
- make_polyamorous_left_outer_joins join_root, child
44
- else
45
- make_polyamorous_inner_joins join_root, child
46
- end
47
- }
48
-
49
- joins.concat outer_joins.flat_map { |oj|
50
- if join_root.match?(oj.join_root) && join_root.table.name == oj.join_root.table.name
51
- walk(join_root, oj.join_root)
52
- else
53
- oj.join_root.children.flat_map { |child|
54
- make_outer_joins(oj.join_root, child)
55
- }
56
- end
57
- }
58
- end
59
-
60
- # Replaces ActiveRecord::Associations::JoinDependency#make_left_outer_joins,
61
- # a new method that was added in Rails 5.0 with the following commit:
62
- # https://github.com/rails/rails/commit/e038975
63
- #
64
- def make_polyamorous_left_outer_joins(parent, child)
65
- tables = child.tables
66
- join_type = Arel::Nodes::OuterJoin
67
- info = make_constraints parent, child, tables, join_type
68
-
69
- info + child.children.flat_map { |c|
70
- make_polyamorous_left_outer_joins(child, c)
71
- }
72
- end
73
-
74
- # Replaces ActiveRecord::Associations::JoinDependency#make_inner_joins
75
- #
76
- def make_polyamorous_inner_joins(parent, child)
77
- tables = child.tables
78
- join_type = child.join_type || Arel::Nodes::InnerJoin
79
- info = make_constraints parent, child, tables, join_type
80
-
81
- info + child.children.flat_map { |c|
82
- make_polyamorous_inner_joins(child, c)
83
- }
84
- end
85
-
86
- private :make_polyamorous_inner_joins, :make_polyamorous_left_outer_joins
87
-
88
- module ClassMethods
89
- # Prepended before ActiveRecord::Associations::JoinDependency#walk_tree
90
- #
91
- def walk_tree(associations, hash)
92
- case associations
93
- when TreeNode
94
- associations.add_to_tree(hash)
95
- when Hash
96
- associations.each do |k, v|
97
- cache =
98
- if TreeNode === k
99
- k.add_to_tree(hash)
100
- else
101
- hash[k] ||= {}
102
- end
103
- walk_tree(v, cache)
104
- end
105
- else
106
- super(associations, hash)
107
- end
108
- end
109
- end
110
-
111
- end
112
- end
@@ -1,12 +0,0 @@
1
- module Polyamorous
2
- module ReflectionExtensions
3
- def build_join_constraint(table, foreign_table)
4
- if polymorphic?
5
- super(table, foreign_table)
6
- .and(foreign_table[foreign_type].eq(klass.name))
7
- else
8
- super(table, foreign_table)
9
- end
10
- end
11
- end
12
- end
@@ -1,2 +0,0 @@
1
- # active_record_5.2.1_ruby_2/reflection.rb
2
- require 'polyamorous/activerecord_5.2.0_ruby_2/reflection'
@@ -1,2 +0,0 @@
1
- # active_record_6.0_ruby_2/join_association
2
- require 'polyamorous/activerecord_5.2.1_ruby_2/join_association'
@@ -1,2 +0,0 @@
1
- # active_record_6.0_ruby_2/reflection.rb
2
- require 'polyamorous/activerecord_5.2.0_ruby_2/reflection'
@@ -1,2 +0,0 @@
1
- # active_record_6.1_ruby_2/join_association
2
- require 'polyamorous/activerecord_6.0_ruby_2/join_association'
@@ -1,2 +0,0 @@
1
- # active_record_6.1_ruby_2/join_dependency.rb
2
- require 'polyamorous/activerecord_6.0_ruby_2/join_dependency'
@@ -1,3 +0,0 @@
1
- module Polyamorous
2
- VERSION = '2.3.0'
3
- end
@@ -1,35 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "polyamorous/version"
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "polyamorous"
7
- s.version = Polyamorous::VERSION
8
- s.authors = ["Ernie Miller", "Ryan Bigg", "Jon Atack", "Xiang Li"]
9
- s.email = ["ernie@erniemiller.org", "radarlistener@gmail.com", "jonnyatack@gmail.com", "bigxiang@gmail.com"]
10
- s.homepage = "https://github.com/activerecord-hackery/ransack/tree/master/polyamorous"
11
- s.license = "MIT"
12
- s.summary = %q{
13
- Loves/is loved by polymorphic belongs_to associations, Ransack, Squeel, MetaSearch...
14
- }
15
- s.description = %q{
16
- This is just an extraction from Ransack/Squeel. You probably don't want to use this
17
- directly. It extends ActiveRecord's associations to support polymorphic belongs_to
18
- associations.
19
- }
20
-
21
- s.add_dependency 'activerecord', '>= 5.0'
22
- s.add_development_dependency 'rspec', '~> 3'
23
- s.add_development_dependency 'machinist', '~> 1.0.6'
24
- s.add_development_dependency 'faker', '~> 1.6.5'
25
- s.add_development_dependency 'sqlite3', '~> 1.3.3'
26
-
27
- s.files = `git ls-files`.split("\n")
28
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
29
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
30
- s.require_paths = ["lib"]
31
-
32
- # specify any dependencies here; for example:
33
- # s.add_development_dependency "rspec"
34
- # s.add_runtime_dependency "rest-client"
35
- end