ransack 2.4.1 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/cronjob.yml +102 -0
  3. data/.github/workflows/rubocop.yml +20 -0
  4. data/.github/workflows/test.yml +43 -18
  5. data/.rubocop.yml +44 -0
  6. data/CHANGELOG.md +22 -4
  7. data/CONTRIBUTING.md +6 -5
  8. data/Gemfile +4 -2
  9. data/README.md +76 -10
  10. data/bug_report_templates/test-ransack-scope-and-column-same-name.rb +78 -0
  11. data/bug_report_templates/test-ransacker-arel-present-predicate.rb +71 -0
  12. data/docs/img/create_release.png +0 -0
  13. data/docs/release_process.md +17 -0
  14. data/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb +20 -1
  15. data/lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb +0 -1
  16. data/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb +11 -1
  17. data/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb +0 -4
  18. data/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb +0 -1
  19. data/lib/polyamorous/activerecord_7.0_ruby_2/join_association.rb +1 -0
  20. data/lib/polyamorous/activerecord_7.0_ruby_2/join_dependency.rb +1 -0
  21. data/lib/polyamorous/activerecord_7.0_ruby_2/reflection.rb +1 -0
  22. data/lib/polyamorous/polyamorous.rb +1 -1
  23. data/lib/polyamorous.rb +1 -0
  24. data/lib/ransack/adapters/active_record/base.rb +1 -1
  25. data/lib/ransack/adapters/active_record/context.rb +9 -5
  26. data/lib/ransack/adapters/active_record/ransack/constants.rb +1 -1
  27. data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +10 -9
  28. data/lib/ransack/configuration.rb +16 -2
  29. data/lib/ransack/constants.rb +2 -3
  30. data/lib/ransack/helpers/form_builder.rb +3 -3
  31. data/lib/ransack/helpers/form_helper.rb +1 -1
  32. data/lib/ransack/helpers.rb +1 -1
  33. data/lib/ransack/locale/sv.yml +70 -0
  34. data/lib/ransack/nodes/attribute.rb +1 -1
  35. data/lib/ransack/nodes/condition.rb +0 -2
  36. data/lib/ransack/nodes/sort.rb +3 -3
  37. data/lib/ransack/nodes/value.rb +1 -1
  38. data/lib/ransack/search.rb +2 -1
  39. data/lib/ransack/translate.rb +1 -1
  40. data/lib/ransack/version.rb +1 -1
  41. data/lib/ransack.rb +2 -2
  42. data/ransack.gemspec +6 -5
  43. data/spec/blueprints/articles.rb +1 -1
  44. data/spec/blueprints/comments.rb +1 -1
  45. data/spec/blueprints/notes.rb +1 -1
  46. data/spec/blueprints/tags.rb +1 -1
  47. data/spec/console.rb +5 -5
  48. data/spec/helpers/ransack_helper.rb +1 -1
  49. data/spec/polyamorous/activerecord_compatibility_spec.rb +15 -0
  50. data/spec/polyamorous/join_association_spec.rb +1 -6
  51. data/spec/polyamorous/join_dependency_spec.rb +0 -16
  52. data/spec/ransack/adapters/active_record/base_spec.rb +20 -13
  53. data/spec/ransack/adapters/active_record/context_spec.rb +1 -2
  54. data/spec/ransack/configuration_spec.rb +14 -0
  55. data/spec/ransack/helpers/form_helper_spec.rb +17 -18
  56. data/spec/ransack/nodes/condition_spec.rb +13 -0
  57. data/spec/ransack/nodes/grouping_spec.rb +2 -2
  58. data/spec/ransack/predicate_spec.rb +1 -1
  59. data/spec/ransack/search_spec.rb +117 -27
  60. data/spec/spec_helper.rb +7 -6
  61. data/spec/support/schema.rb +33 -2
  62. metadata +25 -14
  63. data/lib/polyamorous/activerecord_5.2_ruby_2/join_association.rb +0 -24
  64. data/lib/polyamorous/activerecord_5.2_ruby_2/join_dependency.rb +0 -79
  65. data/lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c8153add4e8f7cc4123bb1c6b7f8b6f4db1fdbb65c2d8498a61ef7fc98eea53
