ransack 1.8.6 → 1.8.7

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: f251a5a3d39a780d575f8f18abd01de4a9096caa
4
- data.tar.gz: 8846114332ef60596d2fc18b52cdb5715928e425
3
+ metadata.gz: a68f79e9c101613e0af4423267942f4d38007d19
4
+ data.tar.gz: ae51bdebc41d71f0902c29aeafd570e8057ad59b
5
5
  SHA512:
6
- metadata.gz: 86d509ea419bfe2bb1d43096e670f0736826c996a36f5fac74c650eaeb081a77832f8ff7edba63beaae0ad17ae2d4d8211aa99e5d003d259dff5fcb127187514
7
- data.tar.gz: 705778bb578589bd055606eedfbe1ec10fdc01ab26508695fc0386d276f233c0bcdb767220331cf2b6b6b8b352d8b9c60edd9ef1c303e66ea4ea6cdb86725cb5
6
+ metadata.gz: 39361cd28cb1002386b506a28c4a4065448bb82c23bb3d989c7038ffa33dba628d170f8a2daca58ed3665707de833fe9f8d325884be8a1812dbc07c6e7abce8a
7
+ data.tar.gz: 1d71cb39bd5524cb9c53313cbd6abf971f248b0c5978b376d3049bfb5ab684e7b6937c7785d0033ba534c52e700559c1c3faa093f368952743e5dd7d41db4f87
@@ -9,6 +9,10 @@ rvm:
9
9
  - 2.0
10
10
 
11
11
  env:
12
+ - RAILS=5-2-stable DB=sqlite3
13
+ - RAILS=5-2-stable DB=mysql
14
+ - RAILS=5-2-stable DB=postgres
15
+
12
16
  - RAILS=5-0-stable DB=sqlite3
13
17
  - RAILS=5-0-stable DB=mysql
14
18
  - RAILS=5-0-stable DB=postgres
@@ -35,6 +39,13 @@ env:
35
39
 
36
40
  matrix:
37
41
  exclude:
42
+ - rvm: 2.1.10
43
+ env: RAILS=5-2-stable DB=sqlite3
44
+ - rvm: 2.1.10
45
+ env: RAILS=5-2-stable DB=mysql
46
+ - rvm: 2.1.10
47
+ env: RAILS=5-2-stable DB=postgres
48
+
38
49
  - rvm: 2.1.10
39
50
  env: RAILS=5-0-stable DB=sqlite3
40
51
  - rvm: 2.1.10
@@ -42,6 +53,13 @@ matrix:
42
53
  - rvm: 2.1.10
43
54
  env: RAILS=5-0-stable DB=postgres
44
55
 
56
+ - rvm: 2.0
57
+ env: RAILS=5-2-stable DB=sqlite3
58
+ - rvm: 2.0
59
+ env: RAILS=5-2-stable DB=mysql
60
+ - rvm: 2.0
61
+ env: RAILS=5-2-stable DB=postgres
62
+
45
63
  - rvm: 2.0
46
64
  env: RAILS=5-0-stable DB=sqlite3
47
65
  - rvm: 2.0
data/Gemfile CHANGED
@@ -38,6 +38,9 @@ else
38
38
  if rails == '3-0-stable'
39
39
  gem 'mysql2', '< 0.3'
40
40
  end
41
+ if rails == '5-2-stable'
42
+ gem 'mysql2', '~> 0.4.4'
43
+ end
41
44
  end
42
45
 
43
46
  if ENV['DB'] =~ /mongoid4/
@@ -14,7 +14,7 @@ Ransack.configure do |config|
14
14
  config.add_predicate name, :arel_predicate => name
15
15
  end
16
16
  Ransack::Constants::DERIVED_PREDICATES.each do |args|
17
- config.add_predicate *args
17
+ config.add_predicate(*args)
18
18
  end
19
19
  end
20
20
 
@@ -14,7 +14,9 @@ module Ransack
14
14
 
15
15
  def initialize(object, options = {})
16
16
  super
