ransack 1.6.0 → 1.6.1
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/CHANGELOG.md +13 -0
- data/Gemfile +1 -1
- data/README.md +15 -9
- data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +2 -3
- data/lib/ransack/version.rb +1 -1
- data/spec/ransack/adapters/active_record/base_spec.rb +11 -3
- 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: 1ed8cd2219b1b16fb129d708c135405bcc3cd1e1
|
4
|
+
data.tar.gz: 08ee652b2fcbbf30f40ee7d7370d9d3fb4a97207
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e1fb6f045a7f24db09af20e541d502f70793adea5f1ae5518f5ebdac9f22e8d60c884693a2858c35bf08b577ef32f6fafd412d046c2450d7b5b23935088bdd5
|
7
|
+
data.tar.gz: c4886f5a0a91bd50df8336eb7cbe971ffdeae7cd36b4a3441d509676267f7236c1c3d10602c8fb7cd780ff0873216566240b27001012a77beecaca1cd21c0d27
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## Version 1.6.1 - 2015-01-14
|
4
|
+
|
5
|
+
* Fix a regression with using `in` predicates caused by PR [#488](https://github.com/activerecord-hackery/ransack/pull/488)). Add a test.
|
6
|
+
|
7
|
+
* README improvements to clarify `sort_link` syntax with associations and
|
8
|
+
Ransack#search vs #ransack.
|
9
|
+
|
10
|
+
* Default the Gemfile to Rails 4-2-stable.
|
11
|
+
|
12
|
+
*Jon Atack*
|
13
|
+
|
14
|
+
|
3
15
|
## Version 1.6.0 - 2015-01-12
|
4
16
|
### Added
|
5
17
|
|
@@ -89,6 +101,7 @@
|
|
89
101
|
|
90
102
|
*Jon Atack*
|
91
103
|
|
104
|
+
|
92
105
|
## Version 1.5.1 - 2014-10-30
|
93
106
|
### Fixed
|
94
107
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -27,7 +27,7 @@ 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.0).](https://github.com/activerecord-hackery/ransack/tree/
|
30
|
+
[View documentation for the last release (1.6.0).](https://github.com/activerecord-hackery/ransack/tree/v1.6.1)
|
31
31
|
|
32
32
|
## Getting started
|
33
33
|
|
@@ -265,17 +265,18 @@ construct much more complex search forms, such as the one on the
|
|
265
265
|
|
266
266
|
### Ransack #search method
|
267
267
|
|
268
|
-
Ransack will try to to make `#search` available in your
|
269
|
-
|
270
|
-
`#ransack` method.
|
268
|
+
Ransack will try to to make the class method `#search` available in your
|
269
|
+
models, but if `#search` has already been defined elsewhere, you can always use
|
270
|
+
the default `#ransack` class method. So the following are equivalent:
|
271
271
|
|
272
272
|
```ruby
|
273
273
|
Article.ransack(params[:q])
|
274
274
|
Article.search(params[:q])
|
275
275
|
```
|
276
276
|
|
277
|
-
Users have reported issues of name conflicts with other gems, so
|
278
|
-
|
277
|
+
Users have reported issues of `#search` name conflicts with other gems, so
|
278
|
+
the `#search` method alias might be deprecated in the next major version of
|
279
|
+
Ransack (2.0). It's advisable to use the default `#ransack` instead.
|
279
280
|
|
280
281
|
For now, if Ransack's `#search` method conflicts with the name of another
|
281
282
|
method named `search` in your code or another gem, you may resolve it either by
|
@@ -293,7 +294,7 @@ Ransack::Adapters::ActiveRecord::Base.class_eval('remove_method :search')
|
|
293
294
|
You can easily use Ransack to search for objects in `has_many` and `belongs_to`
|
294
295
|
associations.
|
295
296
|
|
296
|
-
Given
|
297
|
+
Given these associations...
|
297
298
|
|
298
299
|
```ruby
|
299
300
|
class Employee < ActiveRecord::Base
|
@@ -316,7 +317,7 @@ class Supervisor < ActiveRecord::Base
|
|
316
317
|
end
|
317
318
|
```
|
318
319
|
|
319
|
-
... and a controller
|
320
|
+
... and a controller...
|
320
321
|
|
321
322
|
```ruby
|
322
323
|
class SupervisorsController < ApplicationController
|
@@ -327,7 +328,7 @@ class SupervisorsController < ApplicationController
|
|
327
328
|
end
|
328
329
|
```
|
329
330
|
|
330
|
-
... you might set up your form like this
|
331
|
+
... you might set up your form like this...
|
331
332
|
|
332
333
|
```erb
|
333
334
|
<%= search_form_for @q do |f| %>
|
@@ -350,6 +351,11 @@ end
|
|
350
351
|
<% end %>
|
351
352
|
```
|
352
353
|
|
354
|
+
Please note that in a sort link, the association is expressed as an SQL string
|
355
|
+
(`'employees.last_name'`) with a pluralized table name, instead of the symbol
|
356
|
+
`:employee_last_name` syntax with a class#underscore table name used for
|
357
|
+
Ransack objects elsewhere.
|
358
|
+
|
353
359
|
### Using Ransackers to add custom search functions via Arel
|
354
360
|
|
355
361
|
The main premise behind Ransack is to provide access to
|
@@ -24,7 +24,7 @@ module Ransack
|
|
24
24
|
|
25
25
|
private
|
26
26
|
|
27
|
-
#
|
27
|
+
# TODO: Improve this edge case patch for Arel >= 6.0 (Rails >= 4.2)
|
28
28
|
# that adds several conditionals to handle changing Arel API.
|
29
29
|
# Related to Ransack issue #472 and pull requests #486-488.
|
30
30
|
#
|
@@ -39,8 +39,7 @@ module Ransack
|
|
39
39
|
def casted_array_with_in_predicate?(predicate)
|
40
40
|
return unless defined?(Arel::Nodes::Casted)
|
41
41
|
predicate.class == Arel::Nodes::In &&
|
42
|
-
predicate.right.is_a?(Array)
|
43
|
-
predicate.right[0].class == Arel::Nodes::Casted
|
42
|
+
predicate.right[0].val.is_a?(Array)
|
44
43
|
end
|
45
44
|
|
46
45
|
end
|
data/lib/ransack/version.rb
CHANGED
@@ -80,6 +80,14 @@ module Ransack
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
+
context "search on an `in` predicate with an array" do
|
84
|
+
it "should function correctly when passing an array of ids" do
|
85
|
+
array = Person.all.map(&:id)
|
86
|
+
s = Person.ransack(id_in: array)
|
87
|
+
expect(s.result.count).to eq array.size
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
83
91
|
describe '#ransacker' do
|
84
92
|
# For infix tests
|
85
93
|
def self.sane_adapter?
|
@@ -161,16 +169,16 @@ module Ransack
|
|
161
169
|
expect(s.result.to_a).to eq [p]
|
162
170
|
end
|
163
171
|
|
164
|
-
context "search
|
172
|
+
context "search on an `in` predicate with an array to a ransacker" do
|
165
173
|
it "should function correctly when passing an array of ids" do
|
166
174
|
s = Person.ransack(array_users_in: true)
|
167
|
-
expect(s.result.
|
175
|
+
expect(s.result.count).to be > 0
|
168
176
|
end
|
169
177
|
|
170
178
|
it "should function correctly when passing an array of strings" do
|
171
179
|
p = Person.create!(name: Person.first.id.to_s)
|
172
180
|
s = Person.ransack(array_names_in: true)
|
173
|
-
expect(s.result.
|
181
|
+
expect(s.result.count).to be > 0
|
174
182
|
end
|
175
183
|
end
|
176
184
|
|
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: 1.6.
|
4
|
+
version: 1.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ernie Miller
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-01-
|
13
|
+
date: 2015-01-14 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: actionpack
|