ransack 1.8.10 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/.travis.yml +12 -3
  4. data/CHANGELOG.md +29 -5
  5. data/Gemfile +1 -9
  6. data/README.md +16 -25
  7. data/Rakefile +1 -22
  8. data/lib/polyamorous.rb +5 -18
  9. data/lib/polyamorous/activerecord_5.1_ruby_2/join_dependency.rb +2 -2
  10. data/lib/polyamorous/activerecord_5.2.0_ruby_2/join_dependency.rb +2 -2
  11. data/lib/polyamorous/activerecord_5.2.1_ruby_2/join_association.rb +38 -0
  12. data/lib/polyamorous/activerecord_5.2.1_ruby_2/join_dependency.rb +75 -0
  13. data/lib/ransack/adapters/active_record.rb +0 -9
  14. data/lib/ransack/adapters/active_record/base.rb +8 -0
  15. data/lib/ransack/adapters/active_record/context.rb +118 -182
  16. data/lib/ransack/adapters/active_record/ransack/context.rb +1 -8
  17. data/lib/ransack/adapters/active_record/ransack/translate.rb +1 -5
  18. data/lib/ransack/constants.rb +1 -1
  19. data/lib/ransack/context.rb +4 -0
  20. data/lib/ransack/nodes/value.rb +1 -1
  21. data/lib/ransack/search.rb +1 -1
  22. data/lib/ransack/version.rb +1 -1
  23. data/ransack.gemspec +4 -3
  24. data/spec/helpers/polyamorous_helper.rb +7 -9
  25. data/spec/ransack/adapters/active_record/base_spec.rb +35 -0
  26. data/spec/ransack/adapters/active_record/context_spec.rb +3 -6
  27. data/spec/ransack/helpers/form_builder_spec.rb +3 -15
  28. data/spec/ransack/helpers/form_helper_spec.rb +11 -99
  29. data/spec/ransack/join_association_spec.rb +1 -6
  30. data/spec/ransack/join_dependency_spec.rb +1 -6
  31. data/spec/ransack/search_spec.rb +2 -2
  32. data/spec/support/schema.rb +3 -21
  33. metadata +10 -83
  34. data/lib/polyamorous/activerecord_3_and_4.0_ruby_1.9/join_association.rb +0 -76
  35. data/lib/polyamorous/activerecord_3_and_4.0_ruby_1.9/join_dependency.rb +0 -96
  36. data/lib/polyamorous/activerecord_4.1_ruby_1.9/join_association.rb +0 -2
  37. data/lib/polyamorous/activerecord_4.1_ruby_1.9/join_dependency.rb +0 -4
  38. data/lib/polyamorous/activerecord_4.1_ruby_2/join_association.rb +0 -2
  39. data/lib/polyamorous/activerecord_4.1_ruby_2/join_dependency.rb +0 -3
  40. data/lib/polyamorous/activerecord_4.1_ruby_2/make_polyamorous_inner_joins.rb +0 -14
  41. data/lib/polyamorous/activerecord_4.2_ruby_1.9/join_association.rb +0 -46
  42. data/lib/polyamorous/activerecord_4.2_ruby_1.9/join_dependency.rb +0 -87
  43. data/lib/polyamorous/activerecord_4.2_ruby_2/join_association.rb +0 -2
  44. data/lib/polyamorous/activerecord_4.2_ruby_2/join_dependency.rb +0 -24
  45. data/lib/ransack/adapters/active_record/3.0/compat.rb +0 -173
  46. data/lib/ransack/adapters/active_record/3.0/context.rb +0 -203
  47. data/lib/ransack/adapters/active_record/3.1/context.rb +0 -212
  48. data/lib/ransack/adapters/active_record/3.2/context.rb +0 -44
  49. data/lib/ransack/adapters/mongoid.rb +0 -15
  50. data/lib/ransack/adapters/mongoid/3.2/.gitkeep +0 -0
  51. data/lib/ransack/adapters/mongoid/attributes/attribute.rb +0 -37
  52. data/lib/ransack/adapters/mongoid/attributes/order_predications.rb +0 -17
  53. data/lib/ransack/adapters/mongoid/attributes/predications.rb +0 -141
  54. data/lib/ransack/adapters/mongoid/base.rb +0 -134
  55. data/lib/ransack/adapters/mongoid/context.rb +0 -212
  56. data/lib/ransack/adapters/mongoid/inquiry_hash.rb +0 -23
  57. data/lib/ransack/adapters/mongoid/ransack/constants.rb +0 -88
  58. data/lib/ransack/adapters/mongoid/ransack/context.rb +0 -59
  59. data/lib/ransack/adapters/mongoid/ransack/nodes/condition.rb +0 -22
  60. data/lib/ransack/adapters/mongoid/ransack/translate.rb +0 -13
  61. data/lib/ransack/adapters/mongoid/ransack/visitor.rb +0 -18
  62. data/lib/ransack/adapters/mongoid/table.rb +0 -35
  63. data/spec/mongoid/adapters/mongoid/base_spec.rb +0 -314
  64. data/spec/mongoid/adapters/mongoid/context_spec.rb +0 -56
  65. data/spec/mongoid/configuration_spec.rb +0 -162
  66. data/spec/mongoid/dependencies_spec.rb +0 -8
  67. data/spec/mongoid/helpers/ransack_helper.rb +0 -11
  68. data/spec/mongoid/nodes/condition_spec.rb +0 -49
  69. data/spec/mongoid/nodes/grouping_spec.rb +0 -13
  70. data/spec/mongoid/predicate_spec.rb +0 -155
  71. data/spec/mongoid/search_spec.rb +0 -445
  72. data/spec/mongoid/support/mongoid.yml +0 -11
  73. data/spec/mongoid/support/schema.rb +0 -135
  74. data/spec/mongoid/translate_spec.rb +0 -14
  75. data/spec/mongoid_spec_helper.rb +0 -63
  76. data/spec/ransack/dependencies_spec.rb +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4bd4bc9e3845ed5397dbff350844ec9c983bc19f2cc9f95c15db2a67d97ce3ee
