ransack 1.6.6 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +3 -0
  3. data/.travis.yml +35 -53
  4. data/CHANGELOG.md +530 -9
  5. data/CONTRIBUTING.md +63 -26
  6. data/Gemfile +24 -24
  7. data/README.md +371 -96
  8. data/Rakefile +6 -29
  9. data/lib/polyamorous/activerecord_5.2_ruby_2/join_association.rb +24 -0
  10. data/lib/polyamorous/activerecord_5.2_ruby_2/join_dependency.rb +79 -0
  11. data/lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb +11 -0
  12. data/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb +1 -0
  13. data/lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb +80 -0
  14. data/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb +1 -0
  15. data/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb +74 -0
  16. data/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb +93 -0
  17. data/lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb +1 -0
  18. data/lib/polyamorous/join.rb +70 -0
  19. data/lib/polyamorous/polyamorous.rb +24 -0
  20. data/lib/polyamorous/swapping_reflection_class.rb +11 -0
  21. data/lib/polyamorous/tree_node.rb +7 -0
  22. data/lib/ransack/adapters/active_record/base.rb +23 -2
  23. data/lib/ransack/adapters/active_record/context.rb +206 -139
  24. data/lib/ransack/adapters/active_record/ransack/constants.rb +70 -55
  25. data/lib/ransack/adapters/active_record/ransack/context.rb +10 -18
  26. data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +43 -36
  27. data/lib/ransack/adapters/active_record/ransack/translate.rb +1 -5
  28. data/lib/ransack/adapters/active_record/ransack/visitor.rb +23 -0
  29. data/lib/ransack/adapters/active_record.rb +11 -10
  30. data/lib/ransack/adapters.rb +64 -0
  31. data/lib/ransack/configuration.rb +91 -4
  32. data/lib/ransack/constants.rb +13 -26
  33. data/lib/ransack/context.rb +45 -40
  34. data/lib/ransack/helpers/form_builder.rb +21 -12
  35. data/lib/ransack/helpers/form_helper.rb +99 -69
  36. data/lib/ransack/locale/ar.yml +70 -0
  37. data/lib/ransack/locale/az.yml +70 -0
  38. data/lib/ransack/locale/bg.yml +70 -0
  39. data/lib/ransack/locale/ca.yml +70 -0
  40. data/lib/ransack/locale/da.yml +70 -0
  41. data/lib/ransack/locale/de.yml +70 -0
  42. data/lib/ransack/locale/el.yml +70 -0
  43. data/lib/ransack/locale/es.yml +22 -22
  44. data/lib/ransack/locale/fa.yml +70 -0
  45. data/lib/ransack/locale/fi.yml +71 -0
  46. data/lib/ransack/locale/id.yml +70 -0
  47. data/lib/ransack/locale/it.yml +70 -0
  48. data/lib/ransack/locale/ja.yml +70 -0
  49. data/lib/ransack/locale/nl.yml +4 -4
  50. data/lib/ransack/locale/pt-BR.yml +70 -0
  51. data/lib/ransack/locale/ru.yml +70 -0
  52. data/lib/ransack/locale/sk.yml +70 -0
  53. data/lib/ransack/locale/tr.yml +70 -0
  54. data/lib/ransack/locale/{zh.yml → zh-CN.yml} +13 -13
  55. data/lib/ransack/locale/zh-TW.yml +70 -0
  56. data/lib/ransack/nodes/attribute.rb +6 -3
  57. data/lib/ransack/nodes/bindable.rb +18 -6
  58. data/lib/ransack/nodes/condition.rb +85 -24
  59. data/lib/ransack/nodes/grouping.rb +17 -11
  60. data/lib/ransack/nodes/sort.rb +9 -5
  61. data/lib/ransack/nodes/value.rb +74 -68
  62. data/lib/ransack/nodes.rb +2 -3
  63. data/lib/ransack/predicate.rb +17 -20
  64. data/lib/ransack/search.rb +15 -15
  65. data/lib/ransack/translate.rb +115 -115
  66. data/lib/ransack/version.rb +1 -1
  67. data/lib/ransack/visitor.rb +1 -12
  68. data/lib/ransack.rb +11 -17
  69. data/logo/ransack-h.png +0 -0
  70. data/logo/ransack-h.svg +34 -0
  71. data/logo/ransack-v.png +0 -0
  72. data/logo/ransack-v.svg +34 -0
  73. data/logo/ransack.png +0 -0
  74. data/logo/ransack.svg +21 -0
  75. data/ransack.gemspec +9 -27
  76. data/spec/console.rb +4 -0
  77. data/spec/helpers/polyamorous_helper.rb +19 -0
  78. data/spec/polyamorous/join_association_spec.rb +35 -0
  79. data/spec/polyamorous/join_dependency_spec.rb +97 -0
  80. data/spec/polyamorous/join_spec.rb +19 -0
  81. data/spec/ransack/adapters/active_record/base_spec.rb +380 -91
  82. data/spec/ransack/adapters/active_record/context_spec.rb +72 -33
  83. data/spec/ransack/configuration_spec.rb +87 -14
  84. data/spec/ransack/helpers/form_builder_spec.rb +2 -11
  85. data/spec/ransack/helpers/form_helper_spec.rb +481 -113
  86. data/spec/ransack/nodes/condition_spec.rb +25 -1
  87. data/spec/ransack/nodes/grouping_spec.rb +62 -6
  88. data/spec/ransack/predicate_spec.rb +79 -5
  89. data/spec/ransack/search_spec.rb +159 -79
  90. data/spec/spec_helper.rb +8 -0
  91. data/spec/support/schema.rb +99 -37
  92. metadata +57 -184
  93. data/lib/ransack/adapters/active_record/3.0/compat.rb +0 -179
  94. data/lib/ransack/adapters/active_record/3.0/context.rb +0 -205
  95. data/lib/ransack/adapters/active_record/3.1/context.rb +0 -219
  96. data/lib/ransack/adapters/active_record/3.2/context.rb +0 -44
  97. data/lib/ransack/adapters/active_record/compat.rb +0 -14
  98. data/lib/ransack/adapters/mongoid/3.2/.gitkeep +0 -0
  99. data/lib/ransack/adapters/mongoid/attributes/attribute.rb +0 -37
  100. data/lib/ransack/adapters/mongoid/attributes/order_predications.rb +0 -17
  101. data/lib/ransack/adapters/mongoid/attributes/predications.rb +0 -141
  102. data/lib/ransack/adapters/mongoid/base.rb +0 -126
  103. data/lib/ransack/adapters/mongoid/context.rb +0 -208
  104. data/lib/ransack/adapters/mongoid/inquiry_hash.rb +0 -23
  105. data/lib/ransack/adapters/mongoid/ransack/constants.rb +0 -88
  106. data/lib/ransack/adapters/mongoid/ransack/context.rb +0 -60
  107. data/lib/ransack/adapters/mongoid/ransack/nodes/condition.rb +0 -27
  108. data/lib/ransack/adapters/mongoid/ransack/translate.rb +0 -13
  109. data/lib/ransack/adapters/mongoid/ransack/visitor.rb +0 -24
  110. data/lib/ransack/adapters/mongoid/table.rb +0 -35
  111. data/lib/ransack/adapters/mongoid.rb +0 -13
  112. data/spec/mongoid/adapters/mongoid/base_spec.rb +0 -276
  113. data/spec/mongoid/adapters/mongoid/context_spec.rb +0 -56
  114. data/spec/mongoid/configuration_spec.rb +0 -102
  115. data/spec/mongoid/dependencies_spec.rb +0 -8
  116. data/spec/mongoid/helpers/ransack_helper.rb +0 -11
  117. data/spec/mongoid/nodes/condition_spec.rb +0 -34
  118. data/spec/mongoid/nodes/grouping_spec.rb +0 -13
  119. data/spec/mongoid/predicate_spec.rb +0 -155
  120. data/spec/mongoid/search_spec.rb +0 -446
  121. data/spec/mongoid/support/mongoid.yml +0 -6
  122. data/spec/mongoid/support/schema.rb +0 -128
  123. data/spec/mongoid/translate_spec.rb +0 -14
  124. data/spec/mongoid_spec_helper.rb +0 -59
  125. data/spec/ransack/dependencies_spec.rb +0 -10
