ransack 2.4.0 → 2.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +3 -0
- data/.github/SECURITY.md +12 -0
- data/.github/workflows/test.yml +120 -0
- data/CHANGELOG.md +4 -0
- data/CONTRIBUTING.md +0 -3
- data/README.md +95 -25
- data/lib/ransack/adapters/active_record/base.rb +4 -0
- data/lib/ransack/adapters/active_record/context.rb +7 -0
- data/lib/ransack/configuration.rb +17 -1
- data/lib/ransack/search.rb +2 -1
- data/lib/ransack/version.rb +1 -1
- data/spec/ransack/adapters/active_record/base_spec.rb +4 -0
- data/spec/ransack/configuration_spec.rb +10 -0
- data/spec/ransack/search_spec.rb +49 -2
- data/spec/support/schema.rb +2 -0
- metadata +5 -3
- data/.travis.yml +0 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c8153add4e8f7cc4123bb1c6b7f8b6f4db1fdbb65c2d8498a61ef7fc98eea53
|
4
|
+
data.tar.gz: 1bae6d37282b621109534060b7c32ecbff7c02366cff88d271d48607ca6fd4cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec86fcdc8b81a73c77f3da4e3e9eb2ce7480cae4ce948d64c55d5514d836474fe0c60c727be5d1bca39814afdc96c8bd997e2d245d557689badea217fce67f92
|
7
|
+
data.tar.gz: 6526a66311015b73c4132d7c1b95b2006526cf929c47cb5aec91fc79287f07eb0df85a47d22e47d2b88547796501ce8ecb57c81c044e0113f716e45e516b151d
|
data/.github/FUNDING.yml
ADDED
data/.github/SECURITY.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# Security Policy
|
2
|
+
|
3
|
+
## Supported Versions
|
4
|
+
|
5
|
+
At the moment, only the latest major.minor release stream is supported with
|
6
|
+
security updates.
|
7
|
+
|
8
|
+
## Reporting a Vulnerability
|
9
|
+
|
10
|
+
Please use the Tidelift security contact to [report a security
|
11
|
+
vulnerability](https://tidelift.com/security). Tidelift will coordinate the fix
|
12
|
+
and disclosure.
|
@@ -0,0 +1,120 @@
|
|
1
|
+
name: test
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
pull_request:
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
sqlite3:
|
9
|
+
runs-on: ubuntu-20.04
|
10
|
+
strategy:
|
11
|
+
fail-fast: false
|
12
|
+
matrix:
|
13
|
+
rails:
|
14
|
+
- v6.1.0.rc2
|
15
|
+
- v6.0.3
|
16
|
+
- 6-0-stable
|
17
|
+
- 5-2-stable
|
18
|
+
- v5.2.4
|
19
|
+
ruby:
|
20
|
+
- 2.7.2
|
21
|
+
- 2.6.6
|
22
|
+
env:
|
23
|
+
DB: sqlite3
|
24
|
+
RAILS: ${{ matrix.rails }}
|
25
|
+
steps:
|
26
|
+
- uses: actions/checkout@v2
|
27
|
+
- name: Set up Ruby
|
28
|
+
uses: ruby/setup-ruby@v1
|
29
|
+
with:
|
30
|
+
ruby-version: ${{ matrix.ruby }}
|
31
|
+
- name: Install dependencies
|
32
|
+
run: bundle install
|
33
|
+
- name: Run tests
|
34
|
+
run: bundle exec rspec
|
35
|
+
|
36
|
+
mysql:
|
37
|
+
runs-on: ubuntu-20.04
|
38
|
+
strategy:
|
39
|
+
fail-fast: false
|
40
|
+
matrix:
|
41
|
+
rails:
|
42
|
+
- v6.1.0.rc2
|
43
|
+
- v6.0.3
|
44
|
+
- 6-0-stable
|
45
|
+
- 5-2-stable
|
46
|
+
- v5.2.4
|
47
|
+
ruby:
|
48
|
+
- 2.7.2
|
49
|
+
- 2.6.6
|
50
|
+
env:
|
51
|
+
DB: mysql
|
52
|
+
RAILS: ${{ matrix.rails }}
|
53
|
+
MYSQL_USERNAME: root
|
54
|
+
MYSQL_PASSWORD: root
|
55
|
+
steps:
|
56
|
+
- uses: actions/checkout@v2
|
57
|
+
- name: Set up Ruby
|
58
|
+
uses: ruby/setup-ruby@v1
|
59
|
+
with:
|
60
|
+
ruby-version: ${{ matrix.ruby }}
|
61
|
+
- name: Startup MySQL
|
62
|
+
run: |
|
63
|
+
sudo systemctl start mysql.service
|
64
|
+
- name: Setup databases
|
65
|
+
run: |
|
66
|
+
mysql --user=root --password=root --host=127.0.0.1 -e 'create database ransack collate utf8_general_ci;';
|
67
|
+
mysql --user=root --password=root --host=127.0.0.1 -e 'use ransack;show variables like "%character%";show variables like "%collation%";';
|
68
|
+
- name: Install dependencies
|
69
|
+
run: bundle install
|
70
|
+
- name: Run tests
|
71
|
+
run: bundle exec rspec
|
72
|
+
|
73
|
+
postgres:
|
74
|
+
runs-on: ubuntu-20.04
|
75
|
+
strategy:
|
76
|
+
fail-fast: false
|
77
|
+
matrix:
|
78
|
+
rails:
|
79
|
+
- v6.1.0.rc2
|
80
|
+
- v6.0.3
|
81
|
+
- 6-0-stable
|
82
|
+
- 5-2-stable
|
83
|
+
- v5.2.4
|
84
|
+
ruby:
|
85
|
+
- 2.7.2
|
86
|
+
- 2.6.6
|
87
|
+
env:
|
88
|
+
DB: postgres
|
89
|
+
RAILS: ${{ matrix.rails }}
|
90
|
+
DATABASE_USERNAME: postgres
|
91
|
+
DATABASE_PASSWORD: postgres
|
92
|
+
DATABASE_HOST: 127.0.0.1
|
93
|
+
services:
|
94
|
+
postgres:
|
95
|
+
image: postgres
|
96
|
+
ports:
|
97
|
+
- 5432:5432
|
98
|
+
env:
|
99
|
+
POSTGRES_PASSWORD: postgres
|
100
|
+
POSTGRES_HOST_AUTH_METHOD: trust
|
101
|
+
# Set health checks to wait until postgres has started
|
102
|
+
options: >-
|
103
|
+
--health-cmd pg_isready
|
104
|
+
--health-interval 10s
|
105
|
+
--health-timeout 5s
|
106
|
+
--health-retries 5
|
107
|
+
|
108
|
+
steps:
|
109
|
+
- uses: actions/checkout@v2
|
110
|
+
- name: Set up Ruby
|
111
|
+
uses: ruby/setup-ruby@v1
|
112
|
+
with:
|
113
|
+
ruby-version: ${{ matrix.ruby }}
|
114
|
+
- name: Setup databases
|
115
|
+
run: |
|
116
|
+
psql -h localhost -p 5432 -W postgres -c 'create database ransack;' -U postgres;
|
117
|
+
- name: Install dependencies
|
118
|
+
run: bundle install
|
119
|
+
- name: Run tests
|
120
|
+
run: bundle exec rspec
|
data/CHANGELOG.md
CHANGED
data/CONTRIBUTING.md
CHANGED
@@ -115,9 +115,6 @@ Here's a quick guide:
|
|
115
115
|
$ git config --global user.email "contributor@example.com"
|
116
116
|
|
117
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
118
|
|
122
119
|
11. If necessary, rebase your commits into logical chunks, without errors. To
|
123
120
|
interactively rebase and cherry-pick from, say, the last 10 commits:
|
data/README.md
CHANGED
@@ -1,10 +1,6 @@
|
|
1
1
|
# ![Ransack](./logo/ransack-h.png "Ransack")
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
Please see the [Maintainer wanted issue](https://github.com/activerecord-hackery/ransack/issues/1159) if you are interested.
|
6
|
-
|
7
|
-
[![Build Status](https://travis-ci.org/activerecord-hackery/ransack.svg)](https://travis-ci.org/activerecord-hackery/ransack)
|
3
|
+
[![Build Status](https://github.com/activerecord-hackery/ransack/workflows/test/badge.svg)](https://github.com/activerecord-hackery/ransack/actions)
|
8
4
|
[![Gem Version](https://badge.fury.io/rb/ransack.svg)](http://badge.fury.io/rb/ransack)
|
9
5
|
[![Code Climate](https://codeclimate.com/github/activerecord-hackery/ransack/badges/gpa.svg)](https://codeclimate.com/github/activerecord-hackery/ransack)
|
10
6
|
[![Backers on Open Collective](https://opencollective.com/ransack/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/ransack/sponsors/badge.svg)](#sponsors)
|
@@ -21,7 +17,7 @@ instead.
|
|
21
17
|
|
22
18
|
## Getting started
|
23
19
|
|
24
|
-
Ransack is
|
20
|
+
Ransack is supported for Rails 6.1, 6.0, 5.2 on Ruby 2.6.6 and later.
|
25
21
|
|
26
22
|
In your Gemfile, for the last officially released gem:
|
27
23
|
|
@@ -45,27 +41,14 @@ gem 'ransack', github: 'activerecord-hackery/ransack'
|
|
45
41
|
|
46
42
|
## Usage
|
47
43
|
|
48
|
-
Ransack can be used in one of two modes, simple or advanced.
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
This mode works much like MetaSearch, for those of you who are familiar with
|
53
|
-
it, and requires very little setup effort.
|
54
|
-
|
55
|
-
If you're coming from MetaSearch, things to note:
|
56
|
-
|
57
|
-
1. The default param key for search params is now `:q`, instead of `:search`.
|
58
|
-
This is primarily to shorten query strings, though advanced queries (below)
|
59
|
-
will still run afoul of URL length limits in most browsers and require a
|
60
|
-
switch to HTTP POST requests. This key is [configurable](https://github.com/activerecord-hackery/ransack/wiki/Configuration).
|
44
|
+
Ransack can be used in one of two modes, simple or advanced. For
|
45
|
+
searching/filtering not requiring complex boolean logic, Ransack's simple
|
46
|
+
mode should meet your needs.
|
61
47
|
|
62
|
-
|
63
|
-
|
48
|
+
If you're coming from MetaSearch (Ransack's predecessor), refer to the
|
49
|
+
[Updating From MetaSearch](#updating-from-metasearch) section
|
64
50
|
|
65
|
-
|
66
|
-
search object. Instead, you will get your search results (an
|
67
|
-
ActiveRecord::Relation in the case of the ActiveRecord adapter) via a call to
|
68
|
-
`Ransack#result`.
|
51
|
+
### Simple Mode
|
69
52
|
|
70
53
|
#### In your controller
|
71
54
|
|
@@ -88,6 +71,20 @@ def index
|
|
88
71
|
end
|
89
72
|
```
|
90
73
|
|
74
|
+
##### Default search parameter
|
75
|
+
|
76
|
+
Ransack uses a default `:q` param key for search params. This may be changed by
|
77
|
+
setting the `search_key` option in a Ransack initializer file (typically
|
78
|
+
`config/initializers/ransack.rb`):
|
79
|
+
|
80
|
+
```
|
81
|
+
Ransack.configure do |c|
|
82
|
+
# Change default search parameter key name.
|
83
|
+
# Default key name is :q
|
84
|
+
c.search_key = :query
|
85
|
+
end
|
86
|
+
```
|
87
|
+
|
91
88
|
#### In your view
|
92
89
|
|
93
90
|
The two primary Ransack view helpers are `search_form_for` and `sort_link`,
|
@@ -254,6 +251,20 @@ the order indicator arrow by passing `hide_indicator: true` in the sort link:
|
|
254
251
|
default_order: { last_name: 'asc', first_name: 'desc' }) %>
|
255
252
|
```
|
256
253
|
|
254
|
+
#### PostgreSQL's sort option
|
255
|
+
|
256
|
+
The `NULLS FIRST` and `NULLS LAST` options can be used to determine whether nulls appear before or after non-null values in the sort ordering.
|
257
|
+
|
258
|
+
You may want to configure it like this:
|
259
|
+
|
260
|
+
```rb
|
261
|
+
Ransack.configure do |c|
|
262
|
+
c.postgres_fields_sort_option = :nulls_first # or :nulls_last
|
263
|
+
end
|
264
|
+
```
|
265
|
+
|
266
|
+
See this feature: https://www.postgresql.org/docs/13/queries-order.html
|
267
|
+
|
257
268
|
### Advanced Mode
|
258
269
|
|
259
270
|
"Advanced" searches (ab)use Rails' nested attributes functionality in order to
|
@@ -674,6 +685,43 @@ Trying it out in `rails console`:
|
|
674
685
|
|
675
686
|
That's it! Now you know how to whitelist/blacklist various elements in Ransack.
|
676
687
|
|
688
|
+
### Handling unknown predicates or attributes
|
689
|
+
|
690
|
+
By default, Ransack will ignore any unknown predicates or attributes:
|
691
|
+
|
692
|
+
```ruby
|
693
|
+
Article.ransack(unknown_attr_eq: 'Ernie').result.to_sql
|
694
|
+
=> SELECT "articles".* FROM "articles"
|
695
|
+
```
|
696
|
+
|
697
|
+
Ransack may be configured to raise an error if passed an unknown predicate or
|
698
|
+
attributes, by setting the `ignore_unknown_conditions` option to `false` in your
|
699
|
+
Ransack initializer file at `config/initializers/ransack.rb`:
|
700
|
+
|
701
|
+
```ruby
|
702
|
+
Ransack.configure do |c|
|
703
|
+
# Raise errors if a query contains an unknown predicate or attribute.
|
704
|
+
# Default is true (do not raise error on unknown conditions).
|
705
|
+
c.ignore_unknown_conditions = false
|
706
|
+
end
|
707
|
+
```
|
708
|
+
|
709
|
+
```ruby
|
710
|
+
Article.ransack(unknown_attr_eq: 'Ernie')
|
711
|
+
# ArgumentError (Invalid search term unknown_attr_eq)
|
712
|
+
```
|
713
|
+
|
714
|
+
As an alternative to setting a global configuration option, the `.ransack!`
|
715
|
+
class method also raises an error if passed an unknown condition:
|
716
|
+
|
717
|
+
```ruby
|
718
|
+
Article.ransack!(unknown_attr_eq: 'Ernie')
|
719
|
+
# ArgumentError: Invalid search term unknown_attr_eq
|
720
|
+
```
|
721
|
+
|
722
|
+
This is equivilent to the `ignore_unknown_conditions` configuration option,
|
723
|
+
except it may be applied on a case-by-case basis.
|
724
|
+
|
677
725
|
### Using Scopes/Class Methods
|
678
726
|
|
679
727
|
Continuing on from the preceding section, searching by scopes requires defining
|
@@ -870,6 +918,28 @@ en:
|
|
870
918
|
title: Old Ransack Namespaced Title
|
871
919
|
```
|
872
920
|
|
921
|
+
### Updating From MetaSearch
|
922
|
+
|
923
|
+
Ransack works much like MetaSearch, for those of you who are familiar with
|
924
|
+
it, and requires very little setup effort.
|
925
|
+
|
926
|
+
If you're coming from MetaSearch, things to note:
|
927
|
+
|
928
|
+
1. The default param key for search params is now `:q`, instead of `:search`.
|
929
|
+
This is primarily to shorten query strings, though advanced queries (below)
|
930
|
+
will still run afoul of URL length limits in most browsers and require a
|
931
|
+
switch to HTTP POST requests. This key is
|
932
|
+
[configurable](default-search-parameter) via setting the `search_key` option
|
933
|
+
in your Ransack intitializer file.
|
934
|
+
|
935
|
+
2. `form_for` is now `search_form_for`, and validates that a Ransack::Search
|
936
|
+
object is passed to it.
|
937
|
+
|
938
|
+
3. Common ActiveRecord::Relation methods are no longer delegated by the
|
939
|
+
search object. Instead, you will get your search results (an
|
940
|
+
ActiveRecord::Relation in the case of the ActiveRecord adapter) via a call to
|
941
|
+
`Ransack#result`.
|
942
|
+
|
873
943
|
## Mongoid
|
874
944
|
|
875
945
|
Mongoid support has been moved to its own gem at [ransack-mongoid](https://github.com/activerecord-hackery/ransack-mongoid).
|
@@ -18,6 +18,10 @@ module Ransack
|
|
18
18
|
Search.new(self, params, options)
|
19
19
|
end
|
20
20
|
|
21
|
+
def ransack!(params = {}, options = {})
|
22
|
+
ransack(params, options.merge(ignore_unknown_conditions: false))
|
23
|
+
end
|
24
|
+
|
21
25
|
def ransacker(name, opts = {}, &block)
|
22
26
|
self._ransackers = _ransackers.merge name.to_s => Ransacker
|
23
27
|
.new(self, name, opts, &block)
|
@@ -42,6 +42,13 @@ module Ransack
|
|
42
42
|
if scope_or_sort.is_a?(Symbol)
|
43
43
|
relation = relation.send(scope_or_sort)
|
44
44
|
else
|
45
|
+
case Ransack.options[:postgres_fields_sort_option]
|
46
|
+
when :nulls_first
|
47
|
+
scope_or_sort = scope_or_sort.direction == :asc ? "#{scope_or_sort.to_sql} NULLS FIRST" : "#{scope_or_sort.to_sql} NULLS LAST"
|
48
|
+
when :nulls_last
|
49
|
+
scope_or_sort = scope_or_sort.direction == :asc ? "#{scope_or_sort.to_sql} NULLS LAST" : "#{scope_or_sort.to_sql} NULLS FIRST"
|
50
|
+
end
|
51
|
+
|
45
52
|
relation = relation.order(scope_or_sort)
|
46
53
|
end
|
47
54
|
end
|
@@ -33,7 +33,8 @@ module Ransack
|
|
33
33
|
:up_arrow => '▼'.freeze,
|
34
34
|
:down_arrow => '▲'.freeze,
|
35
35
|
:default_arrow => nil,
|
36
|
-
:sanitize_scope_args => true
|
36
|
+
:sanitize_scope_args => true,
|
37
|
+
:postgres_fields_sort_option => nil
|
37
38
|
}
|
38
39
|
|
39
40
|
def configure
|
@@ -141,6 +142,21 @@ module Ransack
|
|
141
142
|
self.options[:sanitize_scope_args] = boolean
|
142
143
|
end
|
143
144
|
|
145
|
+
# The `NULLS FIRST` and `NULLS LAST` options can be used to determine
|
146
|
+
# whether nulls appear before or after non-null values in the sort ordering.
|
147
|
+
#
|
148
|
+
# User may want to configure it like this:
|
149
|
+
#
|
150
|
+
# Ransack.configure do |c|
|
151
|
+
# c.postgres_fields_sort_option = :nulls_first # or :nulls_last
|
152
|
+
# end
|
153
|
+
#
|
154
|
+
# See this feature: https://www.postgresql.org/docs/13/queries-order.html
|
155
|
+
#
|
156
|
+
def postgres_fields_sort_option=(setting)
|
157
|
+
self.options[:postgres_fields_sort_option] = setting
|
158
|
+
end
|
159
|
+
|
144
160
|
# By default, Ransack displays sort order indicator arrows in sort links.
|
145
161
|
# The default may be globally overridden in an initializer file like
|
146
162
|
# `config/initializers/ransack.rb` as follows:
|
data/lib/ransack/search.rb
CHANGED
@@ -30,6 +30,7 @@ module Ransack
|
|
30
30
|
)
|
31
31
|
@scope_args = {}
|
32
32
|
@sorts ||= []
|
33
|
+
@ignore_unknown_conditions = options[:ignore_unknown_conditions] == false ? false : true
|
33
34
|
build(params.with_indifferent_access)
|
34
35
|
end
|
35
36
|
|
@@ -45,7 +46,7 @@ module Ransack
|
|
45
46
|
base.send("#{key}=", value)
|
46
47
|
elsif @context.ransackable_scope?(key, @context.object)
|
47
48
|
add_scope(key, value)
|
48
|
-
elsif !Ransack.options[:ignore_unknown_conditions]
|
49
|
+
elsif !Ransack.options[:ignore_unknown_conditions] || !@ignore_unknown_conditions
|
49
50
|
raise ArgumentError, "Invalid search term #{key}"
|
50
51
|
end
|
51
52
|
end
|
data/lib/ransack/version.rb
CHANGED
@@ -122,6 +122,10 @@ module Ransack
|
|
122
122
|
expect { Person.ransack('') }.to_not raise_error
|
123
123
|
end
|
124
124
|
|
125
|
+
it 'raises exception if ransack! called with unknown condition' do
|
126
|
+
expect { Person.ransack!(unknown_attr_eq: 'Ernie') }.to raise_error
|
127
|
+
end
|
128
|
+
|
125
129
|
it 'does not modify the parameters' do
|
126
130
|
params = { name_eq: '' }
|
127
131
|
expect { Person.ransack(params) }.not_to change { params }
|
@@ -173,5 +173,15 @@ module Ransack
|
|
173
173
|
.to eq false
|
174
174
|
end
|
175
175
|
end
|
176
|
+
|
177
|
+
it "PG's sort option", if: ::ActiveRecord::Base.connection.adapter_name == "PostgreSQL" do
|
178
|
+
default = Ransack.options.clone
|
179
|
+
|
180
|
+
Ransack.configure { |c| c.postgres_fields_sort_option = :nulls_first }
|
181
|
+
|
182
|
+
expect(Ransack.options[:postgres_fields_sort_option]).to eq :nulls_first
|
183
|
+
|
184
|
+
Ransack.options = default
|
185
|
+
end
|
176
186
|
end
|
177
187
|
end
|
data/spec/ransack/search_spec.rb
CHANGED
@@ -232,7 +232,7 @@ module Ransack
|
|
232
232
|
context 'with an invalid condition' do
|
233
233
|
subject { Search.new(Person, unknown_attr_eq: 'Ernie') }
|
234
234
|
|
235
|
-
context 'when ignore_unknown_conditions is false' do
|
235
|
+
context 'when ignore_unknown_conditions configuration option is false' do
|
236
236
|
before do
|
237
237
|
Ransack.configure { |c| c.ignore_unknown_conditions = false }
|
238
238
|
end
|
@@ -240,13 +240,39 @@ module Ransack
|
|
240
240
|
specify { expect { subject }.to raise_error ArgumentError }
|
241
241
|
end
|
242
242
|
|
243
|
-
context 'when ignore_unknown_conditions is true' do
|
243
|
+
context 'when ignore_unknown_conditions configuration option is true' do
|
244
244
|
before do
|
245
245
|
Ransack.configure { |c| c.ignore_unknown_conditions = true }
|
246
246
|
end
|
247
247
|
|
248
248
|
specify { expect { subject }.not_to raise_error }
|
249
249
|
end
|
250
|
+
|
251
|
+
subject(:with_ignore_unknown_conditions_false) {
|
252
|
+
Search.new(Person,
|
253
|
+
{ unknown_attr_eq: 'Ernie' },
|
254
|
+
{ ignore_unknown_conditions: false }
|
255
|
+
)
|
256
|
+
}
|
257
|
+
|
258
|
+
subject(:with_ignore_unknown_conditions_true) {
|
259
|
+
Search.new(Person,
|
260
|
+
{ unknown_attr_eq: 'Ernie' },
|
261
|
+
{ ignore_unknown_conditions: true }
|
262
|
+
)
|
263
|
+
}
|
264
|
+
|
265
|
+
context 'when ignore_unknown_conditions search parameter is absent' do
|
266
|
+
specify { expect { subject }.not_to raise_error }
|
267
|
+
end
|
268
|
+
|
269
|
+
context 'when ignore_unknown_conditions search parameter is false' do
|
270
|
+
specify { expect { with_ignore_unknown_conditions_false }.to raise_error ArgumentError }
|
271
|
+
end
|
272
|
+
|
273
|
+
context 'when ignore_unknown_conditions search parameter is true' do
|
274
|
+
specify { expect { with_ignore_unknown_conditions_true }.not_to raise_error }
|
275
|
+
end
|
250
276
|
end
|
251
277
|
|
252
278
|
it 'does not modify the parameters' do
|
@@ -507,6 +533,27 @@ module Ransack
|
|
507
533
|
@s.sorts = 'id asc'
|
508
534
|
expect(@s.result.first.id).to eq 1
|
509
535
|
end
|
536
|
+
|
537
|
+
it "PG's sort option", if: ::ActiveRecord::Base.connection.adapter_name == "PostgreSQL" do
|
538
|
+
default = Ransack.options.clone
|
539
|
+
|
540
|
+
s = Search.new(Person, s: 'name asc')
|
541
|
+
expect(s.result.to_sql).to eq "SELECT \"people\".* FROM \"people\" ORDER BY \"people\".\"name\" ASC"
|
542
|
+
|
543
|
+
Ransack.configure { |c| c.postgres_fields_sort_option = :nulls_first }
|
544
|
+
s = Search.new(Person, s: 'name asc')
|
545
|
+
expect(s.result.to_sql).to eq "SELECT \"people\".* FROM \"people\" ORDER BY \"people\".\"name\" ASC NULLS FIRST"
|
546
|
+
s = Search.new(Person, s: 'name desc')
|
547
|
+
expect(s.result.to_sql).to eq "SELECT \"people\".* FROM \"people\" ORDER BY \"people\".\"name\" DESC NULLS LAST"
|
548
|
+
|
549
|
+
Ransack.configure { |c| c.postgres_fields_sort_option = :nulls_last }
|
550
|
+
s = Search.new(Person, s: 'name asc')
|
551
|
+
expect(s.result.to_sql).to eq "SELECT \"people\".* FROM \"people\" ORDER BY \"people\".\"name\" ASC NULLS LAST"
|
552
|
+
s = Search.new(Person, s: 'name desc')
|
553
|
+
expect(s.result.to_sql).to eq "SELECT \"people\".* FROM \"people\" ORDER BY \"people\".\"name\" DESC NULLS FIRST"
|
554
|
+
|
555
|
+
Ransack.options = default
|
556
|
+
end
|
510
557
|
end
|
511
558
|
|
512
559
|
describe '#method_missing' do
|
data/spec/support/schema.rb
CHANGED
@@ -6,6 +6,8 @@ when 'mysql', 'mysql2'
|
|
6
6
|
ActiveRecord::Base.establish_connection(
|
7
7
|
adapter: 'mysql2',
|
8
8
|
database: 'ransack',
|
9
|
+
username: ENV.fetch("MYSQL_USERNAME") { "root" },
|
10
|
+
password: ENV.fetch("MYSQL_PASSWORD") { "" },
|
9
11
|
encoding: 'utf8'
|
10
12
|
)
|
11
13
|
when 'pg', 'postgres', 'postgresql'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ransack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.4.
|
4
|
+
version: 2.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ernie Miller
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2020-
|
14
|
+
date: 2020-12-21 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activerecord
|
@@ -66,8 +66,10 @@ executables: []
|
|
66
66
|
extensions: []
|
67
67
|
extra_rdoc_files: []
|
68
68
|
files:
|
69
|
+
- ".github/FUNDING.yml"
|
70
|
+
- ".github/SECURITY.md"
|
71
|
+
- ".github/workflows/test.yml"
|
69
72
|
- ".gitignore"
|
70
|
-
- ".travis.yml"
|
71
73
|
- CHANGELOG.md
|
72
74
|
- CONTRIBUTING.md
|
73
75
|
- Gemfile
|
data/.travis.yml
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
branches: master
|
2
|
-
|
3
|
-
language: ruby
|
4
|
-
|
5
|
-
rvm:
|
6
|
-
- 2.6.6
|
7
|
-
|
8
|
-
services:
|
9
|
-
- mysql
|
10
|
-
|
11
|
-
env:
|
12
|
-
- RAILS=v6.1.0.rc1 DB=sqlite3
|
13
|
-
- RAILS=v6.1.0.rc1 DB=mysql
|
14
|
-
- RAILS=v6.1.0.rc1 DB=postgres
|
15
|
-
|
16
|
-
- RAILS=v6.0.3 DB=sqlite3
|
17
|
-
- RAILS=v6.0.3 DB=mysql
|
18
|
-
- RAILS=v6.0.3 DB=postgres
|
19
|
-
|
20
|
-
- RAILS=6-0-stable DB=sqlite3
|
21
|
-
- RAILS=6-0-stable DB=mysql
|
22
|
-
- RAILS=6-0-stable DB=postgres
|
23
|
-
|
24
|
-
- RAILS=5-2-stable DB=sqlite3
|
25
|
-
- RAILS=5-2-stable DB=mysql
|
26
|
-
- RAILS=5-2-stable DB=postgres
|
27
|
-
|
28
|
-
- RAILS=v5.2.4 DB=sqlite3
|
29
|
-
- RAILS=v5.2.4 DB=mysql
|
30
|
-
- RAILS=v5.2.4 DB=postgres
|
31
|
-
|
32
|
-
before_script:
|
33
|
-
- if [ "$DB" = "mysql" ];
|
34
|
-
then
|
35
|
-
mysql -e 'create database ransack collate utf8_general_ci;';
|
36
|
-
mysql -e 'use ransack;show variables like "%character%";show variables like "%collation%";';
|
37
|
-
fi
|
38
|
-
|
39
|
-
- if [ "$DB" = "postgres" ];
|
40
|
-
then
|
41
|
-
psql -c 'create database ransack;' -U postgres;
|
42
|
-
fi
|
43
|
-
|
44
|
-
addons:
|
45
|
-
code_climate:
|
46
|
-
repo_token: 8b701c4364d51a0217105e08c06922d600cec3d9e60d546a89e3ddfe46e0664e
|
47
|
-
postgresql: "9.6"
|