4
- data.tar.gz: 293cd8927a3623b7468e1feeddd7a9a37a7e68258f141504395e4894e4511614
3
+ metadata.gz: 35bd0ff11964ff0c0308e7b663a3284510e7f5da71f6799bf061992b6515b616
4
+ data.tar.gz: 415ef127b34f85c7fdcf48e1f66f764d060cefacfa3a9a3d013688ecc38a07da
5
5
  SHA512:
6
- metadata.gz: 7e696c2625dd8fa6b3d5b732aadf561f99076cd252c5b44d2fc17049752734b386d6aa80c8afd7460621cd76f787d4690f435b5c00a13df98e4690fc80ef0ee7
7
- data.tar.gz: e25d3732e1291ce17bc94895f444ce730def58d125fa93ed8f4d4b2048a3e030ed3529aad19fdba0ea76865da3fed53841629c7137b265796b6c051b78a3c052
6
+ metadata.gz: 56239015bf48bc38842fa9f09325a04dc047299c0f17da8429a9a1ea95cf3aedf9d07117da157cc036a8fb8280d2925cf318b62a7b66b8a99acaa8d8a48e4b30
7
+ data.tar.gz: 574ac22523e67dddce34c18a929a9624cde30de3c14e2c53d6476c8136f48541879c1fd4b89467786e3f128327f79f4b6617561de7d11d5fbf6f6e888d37a212
data/.gitignore CHANGED
@@ -3,4 +3,3 @@
3
3
  Gemfile.lock
