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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8dc4a8f835fc26d7d315572626021b65eb52c4ed
4
- data.tar.gz: 79a2066b2c62fa03718561266d7b9a9219f31b96
3
+ metadata.gz: 9bf018bef97fde714331b98465544735b3cdd23c
4
+ data.tar.gz: 3f5e4cae6c7bcf4f09eb6aa3851b521b18150569
5
5
  SHA512:
6
- metadata.gz: e315ac655c3acd20683166b2444d535abeaeeefb525af68740235fff805483ce230d483fe968ace4432141aa47fbb38d413b906dccaeff9c8e50b39e30347567
7
- data.tar.gz: a4de93cc2211f753183182645ce5f8c8810af8b60d3687d3b9bccb07e303c63dd50296a9e61ba8b2cce04efa8fe91c2d1b6303551869a2870fe3abed3e2391b3
6
+ metadata.gz: e6b753315240e2e974e82e2542d3b0dfbd90c6fdb1718d02e917b6ff348764fefb5d87fbbc14d15f400026d9303c71013dca5e9194432e7716f9b81342c54f54
7
+ data.tar.gz: e17e95e45672c4feb667f9a1a940cac994b43a8844cd5606f5a53d6e25e8284fb55b5a6ddfa8119d74dacfa8b58bb9a8198ebcc540e4be3e83ab1887e4ccce24
@@ -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;'
@@ -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 of `search_form_for` no longer worked,
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
- predicates = attributes.map do |attr|
7
- attr.attr.send(
8
- arel_predicate_for_attribute(attr),
9
- formatted_values_for_attribute(attr)
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
- if predicates.size > 1
14
- case combinator
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
- when Constants::OR
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
- # TODO: Improve this edge case patch for Arel >= 6.0 (Rails >= 4.2)
28
- # that adds several conditionals to handle changing Arel API.
29
- # Related to Ransack issue #472 and pull requests #486-488.
30
- #
31
- def return_predicate(predicate)
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
- val = attr.ransacker.formatter.call(val) if
188
- attr.ransacker && attr.ransacker.formatter
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
@@ -153,7 +153,7 @@ module Ransack
153
153
  end
154
154
 
155
155
  def collapse_multiparameter_attributes!(attrs)
156
- attrs.each_key do |k|
156
+ attrs.keys.each do |k|
157
157
  if k.include?(Constants::LEFT_PARENTHESIS)
158
158
  real_attribute, position = k.split(/\(|\)/)
159
159
  cast =
@@ -1,3 +1,3 @@
1
1
  module Ransack
2
- VERSION = "1.6.2"
2
+ VERSION = "1.6.3"
3
3
  end
@@ -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.2
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-14 00:00:00.000000000 Z
13
+ date: 2015-01-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: actionpack