17
- @arel_visitor = @engine.connection.visitor
17
+ if ::ActiveRecord::VERSION::STRING < Constants::RAILS_5_2
18
+ @arel_visitor = @engine.connection.visitor
19
+ end
18
20
  end
19
21
 
20
22
  def relation_for(object)
@@ -25,7 +27,7 @@ module Ransack
25
27
  return nil unless attr && attr.valid?
26
28
  name = attr.arel_attribute.name.to_s
27
29
  table = attr.arel_attribute.relation.table_name
28
- schema_cache = @engine.connection.schema_cache
30
+ schema_cache = ::ActiveRecord::Base.connection.schema_cache
29
31
  unless schema_cache.send(database_table_exists?, table)
30
32
  raise "No table named #{table} exists."
31
33
  end
@@ -135,7 +137,7 @@ module Ransack
135
137
  end
136
138
 
137
139
  def alias_tracker
138
- @join_dependency.alias_tracker
140
+ @join_dependency.send(:alias_tracker)
139
141
  end
140
142
 
141
143
  def lock_association(association)
@@ -145,11 +147,11 @@ module Ransack
145
147
  if ::ActiveRecord::VERSION::STRING >= Constants::RAILS_4_1
146
148
  def remove_association(association)
147
149
  return if @lock_associations.include?(association)