4
4
  pkg/*
5
5
  coverage/*
6
- .DS_Store
@@ -7,6 +7,18 @@ rvm:
7
7
  - 2.2
8
8
 
9
9
  env:
10
+ - RAILS=5-2-stable DB=sqlite3
11
+ - RAILS=5-2-stable DB=mysql
12
+ - RAILS=5-2-stable DB=postgres
13
+
14
+ - RAILS=v5.2.1 DB=sqlite3
15
+ - RAILS=v5.2.1 DB=mysql
16
+ - RAILS=v5.2.1 DB=postgres
17
+
18
+ - RAILS=v5.2.0 DB=sqlite3
19
+ - RAILS=v5.2.0 DB=mysql
20
+ - RAILS=v5.2.0 DB=postgres
21
+
10
22
  - RAILS=5-1-stable DB=sqlite3
11
23
  - RAILS=5-1-stable DB=mysql
12
24
  - RAILS=5-1-stable DB=postgres
@@ -15,9 +27,6 @@ env:
15
27
  - RAILS=5-0-stable DB=mysql
16
28
  - RAILS=5-0-stable DB=postgres
17
29
 
18
- - RAILS=4-2-stable DB=sqlite3
19
- - RAILS=4-2-stable DB=mysql
20
- - RAILS=4-2-stable DB=postgres
21
30
  matrix:
22
31
  allow_failures:
23
32
  - env: RAILS=5-2-stable DB=sqlite3
@@ -1,8 +1,32 @@
1
1
  # Change Log
2
2
 
3
- ## Version 1.8.9 - 2018-08-09
3
+ ## Unreleased
4
4
 
5
- * Locked Active Record compatibiity at 5.1.0
5
+ ## Version 2.0.0 - 2018-08-09
6
+
7
+ * Add support for Active Record 5.2.1
8
+ PR [#938](https://github.com/activerecord-hackery/ransack/pull/938)
9
+
10
+ * Fix sort with joins on existing association
11
+ PR [#937](https://github.com/activerecord-hackery/ransack/pull/937)
12
+
13
+ * Add the ability to skip arg sanitization on a per scope basis. Using
14
+ `ransackable_scopes_skip_sanitize_args`, users can define a list of
15
+ scopes which will bypass parameter sanitization. This allows passing 0,
16
+ 1, t, f, etc. to a scope as an actual parameter.
17
+ PR [#933](https://github.com/activerecord-hackery/ransack/pull/933)
18
+
19
+ * Drop support for Active Record < 5.0.
20
+ PR [#929](https://github.com/activerecord-hackery/ransack/pull/929)
21
+
22
+ * Extract mongoid support to a separate gem.
23
+ PR [#928](https://github.com/activerecord-hackery/ransack/pull/928)
24
+
25
+ * Absorb polyamorous
26
+ PR [#927](https://github.com/activerecord-hackery/ransack/pull/927)
27
+
28
+ * Fix broken monkey patch of #form_with
29
+ PR [#922](https://github.com/activerecord-hackery/ransack/pull/922)
6
30
 
7
31
  ## Version 1.8.8 - 2018-03-16
8
32
  * Fix multiple database support
@@ -19,14 +43,14 @@
19
43
 
20
44
  * Rails 5.2 support
21
45
  PR [#868](https://github.com/activerecord-hackery/ransack/pull/868)
22
-
46
+
23
47
  * Lock pg gem to 0.21 to support older releases
24
48
 
25
49
  * Warnings cleanup
26
50
  PR [#867](https://github.com/activerecord-hackery/ransack/pull/867)
27
51
 
28
52
  * Wildcard escaping
29
- PR [#866]
53
+ PR [#866]
30
54
 
31
55
  ## Version 1.8.6 - 2018-01-23
32
56
 
@@ -40,7 +64,7 @@
40
64
 
41
65
  ## Version 1.8.5
42
66
 
43
- ### Added
67
+ ### Added
44
68
 
45
69
  * Added Turkish Translations
46
70
  PR [#835](https://github.com/activerecord-hackery/ransack/issues/835).
data/Gemfile CHANGED
@@ -22,7 +22,7 @@ when /^v/ # A tagged version
22
22
  gem 'activerecord', require: false
23
23
  gem 'actionpack'
24
24
  end
25
- if rails == 'v5.2.0'
25
+ if rails >= 'v5.2.0'
26
26
  gem 'mysql2', '~> 0.4.4'
27
27
  end
28
28
  else
@@ -40,14 +40,6 @@ else
40
40
  end
41
41
  end
42
42
 
43
- if ENV['DB'] =~ /mongoid4/
44
- gem 'mongoid', '~> 4.0.0', require: false
45
- end
46
-
47
- if ENV['DB'] =~ /mongoid5/
48
- gem 'mongoid', '~> 5.0.0', require: false
49
- end
50
-
51
43
  group :test do
52
44
  # TestUnit was removed from Ruby 2.2 but still needed for testing Rails 3.x.
53
45
  gem 'test-unit', '~> 3.0' if RUBY_VERSION >= '2.2'
data/README.md CHANGED
@@ -1,28 +1,5 @@
1
1
  # Ransack
2
2
 
3
- ### Maintainer Wanted
4
-
5
- A note from [Sean](https://github.com/seanfcarroll).
6
- Ransack is a fantastic gem, and a key part of many Rails projects. It is also a core component of [ActiveAdmin](https://github.com/activeadmin/activeadmin) and generally a great way to add fairly complex search and filtering without having to resort to external services, such as Elasticsearch.
7
-
8
- In my humble opinion, Ransack can be much more, if it does a bit less. What I mean is that the API vector of Ransack is quite large, and really has been issue-driven. There are complications with Polymorphic relations, complex joins and MongoDB. It's not clear sometimes if there is a bug or not.
9
-
10
- I was hoping to lead Ransack to version 2.0, and in my opinion this would have included:
11
-
12
- - Absorbing Polyamorous
13
- - Splitting MongoDB support into a seperate gem
14
- - Dropping support for older Rails versions; strictly follow the [Rails support policy](http://guides.rubyonrails.org/maintenance_policy.html). This is important as the codebase is littered with code for de-supported Rails versions
15
- - Add a generator to build in Ransack with a scaffold
16
- - Generate tests for Ransack-enabled applications
17
- - Update the Wiki / docs with lots of examples of 'how-to', questions are the majority of issues on Ransack
18
- - Increase supported translations
19
-
20
- Unfortunately I am quite occupied at present with several projects, including [crowdAI](https://github.com/crowdAI/crowdai), and I will need to step down as a maintainer. I have also posted it [here](https://github.com/pickhardt/maintainers-wanted).
21
-
22
- If you want to step up, please contact me on gmail as **sfcarroll**
23
-
24
-
25
-
26
3
  [![Build Status](https://travis-ci.org/activerecord-hackery/ransack.svg)](https://travis-ci.org/activerecord-hackery/ransack)
27
4
  [![Gem Version](https://badge.fury.io/rb/ransack.svg)](http://badge.fury.io/rb/ransack)
28
5
  [![Code Climate](https://codeclimate.com/github/activerecord-hackery/ransack/badges/gpa.svg)](https://codeclimate.com/github/activerecord-hackery/ransack)
@@ -448,7 +425,7 @@ List of all possible predicates
448
425
  | `*_lteq` | less than or equal | |
449
426
  | `*_gt` | greater than | |
450
427
  | `*_gteq` | greater than or equal | |
451
- | `*_present` | not null and not empty | e.g. `q[name_present]=1` (SQL: `col is not null AND col != ''`) |
428
+ | `*_present` | not null and not empty | Only compatible with string columns. Example: `q[name_present]=1` (SQL: `col is not null AND col != ''`) |
452
429
  | `*_blank` | is null or empty. | (SQL: `col is null OR col = ''`) |
453
430
  | `*_null` | is null | |
454
431
  | `*_not_null` | is not null | |
@@ -734,7 +711,7 @@ boolean. This is currently resolved in Rails 5 :smiley:
734
711
  However, perhaps you have `user_id: [1]` and you do not want Ransack to convert
735
712
  1 into a boolean. (Values sanitized to booleans can be found in the
736
713
  [constants.rb](https://github.com/activerecord-hackery/ransack/blob/master/lib/ransack/constants.rb#L28)).
737
- To turn this off, and handle type conversions yourself, set
714
+ To turn this off globally, and handle type conversions yourself, set
738
715
  `sanitize_custom_scope_booleans` to false in an initializer file like
739
716
  config/initializers/ransack.rb:
740
717
 
@@ -744,6 +721,19 @@ Ransack.configure do |c|
744
721
  end
745
722
  ```
746
723
 
724
+ To turn this off on a per-scope basis Ransack adds the following method to
725
+ `ActiveRecord::Base` that you can redefine to selectively override sanitization:
726
+
727
+ `ransackable_scopes_skip_sanitize_args`
728
+
729
+ Add the scope you wish to bypass this behavior to ransackable_scopes_skip_sanitize_args:
730
+
731
+ ```ruby
732
+ def ransackable_scopes_skip_sanitize_args
733
+ [:scope_to_skip_sanitize_args]
734
+ end
735
+ ```
736
+
747
737
  Scopes are a recent addition to Ransack and currently have a few caveats:
748
738
  First, a scope involving child associations needs to be defined in the parent
749
739
  table model, not in the child model. Second, scopes with an array as an
@@ -875,6 +865,7 @@ en:
875
865
 
876
866
  ## Mongoid
877
867
 
868
+ Mongoid support has been moved to its own gem at [ransack-mongoid](https://github.com/activerecord-hackery/ransack-mongoid).
878
869
  Ransack works with Mongoid in the same way as Active Record, except that with
879
870
  Mongoid, associations are not currently supported. Demo source code may be found
880
871
  [here](https://github.com/Zhomart/ransack-mongodb-demo). A `result` method
data/Rakefile CHANGED
@@ -11,17 +11,8 @@ RSpec::Core::RakeTask.new(:spec) do |rspec|
11
11
  # rspec.rspec_opts = ['--backtrace']
12
12
  end
13
13
 
14
- RSpec::Core::RakeTask.new(:mongoid) do |rspec|
15
- ENV['SPEC'] = 'spec/mongoid/**/*_spec.rb'
16
- rspec.rspec_opts = ['--backtrace']
17
- end
18
-
19
14
  task :default do