data/CONTRIBUTING.md CHANGED
@@ -1,16 +1,20 @@
1
1
  # Contributing to Ransack
2
2
 
3
- Please take a moment to review this document in order to make the contribution
4
- process easy and effective for everyone involved!
3
+ Please take a moment to review this document to make contributing easy and
4
+ effective for everyone involved!
5
5
 
6
6
  Ransack is an open source project and we encourage contributions.
7
7
 
8
+ Please do not use the issue tracker for personal support requests. Stack
9
+ Overflow is a better place for that where a wider community can help you!
10
+
8
11
  ## Filing an issue
9
12
 
10
- A bug is a _demonstrable problem_ that is caused by the code in the repository.
11
- Good bug reports are extremely helpful! Please do not use the issue tracker for personal support requests.
13
+ Good issue reports are extremely helpful! Please only open an issue if a bug
14
+ is caused by Ransack, is new (has not already been reported), and can be
15
+ reproduced from the information you provide.
12
16
 
13
- Guidelines for bug reports:
17
+ Steps:
14
18
 
15
19
  1. **Use the GitHub issue search** — check if the issue has already been
16
20
  reported.
@@ -18,18 +22,25 @@ Guidelines for bug reports:
18
22
  2. **Check if the issue has been fixed** — try to reproduce it using the
