ransack 1.6.4 → 1.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +1 -11
- data/CHANGELOG.md +50 -10
- data/CONTRIBUTING.md +29 -18
- data/README.md +9 -31
- data/lib/ransack/adapters/active_record/context.rb +22 -17
- data/lib/ransack/adapters/active_record/ransack/context.rb +1 -1
- data/lib/ransack/predicate.rb +2 -2
- data/lib/ransack/translate.rb +0 -5
- data/lib/ransack/version.rb +1 -1
- data/spec/mongoid/configuration_spec.rb +36 -0
- data/spec/ransack/adapters/active_record/base_spec.rb +7 -6
- data/spec/ransack/configuration_spec.rb +36 -0
- data/spec/ransack/helpers/form_helper_spec.rb +65 -58
- data/spec/ransack/search_spec.rb +134 -104
- data/spec/spec_helper.rb +3 -4
- data/spec/support/schema.rb +36 -23
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab38816eaa6fefc0b47ab0814d69ddf4f9dfbbf8
|
4
|
+
data.tar.gz: ed98ed6e4ede9c729fb05cc4ddfb00d646a79149
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 837ce300a188d1e7cf59eff19548d4dc1b1c817276249d83326b9b776b8ba3ae49072ebf1850e3437a54d70a1fafbf3473165856d88afdbb5f139d505ea4309d
|
7
|
+
data.tar.gz: d1cbcb0ec2d6876511b4624a93c9a85f3d5500705305faf8dc566e54c16c3d5572b5838882723d9ee3fc6df696dd5b3ccfe8dfbb73ed47008f782d42983e496c
|
data/.travis.yml
CHANGED
@@ -5,7 +5,7 @@ language: ruby
|
|
5
5
|
sudo: false
|
6
6
|
|
7
7
|
rvm:
|
8
|
-
- 2.2
|
8
|
+
- 2.2.1
|
9
9
|
- 2.1
|
10
10
|
- 2.0
|
11
11
|
- 1.9
|
@@ -33,10 +33,6 @@ env:
|
|
33
33
|
- RAILS=3-1-stable DB=mysql
|
34
34
|
- RAILS=3-1-stable DB=postgres
|
35
35
|
|
36
|
-
- RAILS=3-0-stable DB=sqlite
|
37
|
-
- RAILS=3-0-stable DB=mysql
|
38
|
-
- RAILS=3-0-stable DB=postgres
|
39
|
-
|
40
36
|
matrix:
|
41
37
|
include:
|
42
38
|
- rvm: 2.2
|
@@ -52,12 +48,6 @@ matrix:
|
|
52
48
|
env: RAILS=3-1-stable DB=mysql
|
53
49
|
- rvm: 2.2
|
54
50
|
env: RAILS=3-1-stable DB=postgres
|
55
|
-
- rvm: 2.2
|
56
|
-
env: RAILS=3-0-stable DB=sqlite
|
57
|
-
- rvm: 2.2
|
58
|
-
env: RAILS=3-0-stable DB=mysql
|
59
|
-
- rvm: 2.2
|
60
|
-
env: RAILS=3-0-stable DB=postgres
|
61
51
|
allow_failures:
|
62
52
|
- env: RAILS=master DB=sqlite3
|
63
53
|
- env: RAILS=master DB=mysql
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,48 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## Version 1.6.
|
3
|
+
## Version 1.6.5 - 2015-03-28 - Rails 5.0.0 update
|
4
|
+
### Added
|
5
|
+
|
6
|
+
* [WIP/experimental] Add compatibility with Rails 5/master and Arel 7.
|
7
|
+
|
8
|
+
* Update the [Contributing Guide](CONTRIBUTING.md) with detailed steps for
|
9
|
+
contributing to Ransack.
|
10
|
+
|
11
|
+
* Broaden the test suite database options in `schema.rb` and add
|
12
|
+
code documentation.
|
13
|
+
|
14
|
+
* Improve the header message when running tests.
|
15
|
+
|
16
|
+
*Jon Atack*
|
17
|
+
|
18
|
+
* Allow `:wants_array` to be set to `false` in the predicate options
|
19
|
+
([#32](https://github.com/activerecord-hackery/ransack/issues/32)).
|
20
|
+
|
21
|
+
*Michael Pavling*
|
22
|
+
|
23
|
+
* Add a failing spec for issue
|
24
|
+
[#374](https://github.com/activerecord-hackery/ransack/issues/374).
|
25
|
+
|
26
|
+
*Jamie Davidson*, *Jon Atack*
|
27
|
+
|
28
|
+
### Fixed
|
29
|
+
|
30
|
+
* Stop relying on `Active Record::relation#where_values` which are deprecated
|
31
|
+
in Rails 5.
|
32
|
+
|
33
|
+
* Make the test for passing search arguments to a ransacker
|
34
|
+
(`ransacker_args`) work correctly with Sqlite3.
|
35
|
+
|
36
|
+
*Jon Atack*
|
37
|
+
|
38
|
+
### Changed
|
39
|
+
|
40
|
+
* Stop CI testing for Rails 3.0 to reduce the size of the Travis test matrix.
|
41
|
+
|
42
|
+
*Jon Atack*
|
43
|
+
|
44
|
+
|
45
|
+
## Version 1.6.4 - 2015-03-20 - Rails 4.2.1 update
|
4
46
|
|
5
47
|
* ActionView patch to maintain compatibility with Rails 4.2.1 released today.
|
6
48
|
|
@@ -16,6 +58,7 @@
|
|
16
58
|
|
17
59
|
*Denis Tataurov*, *Jon Atack*
|
18
60
|
|
61
|
+
|
19
62
|
## Version 1.6.3 - 2015-01-21
|
20
63
|
|
21
64
|
* Fix a regression
|
@@ -147,24 +190,22 @@
|
|
147
190
|
|
148
191
|
|
149
192
|
## Version 1.5.1 - 2014-10-30
|
150
|
-
### Fixed
|
151
|
-
|
152
|
-
* Fix a regression caused by incorrect string constants in `context.rb`.
|
153
|
-
|
154
|
-
*Kazuhiro Nishiyama*
|
155
|
-
|
156
193
|
### Added
|
157
194
|
|
158
195
|
* Add base specs for search on fields with `_start` and `_end`.
|
159
196
|
|
160
|
-
*Jon Atack*
|
161
|
-
|
162
197
|
* Add a failing spec for detecting attribute fields containing `_and_` that
|
163
198
|
needs to be fixed. Attribute names containing `_and_` and `_or_` are still
|
164
199
|
not parsed/detected correctly.
|
165
200
|
|
166
201
|
*Jon Atack*
|
167
202
|
|
203
|
+
### Fixed
|
204
|
+
|
205
|
+
* Fix a regression caused by incorrect string constants in `context.rb`.
|
206
|
+
|
207
|
+
*Kazuhiro Nishiyama*
|
208
|
+
|
168
209
|
### Changed
|
169
210
|
|
170
211
|
* Remove duplicate code in `spec/support/schema.rb`.
|
@@ -241,7 +282,6 @@
|
|
241
282
|
|
242
283
|
|
243
284
|
## Version 1.4.1 - 2014-09-23
|
244
|
-
### Fixed
|
245
285
|
|
246
286
|
* Fix README markdown so RubyGems documentation picks up the formatting correctly.
|
247
287
|
|
data/CONTRIBUTING.md
CHANGED
@@ -34,7 +34,8 @@ if the information requested is provided.
|
|
34
34
|
## Pull requests
|
35
35
|
|
36
36
|
We gladly accept pull requests to fix bugs and, in some circumstances, add new
|
37
|
-
features to Ransack.
|
37
|
+
features to Ransack. If you'd like to contribute and wonder what would be
|
38
|
+
helpful, simply run a search for "FIXME" and "TODO" on the codebase :smiley:
|
38
39
|
|
39
40
|
If you're new to contributing to open source, welcome! It can seem scary, so
|
40
41
|
here is a [great blog post to help you get started]
|
@@ -47,37 +48,47 @@ backward compatibility has a very good reason for doing so.
|
|
47
48
|
|
48
49
|
Here's a quick guide:
|
49
50
|
|
50
|
-
1. Fork the repo
|
51
|
-
and install the development dependencies by running `bundle install`.
|
51
|
+
1. Fork the repo.
|
52
52
|
|
53
|
-
2.
|
53
|
+
2. Create a thoughtfully-named branch for your changes (`git checkout -b my-new-feature`).
|
54
|
+
|
55
|
+
3. Install the development dependencies by running `bundle install`.
|
56
|
+
|
57
|
+
4. Begin by running the tests. We only take pull requests with passing tests,
|
54
58
|
and it's great to know that you have a clean slate:
|
55
59
|
|
56
60
|
$ bundle exec rake spec
|
57
61
|
|
58
|
-
|
62
|
+
The test suite runs by default with SQLite3. To run the test suite with PostgreSQL or MySQL, use:
|
63
|
+
|
64
|
+
$ DB=postgresql bundle exec rake spec (`DB=pg` & `DB=postgres` work too)
|
65
|
+
$ DB=mysql bundle exec rake spec
|
66
|
+
|
67
|
+
5. Hack away! Please use Ruby features that are compatible down to Ruby 1.9.
|
59
68
|
Since version 1.5, Ransack no longer maintains Ruby 1.8 compatibility.
|
60
69
|
|
61
|
-
|
70
|
+
6. Add tests for your changes. Only refactoring and documentation changes
|
62
71
|
require no new tests. If you are adding functionality or fixing a bug, we
|
63
72
|
need a test!
|
64
73
|
|
65
|
-
|
74
|
+
7. Make the tests pass.
|
66
75
|
|
67
|
-
|
76
|
+
8. Update the Change Log. If you are adding new functionality, document it in
|
68
77
|
the README.
|
69
78
|
|
70
|
-
|
79
|
+
9. Commit your changes (`git commit -am 'Add feature/fix bug/improve docs'`).
|
71
80
|
|
72
|
-
|
81
|
+
10. If necessary, rebase your commits into logical chunks, without errors. To
|
82
|
+
interactively rebase and cherry-pick from, say, the last 10 commits:
|
83
|
+
`git rebase -i HEAD~10`, then `git push -f`.
|
73
84
|
|
74
|
-
|
75
|
-
|
76
|
-
|
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
|
87
|
+
Ransack's `master` branch.
|
77
88
|
|
78
|
-
|
79
|
-
add `[skip ci]` to your commit message so the Travis
|
80
|
-
needlessly.
|
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.
|
81
92
|
|
82
93
|
At this point you're waiting on us. We like to at least comment on, if not
|
83
94
|
accept, pull requests within three business days (and, typically, one business
|
@@ -85,14 +96,14 @@ day). We may suggest some changes or improvements or alternatives.
|
|
85
96
|
|
86
97
|
Some things that will increase the chance that your pull request is accepted:
|
87
98
|
|
88
|
-
* Use idiomatic Ruby and follow the syntax conventions below.
|
89
99
|
* Include tests that fail without your code, and pass with it.
|
90
100
|
* Update the README, the change log, the wiki documentation... anything that is
|
91
101
|
affected by your contribution.
|
102
|
+
* Use idiomatic Ruby and follow the syntax conventions below.
|
92
103
|
|
93
104
|
Syntax:
|
94
105
|
|
95
|
-
*
|
106
|
+
* Indent with two spaces, no tabs.
|
96
107
|
* 80 characters per line.
|
97
108
|
* No trailing whitespace. Blank lines should not have any space.
|
98
109
|
* Prefer `&&`/`||` over `and`/`or`.
|
data/README.md
CHANGED
@@ -27,17 +27,18 @@ instead.
|
|
27
27
|
If you're viewing this at
|
28
28
|
[github.com/activerecord-hackery/ransack](https://github.com/activerecord-hackery/ransack),
|
29
29
|
you're reading the documentation for the master branch with the latest features.
|
30
|
-
[View documentation for the last release (1.6.
|
31
|
-
(https://github.com/activerecord-hackery/ransack/tree/v1.6.
|
30
|
+
[View documentation for the last release (1.6.5).]
|
31
|
+
(https://github.com/activerecord-hackery/ransack/tree/v1.6.5)
|
32
32
|
|
33
33
|
## Getting started
|
34
34
|
|
35
|
-
Ransack is compatible with Rails 3 and 4 (including 4.2) on Ruby 1.9 and
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
35
|
+
Ransack is compatible with Rails 3 and 4 (including 4.2.1) on Ruby 1.9 and
|
36
|
+
later. It currently works with Rails 5 as well, though changes in Arel and
|
37
|
+
Active Record keep that a moving target. If you are using Ruby 1.8, you can use
|
38
|
+
an earlier version of Ransack up to v1.3.0.
|
39
|
+
|
40
|
+
Ransack works out-of-the-box with Active Record and also features experimental
|
41
|
+
support for Mongoid 4.0 (without associations, further details below).
|
41
42
|
|
42
43
|
In your Gemfile, for the last officially released Ransack gem:
|
43
44
|
|
@@ -51,29 +52,6 @@ Or, if you would like to use the latest updates, use the `master` branch:
|
|
51
52
|
gem 'ransack', github: 'activerecord-hackery/ransack'
|
52
53
|
```
|
53
54
|
|
54
|
-
The other branches (`rails-4`, `rails-4.1`, and `rails-4.2`) were each used for
|
55
|
-
developing and running Ransack with the latest upcoming version of Rails at the
|
56
|
-
time. They are smaller and possibly slightly faster because they do not have to
|
57
|
-
support previous versions of Rails and Active Record. Once support for that
|
58
|
-
Rails version is merged from the branch into Ransack master, the branch is no
|
59
|
-
longer actively maintained -- unless the open source community submits pull
|
60
|
-
requests to maintain them. You are welcome to do so!
|
61
|
-
|
62
|
-
To use one of the branches, for example the `rails-4.1` branch:
|
63
|
-
|
64
|
-
```ruby
|
65
|
-
gem 'ransack', github: 'activerecord-hackery/ransack', branch: 'rails-4.1'
|
66
|
-
```
|
67
|
-
|
68
|
-
If you are using Rails master, be advised that Ransack master does not yet work
|
69
|
-
with the breaking changes in Rails master and Arel master added since December
|
70
|
-
2014. The most recent working commits are:
|
71
|
-
|
72
|
-
```ruby
|
73
|
-
gem 'rails', github: 'rails/rails', ref: '266ff70'
|
74
|
-
gem 'arel', github: 'rails/arel', ref: '008445d'
|
75
|
-
```
|
76
|
-
|
77
55
|
## Usage
|
78
56
|
|
79
57
|
Ransack can be used in one of two modes, simple or advanced.
|
@@ -96,7 +96,7 @@ module Ransack
|
|
96
96
|
def join_sources
|
97
97
|
base =
|
98
98
|
if ::ActiveRecord::VERSION::MAJOR >= 5
|
99
|
-
Arel::SelectManager.new(@object.
|
99
|
+
Arel::SelectManager.new(@object.table)
|
100
100
|
else
|
101
101
|
Arel::SelectManager.new(@object.engine, @object.table)
|
102
102
|
end
|
@@ -171,39 +171,37 @@ module Ransack
|
|
171
171
|
if relation.respond_to?(:join_dependency) # Squeel will enable this
|
172
172
|
relation.join_dependency
|
173
173
|
else
|
174
|
-
|
174
|
+
build_joins(relation)
|
175
175
|
end
|
176
176
|
end
|
177
177
|
|
178
178
|
# Checkout active_record/relation/query_methods.rb +build_joins+ for
|
179
179
|
# reference. Lots of duplicated code maybe we can avoid it
|
180
|
-
def
|
180
|
+
def build_joins(relation)
|
181
181
|
buckets = relation.joins_values.group_by do |join|
|
182
182
|
case join
|
183
183
|
when String
|
184
|
-
|
184
|
+
:string_join
|
185
185
|
when Hash, Symbol, Array
|
186
|
-
|
187
|
-
when JoinDependency
|
188
|
-
|
186
|
+
:association_join
|
187
|
+
when ActiveRecord::Associations::JoinDependency
|
188
|
+
:stashed_join
|
189
189
|
when Arel::Nodes::Join
|
190
|
-
|
190
|
+
:join_node
|
191
191
|
else
|
192
192
|
raise 'unknown class: %s' % join.class.name
|
193
193
|
end
|
194
194
|
end
|
195
|
-
|
196
|
-
association_joins
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
join_nodes = buckets[Constants::JOIN_NODE] || []
|
201
|
-
|
202
|
-
string_joins = (buckets[Constants::STRING_JOIN] || []).map(&:strip).uniq
|
195
|
+
buckets.default = []
|
196
|
+
association_joins = buckets[:association_join]
|
197
|
+
stashed_association_joins = buckets[:stashed_join]
|
198
|
+
join_nodes = buckets[:join_node].uniq
|
199
|
+
string_joins = buckets[:string_join].map(&:strip).uniq
|
203
200
|
|
204
201
|
join_list =
|
205
202
|
if ::ActiveRecord::VERSION::MAJOR >= 5
|
206
|
-
|
203
|
+
join_nodes +
|
204
|
+
convert_join_strings_to_ast(relation.table, string_joins)
|
207
205
|
else
|
208
206
|
relation.send :custom_join_ast,
|
209
207
|
relation.table.from(relation.table), string_joins
|
@@ -224,6 +222,13 @@ module Ransack
|
|
224
222
|
end
|
225
223
|
end
|
226
224
|
|
225
|
+
def convert_join_strings_to_ast(table, joins)
|
226
|
+
joins
|
227
|
+
.flatten
|
228
|
+
.reject(&:blank?)
|
229
|
+
.map { |join| table.create_string_join(Arel.sql(join)) }
|
230
|
+
end
|
231
|
+
|
227
232
|
if ::ActiveRecord::VERSION::STRING >= Constants::RAILS_4_1
|
228
233
|
|
229
234
|
def build_or_find_association(name, parent = @base, klass = nil)
|
@@ -37,7 +37,7 @@ module Ransack
|
|
37
37
|
end
|
38
38
|
|
39
39
|
@default_table = Arel::Table.new(
|
40
|
-
@base.table_name, :
|
40
|
+
@base.table_name, as: @base.aliased_table_name, type_caster: self
|
41
41
|
)
|
42
42
|
@bind_pairs = Hash.new do |hash, key|
|
43
43
|
parent, attr_name = get_parent_and_attribute_name(key.to_s)
|
data/lib/ransack/predicate.rb
CHANGED
@@ -48,8 +48,8 @@ module Ransack
|
|
48
48
|
@validator = opts[:validator] ||
|
49
49
|
lambda { |v| v.respond_to?(:empty?) ? !v.empty? : !v.nil? }
|
50
50
|
@compound = opts[:compound]
|
51
|
-
@wants_array = opts
|
52
|
-
Constants::IN_NOT_IN.include?(@arel_predicate)
|
51
|
+
@wants_array = opts.fetch(:wants_array,
|
52
|
+
@compound || Constants::IN_NOT_IN.include?(@arel_predicate))
|
53
53
|
end
|
54
54
|
|
55
55
|
def eql?(other)
|
data/lib/ransack/translate.rb
CHANGED
@@ -150,11 +150,6 @@ module Ransack
|
|
150
150
|
end
|
151
151
|
|
152
152
|
def self.i18n_key(klass)
|
153
|
-
# if ActiveRecord::VERSION::MAJOR == 3 && ActiveRecord::VERSION::MINOR == 0
|
154
|
-
# klass.model_name.i18n_key.to_s.tr('.', '/')
|
155
|
-
# else
|
156
|
-
# klass.model_name.i18n_key.to_s
|
157
|
-
# end
|
158
153
|
raise "not implemented"
|
159
154
|
end
|
160
155
|
end
|
data/lib/ransack/version.rb
CHANGED
@@ -62,5 +62,41 @@ module Ransack
|
|
62
62
|
expect(Ransack.predicates).not_to have_key 'test_array_predicate_any'
|
63
63
|
expect(Ransack.predicates).not_to have_key 'test_array_predicate_all'
|
64
64
|
end
|
65
|
+
|
66
|
+
describe '`wants_array` option takes precedence over Arel predicate' do
|
67
|
+
it 'implicitly wants an array for in/not in predicates' do
|
68
|
+
Ransack.configure do |config|
|
69
|
+
config.add_predicate(
|
70
|
+
:test_in_predicate,
|
71
|
+
:arel_predicate => 'in'
|
72
|
+
)
|
73
|
+
config.add_predicate(
|
74
|
+
:test_not_in_predicate,
|
75
|
+
:arel_predicate => 'not_in'
|
76
|
+
)
|
77
|
+
end
|
78
|
+
|
79
|
+
expect(Ransack.predicates['test_in_predicate'].wants_array).to eq true
|
80
|
+
expect(Ransack.predicates['test_not_in_predicate'].wants_array).to eq true
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'explicitly does not want array for in/not_in predicates' do
|
84
|
+
Ransack.configure do |config|
|
85
|
+
config.add_predicate(
|
86
|
+
:test_in_predicate_no_array,
|
87
|
+
:arel_predicate => 'in',
|
88
|
+
:wants_array => false
|
89
|
+
)
|
90
|
+
config.add_predicate(
|
91
|
+
:test_not_in_predicate_no_array,
|
92
|
+
:arel_predicate => 'not_in',
|
93
|
+
:wants_array => false
|
94
|
+
)
|
95
|
+
end
|
96
|
+
|
97
|
+
expect(Ransack.predicates['test_in_predicate_no_array'].wants_array).to eq false
|
98
|
+
expect(Ransack.predicates['test_not_in_predicate_no_array'].wants_array).to eq false
|
99
|
+
end
|
100
|
+
end
|
65
101
|
end
|
66
102
|
end
|
@@ -71,7 +71,7 @@ module Ransack
|
|
71
71
|
end
|
72
72
|
|
73
73
|
it 'does not raise exception for string :params argument' do
|
74
|
-
|
74
|
+
expect { Person.ransack('') }.to_not raise_error
|
75
75
|
end
|
76
76
|
|
77
77
|
it 'does not modify the parameters' do
|
@@ -319,19 +319,20 @@ module Ransack
|
|
319
319
|
c: [{
|
320
320
|
a: {
|
321
321
|
'0' => {
|
322
|
-
name: '
|
322
|
+
name: 'with_arguments', ransacker_args: [10, 100]
|
323
323
|
}
|
324
324
|
},
|
325
325
|
p: 'cont',
|
326
|
-
v: ['
|
326
|
+
v: ['Passing arguments to ransackers!']
|
327
327
|
}]
|
328
328
|
)
|
329
329
|
expect(s.result.to_sql).to match(
|
330
|
-
/
|
330
|
+
/LENGTH\(articles.body\) BETWEEN 10 AND 100/
|
331
331
|
)
|
332
332
|
expect(s.result.to_sql).to match(
|
333
|
-
/LIKE \'\%
|
334
|
-
|
333
|
+
/LIKE \'\%Passing arguments to ransackers!\%\'/
|
334
|
+
)
|
335
|
+
expect { s.result.first }.to_not raise_error
|
335
336
|
end
|
336
337
|
end
|
337
338
|
|