20
- if ENV['DB'] =~ /mongoid/
21
- Rake::Task["mongoid"].invoke
22
- else
23
- Rake::Task["spec"].invoke
24
- end
15
+ Rake::Task["spec"].invoke
25
16
  end
26
17
 
27
18
  desc "Open an irb session with Ransack and the sample data used in specs"
@@ -31,15 +22,3 @@ task :console do
31
22
  ARGV.clear
32
23
  Pry.start
33
24
  end
34
-
35
- desc "Open an irb session with Ransack, Mongoid and the sample data used in specs"
36
- task :mongoid_console do
37
- require 'irb'
38
- require 'irb/completion'
39
- require 'pry'
40
- require 'mongoid'
41
- require File.expand_path('../lib/ransack.rb', __FILE__)
42
- require File.expand_path('../spec/mongoid/support/schema.rb', __FILE__)
43
- ARGV.clear
44
- Pry.start
45
- end
@@ -24,28 +24,15 @@ if defined?(::ActiveRecord)
24
24
  require 'polyamorous/swapping_reflection_class'
25
25
 
26
26
  ar_version = ::ActiveRecord::VERSION::STRING[0,3]
27
- ar_version = '3_and_4.0' if ar_version < '4.1'
28
- ar_version = ::ActiveRecord::VERSION::STRING[0,5] if ar_version == '5.2'
29
-
30
- method, ruby_version =
31
- if RUBY_VERSION >= '2.0' && ar_version >= '4.1'
32
- # Ruby 2; we can use `prepend` to patch Active Record cleanly.
33
- [:prepend, '2']
34
- else
35
- # Ruby 1.9; we must use `alias_method` to patch Active Record.
36
- [:include, '1.9']
37
- end
27
+ ar_version = ::ActiveRecord::VERSION::STRING[0,5] if ar_version >= '5.2'
38
28
 