19
23
  `master` branch in the repository.
20
24
 
21
- 3. **Isolate and report the problem** — ideally create a reduced test
22
- case.
25
+ 3. **Isolate the real problem** — make sure the issue is really a bug in
26
+ Ransack and not in your code or another gem.
27
+
28
+ 4. **Report the issue** by providing the link to a self-contained
29
+ gist like [this](https://gist.github.com/jonatack/63048bc5062a84ba9e09) or
30
+ [this](https://gist.github.com/jonatack/5df41a0edb53b7bad989). Please use
31
+ these code examples as a bug-report template for your Ransack issue!
23
32
 
24
- When filing an issue, please provide these details:
33
+ If you do not provide a self-contained gist and would like your issue to be reviewed, do provide at a minimum:
25
34
 
26
- * A comprehensive list of steps to reproduce the issue, or - far better - **a failing spec**.
27
- * The version (and branch) of Ransack *and* the versions of Rails, Ruby, and your operating system.
35
+ * A comprehensive list of steps to reproduce the issue, or even better, a
36
+ passing/failing test spec.
37
+ * Whether you are using Ransack through another gem like ActiveAdmin,
38
+ SimpleForm, etc.
39
+ * The versions of Ruby, Rails, Ransack and the database.
28
40
  * Any relevant stack traces ("Full trace" preferred).
29
41
 
30
- Any issue that is open for 14 days without actionable information or activity
31
- will be marked as "stalled" and then closed. Stalled issues can be re-opened
32
- if the information requested is provided.
42
+ Issues filed without the above information or that remain open without activity
43
+ for 14 days will be closed. They can be re-opened if actionable information to reproduce the issue is provided.
33
44
 
34
45
  ## Pull requests
35
46
 
@@ -53,6 +64,9 @@ Here's a quick guide:
53
64
  2. Create a thoughtfully-named branch for your changes (`git checkout -b my-new-feature`).
54
65
 
55
66
  3. Install the development dependencies by running `bundle install`.
67
+ To install rails other than latest (set in Gemfile): `RAILS='5-2-stable' bundle install`
68
+
69
+ $ RAILS='5-2-stable' bundle install
56
70
 
57
71
  4. Begin by running the tests. We only take pull requests with passing tests,
58
72
  and it's great to know that you have a clean slate:
@@ -61,11 +75,30 @@ Here's a quick guide:
61
75
 
62
76
  The test suite runs by default with SQLite3. To run the test suite with PostgreSQL or MySQL, use:
63
77
 
64
- $ DB=postgresql bundle exec rake spec (`DB=pg` & `DB=postgres` work too)
78
+ $ DB=pg bundle exec rake spec (`DB=postgres` & `DB=postgresql` work too)
65
79
  $ DB=mysql bundle exec rake spec
66
80
 
67
- 5. Hack away! Please use Ruby features that are compatible down to Ruby 1.9.
68
- Since version 1.5, Ransack no longer maintains Ruby 1.8 compatibility.
81
+ For Postgres and MySQL, databases are expected to exist, called 'ransack'. To create use these commands (assuming OS X and Homebrew):
82
+
83
+ ### Postgres
84
+ $ createdb ransack
85
+
86
+ ### MySQL
87
+ $ mysql -u root
88
+ mysql> create database ransack;
89
+
90
+ The test suite runs by default
91
+
92
+ To run only the tests in a particular file: `bundle exec rspec <path/to/filename>`
93
+
94
+ $ bundle exec rspec spec/ransack/search_spec.rb
95
+
96
+ To run a single test in that file: `bundle exec rspec <path/to/filename> -e "test name"`
97
+
98
+ $ bundle exec rspec spec/ransack/search_spec.rb -e "accepts a context option"
99
+
100
+ 5. Hack away! Please use Ruby features that are compatible down to Ruby 2.3.
101
+ Since version 2.3.1, Ransack no longer maintains Ruby 2.2 compatibility.
69
102
 
70
103
  6. Add tests for your changes. Only refactoring and documentation changes
71
104
  require no new tests. If you are adding functionality or fixing a bug, we
@@ -76,20 +109,24 @@ Here's a quick guide:
76
109
  8. Update the Change Log. If you are adding new functionality, document it in
77
110
  the README.
78
111
 
79
- 9. Commit your changes (`git commit -am 'Add feature/fix bug/improve docs'`).
112
+ 9. Make sure git knows your name and email address in your `~/.gitconfig` file:
113
+
114
+ $ git config --global user.name "Your Name"
115
+ $ git config --global user.email "contributor@example.com"
80
116
 
81
- 10. If necessary, rebase your commits into logical chunks, without errors. To
117
+ 10. Commit your changes (`git commit -am 'Add feature/fix bug/improve docs'`).
118
+ If your pull request only contains documentation changes, please remember
119
+ to add `[skip ci]` to the beginning of your commit message so the Travis
120
+ test suite doesn't :runner: needlessly.
121
+
122
+ 11. If necessary, rebase your commits into logical chunks, without errors. To
82
123
  interactively rebase and cherry-pick from, say, the last 10 commits:
83
124
  `git rebase -i HEAD~10`, then `git push -f`.
84
125
 
85
- 11. Push the branch up to your fork on Github
86
- (`git push origin my-new-feature`) and from Github submit a pull request to
126
+ 12. Push the branch up to your fork on GitHub
127
+ (`git push origin my-new-feature`) and from GitHub submit a pull request to
87
128
  Ransack's `master` branch.
88
129
 
89
- 12. If your pull request only contains documentation changes, please remember
90
- to add `[skip ci]` to the beginning of your commit message so the Travis
91
- test suite doesn't :runner: needlessly.
92
-
93
130
  At this point you're waiting on us. We like to at least comment on, if not
94
131
  accept, pull requests within three business days (and, typically, one business
95
132
  day). We may suggest some changes or improvements or alternatives.
@@ -107,11 +144,11 @@ Syntax:
107
144
  * 80 characters per line.
108
145
  * No trailing whitespace. Blank lines should not have any space.
109
146
  * Prefer `&&`/`||` over `and`/`or`.
110
- * `MyClass.my_method(my_arg)` not `my_method( my_arg )` or my_method my_arg.
147
+ * `MyClass.my_method(my_arg)` not `my_method( my_arg )` or `my_method my_arg`.
111
148
  * `a = b` and not `a=b`.
112
149
  * `a_method { |block| ... }` and not `a_method { | block | ... }` or
113
150
  `a_method{|block| ...}`.
114
151
  * Prefer simplicity, readability, and maintainability over terseness.
115
152
  * Follow the conventions you see used in the code already.
116
153
 
117
- And in case we didn't emphasize it enough: we love tests!
154
+ And in case we didn't emphasize it enough: We love tests!
data/Gemfile CHANGED
@@ -3,49 +3,49 @@ gemspec
3
3
 
4
4
  gem 'rake'
5
5
 
6
- rails = ENV['RAILS'] || '4-2-stable'
7
-
8
- if rails == 'master'
9
- gem 'arel', github: 'rails/arel'
10
- gem 'polyamorous', github: 'activerecord-hackery/polyamorous'
11
- else
12
- gem 'polyamorous', '~> 1.2'
13
- end
14
-
15
- gem 'pry'
16
-
17
- # Provide timezone information on Windows
18
- gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw]
6
+ rails = ENV['RAILS'] || '6-0-stable'
7
+
8
+ rails_version = case rails
9
+ when /\// # A path
10
+ File.read(File.join(rails, "RAILS_VERSION"))
11
+ when /^v/ # A tagged version
12
+ rails.gsub(/^v/, '')
13
+ else
14
+ rails
15
+ end
16
+
17
+ gem 'faker', '~> 1.0'
18
+ gem 'sqlite3', ::Gem::Version.new(rails_version) >= ::Gem::Version.new('6-0-stable') ? '~> 1.4.1' : '~> 1.3.3'
19
+ gem 'pg', '~> 1.0'
20
+ gem 'pry', '~> 0.12.2'
21
+ gem 'byebug'
19
22
 
20
23
  case rails
21
24
  when /\// # A path
22
25
  gem 'activesupport', path: "#{rails}/activesupport"
26
+ gem 'activemodel', path: "#{rails}/activemodel"
23
27
  gem 'activerecord', path: "#{rails}/activerecord", require: false
24
28
  gem 'actionpack', path: "#{rails}/actionpack"
29
+ gem 'actionview', path: "#{rails}/actionview"
25
30
  when /^v/ # A tagged version
26
- git 'git://github.com/rails/rails.git', :tag => rails do
31
+ git 'https://github.com/rails/rails.git', :tag => rails do
27
32
  gem 'activesupport'
28
33
  gem 'activemodel'
29
34
  gem 'activerecord', require: false
30
35
  gem 'actionpack'
31
36
  end
32
37
  else
33
- git 'git://github.com/rails/rails.git', :branch => rails do
38
+ git 'https://github.com/rails/rails.git', :branch => rails do
34
39
  gem 'activesupport'
35
40
  gem 'activemodel'
36
41
  gem 'activerecord', require: false
37
42
  gem 'actionpack'
38
43
  end
39
- if rails == '3-0-stable'
40
- gem 'mysql2', '< 0.3'
41
- end
42
- end
43
-
44
- if ENV['DB'] =~ /mongodb/
45
- gem 'mongoid', '~> 4.0.0', require: false
46
44
  end
45
+ gem 'mysql2', '~> 0.5.2'
47
46
 
48
- # Removed from Ruby 2.2 but needed for testing Rails 3.x.
49
47
  group :test do
50
- gem 'test-unit', '~> 3.0' if RUBY_VERSION >= '2.2'
48
+ gem 'machinist', '~> 1.0.6'
49
+ gem 'rspec', '~> 3'
50
+ gem 'simplecov', :require => false
51
51
  end