4
- data.tar.gz: 1bae6d37282b621109534060b7c32ecbff7c02366cff88d271d48607ca6fd4cb
3
+ metadata.gz: 613abc9bb025f01243aa427878dec0cb7e990e3a9deb3e1436b7f0f3b124bf44
4
+ data.tar.gz: 1466899c236bc6c9d1e95fc5262b5b3d6cde18f51929273168ff3286ead4be34
5
5
  SHA512:
6
- metadata.gz: ec86fcdc8b81a73c77f3da4e3e9eb2ce7480cae4ce948d64c55d5514d836474fe0c60c727be5d1bca39814afdc96c8bd997e2d245d557689badea217fce67f92
7
- data.tar.gz: 6526a66311015b73c4132d7c1b95b2006526cf929c47cb5aec91fc79287f07eb0df85a47d22e47d2b88547796501ce8ecb57c81c044e0113f716e45e516b151d
6
+ metadata.gz: 2d8f6c96d9b0d4af4d5d64c3aa24cbe79abefe78388ff35637577a46b99b99decf25e51433368634ae557a72707470a9291c62ca33cae15b7ce0edb51b682712
7
+ data.tar.gz: 66bcf53be5d9f201f0e51db95140a56b29e3d61c0b9d79fbd3238e3e67a2b0bb5463dc08ebf445155d502f1b8bfb87b0be38040521219733a852471f32385e0b
@@ -0,0 +1,102 @@
1
+ name: cronjob
2
+
3
+ on:
4
+ schedule:
5
+ - cron: "0 0 * * *"
6
+
7
+ jobs:
8
+ sqlite3:
9
+ runs-on: ubuntu-20.04
10
+ strategy:
11
+ fail-fast: false
12
+ matrix:
13
+ ruby:
14
+ - 3.0.2
15
+ - 2.7.4
16
+ env:
17
+ DB: sqlite3
18
+ RAILS: main
19
+ steps:
20
+ - uses: actions/checkout@v2
21
+ - name: Set up Ruby
22
+ uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: ${{ matrix.ruby }}
25
+ - name: Install dependencies
26
+ run: bundle install
27
+ - name: Run tests
28
+ run: bundle exec rspec
29
+
30
+ mysql:
31
+ runs-on: ubuntu-20.04
32
+ strategy:
33
+ fail-fast: false
34
+ matrix:
35
+ ruby:
36
+ - 3.0.2
37
+ - 2.7.4
38
+ env:
39
+ DB: mysql
40
+ RAILS: main
41
+ MYSQL_USERNAME: root
42
+ MYSQL_PASSWORD: root
43
+ steps:
44
+ - uses: actions/checkout@v2
45
+ - name: Set up Ruby
46
+ uses: ruby/setup-ruby@v1
47
+ with:
48
+ ruby-version: ${{ matrix.ruby }}
49
+ - name: Startup MySQL
50
+ run: |
51
+ sudo systemctl start mysql.service
52
+ - name: Setup databases
53
+ run: |
54
+ mysql --user=root --password=root --host=127.0.0.1 -e 'create database ransack collate utf8_general_ci;';
55
+ mysql --user=root --password=root --host=127.0.0.1 -e 'use ransack;show variables like "%character%";show variables like "%collation%";';
56
+ - name: Install dependencies
57
+ run: bundle install
58
+ - name: Run tests
59
+ run: bundle exec rspec
60
+
61
+ postgres:
62
+ runs-on: ubuntu-20.04
63
+ strategy:
64
+ fail-fast: false
65
+ matrix:
66
+ ruby:
67
+ - 3.0.2
68
+ - 2.7.4
69
+ env:
70
+ DB: postgres
71
+ RAILS: main
72
+ DATABASE_USERNAME: postgres
73
+ DATABASE_PASSWORD: postgres
74
+ DATABASE_HOST: 127.0.0.1
75
+ services:
76
+ postgres:
77
+ image: postgres
78
+ ports:
79
+ - 5432:5432
80
+ env:
81
+ POSTGRES_PASSWORD: postgres
82
+ POSTGRES_HOST_AUTH_METHOD: trust
83
+ # Set health checks to wait until postgres has started
84
+ options: >-
85
+ --health-cmd pg_isready
86
+ --health-interval 10s
87
+ --health-timeout 5s
88
+ --health-retries 5
89
+
90
+ steps:
91
+ - uses: actions/checkout@v2
92
+ - name: Set up Ruby
93
+ uses: ruby/setup-ruby@v1
94
+ with:
95
+ ruby-version: ${{ matrix.ruby }}
96
+ - name: Setup databases
97
+ run: |
98
+ psql -h localhost -p 5432 -W postgres -c 'create database ransack;' -U postgres;
99
+ - name: Install dependencies
100
+ run: bundle install
101
+ - name: Run tests
102
+ run: bundle exec rspec
@@ -0,0 +1,20 @@
1
+ name: rubocop
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+
7
+ jobs:
8
+ build:
9
+ runs-on: ubuntu-20.04
10
+
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ - name: Set up Ruby
14
+ uses: ruby/setup-ruby@v1
15
+ with:
16
+ ruby-version: 3.0.1
17
+ - name: Install gems
18
+ run: bundle install --jobs 4 --retry 3
19
+ - name: Run RuboCop
20
+ run: bundle exec rubocop --parallel
@@ -11,14 +11,17 @@ jobs:
11
11
  fail-fast: false