39
29
  %w(join_association join_dependency).each do |file|
40
- require "polyamorous/activerecord_#{ar_version}_ruby_#{ruby_version}/#{file}"
30
+ require "polyamorous/activerecord_#{ar_version}_ruby_2/#{file}"
41
31
  end
42
32
 
43
- Polyamorous::JoinDependency.send(method, Polyamorous::JoinDependencyExtensions)
44
- if method == :prepend
45
- Polyamorous::JoinDependency.singleton_class
46
- .send(:prepend, Polyamorous::JoinDependencyExtensions::ClassMethods)
47
- end
48
- Polyamorous::JoinAssociation.send(method, Polyamorous::JoinAssociationExtensions)
33
+ Polyamorous::JoinDependency.send(:prepend, Polyamorous::JoinDependencyExtensions)
34
+ Polyamorous::JoinDependency.singleton_class.send(:prepend, Polyamorous::JoinDependencyExtensions::ClassMethods)
35
+ Polyamorous::JoinAssociation.send(:prepend, Polyamorous::JoinAssociationExtensions)
49
36
 
50
37
  Polyamorous::JoinBase.class_eval do
51
38
  if method_defined?(:active_record)
@@ -9,7 +9,7 @@ module Polyamorous
9
9
  if name.is_a? Join
