ransack 1.6.2 → 1.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -8
- data/CHANGELOG.md +13 -1
- data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +37 -24
- data/lib/ransack/nodes/condition.rb +7 -4
- data/lib/ransack/search.rb +1 -1
- data/lib/ransack/version.rb +1 -1
- data/spec/ransack/adapters/active_record/base_spec.rb +12 -0
- 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: 9bf018bef97fde714331b98465544735b3cdd23c
|
4
|
+
data.tar.gz: 3f5e4cae6c7bcf4f09eb6aa3851b521b18150569
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6b753315240e2e974e82e2542d3b0dfbd90c6fdb1718d02e917b6ff348764fefb5d87fbbc14d15f400026d9303c71013dca5e9194432e7716f9b81342c54f54
|
7
|
+
data.tar.gz: e17e95e45672c4feb667f9a1a940cac994b43a8844cd5606f5a53d6e25e8284fb55b5a6ddfa8119d74dacfa8b58bb9a8198ebcc540e4be3e83ab1887e4ccce24
|
data/.travis.yml
CHANGED
@@ -45,6 +45,13 @@ matrix:
|
|
45
45
|
env: RAILS=master DB=mysql
|
46
46
|
- rvm: 2.2
|
47
47
|
env: RAILS=master DB=postgres
|
48
|
+
exclude:
|
49
|
+
- rvm: 2.2
|
50
|
+
env: RAILS=3-1-stable DB=sqlite
|
51
|
+
- rvm: 2.2
|
52
|
+
env: RAILS=3-1-stable DB=mysql
|
53
|
+
- rvm: 2.2
|
54
|
+
env: RAILS=3-1-stable DB=postgres
|
48
55
|
exclude:
|
49
56
|
- rvm: 2.2
|
50
57
|
env: RAILS=3-0-stable DB=sqlite
|
@@ -52,24 +59,16 @@ matrix:
|
|
52
59
|
env: RAILS=3-0-stable DB=mysql
|
53
60
|
- rvm: 2.2
|
54
61
|
env: RAILS=3-0-stable DB=postgres
|
55
|
-
|
56
62
|
allow_failures:
|
57
63
|
- env: RAILS=master DB=sqlite3
|
58
64
|
- env: RAILS=master DB=mysql
|
59
65
|
- env: RAILS=master DB=postgres
|
60
|
-
|
61
66
|
- rvm: 2.2
|
62
67
|
env: RAILS=3-2-stable DB=sqlite
|
63
68
|
- rvm: 2.2
|
64
69
|
env: RAILS=3-2-stable DB=mysql
|
65
70
|
- rvm: 2.2
|
66
71
|
env: RAILS=3-2-stable DB=postgres
|
67
|
-
- rvm: 2.2
|
68
|
-
env: RAILS=3-1-stable DB=sqlite
|
69
|
-
- rvm: 2.2
|
70
|
-
env: RAILS=3-1-stable DB=mysql
|
71
|
-
- rvm: 2.2
|
72
|
-
env: RAILS=3-1-stable DB=postgres
|
73
72
|
|
74
73
|
before_script:
|
75
74
|
- mysql -e 'create database ransack collate utf8_general_ci;'
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,22 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## Version 1.6.3 - 2015-01-21
|
4
|
+
|
5
|
+
* Fix a regression
|
6
|
+
([#496](https://github.com/activerecord-hackery/ransack/issues/496)) caused
|
7
|
+
by [ee571fe](https://github.com/activerecord-hackery/ransack/commit/ee571fe)
|
8
|
+
where passing a multi-parameter attribute (like `date_select`) raised
|
9
|
+
`RuntimeError: can't add a new key into hash during iteration`, and add a
|
10
|
+
regression spec for the issue.
|
11
|
+
|
12
|
+
*Nate Berkopec*, *Jon Atack*
|
13
|
+
|
14
|
+
|
3
15
|
## Version 1.6.2 - 2015-01-14
|
4
16
|
|
5
17
|
* Fix a regression
|
6
18
|
([#494](https://github.com/activerecord-hackery/ransack/issues/494))
|
7
|
-
where passing an array of routes
|
19
|
+
where passing an array of routes to `search_form_for` no longer worked,
|
8
20
|
and add a failing/passing test that would have caught the issue.
|
9
21
|
|
10
22
|
*Daniel Rikowski*, *Jon Atack*
|
@@ -3,45 +3,58 @@ module Ransack
|
|
3
3
|
class Condition
|
4
4
|
|
5
5
|
def arel_predicate
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
arel_predicate_for(attributes_array)
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def attributes_array
|
12
|
+
attributes.map do |a|
|
13
|
+
a.attr.send(
|
14
|
+
arel_predicate_for_attribute(a), formatted_values_for_attribute(a)
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def arel_predicate_for(predicates)
|
20
|
+
if predicates.size > 1
|
21
|
+
combinator_for(predicates)
|
22
|
+
else
|
23
|
+
format_predicate(predicates.first)
|
24
|
+
end
|
11
25
|
end
|
12
26
|
|
13
|
-
|
14
|
-
|
15
|
-
when Constants::AND
|
27
|
+
def combinator_for(predicates)
|
28
|
+
if combinator === Constants::AND
|
16
29
|
Arel::Nodes::Grouping.new(Arel::Nodes::And.new(predicates))
|
17
|
-
|
30
|
+
elsif combinator === Constants::OR
|
18
31
|
predicates.inject(&:or)
|
19
32
|
end
|
20
|
-
else
|
21
|
-
return_predicate(predicates.first)
|
22
33
|
end
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
34
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
if casted_array_with_in_predicate?(predicate)
|
33
|
-
predicate.right[0] = predicate.right[0].val
|
34
|
-
.map { |v| v.is_a?(String) ? Arel::Nodes.build_quoted(v) : v }
|
35
|
+
def format_predicate(predicate)
|
36
|
+
predicate.tap do
|
37
|
+
if casted_array_with_in_predicate?(predicate)
|
38
|
+
predicate.right[0] = predicate.right[0].val.map { |v| format(v) }
|
39
|
+
end
|
35
40
|
end
|
36
|
-
predicate
|
37
41
|
end
|
38
|
-
|
42
|
+
|
39
43
|
def casted_array_with_in_predicate?(predicate)
|
40
44
|
return unless defined?(Arel::Nodes::Casted)
|
41
45
|
predicate.class == Arel::Nodes::In &&
|
42
46
|
predicate.right[0].val.is_a?(Array)
|
43
47
|
end
|
44
48
|
|
49
|
+
# Necessary for Arel >= 6.0 (Rails >= 4.2)
|
50
|
+
def format(value)
|
51
|
+
if value.is_a?(String)
|
52
|
+
Arel::Nodes.build_quoted(value)
|
53
|
+
else
|
54
|
+
value
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
45
58
|
end
|
46
59
|
end
|
47
60
|
end
|
@@ -123,9 +123,11 @@ module Ransack
|
|
123
123
|
end
|
124
124
|
|
125
125
|
def value
|
126
|
-
predicate.wants_array
|
127
|
-
values.map { |v| v.cast(default_type) }
|
126
|
+
if predicate.wants_array
|
127
|
+
values.map { |v| v.cast(default_type) }
|
128
|
+
else
|
128
129
|
values.first.cast(default_type)
|
130
|
+
end
|
129
131
|
end
|
130
132
|
|
131
133
|
def build(params)
|
@@ -184,8 +186,9 @@ module Ransack
|
|
184
186
|
|
185
187
|
def formatted_values_for_attribute(attr)
|
186
188
|
formatted = casted_values_for_attribute(attr).map do |val|
|
187
|
-
|
188
|
-
|
189
|
+
if attr.ransacker && attr.ransacker.formatter
|
190
|
+
val = attr.ransacker.formatter.call(val)
|
191
|
+
end
|
189
192
|
val = predicate.format(val)
|
190
193
|
val
|
191
194
|
end
|
data/lib/ransack/search.rb
CHANGED
data/lib/ransack/version.rb
CHANGED
@@ -152,6 +152,18 @@ module Ransack
|
|
152
152
|
s = Person.ransack('')
|
153
153
|
end
|
154
154
|
|
155
|
+
it "should function correctly with a multi-parameter attribute" do
|
156
|
+
date = Date.current
|
157
|
+
s = Person.ransack(
|
158
|
+
{ "created_at_gteq(1i)" => date.year,
|
159
|
+
"created_at_gteq(2i)" => date.month,
|
160
|
+
"created_at_gteq(3i)" => date.day
|
161
|
+
}
|
162
|
+
)
|
163
|
+
expect(s.result.to_sql).to match />=/
|
164
|
+
expect(s.result.to_sql).to match date.to_s
|
165
|
+
end
|
166
|
+
|
155
167
|
it "should function correctly when using fields with dots in them" do
|
156
168
|
s = Person.ransack(:email_cont => "example.com")
|
157
169
|
expect(s.result.exists?).to be true
|
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.3
|
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-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: actionpack
|