12
12
  matrix:
13
13
  rails:
14
- - v6.1.0.rc2
15
- - v6.0.3
14
+ - v7.0.0
15
+ - v6.1.4
16
+ - v6.0.4
16
17
  - 6-0-stable
17
- - 5-2-stable
18
- - v5.2.4
19
18
  ruby:
20
- - 2.7.2
21
- - 2.6.6
19
+ - 3.0.2
20
+ - 2.7.4
21
+ - 2.6.7
22
+ exclude:
23
+ - rails: v7.0.0
24
+ ruby: 2.6.7
22
25
  env:
23
26
  DB: sqlite3
24
27
  RAILS: ${{ matrix.rails }}
@@ -39,14 +42,17 @@ jobs:
39
42
  fail-fast: false
40
43
  matrix:
41
44
  rails:
42
- - v6.1.0.rc2
43
- - v6.0.3
45
+ - v7.0.0
46
+ - v6.1.4
47
+ - v6.0.4
44
48
  - 6-0-stable
45
- - 5-2-stable
46
- - v5.2.4
47
49
  ruby:
48
- - 2.7.2
49
- - 2.6.6
50
+ - 3.0.2
51
+ - 2.7.4
52
+ - 2.6.7
53
+ exclude:
54
+ - rails: v7.0.0
55
+ ruby: 2.6.7
50
56
  env:
51
57
  DB: mysql
52
58
  RAILS: ${{ matrix.rails }}
@@ -76,14 +82,17 @@ jobs:
76
82
  fail-fast: false
77
83
  matrix:
78
84
  rails:
79
- - v6.1.0.rc2
80
- - v6.0.3
85
+ - v7.0.0
86
+ - v6.1.4
87
+ - v6.0.4
81
88
  - 6-0-stable
82
- - 5-2-stable
83
- - v5.2.4
84
89
  ruby:
85
- - 2.7.2
86
- - 2.6.6
90
+ - 3.0.2
91
+ - 2.7.4
92
+ - 2.6.7
93
+ exclude:
94
+ - rails: v7.0.0
95
+ ruby: 2.6.7
87
96
  env:
88
97
  DB: postgres
89
98
  RAILS: ${{ matrix.rails }}
@@ -118,3 +127,19 @@ jobs:
118
127
  run: bundle install
119
128
  - name: Run tests
120
129
  run: bundle exec rspec
130
+
131
+ bug-report-templates:
132
+ runs-on: ubuntu-20.04
133
+ steps:
134
+ - uses: actions/checkout@v2
135
+ - name: Set up Ruby
136
+ uses: ruby/setup-ruby@v1
137
+ with:
138
+ ruby-version: 3.0.2
139
+ - name: Install dependencies
140
+ run: bundle install
141
+ - name: Run bug report templates
142
+ run: |
143
+ ruby bug_report_templates/test-ransacker-arel-present-predicate.rb
144
+ ruby bug_report_templates/test-ransack-scope-and-column-same-name.rb
145
+ rm Gemfile Gemfile.lock
data/.rubocop.yml ADDED
@@ -0,0 +1,44 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ DisabledByDefault: true
5
+
6
+ Layout/EmptyLineAfterMagicComment:
7
+ Enabled: true
8
+
9
+ Layout/EmptyLineBetweenDefs:
10
+ Enabled: true
11
+
12
+ Layout/EmptyLines:
13
+ Enabled: true
14
+
15
+ Layout/FirstArrayElementIndentation:
16
+ EnforcedStyle: consistent
17
+
18
+ Layout/SpaceAfterComma:
19
+ Enabled: true
20
+
21
+ Layout/SpaceInsideBlockBraces:
22
+ Enabled: true
23
+
24
+ Layout/SpaceInsideHashLiteralBraces:
25
+ Enabled: true
26
+
27
+ Layout/SpaceInsideParens:
28
+ Enabled: true
29
+
30
+ Layout/TrailingEmptyLines:
31
+ Enabled: true
32
+
33
+ Style/RedundantFileExtensionInRequire:
34
+ Enabled: true
35
+
36
+ Style/RedundantReturn:
37
+ Enabled: true
38
+
39
+ Style/SelfAssignment:
40
+ Enabled: true
41
+
42
+ Style/Semicolon:
43
+ Enabled: true
44
+
data/CHANGELOG.md CHANGED
@@ -1,14 +1,32 @@
1
1
  # Change Log