10
10
  reflection = find_reflection base_klass, name.name
11
11
  reflection.check_validity!
12
- reflection.check_eager_loadable! if ActiveRecord::VERSION::MAJOR >= 5
12
+ reflection.check_eager_loadable!
13
13
 
14
14
  klass = if reflection.polymorphic?
15
15
  name.klass || base_klass
@@ -20,7 +20,7 @@ module Polyamorous
20
20
  else
21
21
  reflection = find_reflection base_klass, name
22
22
  reflection.check_validity!
23
- reflection.check_eager_loadable! if ActiveRecord::VERSION::MAJOR >= 5
23
+ reflection.check_eager_loadable!
24
24
 
25
25
  if reflection.polymorphic?
26
26
  raise ActiveRecord::EagerLoadPolymorphicError.new(reflection)
@@ -9,7 +9,7 @@ module Polyamorous
9
9
  if name.is_a? Join
10
10
  reflection = find_reflection base_klass, name.name
11
11
  reflection.check_validity!
12
- reflection.check_eager_loadable! if ActiveRecord::VERSION::MAJOR >= 5
12
+ reflection.check_eager_loadable!
13
13
 
14
14
  klass = if reflection.polymorphic?
15
15
  name.klass || base_klass
@@ -20,7 +20,7 @@ module Polyamorous
20
20
  else
21
21
  reflection = find_reflection base_klass, name
22
22
  reflection.check_validity!
23
- reflection.check_eager_loadable! if ActiveRecord::VERSION::MAJOR >= 5
23
+ reflection.check_eager_loadable!
24
24
 
25
25
  if reflection.polymorphic?
26
26
  raise ActiveRecord::EagerLoadPolymorphicError.new(reflection)
