ransack 1.7.0 → 2.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. checksums.yaml +5 -5
  2. data/.github/FUNDING.yml +3 -0
  3. data/.github/SECURITY.md +12 -0
  4. data/.github/workflows/test.yml +120 -0
  5. data/.gitignore +3 -0
  6. data/CHANGELOG.md +463 -27
  7. data/CONTRIBUTING.md +52 -22
  8. data/Gemfile +24 -24
  9. data/README.md +453 -126
  10. data/Rakefile +6 -25
  11. data/lib/polyamorous/activerecord_5.2_ruby_2/join_association.rb +24 -0
  12. data/lib/polyamorous/activerecord_5.2_ruby_2/join_dependency.rb +79 -0
  13. data/lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb +11 -0
  14. data/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb +1 -0
  15. data/lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb +80 -0
  16. data/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb +1 -0
  17. data/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb +74 -0
  18. data/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb +93 -0
  19. data/lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb +1 -0
  20. data/lib/polyamorous/join.rb +70 -0
  21. data/lib/polyamorous/polyamorous.rb +24 -0
  22. data/lib/polyamorous/swapping_reflection_class.rb +11 -0
  23. data/lib/polyamorous/tree_node.rb +7 -0
  24. data/lib/ransack/adapters/active_record/base.rb +27 -2
  25. data/lib/ransack/adapters/active_record/context.rb +213 -139
  26. data/lib/ransack/adapters/active_record/ransack/constants.rb +70 -55
  27. data/lib/ransack/adapters/active_record/ransack/context.rb +10 -18
  28. data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +42 -32
  29. data/lib/ransack/adapters/active_record/ransack/translate.rb +1 -5
  30. data/lib/ransack/adapters/active_record/ransack/visitor.rb +23 -0
  31. data/lib/ransack/adapters/active_record.rb +11 -10
  32. data/lib/ransack/adapters.rb +45 -23
  33. data/lib/ransack/configuration.rb +107 -4
  34. data/lib/ransack/constants.rb +13 -26
  35. data/lib/ransack/context.rb +45 -33
  36. data/lib/ransack/helpers/form_builder.rb +21 -12
  37. data/lib/ransack/helpers/form_helper.rb +75 -70
  38. data/lib/ransack/locale/ar.yml +70 -0
  39. data/lib/ransack/locale/az.yml +70 -0
  40. data/lib/ransack/locale/bg.yml +70 -0
  41. data/lib/ransack/locale/ca.yml +70 -0
  42. data/lib/ransack/locale/da.yml +70 -0
  43. data/lib/ransack/locale/el.yml +70 -0
  44. data/lib/ransack/locale/es.yml +22 -22
  45. data/lib/ransack/locale/fa.yml +70 -0
  46. data/lib/ransack/locale/fi.yml +71 -0
  47. data/lib/ransack/locale/id.yml +70 -0
  48. data/lib/ransack/locale/it.yml +70 -0
  49. data/lib/ransack/locale/ja.yml +70 -0
  50. data/lib/ransack/locale/nl.yml +4 -4
  51. data/lib/ransack/locale/pt-BR.yml +70 -0
  52. data/lib/ransack/locale/ru.yml +70 -0
  53. data/lib/ransack/locale/sk.yml +70 -0
  54. data/lib/ransack/locale/tr.yml +70 -0
  55. data/lib/ransack/locale/{zh.yml → zh-CN.yml} +13 -13
  56. data/lib/ransack/locale/zh-TW.yml +70 -0
  57. data/lib/ransack/nodes/attribute.rb +5 -2
  58. data/lib/ransack/nodes/bindable.rb +18 -6
  59. data/lib/ransack/nodes/condition.rb +85 -28
  60. data/lib/ransack/nodes/grouping.rb +17 -11
  61. data/lib/ransack/nodes/sort.rb +9 -5
  62. data/lib/ransack/nodes/value.rb +74 -68
  63. data/lib/ransack/nodes.rb +1 -1
  64. data/lib/ransack/predicate.rb +17 -20
  65. data/lib/ransack/search.rb +17 -8
  66. data/lib/ransack/translate.rb +115 -115
  67. data/lib/ransack/version.rb +1 -1
  68. data/lib/ransack/visitor.rb +1 -12
  69. data/lib/ransack.rb +9 -9
  70. data/logo/ransack-h.png +0 -0
  71. data/logo/ransack-h.svg +34 -0
  72. data/logo/ransack-v.png +0 -0
  73. data/logo/ransack-v.svg +34 -0
  74. data/logo/ransack.png +0 -0
  75. data/logo/ransack.svg +21 -0
  76. data/ransack.gemspec +7 -24
  77. data/spec/console.rb +4 -0
  78. data/spec/helpers/polyamorous_helper.rb +19 -0
  79. data/spec/polyamorous/join_association_spec.rb +35 -0
  80. data/spec/polyamorous/join_dependency_spec.rb +97 -0
  81. data/spec/polyamorous/join_spec.rb +19 -0
  82. data/spec/ransack/adapters/active_record/base_spec.rb +370 -75
  83. data/spec/ransack/adapters/active_record/context_spec.rb +72 -34
  84. data/spec/ransack/configuration_spec.rb +97 -14
  85. data/spec/ransack/helpers/form_builder_spec.rb +2 -11
  86. data/spec/ransack/helpers/form_helper_spec.rb +481 -113
  87. data/spec/ransack/nodes/condition_spec.rb +24 -0
  88. data/spec/ransack/nodes/grouping_spec.rb +56 -0
  89. data/spec/ransack/predicate_spec.rb +79 -5
  90. data/spec/ransack/search_spec.rb +207 -81
  91. data/spec/spec_helper.rb +8 -0
  92. data/spec/support/schema.rb +100 -42
  93. metadata +57 -184
  94. data/.travis.yml +0 -69
  95. data/lib/ransack/adapters/active_record/3.0/compat.rb +0 -179
  96. data/lib/ransack/adapters/active_record/3.0/context.rb +0 -201
  97. data/lib/ransack/adapters/active_record/3.1/context.rb +0 -215
  98. data/lib/ransack/adapters/active_record/3.2/context.rb +0 -44
  99. data/lib/ransack/adapters/active_record/compat.rb +0 -14
  100. data/lib/ransack/adapters/mongoid/3.2/.gitkeep +0 -0
  101. data/lib/ransack/adapters/mongoid/attributes/attribute.rb +0 -37
  102. data/lib/ransack/adapters/mongoid/attributes/order_predications.rb +0 -17
  103. data/lib/ransack/adapters/mongoid/attributes/predications.rb +0 -141
  104. data/lib/ransack/adapters/mongoid/base.rb +0 -130
  105. data/lib/ransack/adapters/mongoid/context.rb +0 -208
  106. data/lib/ransack/adapters/mongoid/inquiry_hash.rb +0 -23
  107. data/lib/ransack/adapters/mongoid/ransack/constants.rb +0 -88
  108. data/lib/ransack/adapters/mongoid/ransack/context.rb +0 -60
  109. data/lib/ransack/adapters/mongoid/ransack/nodes/condition.rb +0 -27
  110. data/lib/ransack/adapters/mongoid/ransack/translate.rb +0 -13
  111. data/lib/ransack/adapters/mongoid/ransack/visitor.rb +0 -24
  112. data/lib/ransack/adapters/mongoid/table.rb +0 -35
  113. data/lib/ransack/adapters/mongoid.rb +0 -13
  114. data/spec/mongoid/adapters/mongoid/base_spec.rb +0 -276
  115. data/spec/mongoid/adapters/mongoid/context_spec.rb +0 -56
  116. data/spec/mongoid/configuration_spec.rb +0 -102
  117. data/spec/mongoid/dependencies_spec.rb +0 -8
  118. data/spec/mongoid/helpers/ransack_helper.rb +0 -11
  119. data/spec/mongoid/nodes/condition_spec.rb +0 -34
  120. data/spec/mongoid/nodes/grouping_spec.rb +0 -13
  121. data/spec/mongoid/predicate_spec.rb +0 -155
  122. data/spec/mongoid/search_spec.rb +0 -446
  123. data/spec/mongoid/support/mongoid.yml +0 -6
  124. data/spec/mongoid/support/schema.rb +0 -128
  125. data/spec/mongoid/translate_spec.rb +0 -14
  126. data/spec/mongoid_spec_helper.rb +0 -59
  127. data/spec/ransack/dependencies_spec.rb +0 -12
