ransack 1.8.0 → 1.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +37 -3
- data/README.md +3 -4
- data/Rakefile +3 -4
- data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +12 -6
- data/lib/ransack/constants.rb +0 -3
- data/lib/ransack/helpers/form_builder.rb +3 -3
- data/lib/ransack/helpers/form_helper.rb +14 -7
- data/lib/ransack/nodes/sort.rb +1 -1
- data/lib/ransack/version.rb +1 -1
- data/spec/console.rb +4 -0
- data/spec/ransack/adapters/active_record/base_spec.rb +15 -3
- data/spec/support/schema.rb +12 -2
- 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: 0000005ab1d9a09827cede9e9d949a7b87308f75
|
4
|
+
data.tar.gz: 72f3bddda6c78c9014b6a4fb1c6e49a622c9e7f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fcba1e08c4c8a1096182999c56da5765c9acb8adbb6ccc1e15870b436c9420baafb755ae5988568e14dee0212a062c6cc519e9d8e9eb4e4ee8776c8b1c9912d
|
7
|
+
data.tar.gz: 9d77b3d4de15b392e621d9ad11e546d933f2963075eac390414066dc5957a674c3dad7ccf105a669eaa2c329dae02b2d7d08dbe11666b16ced46c019a39187a3
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,39 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## Version 1.8.1 - 2016-07-27
|
4
|
+
### Fixed
|
5
|
+
|
6
|
+
* Fix `rake console` to run a command-line console with ransack + seed data.
|
7
|
+
Commits
|
8
|
+
[2cc781e](https://github.com/activerecord-hackery/ransack/commit/2cc781e),
|
9
|
+
[f2e85ad](https://github.com/activerecord-hackery/ransack/commit/f2e85ad),
|
10
|
+
[6a059ba](https://github.com/activerecord-hackery/ransack/commit/6a059ba).
|
11
|
+
|
12
|
+
*Jon Atack*
|
13
|
+
|
14
|
+
* Fix returned value of `Ransack::Nodes::Condition#format_predicate`. PR
|
15
|
+
[#692](https://github.com/activerecord-hackery/ransack/pull/692).
|
16
|
+
|
17
|
+
*Masahiro Saito*
|
18
|
+
|
19
|
+
* Better test coverage on passing arrays to ransackers. Commit
|
20
|
+
[98df2c5](https://github.com/activerecord-hackery/ransack/commit/98df2c5).
|
21
|
+
|
22
|
+
*Jon Atack*
|
23
|
+
|
24
|
+
* Fix missing Ransack::Constants::ASC constant. Commit
|
25
|
+
[aece23c](https://github.com/activerecord-hackery/ransack/commit/aece23c).
|
26
|
+
|
27
|
+
*Jon Atack*
|
28
|
+
|
29
|
+
### Changed
|
30
|
+
|
31
|
+
* Replace arrow constants with frozen strings in public methods. Commits
|
32
|
+
[c0dff33](https://github.com/activerecord-hackery/ransack/commit/c0dff33),
|
33
|
+
[e489ca7](https://github.com/activerecord-hackery/ransack/commit/e489ca7).
|
34
|
+
|
35
|
+
*Jon Atack*
|
36
|
+
|
3
37
|
## Version 1.8.0 - 2016-07-14
|
4
38
|
### Added
|
5
39
|
|
@@ -8,18 +42,18 @@
|
|
8
42
|
|
9
43
|
*Josef Šimánek*
|
10
44
|
|
11
|
-
*
|
45
|
+
* Add optional block argument for the `sort_link` method. PR
|
12
46
|
[#604](https://github.com/activerecord-hackery/ransack/pull/604).
|
13
47
|
|
14
48
|
*Andrea Dal Ponte*
|
15
49
|
|
16
|
-
*
|
50
|
+
* Add `ransack_alias` to allow users to customize the names for long
|
17
51
|
ransack field names. PR
|
18
52
|
[#623](https://github.com/activerecord-hackery/ransack/pull/623).
|
19
53
|
|
20
54
|
*Ray Zane*
|
21
55
|
|
22
|
-
*
|
56
|
+
* Add support for searching on attributes that have been added to
|
23
57
|
Active Record models with `alias_attribute` (Rails >= 4 only). PR
|
24
58
|
[#592](https://github.com/activerecord-hackery/ransack/pull/592), commit
|
25
59
|
[549342a](https://github.com/activerecord-hackery/ransack/commit/549342a).
|
data/README.md
CHANGED
@@ -29,7 +29,7 @@ instead.
|
|
29
29
|
If you're viewing this at
|
30
30
|
[github.com/activerecord-hackery/ransack](https://github.com/activerecord-hackery/ransack),
|
31
31
|
you're reading the documentation for the master branch with the latest features.
|
32
|
-
[View documentation for the last release (1.8.
|
32
|
+
[View documentation for the last release (1.8.1).](https://github.com/activerecord-hackery/ransack/tree/v1.8.1)
|
33
33
|
|
34
34
|
## Getting started
|
35
35
|
|
@@ -56,9 +56,8 @@ branch:
|
|
56
56
|
gem 'ransack', github: 'activerecord-hackery/ransack'
|
57
57
|
```
|
58
58
|
|
59
|
-
|
60
|
-
|
61
|
-
[updated version of the `will_paginate` gem here](https://github.com/jonatack/will_paginate).
|
59
|
+
If you are using Rails 5 or master and need pagination compatible with it and
|
60
|
+
Ransack, there is a [Rails 5 version of the `will_paginate` gem here](https://github.com/jonatack/will_paginate).
|
62
61
|
It is also optimized for Ruby 2.2+. To use it, in your Gemfile:
|
63
62
|
`gem 'will_paginate', github: 'jonatack/will_paginate'`.
|
64
63
|
|
data/Rakefile
CHANGED
@@ -26,11 +26,10 @@ end
|
|
26
26
|
|
27
27
|
desc "Open an irb session with Ransack and the sample data used in specs"
|
28
28
|
task :console do
|
29
|
-
require '
|
30
|
-
require '
|
31
|
-
require 'console'
|
29
|
+
require 'pry'
|
30
|
+
require File.expand_path('../spec/console.rb', __FILE__)
|
32
31
|
ARGV.clear
|
33
|
-
|
32
|
+
Pry.start
|
34
33
|
end
|
35
34
|
|
36
35
|
desc "Open an irb session with Ransack, Mongoid and the sample data used in specs"
|
@@ -26,17 +26,23 @@ module Ransack
|
|
26
26
|
arel_pred = arel_predicate_for_attribute(attribute)
|
27
27
|
arel_values = formatted_values_for_attribute(attribute)
|
28
28
|
predicate = attribute.attr.public_send(arel_pred, arel_values)
|
29
|
-
|
30
|
-
|
29
|
+
|
30
|
+
if in_predicate?(predicate)
|
31
|
+
predicate.right = predicate.right.map do |predicate|
|
32
|
+
casted_array?(predicate) ? format_values_for(predicate) : predicate
|
33
|
+
end
|
31
34
|
end
|
35
|
+
|
32
36
|
predicate
|
33
37
|
end
|
34
38
|
|
35
|
-
def
|
39
|
+
def in_predicate?(predicate)
|
36
40
|
return unless defined?(Arel::Nodes::Casted)
|
37
|
-
predicate.class == Arel::Nodes::In
|
38
|
-
|
39
|
-
|
41
|
+
predicate.class == Arel::Nodes::In
|
42
|
+
end
|
43
|
+
|
44
|
+
def casted_array?(predicate)
|
45
|
+
predicate.respond_to?(:val) && predicate.val.is_a?(Array)
|
40
46
|
end
|
41
47
|
|
42
48
|
def format_values_for(predicate)
|
data/lib/ransack/constants.rb
CHANGED
@@ -176,9 +176,9 @@ module Ransack
|
|
176
176
|
|
177
177
|
def sort_array
|
178
178
|
[
|
179
|
-
[
|
180
|
-
[
|
181
|
-
]
|
179
|
+
['asc'.freeze, object.translate('asc'.freeze)].freeze,
|
180
|
+
['desc'.freeze, object.translate('desc'.freeze)].freeze
|
181
|
+
].freeze
|
182
182
|
end
|
183
183
|
|
184
184
|
def combinator_choices
|
@@ -97,6 +97,14 @@ module Ransack
|
|
97
97
|
@default_order = @options.delete :default_order
|
98
98
|
end
|
99
99
|
|
100
|
+
def up_arrow
|
101
|
+
'▼'.freeze
|
102
|
+
end
|
103
|
+
|
104
|
+
def down_arrow
|
105
|
+
'▲'.freeze
|
106
|
+
end
|
107
|
+
|
100
108
|
def name
|
101
109
|
[ERB::Util.h(@label_text), order_indicator]
|
102
110
|
.compact
|
@@ -190,16 +198,15 @@ module Ransack
|
|
190
198
|
|
191
199
|
def order_indicator
|
192
200
|
return if @hide_indicator || no_sort_direction_specified?
|
193
|
-
|
201
|
+
if @current_dir == 'desc'.freeze
|
202
|
+
up_arrow
|
203
|
+
else
|
204
|
+
down_arrow
|
205
|
+
end
|
194
206
|
end
|
195
207
|
|
196
208
|
def no_sort_direction_specified?(dir = @current_dir)
|
197
|
-
|
198
|
-
end
|
199
|
-
|
200
|
-
def direction_arrow
|
201
|
-
return Constants::DESC_ARROW if @current_dir == 'desc'.freeze
|
202
|
-
Constants::ASC_ARROW
|
209
|
+
dir != 'asc'.freeze && dir != 'desc'.freeze
|
203
210
|
end
|
204
211
|
|
205
212
|
def direction_text(dir)
|
data/lib/ransack/nodes/sort.rb
CHANGED
data/lib/ransack/version.rb
CHANGED
data/spec/console.rb
CHANGED
@@ -16,6 +16,10 @@ Sham.define do
|
|
16
16
|
salary { |index| 30000 + (index * 1000) }
|
17
17
|
tag_name { Faker::Lorem.words(3).join(' ') }
|
18
18
|
note { Faker::Lorem.words(7).join(' ') }
|
19
|
+
only_admin { Faker::Lorem.words(3).join(' ') }
|
20
|
+
only_search { Faker::Lorem.words(3).join(' ') }
|
21
|
+
only_sort { Faker::Lorem.words(3).join(' ') }
|
22
|
+
notable_id { |id| id }
|
19
23
|
end
|
20
24
|
|
21
25
|
Schema.create
|
@@ -314,14 +314,26 @@ module Ransack
|
|
314
314
|
|
315
315
|
context 'searching on an `in` predicate with a ransacker' do
|
316
316
|
it 'should function correctly when passing an array of ids' do
|
317
|
-
s = Person.ransack(
|
317
|
+
s = Person.ransack(array_people_ids_in: true)
|
318
318
|
expect(s.result.count).to be > 0
|
319
|
+
|
320
|
+
s = Person.ransack(array_where_people_ids_in: [1, '2', 3])
|
321
|
+
expect(s.result.count).to be 3
|
322
|
+
expect(s.result.map(&:id)).to eq [3, 2, 1]
|
319
323
|
end
|
320
324
|
|
321
325
|
it 'should function correctly when passing an array of strings' do
|
322
|
-
Person.
|
323
|
-
|
326
|
+
a, b = Person.select(:id).order(:id).limit(2).map { |a| a.id.to_s }
|
327
|
+
|
328
|
+
Person.create!(name: a)
|
329
|
+
s = Person.ransack(array_people_names_in: true)
|
324
330
|
expect(s.result.count).to be > 0
|
331
|
+
s = Person.ransack(array_where_people_names_in: a)
|
332
|
+
expect(s.result.count).to be 1
|
333
|
+
|
334
|
+
Person.create!(name: b)
|
335
|
+
s = Person.ransack(array_where_people_names_in: [a, b])
|
336
|
+
expect(s.result.count).to be 2
|
325
337
|
end
|
326
338
|
|
327
339
|
it 'should function correctly with an Arel SqlLiteral' do
|
data/spec/support/schema.rb
CHANGED
@@ -66,16 +66,26 @@ class Person < ActiveRecord::Base
|
|
66
66
|
parent.table[:name]
|
67
67
|
end
|
68
68
|
|
69
|
-
ransacker :
|
69
|
+
ransacker :array_people_ids,
|
70
70
|
formatter: proc { |v| Person.first(2).map(&:id) } do |parent|
|
71
71
|
parent.table[:id]
|
72
72
|
end
|
73
73
|
|
74
|
-
ransacker :
|
74
|
+
ransacker :array_where_people_ids,
|
75
|
+
formatter: proc { |v| Person.where(id: v).map(&:id) } do |parent|
|
76
|
+
parent.table[:id]
|
77
|
+
end
|
78
|
+
|
79
|
+
ransacker :array_people_names,
|
75
80
|
formatter: proc { |v| Person.first(2).map { |p| p.id.to_s } } do |parent|
|
76
81
|
parent.table[:name]
|
77
82
|
end
|
78
83
|
|
84
|
+
ransacker :array_where_people_names,
|
85
|
+
formatter: proc { |v| Person.where(id: v).map { |p| p.id.to_s } } do |parent|
|
86
|
+
parent.table[:name]
|
87
|
+
end
|
88
|
+
|
79
89
|
ransacker :doubled_name do |parent|
|
80
90
|
Arel::Nodes::InfixOperation.new(
|
81
91
|
'||', parent.table[:name], parent.table[:name]
|
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.8.
|
4
|
+
version: 1.8.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: 2016-07-
|
13
|
+
date: 2016-07-27 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: actionpack
|