@@ -0,0 +1,38 @@
1
+ # active_record_5.2.1_ruby_2/join_association.rb
2
+
3
+ module Polyamorous
4
+ module JoinAssociationExtensions
5
+ include SwappingReflectionClass
6
+ def self.prepended(base)
7
+ base.class_eval { attr_reader :join_type }
8
+ end
9
+
10
+ def initialize(reflection, children, polymorphic_class = nil, join_type = Arel::Nodes::InnerJoin)
11
+ @join_type = join_type
12
+ if polymorphic_class && ::ActiveRecord::Base > polymorphic_class
13
+ swapping_reflection_klass(reflection, polymorphic_class) do |reflection|
14
+ super(reflection, children)
15
+ self.reflection.options[:polymorphic] = true
16
+ end
17
+ else
18
+ super(reflection, children)
19
+ end
20
+ end
21
+
22
+ # Reference: https://github.com/rails/rails/commit/9b15db5
23
+ # NOTE: Not sure we still need it?
24
+ #
25
+ def ==(other)
26
+ base_klass == other.base_klass
27
+ end
28
+
29
+ def build_constraint(klass, table, key, foreign_table, foreign_key)
30
+ if reflection.polymorphic?
31
+ super(klass, table, key, foreign_table, foreign_key)
32
+ .and(foreign_table[reflection.foreign_type].eq(reflection.klass.name))
33
+ else
34
+ super(klass, table, key, foreign_table, foreign_key)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,75 @@
1
+ # active_record_5.2.1_ruby_2/join_dependency.rb
2
+
3
+ module Polyamorous
4
+ module JoinDependencyExtensions
5
+ # Replaces ActiveRecord::Associations::JoinDependency#build
6
+ #
7
+ def build(associations, base_klass)
8
+ associations.map do |name, right|
9
+ if name.is_a? Join
10
+ reflection = find_reflection base_klass, name.name
11
+ reflection.check_validity!
12
+ reflection.check_eager_loadable!
13
+
14
+ klass = if reflection.polymorphic?
15
+ name.klass || base_klass
16
+ else
17
+ reflection.klass
18
+ end
19
+ JoinAssociation.new(reflection, build(right, klass), name.klass, name.type)
20
+ else
21
+ reflection = find_reflection base_klass, name
22
+ reflection.check_validity!
23
+ reflection.check_eager_loadable!
24
+
25
+ if reflection.polymorphic?
26
+ raise ActiveRecord::EagerLoadPolymorphicError.new(reflection)
27
+ end
28
+ JoinAssociation.new(reflection, build(right, reflection.klass))
29
+ end
30
+ end
31
+ end
32
+
33
+ def find_join_association_respecting_polymorphism(reflection, parent, klass)
34
+ if association = parent.children.find { |j| j.reflection == reflection }
35
+ unless reflection.polymorphic?
36
+ association
37
+ else
38
+ association if association.base_klass == klass
39
+ end
40
+ end
41
+ end
42
+
43
+ def build_join_association_respecting_polymorphism(reflection, parent, klass)
44
+ if reflection.polymorphic? && klass
45
+ JoinAssociation.new(reflection, self, klass)
46
+ else
47
+ JoinAssociation.new(reflection, self)
48
+ end
49
+ end
50
+
51
+ module ClassMethods
52
+ # Prepended before ActiveRecord::Associations::JoinDependency#walk_tree
53
+ #
54
+ def walk_tree(associations, hash)
55
+ case associations
56
+ when TreeNode
57
+ associations.add_to_tree(hash)
58
+ when Hash
59
+ associations.each do |k, v|
60
+ cache =
61
+ if TreeNode === k
62
+ k.add_to_tree(hash)
63
+ else
64
+ hash[k] ||= {}
65
+ end
66
+ walk_tree(v, cache)
67
+ end
68
+ else
69
+ super(associations, hash)
70
+ end
71
+ end
72
+ end
73
+
74
+ end
75
+ end
@@ -12,12 +12,3 @@ ActiveSupport.on_load(:active_record) do
12
12
  end
13
13
 
14
14
  require 'ransack/adapters/active_record/context'
15
-
16
- case ActiveRecord::VERSION::STRING
17
- when /^3\.0\./
18
- require 'ransack/adapters/active_record/3.0/context'
19
- when /^3\.1\./
20
- require 'ransack/adapters/active_record/3.1/context'
21
- when /^3\.2\./
22
- require 'ransack/adapters/active_record/3.2/context'
23
- end
@@ -64,6 +64,14 @@ module Ransack
64
64
  []
65
65
  end
66
66
 
67
+ # ransack_scope_skip_sanitize_args, by default, returns an empty array.
68
+ # i.e. use the sanitize_scope_args setting to determin if args should be converted.
69
+ # For overriding with a list of scopes which should be passed the args as-is.
70
+ #
71
+ def ransackable_scopes_skip_sanitize_args
72
+ []
73
+ end
74
+
67
75
  end
68
76
  end
69
77
  end