148
- @join_dependency.join_root.children.delete_if { |stashed|
150
+ @join_dependency.instance_variable_get(:@join_root).children.delete_if { |stashed|
149
151
  stashed.eql?(association)
150
152
  }
151
153
  @object.joins_values.delete_if { |jd|
152
- jd.join_root.children.map(&:object_id) == [association.object_id]
154
+ jd.instance_variable_get(:@join_root).children.map(&:object_id) == [association.object_id]
153
155
  }
154
156
  end
155
157
  else
@@ -181,7 +183,6 @@ module Ransack
181
183
  def build_correlated_subquery(association)
182
184
  join_constraints = extract_joins(association)
183
185
  join_root = join_constraints.shift
184
- join_table = join_root.left
185
186
  correlated_key = join_root.right.expr.left
186
187
  subquery = Arel::SelectManager.new(association.base_klass)
187
188
  subquery.from(join_root.left)
@@ -280,12 +281,17 @@ module Ransack
280
281
  relation.table.from(relation.table), string_joins
281
282
  end
282
283
 
283
- join_dependency = JoinDependency.new(
284
- relation.klass, association_joins, join_list
285
- )
286
-
287
- join_nodes.each do |join|
288
- join_dependency.alias_tracker.aliases[join.left.name.downcase] = 1
284
+ if ::ActiveRecord::VERSION::STRING < Constants::RAILS_5_2
285
+ join_dependency = JoinDependency.new(relation.klass, association_joins, join_list)
286
+ join_nodes.each do |join|
287
+ join_dependency.send(:alias_tracker).aliases[join.left.name.downcase] = 1
288
+ end
289
+ else
290
+ alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(::ActiveRecord::Base.connection, relation.table.name, join_list)
291
+ join_dependency = JoinDependency.new(relation.klass, relation.table, association_joins, alias_tracker)
292
+ join_nodes.each do |join|
293
+ join_dependency.alias_tracker.aliases[join.left.name.downcase] = 1
294
+ end
289
295
  end
290
296
 
291
297
  if ::ActiveRecord::VERSION::STRING >= Constants::RAILS_4_1
@@ -308,7 +314,7 @@ module Ransack
308
314
  if ::ActiveRecord::VERSION::STRING >= Constants::RAILS_4_1
309
315
 
310
316
  def find_association(name, parent = @base, klass = nil)
311
- @join_dependency.join_root.children.detect do |assoc|
317
+ @join_dependency.instance_variable_get(:@join_root).children.detect do |assoc|
312
318
  assoc.reflection.name == name &&
313
319
  (@associations_pot.empty? || @associations_pot[assoc] == parent) &&
314
320
  (!klass || assoc.reflection.klass == klass)
@@ -316,21 +322,34 @@ module Ransack
316
322
  end
317
323
 
318
324
  def build_association(name, parent = @base, klass = nil)
319
- jd = JoinDependency.new(
320
- parent.base_klass,
321
- Polyamorous::Join.new(name, @join_type, klass),
322
- []
323
- )
324
- found_association = jd.join_root.children.last
325
+ if ::ActiveRecord::VERSION::STRING < Constants::RAILS_5_2
326
+ jd = JoinDependency.new(
327
+ parent.base_klass,
328
+ Polyamorous::Join.new(name, @join_type, klass),
329
+ []
330
+ )
331
+ found_association = jd.join_root.children.last
332
+ else
333
+ alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(::ActiveRecord::Base.connection, parent.table.name, [])
334
+ jd = JoinDependency.new(
335
+ parent.base_klass,
336
+ parent.base_klass.arel_table,
337
+ Polyamorous::Join.new(name, @join_type, klass),
338
+ alias_tracker
339
+ )
340
+ found_association = jd.instance_variable_get(:@join_root).children.last
341
+ end
342
+
343
+
325
344
  @associations_pot[found_association] = parent
326
345
 
327
346
  # TODO maybe we dont need to push associations here, we could loop
328
347
  # through the @associations_pot instead
329
- @join_dependency.join_root.children.push found_association
348
+ @join_dependency.instance_variable_get(:@join_root).children.push found_association
330
349
 
331
350
  # Builds the arel nodes properly for this association
332
351
  @join_dependency.send(
333
- :construct_tables!, jd.join_root, found_association
352
+ :construct_tables!, jd.instance_variable_get(:@join_root), found_association
334
353
  )
335
354
 
336
355
  # Leverage the stashed association functionality in AR
@@ -340,7 +359,7 @@ module Ransack
340
359
  end
341
360
 
342
361
  def extract_joins(association)
343
- parent = @join_dependency.join_root
362
+ parent = @join_dependency.instance_variable_get(:@join_root)
344
363
  reflection = association.reflection
345
364
  join_constraints = if ::ActiveRecord::VERSION::STRING < Constants::RAILS_5_1
346
365
  association.join_constraints(
@@ -385,7 +404,7 @@ module Ransack
385
404
  end
386
405
 
387
406
  def find_association(name, parent = @base, klass = nil)
388
- found_association = @join_dependency.join_associations
407
+ @join_dependency.join_associations
389
408
  .detect do |assoc|
390
409
  assoc.reflection.name == name &&
391
410
  assoc.parent == parent &&
@@ -104,7 +104,7 @@ module Ransack
104
104
  case ActiveRecord::Base.connection.adapter_name
105
105
  when "Mysql2".freeze, "PostgreSQL".freeze
106
106
  # Necessary for PostgreSQL and MySQL
107
- unescaped.to_s.gsub(/([\\|\%|_|.])/, '\\\\\\1')
107
+ unescaped.to_s.gsub(/([\\%_.])/, '\\\\\\1')
108
108
  else
109
109
  unescaped
110
110
  end
@@ -30,7 +30,9 @@ module Ransack
30
30
  @associations_pot = {}
31
31
  @lock_associations = []
32
32
 
33
- if ::ActiveRecord::VERSION::STRING >= Constants::RAILS_4_1
33
+ if ::ActiveRecord::VERSION::STRING >= Constants::RAILS_5_2
34
+ @base = @join_dependency.instance_variable_get(:@join_root)
35
+ elsif ::ActiveRecord::VERSION::STRING >= Constants::RAILS_4_1
34
36
  @base = @join_dependency.join_root
35
37
  @engine = @base.base_klass.arel_engine
36
38
  else
@@ -33,8 +33,8 @@ module Ransack
33
33
  predicate = attribute.attr.public_send(arel_pred, arel_values)
34
34
 
35
35
  if in_predicate?(predicate)
36
- predicate.right = predicate.right.map do |predicate|
37
- casted_array?(predicate) ? format_values_for(predicate) : predicate
36
+ predicate.right = predicate.right.map do |pr|
37
+ casted_array?(pr) ? format_values_for(pr) : pr
38
38
  end
39
39
  end
40
40
 
@@ -47,6 +47,7 @@ module Ransack
47
47
 
48
48
  RAILS_4_1 = '4.1'.freeze
49
49
  RAILS_5_1 = '5.1'.freeze
50
+ RAILS_5_2 = '5.2'.freeze
50
51
 
51
52
  RANSACK_SLASH_SEARCHES = 'ransack/searches'.freeze
52
53
  RANSACK_SLASH_SEARCHES_SLASH_SEARCH = 'ransack/searches/search'.freeze
@@ -6,9 +6,15 @@ module ActionView::Helpers::Tags
6
6
  # https://github.com/rails/rails/commit/c1a118a
7
7
  class Base
8
8
  private
9
- def value(object)
10
- object.send @method_name if object # use send instead of public_send
11
- end
9
+ if ::ActiveRecord::VERSION::STRING < '5.2'
10
+ def value(object)
11
+ object.send @method_name if object # use send instead of public_send
12
+ end
13
+ else # rails/rails#29791
14
+ def value
15
+ @object.send @method_name if @object
16
+ end
17
+ end
12
18
  end
13
19
  end
14
20
 
@@ -237,7 +243,7 @@ module Ransack
237
243
  Translate.association(base, :context => object.context),
238
244
  collection_for_base(action, base)
239
245
  ]
240
- rescue UntraversableAssociationError => e
246
+ rescue UntraversableAssociationError
241
247
  nil
242
248
  end
243
249
  end
@@ -5,7 +5,7 @@ module Ransack
5
5
 
6
6
  attr_reader :name, :ransacker_args
7
7
 
8
- delegate :blank?, :present?, :==, :to => :name
8
+ delegate :blank?, :present?, :to => :name
9
9
  delegate :engine, :to => :context
10
10
 
11
11
  def initialize(context, name = nil, ransacker_args = [])
@@ -68,7 +68,6 @@ module Ransack
68
68
  def respond_to?(method_id)
69
69
  super or begin
70
70
  method_name = method_id.to_s
71
- writer = method_name.sub!(/\=$/, ''.freeze)
72
71
  attribute_method?(method_name) ? true : false
73
72
  end
74
73
  end
@@ -1,3 +1,3 @@
1
1
  module Ransack
2
- VERSION = '1.8.6'
2
+ VERSION = '1.8.7'
3
3
  end
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
25
25
  s.add_development_dependency 'machinist', '~> 1.0.6'
26
26
  s.add_development_dependency 'faker', '~> 0.9.5'
27
27
  s.add_development_dependency 'sqlite3', '~> 1.3.3'
28
- s.add_development_dependency 'pg'
28
+ s.add_development_dependency 'pg', '~> 0.21'
29
29
  s.add_development_dependency 'mysql2', '0.3.20'
30
30
  s.add_development_dependency 'pry', '0.10'
31
31
 
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.6
4
+ version: 1.8.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ernie Miller
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2018-01-23 00:00:00.000000000 Z
14
+ date: 2018-02-05 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: actionpack
@@ -143,16 +143,16 @@ dependencies:
143
143
  name: pg
144
144
  requirement: !ruby/object:Gem::Requirement
145
145
  requirements:
146
- - - ">="
146
+ - - "~>"
147
147
  - !ruby/object:Gem::Version
148
- version: '0'
148
+ version: '0.21'
149
149
  type: :development
150
150
  prerelease: false
151
151
  version_requirements: !ruby/object:Gem::Requirement
152
152
  requirements:
153
- - - ">="
153
+ - - "~>"
154
154
  - !ruby/object:Gem::Version
155
- version: '0'
155
+ version: '0.21'
156
156
  - !ruby/object:Gem::Dependency
157
157
  name: mysql2
158
158
  requirement: !ruby/object:Gem::Requirement