2
2
 
3
+ ## Unreleased
4
+
5
+ ## 2.6.0 - 2022-03-08
6
+
7
+ * Fix regression when joining a table with itself.
8
+ PR [1275](https://github.com/activerecord-hackery/ransack/pull/1276)
9
+
10
+ * Drop support for ActiveRecord older than 6.0.4.
11
+ PR [1276](https://github.com/activerecord-hackery/ransack/pull/1276)
12
+
13
+ ## 2.5.0 - 2021-12-26
14
+
15
+ * ActiveRecord 7.0 support
16
+
17
+ * Drop support for rubies under 2.5. PR #1189
18
+
19
+ * Have casted array predicates type checked to Arel::Nodes::Casted fixing non-casted array predicates.
20
+ PR [1246](https://github.com/activerecord-hackery/ransack/pull/1246)
21
+
22
+ ## 2.4.1 - 2020-12-21
23
+
3
24
  * Add `ActiveRecord::Base.ransack!` which raises error if passed unknown condition
4
25
 
5
26
  *Aaron Lipman*
6
27
 
7
28
  ## 2.4.0 - 2020-11-27
8
29
 
9
- *
10
- PR []()
11
-
12
30
  * Support ActiveRecord 6.1.0.rc1.
13
31
  PR [1172](https://github.com/activerecord-hackery/ransack/pull/1172)
14
32
 
@@ -199,7 +217,7 @@
199
217
  ignored when block parameter is specified.
200
218
  PR [#818](https://github.com/activerecord-hackery/ransack/pull/818).
201
219
 
202
- * No need pass some arugments to JoinAssociation#join_constraints in Rails 5.1.
220
+ * No need pass some arguments to JoinAssociation#join_constraints in Rails 5.1.
203
221
  PR [#814](https://github.com/activerecord-hackery/ransack/pull/814).
204
222
  Fixes [#807](https://github.com/activerecord-hackery/ransack/issues/807).
205
223
  Reference [rails/rails#28267](https://github.com/rails/rails/pull/28267)
data/CONTRIBUTING.md CHANGED
@@ -26,8 +26,8 @@ Steps:
26
26
  Ransack and not in your code or another gem.
27
27
 
28
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
29
+ gist like [this](https://github.com/activerecord-hackery/ransack/blob/run_bug_report_templates/bug_report_templates/test-ransack-scope-and-column-same-name.rb) or
30
+ [this](https://github.com/activerecord-hackery/ransack/blob/run_bug_report_templates/bug_report_templates/test-ransacker-arel-present-predicate.rb). Please use
31
31
  these code examples as a bug-report template for your Ransack issue!
32
32
 
33
33
  If you do not provide a self-contained gist and would like your issue to be reviewed, do provide at a minimum:
@@ -64,9 +64,7 @@ Here's a quick guide:
64
64
  2. Create a thoughtfully-named branch for your changes (`git checkout -b my-new-feature`).
65
65
 
66
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
67
+ To install rails other than latest (set in Gemfile): `RAILS='6-0-stable' bundle install`
70
68
 
71
69
  4. Begin by running the tests. We only take pull requests with passing tests,
72
70
  and it's great to know that you have a clean slate:
@@ -115,6 +113,9 @@ Here's a quick guide:
115
113
  $ git config --global user.email "contributor@example.com"
116
114
 
117
115
  10. Commit your changes (`git commit -am 'Add feature/fix bug/improve docs'`).
116
+ If your pull request only contains documentation changes, please remember
117
+ to add `[skip ci]` to the beginning of your commit message so the CI
118
+ test suite doesn't :runner: needlessly.
118
119
 
119
120
  11. If necessary, rebase your commits into logical chunks, without errors. To
120
121
  interactively rebase and cherry-pick from, say, the last 10 commits:
data/Gemfile CHANGED
@@ -14,8 +14,8 @@ rails_version = case rails
14
14
  rails
15
15
  end
16
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'
17
+ gem 'faker', '~> 2.0'
18
+ gem 'sqlite3', ::Gem::Version.new(rails_version == 'main' ? '6.2.0.alpha' : rails_version) >= ::Gem::Version.new('6-0-stable') ? '~> 1.4.1' : '~> 1.3.3'
19
19
  gem 'pg', '~> 1.0'
20
20
  gem 'pry', '~> 0.12.2'
21
21
  gem 'byebug'
@@ -49,3 +49,5 @@ group :test do
49
49
  gem 'rspec', '~> 3'
50
50
  gem 'simplecov', :require => false
51
51
  end
52
+
53
+ gem 'rubocop', require: false
data/README.md CHANGED
@@ -11,13 +11,11 @@ Ransack enables the creation of both
11
11
  for your Ruby on Rails application
12
12
  ([demo source code here](https://github.com/activerecord-hackery/ransack_demo)).
13
13
  If you're looking for something that simplifies query generation at the model
14
- or controller layer, you're probably not looking for Ransack (or MetaSearch,
15
- for that matter). Try [Squeel](https://github.com/activerecord-hackery/squeel)
16
- instead.
14
+ or controller layer, you're probably not looking for Ransack.
17
15
 
18
16
  ## Getting started
19
17
 
20
- Ransack is supported for Rails 6.1, 6.0, 5.2 on Ruby 2.6.6 and later.
18
+ Ransack is supported for Rails 7.0, 6.x on Ruby 2.6.6 and later.
21
19
 
22
20
  In your Gemfile, for the last officially released gem:
23
21
 
@@ -65,19 +63,18 @@ this example, with preloading each Person's Articles and pagination):
65
63
  def index
66
64
  @q = Person.ransack(params[:q])
67
65
  @people = @q.result.includes(:articles).page(params[:page])
68
-
69
- # or use `to_a.uniq` to remove duplicates (can also be done in the view):
70
- @people = @q.result.includes(:articles).page(params[:page]).to_a.uniq
71
66
  end
72
67
  ```
73
68
 
74
- ##### Default search parameter
69
+ ##### Default search options
70
+
71
+ **Search parameter**
75
72
 
76
73
  Ransack uses a default `:q` param key for search params. This may be changed by
77
74
  setting the `search_key` option in a Ransack initializer file (typically
78
75
  `config/initializers/ransack.rb`):
79
76
 
80
- ```
77
+ ```ruby
81
78
  Ransack.configure do |c|
82
79
  # Change default search parameter key name.
83
80
  # Default key name is :q
@@ -85,6 +82,19 @@ Ransack.configure do |c|
85
82
  end
86
83
  ```
87
84
 
85
+ **String search**
86
+
87
+ After version 2.4.0 when searching a string query Ransack by default strips all whitespace around the query string.
88
+ This may be disabled by setting the `strip_whitespace` option in a Ransack initializer file:
89
+
90
+ ```ruby
91
+ Ransack.configure do |c|
92
+ # Change whitespace stripping behaviour.
93
+ # Default is true
94
+ c.strip_whitespace = false
95
+ end
96
+ ```
97
+
88
98
  #### In your view
89
99
 
90
100
  The two primary Ransack view helpers are `search_form_for` and `sort_link`,
@@ -263,8 +273,45 @@ Ransack.configure do |c|
263
273
  end
264
274
  ```
265
275
 
276
+ To treat nulls as having the lowest or highest value respectively. To force nulls to always be first or last, use
277
+
278
+ ```rb
279
+ Ransack.configure do |c|
280
+ c.postgres_fields_sort_option = :nulls_always_first # or :nulls_always_last
281
+ end
282
+ ```
283
+
266
284
  See this feature: https://www.postgresql.org/docs/13/queries-order.html
267
285
 
286
+ #### Case Insensitive Sorting in PostgreSQL
287
+
288
+ In order to request PostgreSQL to do a case insensitive sort for all string columns of a model at once, Ransack can be extended by using this approach:
289
+
290
+ ```ruby
291
+ module RansackObject
292
+
293
+ def self.included(base)
294
+ base.columns.each do |column|
295
+ if column.type == :string
296
+ base.ransacker column.name.to_sym, type: :string do
297
+ Arel.sql("lower(#{base.table_name}.#{column.name})")
298
+ end
299
+ end
300
+ end
301
+ end
302
+ end
303
+ ```
304
+
305
+ ```ruby
306
+ class UserWithManyAttributes < ActiveRecord::Base
307
+ include RansackObject
308
+ end
309
+ ```
310
+
311
+ If this approach is taken, it is advisable to [add a functional index](https://www.postgresql.org/docs/13/citext.html).
312
+
313
+ This was originally asked in [a Ransack issue](https://github.com/activerecord-hackery/ransack/issues/1201) and a solution was found on [Stack Overflow](https://stackoverflow.com/a/34677378).
314
+
268
315
  ### Advanced Mode
269
316
 
270
317
  "Advanced" searches (ab)use Rails' nested attributes functionality in order to
@@ -423,6 +470,25 @@ query parameters in your URLs.
423
470
  <% end %>
424
471
  ```
425
472
 
473
+ You can also use `ransack_alias` for sorting.
474
+
475
+ ```ruby
476
+ class Post < ActiveRecord::Base
477
+ belongs_to :author
478
+
479
+ # Abbreviate :author_first_name to :author
480
+ ransack_alias :author, :author_first_name
481
+ end
482
+ ```
483
+
484
+ Now, you can use `:author` instead of `:author_first_name` in a `sort_link`.
485
+
486
+ ```erb
487
+ <%= sort_link(@q, :author) %>
488
+ ```
489
+
490
+ Note that using `:author_first_name_or_author_last_name_cont` would produce an invalid sql query. In those cases, Ransack ignores the sorting clause.
491
+
426
492
  ### Search Matchers
427
493
 
428
494
  List of all possible predicates
@@ -719,7 +785,7 @@ Article.ransack!(unknown_attr_eq: 'Ernie')
719
785
  # ArgumentError: Invalid search term unknown_attr_eq
720
786
  ```
721
787
 
722
- This is equivilent to the `ignore_unknown_conditions` configuration option,
788
+ This is equivalent to the `ignore_unknown_conditions` configuration option,
723
789
  except it may be applied on a case-by-case basis.
724
790
 
725
791
  ### Using Scopes/Class Methods
@@ -0,0 +1,78 @@
1
+ # test-ransack-scope-and-column-same-name.rb
2
+
3
+ # This is a stand-alone test case.
4
+
5
+ # Run it in your console with: `ruby test-ransack-scope-and-column-same-name.rb`
6
+
7
+ # If you change the gem dependencies, run it with:
8
+ # `rm gemfile* && ruby test-ransack-scope-and-column-same-name.rb`
9
+
10
+ unless File.exist?('Gemfile')
11
+ File.write('Gemfile', <<-GEMFILE)
12
+ source 'https://rubygems.org'
13
+
14
+ # Rails master
15
+ gem 'rails', github: 'rails/rails', branch: '6-1-stable'
16
+
17
+ # Rails last release
18
+ # gem 'rails'
19
+
20
+ gem 'sqlite3'
21
+ gem 'ransack', github: 'activerecord-hackery/ransack'
22
+ GEMFILE
23
+
24
+ system 'bundle install'
25
+ end
26
+
27
+ require 'bundler'
28
+ Bundler.setup(:default)
29
+
30
+ require 'active_record'
31
+ require 'minitest/autorun'
32
+ require 'logger'
33
+ require 'ransack'
34
+
35
+ # This connection will do for database-independent bug reports.
36
+ ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
37
+ ActiveRecord::Base.logger = Logger.new(STDOUT)
38
+
39
+ # Display versions.
40
+ message = "Running test case with Ruby #{RUBY_VERSION}, Active Record #{
41
+ ::ActiveRecord::VERSION::STRING}, Arel #{Arel::VERSION} and #{
42
+ ::ActiveRecord::Base.connection.adapter_name}"
43
+ line = '=' * message.length
44
+ puts line, message, line
45
+
46
+ ActiveRecord::Schema.define do
47
+ create_table :users, force: true do |t|
48
+ t.boolean :active, null: false, default: true
49
+ end
50
+ end
51
+
52
+ class User < ActiveRecord::Base
53
+ scope :activated, -> (boolean = true) { where(active: boolean) }
54
+
55
+ private
56
+
57
+ def self.ransackable_scopes(auth_object = nil)
58
+ %i(activated)
59
+ end
60
+ end
61
+
62
+ class BugTest < Minitest::Test
63
+ def test_activated_scope_equals_true
64
+ sql = User.ransack({ activated: true }).result.to_sql
65
+ puts sql
66
+ assert_equal(
67
+ "SELECT \"users\".* FROM \"users\" WHERE \"users\".\"active\" = 1", sql
68
+ )
69
+ end
70
+
71
+ def test_activated_scope_equals_false
72
+ sql = User.ransack({ activated: false }).result.to_sql
73
+ puts sql
74
+ assert_equal(
75
+ "SELECT \"users\".* FROM \"users\"", sql
76
+ )
77
+ end
78
+ end
@@ -0,0 +1,71 @@
1
+ # test-ransacker-arel-present-predicate.rb
2
+
3
+ # Run it in your console with: `ruby test-ransacker-arel-present-predicate.rb`
4
+
5
+ # If you change the gem dependencies, run it with:
6
+ # `rm gemfile* && ruby test-ransacker-arel-present-predicate.rb`
7
+
8
+ unless File.exist?('Gemfile')
9
+ File.write('Gemfile', <<-GEMFILE)
10
+ source 'https://rubygems.org'
11
+
12
+ # Rails master
13
+ gem 'rails', github: 'rails/rails', branch: '6-1-stable'
14
+
15
+ # Rails last release
16
+ # gem 'rails'
17
+
18
+ gem 'sqlite3'
19
+ gem 'ransack', github: 'activerecord-hackery/ransack'
20
+ GEMFILE
21
+
22
+ system 'bundle install'
23
+ end
24
+
25
+ require 'bundler'
26
+ Bundler.setup(:default)
27
+
28
+ require 'active_record'
29
+ require 'minitest/autorun'
30
+ require 'logger'
31
+ require 'ransack'
32
+
33
+ # This connection will do for database-independent bug reports.
34
+ ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
35
+ ActiveRecord::Base.logger = Logger.new(STDOUT)
36
+
37
+ # Display versions.
38
+ message = "Running test case with Ruby #{RUBY_VERSION}, Active Record #{
39
+ ::ActiveRecord::VERSION::STRING}, Arel #{Arel::VERSION} and #{
40
+ ::ActiveRecord::Base.connection.adapter_name}"
41
+ line = '=' * message.length
42
+ puts line, message, line
43
+
44
+ ActiveRecord::Schema.define do
45
+ create_table :projects, force: true do |t|
46
+ t.string :name
47
+ t.string :number
48
+ end
49
+ end
50
+
51
+ class Project < ActiveRecord::Base
52
+ ransacker :name do
53
+ Arel.sql('projects.name')
54
+ end
55
+
56
+ ransacker :number do |parent|
57
+ parent.table[:number]
58
+ end
59
+ end
60
+
61
+ class BugTest < Minitest::Test
62
+ def test_ransackers
63
+ sql = Project.ransack({ number_present: 1 }).result.to_sql
64
+ puts sql
65
+ assert_equal "SELECT \"projects\".* FROM \"projects\" WHERE (\"projects\".\"number\" IS NOT NULL AND \"projects\".\"number\" != '')", sql
66
+
67
+ sql = Project.ransack({ name_present: 1 }).result.to_sql
68
+ puts sql
69
+ assert_equal "SELECT \"projects\".* FROM \"projects\" WHERE (projects.name IS NOT NULL AND projects.name != '')", sql
70
+ end
71
+ end
Binary file
@@ -0,0 +1,17 @@
1
+ ## Release Process
2
+
3
+ *For maintainers of Ransack.*
4
+
5
+ To release a new version of Ransack and publish it to RubyGems, take the following steps:
6
+
7
+ - Create a new release, marked `Prerelease`.
8
+ - Update the versions file to the new release, commit and push to `master`.
9
+ - Update the [`version.rb`](../lib/ransack/version.rb) file to the new release, commit and push to `master`.
10
+ - From the terminal, run the following commands:
11
+
12
+ ```bash
13
+ rake build
14
+ rake release
15
+ ```
16
+
17
+ ![Create a Release](img/create_release.png)