@@ -1,128 +0,0 @@
1
- require 'mongoid'
2
-
3
- Mongoid.load!(File.expand_path("../mongoid.yml", __FILE__), :test)
4
-
5
- class Person
6
- include Mongoid::Document
7
- include Mongoid::Timestamps
8
-
9
- field :name, type: String
10
- field :email, type: String
11
- field :only_search, type: String
12
- field :only_sort, type: String
13
- field :only_admin, type: String
14
- field :salary, type: Integer
15
- field :awesome, type: Boolean, default: false
16
-
17
- belongs_to :parent, :class_name => 'Person', inverse_of: :children
18
- has_many :children, :class_name => 'Person', inverse_of: :parent
19
-
20
- has_many :articles
21
- has_many :comments
22
-
23
- # has_many :authored_article_comments, :through => :articles,
24
- # :source => :comments, :foreign_key => :person_id
25
-
26
- has_many :notes, :as => :notable
27
-
28
- default_scope -> { order(id: :desc) }
29
-
30
- scope :restricted, lambda { where(restricted: 1) }
31
- scope :active, lambda { where(active: 1) }
32
- scope :over_age, lambda { |y| where(:age.gt => y) }
33
-
34
- ransacker :reversed_name, :formatter => proc { |v| v.reverse } do |parent|
35
- parent.table[:name]
36
- end
37
-
38
- ransacker :doubled_name do |parent|
39
- # Arel::Nodes::InfixOperation.new(
40
- # '||', parent.table[:name], parent.table[:name]
41
- # )
42
- parent.table[:name]
43
- end
44
-
45
- def self.ransackable_attributes(auth_object = nil)
46
- if auth_object == :admin
47
- all_ransackable_attributes - ['only_sort']
48
- else
49
- all_ransackable_attributes - ['only_sort', 'only_admin']
50
- end
51
- end
52
-
53
- def self.ransortable_attributes(auth_object = nil)
54
- if auth_object == :admin
55
- all_ransackable_attributes - ['only_search']
56
- else
57
- all_ransackable_attributes - ['only_search', 'only_admin']
58
- end
59
- end
60
- end
61
-
62
- class Article
63
- include Mongoid::Document
64
-
65
- field :title, type: String
66
- field :body, type: String
67
-
68
- belongs_to :person
69
- has_many :comments
70
- # has_and_belongs_to_many :tags
71
- has_many :notes, :as => :notable
72
- end
73
-
74
- module Namespace
75
- class Article < ::Article
76
-
77
- end
78
- end
79
-
80
- class Comment
81
- include Mongoid::Document
82
-
83
- field :body, type: String
84
-
85
-
86
- belongs_to :article
87
- belongs_to :person
88
- end
89
-
90
- class Tag
91
- include Mongoid::Document
92
-
93
- field :name, type: String
94
-
95
- # has_and_belongs_to_many :articles
96
- end
97
-
98
- class Note
99
- include Mongoid::Document
100
-
101
- field :note, type: String
102
-
103
- belongs_to :notable, :polymorphic => true
104
- end
105
-
106
- module Schema
107
- def self.create
108
- 10.times do
109
- person = Person.make.save!
110
- Note.make.save!(:notable => person)
111
- 3.times do
112
- article = Article.create!(:person => person)
113
- 3.times do
114
- # article.tags = [Tag.make.save!, Tag.make.save!, Tag.make.save!]
115
- end
116
- Note.create.save!(:notable => article)
117
- 10.times do
118
- Comment.create.save!(:article => article, :person => person)
119
- end
120
- end
121
- end
122
-
123
- Comment.create!(
124
- :body => 'First post!',
125
- :article => Article.create!(:title => 'Hello, world!')
126
- )
127
- end
128
- end
@@ -1,14 +0,0 @@
1
- require 'mongoid_spec_helper'
2
-
3
- module Ransack
4
- describe Translate do
5
-
6
- describe '.attribute' do
7
- it 'translate namespaced attribute like AR does' do
8
- ar_translation = ::Namespace::Article.human_attribute_name(:title)
9
- ransack_translation = Ransack::Translate.attribute(:title, :context => ::Namespace::Article.search.context)
10
- expect(ransack_translation).to eq ar_translation
11
- end
12
- end
13
- end
14
- end
@@ -1,59 +0,0 @@
1
- require 'machinist/object'
2
- require 'sham'
3
- require 'faker'
4
- require 'pry'
5
- require 'mongoid'
6
- require 'ransack'
7
-
8
- I18n.enforce_available_locales = false
9
- Time.zone = 'Eastern Time (US & Canada)'
10
- I18n.load_path += Dir[File.join(File.dirname(__FILE__), 'support', '*.yml')]
11
-
12
- Dir[File.expand_path('../{mongoid/helpers,mongoid/support,blueprints}/*.rb', __FILE__)]
13
- .each do |f|
14
- require f
15
- end
16
-
17
- Sham.define do
18
- name { Faker::Name.name }
19
- title { Faker::Lorem.sentence }
20
- body { Faker::Lorem.paragraph }
21
- salary { |index| 30000 + (index * 1000) }
22
- tag_name { Faker::Lorem.words(3).join(' ') }
23
- note { Faker::Lorem.words(7).join(' ') }
24
- only_admin { Faker::Lorem.words(3).join(' ') }
25
- only_search { Faker::Lorem.words(3).join(' ') }
26
- only_sort { Faker::Lorem.words(3).join(' ') }
27
- notable_id { |id| id }
28
- end
29
-
30
- RSpec.configure do |config|
31
- config.alias_it_should_behave_like_to :it_has_behavior, 'has behavior'
32
-
33
- config.before(:suite) do
34
- puts '=' * 80
35
- connection_name = Mongoid.default_session.inspect
36
- puts "Running specs against #{connection_name}, Mongoid #{
37
- Mongoid::VERSION}, Moped #{Moped::VERSION} and Origin #{Origin::VERSION}..."
38
- puts '=' * 80
39
- Schema.create
40
- end
41
-
42
- config.before(:all) { Sham.reset(:before_all) }
43
- config.before(:each) { Sham.reset(:before_each) }
44
-
45
- config.include RansackHelper
46
- end
47
-
48
- RSpec::Matchers.define :be_like do |expected|
49
- match do |actual|
50
- actual.gsub(/^\s+|\s+$/, '').gsub(/\s+/, ' ').strip ==
51
- expected.gsub(/^\s+|\s+$/, '').gsub(/\s+/, ' ').strip
52
- end
53
- end
54
-
55
- RSpec::Matchers.define :have_attribute_method do |expected|
56
- match do |actual|
57
- actual.attribute_method?(expected)
58
- end
59
- end
@@ -1,12 +0,0 @@
1
- =begin
2
- rails = ::ActiveRecord::VERSION::STRING.first(3)
3
-
4
- if %w(3.2 4.0 4.1).include?(rails) || rails == '3.1' && RUBY_VERSION < '2.2'
5
- describe 'Ransack' do
6
- it 'can be required without errors' do
7
- output = `bundle exec ruby -e "require 'ransack'" 2>&1`
8
- expect(output).to be_empty
9
- end
10
- end
11
- end
12
- =end