ransack 1.6.6 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +14 -10
- data/CHANGELOG.md +90 -1
- data/CONTRIBUTING.md +14 -10
- data/README.md +26 -8
- data/Rakefile +1 -5
- data/lib/ransack.rb +6 -12
- data/lib/ransack/adapters.rb +42 -0
- data/lib/ransack/adapters/active_record/3.0/context.rb +7 -11
- data/lib/ransack/adapters/active_record/3.1/context.rb +10 -14
- data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +4 -7
- data/lib/ransack/adapters/mongoid/base.rb +5 -1
- data/lib/ransack/adapters/mongoid/context.rb +4 -4
- data/lib/ransack/context.rb +1 -8
- data/lib/ransack/helpers/form_helper.rb +48 -23
- data/lib/ransack/locale/de.yml +70 -0
- data/lib/ransack/nodes.rb +2 -3
- data/lib/ransack/nodes/attribute.rb +1 -1
- data/lib/ransack/nodes/condition.rb +7 -3
- data/lib/ransack/search.rb +1 -9
- data/lib/ransack/version.rb +1 -1
- data/ransack.gemspec +4 -5
- data/spec/mongoid/nodes/condition_spec.rb +1 -1
- data/spec/ransack/adapters/active_record/base_spec.rb +14 -16
- data/spec/ransack/adapters/active_record/context_spec.rb +5 -4
- data/spec/ransack/dependencies_spec.rb +2 -0
- data/spec/ransack/nodes/condition_spec.rb +1 -1
- data/spec/ransack/nodes/grouping_spec.rb +6 -6
- data/spec/ransack/search_spec.rb +3 -2
- data/spec/support/schema.rb +6 -0
- metadata +10 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a62534d07f2b79f6ac71228f7b8884c2f97891f
|
4
|
+
data.tar.gz: 983a58938313d8b5ded1e13ff182f0ee1c27ee48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb11af400660331859ddeeb11819d14849fd398ffe3b00368c860ee47baeeace67cb29116d15b46dcad92f1466bb19d6f9e85070baea384ef49500ad1aa1e3a1
|
7
|
+
data.tar.gz: 5ed69b32c4bd6a65b60e8dd2cccb5c634738b8fe3a3a7266ccc5c6a67ab2b720b016afbfcd8e7740c0ed76dea0c00d46db0c8a61b545b7e7ff66d324bd1057d3
|
data/.travis.yml
CHANGED
@@ -5,7 +5,7 @@ language: ruby
|
|
5
5
|
sudo: false
|
6
6
|
|
7
7
|
rvm:
|
8
|
-
- 2.2.
|
8
|
+
- 2.2.3
|
9
9
|
- 2.1
|
10
10
|
- 2.0
|
11
11
|
- 1.9
|
@@ -35,31 +35,35 @@ env:
|
|
35
35
|
|
36
36
|
matrix:
|
37
37
|
include:
|
38
|
-
- rvm: 2.2
|
38
|
+
- rvm: 2.2.3
|
39
39
|
env: RAILS=master DB=sqlite3
|
40
|
-
- rvm: 2.2
|
40
|
+
- rvm: 2.2.3
|
41
41
|
env: RAILS=master DB=mysql
|
42
|
-
- rvm: 2.2
|
42
|
+
- rvm: 2.2.3
|
43
43
|
env: RAILS=master DB=postgres
|
44
44
|
exclude:
|
45
|
-
- rvm: 2.2
|
45
|
+
- rvm: 2.2.3
|
46
46
|
env: RAILS=3-1-stable DB=sqlite
|
47
|
-
- rvm: 2.2
|
47
|
+
- rvm: 2.2.3
|
48
48
|
env: RAILS=3-1-stable DB=mysql
|
49
|
-
- rvm: 2.2
|
49
|
+
- rvm: 2.2.3
|
50
50
|
env: RAILS=3-1-stable DB=postgres
|
51
51
|
allow_failures:
|
52
52
|
- env: RAILS=master DB=sqlite3
|
53
53
|
- env: RAILS=master DB=mysql
|
54
54
|
- env: RAILS=master DB=postgres
|
55
|
-
- rvm: 2.2
|
55
|
+
- rvm: 2.2.3
|
56
56
|
env: RAILS=3-2-stable DB=sqlite
|
57
|
-
- rvm: 2.2
|
57
|
+
- rvm: 2.2.3
|
58
58
|
env: RAILS=3-2-stable DB=mysql
|
59
|
-
- rvm: 2.2
|
59
|
+
- rvm: 2.2.3
|
60
60
|
env: RAILS=3-2-stable DB=postgres
|
61
61
|
|
62
62
|
before_script:
|
63
63
|
- mysql -e 'create database ransack collate utf8_general_ci;'
|
64
64
|
- mysql -e 'use ransack;show variables like "%character%";show variables like "%collation%";'
|
65
65
|
- psql -c 'create database ransack;' -U postgres
|
66
|
+
|
67
|
+
addons:
|
68
|
+
code_climate:
|
69
|
+
repo_token: 8b701c4364d51a0217105e08c06922d600cec3d9e60d546a89e3ddfe46e0664e
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,98 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## Unreleased
|
4
|
+
|
5
|
+
|
6
|
+
## Version 1.7.0 - 2015-08-20
|
7
|
+
### Fixed
|
8
|
+
|
9
|
+
* Fix
|
10
|
+
[#499](https://github.com/activerecord-hackery/ransack/issues/499) and
|
11
|
+
[#549](https://github.com/activerecord-hackery/ransack/issues/549).
|
12
|
+
Ransack now loads only Active Record if both Active Record and Mongoid are
|
13
|
+
running to avoid the two adapters overriding each other. This clarifies
|
14
|
+
that Ransack currently knows how to work with only one database adapter
|
15
|
+
active at a time. PR
|
16
|
+
[#541](https://github.com/activerecord-hackery/ransack/pull/541).
|
17
|
+
|
18
|
+
*ASnow (Большов Андрей)*
|
19
|
+
|
20
|
+
* Fix [#299](https://github.com/activerecord-hackery/ransack/issues/299)
|
21
|
+
`attribute_method?` parsing for attribute names containing `_and_`
|
22
|
+
and `_or_`. Attributes named like `foo_and_bar` or `foo_or_bar` are
|
23
|
+
recognized now instead of running failing checks for `foo` and `bar`.
|
24
|
+
PR [#562](https://github.com/activerecord-hackery/ransack/pull/562).
|
25
|
+
|
26
|
+
*Ryohei Hoshi*
|
27
|
+
|
28
|
+
* Fix a time-dependent test failure. When the database has
|
29
|
+
`default_timezone = :local` (system time) and the `Time.zone` is set to
|
30
|
+
elsewhere, then `Date.current` does not match what the query produces for
|
31
|
+
the stored timestamps. Resolved by setting everything to UTC. PR
|
32
|
+
[#561](https://github.com/activerecord-hackery/ransack/pull/561).
|
33
|
+
|
34
|
+
*Andrew Vit*
|
35
|
+
|
36
|
+
* Avoid overwriting association conditions with default scope in Rails 3.
|
37
|
+
When a model with default scope was associated with conditions
|
38
|
+
(`has_many :x, conditions: ...`), the default scope would overwrite the
|
39
|
+
association conditions. This patch ensures that both sources of conditions
|
40
|
+
are applied. Avoid selecting records from joins that would normally be
|
41
|
+
filtered out if they were selected from the base table. Only applies to
|
42
|
+
Rails 3, as this issue was fixed since Rails 4. PR
|
43
|
+
[#560](https://github.com/activerecord-hackery/ransack/pull/560).
|
44
|
+
|
45
|
+
*Andrew Vit*
|
46
|
+
|
47
|
+
* Fix RSpec `its` method deprecation warning: 'Use of rspec-core's `its`
|
48
|
+
method is deprecated. Use the rspec-its gem instead
|
49
|
+
([c09aa17](https://github.com/activerecord-hackery/ransack/commit/c09aa17)).
|
50
|
+
|
51
|
+
* Fix deprecated RSpec syntax in `grouping_spec.rb`
|
52
|
+
([ba92a0b](https://github.com/activerecord-hackery/ransack/commit/ba92a0b)).
|
53
|
+
|
54
|
+
*Jon Atack*
|
55
|
+
|
56
|
+
### Added
|
57
|
+
|
58
|
+
* Add Mongoid support for referenced/embedded relations. PR
|
59
|
+
[#498](https://github.com/activerecord-hackery/ransack/pull/498).
|
60
|
+
TODO: Missing spec coverage! Add documentation!
|
61
|
+
|
62
|
+
*Penn Su*
|
63
|
+
|
64
|
+
* Add German locale file (de.yml). PR
|
65
|
+
[#537](https://github.com/activerecord-hackery/ransack/pull/537).
|
66
|
+
|
67
|
+
*Philipp Weissensteiner*
|
68
|
+
|
69
|
+
### Changed
|
70
|
+
|
71
|
+
* Upgrade gemspec dependencies: MySQL2 from '0.3.14' to '0.3.18', and RSpec
|
72
|
+
from '~> 2.14.0' to '~> 2' which loads 2.99
|
73
|
+
([000cd2](https://github.com/activerecord-hackery/ransack/commit/000cd2)).
|
74
|
+
|
75
|
+
* Upgrade spec suite to RSpec 3 `expect` syntax backward compatible with
|
76
|
+
RSpec 2.9
|
77
|
+
([87cd36d](https://github.com/activerecord-hackery/ransack/commit/87cd36d)
|
78
|
+
and
|
79
|
+
[d296caa](https://github.com/activerecord-hackery/ransack/commit/d296caa)).
|
80
|
+
|
81
|
+
* Various FormHelper refactorings
|
82
|
+
([17dd97a](https://github.com/activerecord-hackery/ransack/commit/17dd97a)
|
83
|
+
and
|
84
|
+
[29a73b9](https://github.com/activerecord-hackery/ransack/commit/29a73b9)).
|
85
|
+
|
86
|
+
* Various documentation updates.
|
87
|
+
|
88
|
+
*Jon Atack*
|
89
|
+
|
90
|
+
|
3
91
|
## Version 1.6.6 - 2015-04-05
|
4
92
|
### Changed
|
5
93
|
|
6
|
-
* Upgrade Polyamorous dependency to version 1.2.0, which uses Module#prepend
|
94
|
+
* Upgrade Polyamorous dependency to version 1.2.0, which uses `Module#prepend`
|
95
|
+
instead of `alias_method` for hooking into Active Record (with Ruby 2.x).
|
7
96
|
|
8
97
|
*Jon Atack*
|
9
98
|
|
data/CONTRIBUTING.md
CHANGED
@@ -1,16 +1,20 @@
|
|
1
1
|
# Contributing to Ransack
|
2
2
|
|
3
|
-
Please take a moment to review this document
|
4
|
-
|
3
|
+
Please take a moment to review this document to make contributing easy and
|
4
|
+
effective for everyone involved!
|
5
5
|
|
6
6
|
Ransack is an open source project and we encourage contributions.
|
7
7
|
|
8
8
|
## Filing an issue
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
Good issue reports are extremely helpful! Please only open an issue if a bug
|
11
|
+
is caused by Ransack, is new (has not already been reported), and can be
|
12
|
+
reproduced from the information you provide.
|
12
13
|
|
13
|
-
|
14
|
+
Please do not use the issue tracker personal support requests. Stack Overflow
|
15
|
+
is a better place for that where a wider community can help you.
|
16
|
+
|
17
|
+
Steps:
|
14
18
|
|
15
19
|
1. **Use the GitHub issue search** — check if the issue has already been
|
16
20
|
reported.
|
@@ -23,13 +27,13 @@ Guidelines for bug reports:
|
|
23
27
|
|
24
28
|
When filing an issue, please provide these details:
|
25
29
|
|
26
|
-
* A comprehensive list of steps to reproduce the issue
|
27
|
-
* The
|
30
|
+
* A comprehensive list of steps to reproduce the issue :smiley: or even better, a failing spec!
|
31
|
+
* The versions of Ruby, Rails, Ransack and your operating system and database.
|
28
32
|
* Any relevant stack traces ("Full trace" preferred).
|
29
33
|
|
30
34
|
Any issue that is open for 14 days without actionable information or activity
|
31
35
|
will be marked as "stalled" and then closed. Stalled issues can be re-opened
|
32
|
-
if
|
36
|
+
if actionable information to reproduce the issue is provided.
|
33
37
|
|
34
38
|
## Pull requests
|
35
39
|
|
@@ -107,11 +111,11 @@ Syntax:
|
|
107
111
|
* 80 characters per line.
|
108
112
|
* No trailing whitespace. Blank lines should not have any space.
|
109
113
|
* Prefer `&&`/`||` over `and`/`or`.
|
110
|
-
* `MyClass.my_method(my_arg)` not `my_method( my_arg )` or my_method my_arg
|
114
|
+
* `MyClass.my_method(my_arg)` not `my_method( my_arg )` or `my_method my_arg`.
|
111
115
|
* `a = b` and not `a=b`.
|
112
116
|
* `a_method { |block| ... }` and not `a_method { | block | ... }` or
|
113
117
|
`a_method{|block| ...}`.
|
114
118
|
* Prefer simplicity, readability, and maintainability over terseness.
|
115
119
|
* Follow the conventions you see used in the code already.
|
116
120
|
|
117
|
-
And in case we didn't emphasize it enough:
|
121
|
+
And in case we didn't emphasize it enough: We love tests!
|
data/README.md
CHANGED
@@ -29,18 +29,19 @@ 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.
|
33
|
-
(https://github.com/activerecord-hackery/ransack/tree/v1.6.6)
|
32
|
+
[View documentation for the last release (1.7.0).](https://github.com/activerecord-hackery/ransack/tree/v1.7.0)
|
34
33
|
|
35
34
|
## Getting started
|
36
35
|
|
37
|
-
Ransack is compatible with Rails 3 and 4
|
38
|
-
|
39
|
-
|
40
|
-
1.
|
36
|
+
Ransack is compatible with Rails 3 and 4 on Ruby 1.9 and later (Ruby 2.2
|
37
|
+
recommended). JRuby 9 ought to work as well (see
|
38
|
+
[this](https://github.com/activerecord-hackery/polyamorous/issues/17)).
|
39
|
+
If you are using Ruby 1.8 or an earlier JRuby and run into compatibility
|
40
|
+
issues, you can use an earlier version of Ransack, say, up to 1.3.0.
|
41
41
|
|
42
|
-
Ransack works out-of-the-box with Active Record and also features
|
43
|
-
support for Mongoid 4.0 (without associations, further details
|
42
|
+
Ransack works out-of-the-box with Active Record and also features limited
|
43
|
+
support for Mongoid 4.0 (without associations, further details
|
44
|
+
[below](https://github.com/activerecord-hackery/ransack#mongoid)).
|
44
45
|
|
45
46
|
In your Gemfile, for the last officially released gem:
|
46
47
|
|
@@ -54,6 +55,12 @@ Or, if you would like to use the latest updates, use the `master` branch:
|
|
54
55
|
gem 'ransack', github: 'activerecord-hackery/ransack'
|
55
56
|
```
|
56
57
|
|
58
|
+
## Issues tracker
|
59
|
+
|
60
|
+
* Before filing an issue, please read the [Contributing Guide](CONTRIBUTING.md).
|
61
|
+
* File an issue if a bug is caused by Ransack, is new (has not already been reported), and _can be reproduced from the information you provide_.
|
62
|
+
* Contributions are welcome, but please do not add "+1" comments to issues or pull requests :smiley:
|
63
|
+
|
57
64
|
## Usage
|
58
65
|
|
59
66
|
Ransack can be used in one of two modes, simple or advanced.
|
@@ -655,6 +662,17 @@ called on a `ransack` search returns a `Mongoid::Criteria` object:
|
|
655
662
|
@people = @q.result.active.order_by(updated_at: -1).limit(10)
|
656
663
|
```
|
657
664
|
|
665
|
+
_NOTE: Ransack currently works with either Active Record or Mongoid, but not
|
666
|
+
both in the same application. If both are present, Ransack will default to
|
667
|
+
Active Record only. Here is the code containing the logic:_
|
668
|
+
|
669
|
+
```ruby
|
670
|
+
@current_adapters ||= {
|
671
|
+
:active_record => defined?(::ActiveRecord::Base),
|
672
|
+
:mongoid => defined?(::Mongoid) && !defined?(::ActiveRecord::Base)
|
673
|
+
}
|
674
|
+
```
|
675
|
+
|
658
676
|
## Semantic Versioning
|
659
677
|
|
660
678
|
Ransack attempts to follow semantic versioning in the format of `x.y.z`, where:
|
data/Rakefile
CHANGED
@@ -1,15 +1,11 @@
|
|
1
1
|
require 'bundler'
|
2
2
|
require 'rspec/core/rake_task'
|
3
|
-
require 'active_record'
|
4
3
|
|
5
4
|
Bundler::GemHelper.install_tasks
|
6
5
|
|
7
6
|
RSpec::Core::RakeTask.new(:spec) do |rspec|
|
8
7
|
ENV['SPEC'] = 'spec/ransack/**/*_spec.rb'
|
9
|
-
|
10
|
-
# Raises `invalid option: --backtrace` with Rails 3.x on Ruby 2.2
|
11
|
-
rspec.rspec_opts = ['--backtrace']
|
12
|
-
end
|
8
|
+
rspec.rspec_opts = ['--backtrace']
|
13
9
|
end
|
14
10
|
|
15
11
|
RSpec::Core::RakeTask.new(:mongoid) do |rspec|
|
data/lib/ransack.rb
CHANGED
@@ -2,15 +2,11 @@ require 'active_support/core_ext'
|
|
2
2
|
|
3
3
|
require 'ransack/configuration'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
else
|
8
|
-
require 'ransack/adapters/active_record/ransack/constants'
|
9
|
-
end
|
5
|
+
require 'ransack/adapters'
|
6
|
+
Ransack::Adapters.require_constants
|
10
7
|
|
11
8
|
module Ransack
|
12
9
|
extend Configuration
|
13
|
-
|
14
10
|
class UntraversableAssociationError < StandardError; end;
|
15
11
|
end
|
16
12
|
|
@@ -18,20 +14,18 @@ Ransack.configure do |config|
|
|
18
14
|
Ransack::Constants::AREL_PREDICATES.each do |name|
|
19
15
|
config.add_predicate name, :arel_predicate => name
|
20
16
|
end
|
21
|
-
|
22
17
|
Ransack::Constants::DERIVED_PREDICATES.each do |args|
|
23
18
|
config.add_predicate *args
|
24
19
|
end
|
25
20
|
end
|
26
21
|
|
27
|
-
require 'ransack/translate'
|
28
|
-
require 'ransack/adapters/active_record/ransack/translate' if defined?(::ActiveRecord::Base)
|
29
|
-
require 'ransack/adapters/mongoid/ransack/translate' if defined?(::Mongoid)
|
30
22
|
require 'ransack/search'
|
31
23
|
require 'ransack/ransacker'
|
32
|
-
require 'ransack/adapters/active_record' if defined?(::ActiveRecord::Base)
|
33
|
-
require 'ransack/adapters/mongoid' if defined?(::Mongoid)
|
34
24
|
require 'ransack/helpers'
|
35
25
|
require 'action_controller'
|
36
26
|
|
27
|
+
require 'ransack/translate'
|
28
|
+
|
29
|
+
Ransack::Adapters.require_adapter
|
30
|
+
|
37
31
|
ActionController::Base.helper Ransack::Helpers::FormHelper
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Ransack
|
2
|
+
module Adapters
|
3
|
+
|
4
|
+
def self.current_adapters
|
5
|
+
@current_adapters ||= {
|
6
|
+
:active_record => defined?(::ActiveRecord::Base),
|
7
|
+
:mongoid => defined?(::Mongoid) && !defined?(::ActiveRecord::Base)
|
8
|
+
}
|
9
|
+
end
|
10
|
+
def self.require_constants
|
11
|
+
require 'ransack/adapters/mongoid/ransack/constants' if current_adapters[:mongoid]
|
12
|
+
require 'ransack/adapters/active_record/ransack/constants' if current_adapters[:active_record]
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.require_adapter
|
16
|
+
if current_adapters[:active_record]
|
17
|
+
require 'ransack/adapters/active_record/ransack/translate'
|
18
|
+
require 'ransack/adapters/active_record'
|
19
|
+
end
|
20
|
+
|
21
|
+
if current_adapters[:mongoid]
|
22
|
+
require 'ransack/adapters/mongoid/ransack/translate'
|
23
|
+
require 'ransack/adapters/mongoid'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.require_context
|
28
|
+
require 'ransack/adapters/active_record/ransack/visitor' if current_adapters[:active_record]
|
29
|
+
require 'ransack/adapters/mongoid/ransack/visitor' if current_adapters[:mongoid]
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.require_nodes
|
33
|
+
require 'ransack/adapters/active_record/ransack/nodes/condition' if current_adapters[:active_record]
|
34
|
+
require 'ransack/adapters/mongoid/ransack/nodes/condition' if current_adapters[:mongoid]
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.require_search
|
38
|
+
require 'ransack/adapters/active_record/ransack/context' if current_adapters[:active_record]
|
39
|
+
require 'ransack/adapters/mongoid/ransack/context' if current_adapters[:mongoid]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -182,23 +182,19 @@ module Ransack
|
|
182
182
|
:build, Polyamorous::Join.new(name, @join_type, klass), parent
|
183
183
|
)
|
184
184
|
found_association = @join_dependency.join_associations.last
|
185
|
-
|
185
|
+
|
186
|
+
default_conditions = found_association.active_record.scoped.arel.constraints
|
187
|
+
if default_conditions.any?
|
188
|
+
and_default_conditions = "AND #{default_conditions.reduce(&:and).to_sql}"
|
189
|
+
end
|
190
|
+
|
186
191
|
# Leverage the stashed association functionality in AR
|
187
|
-
@object = @object.joins(found_association)
|
192
|
+
@object = @object.joins(found_association).joins(and_default_conditions)
|
188
193
|
end
|
189
194
|
|
190
195
|
found_association
|
191
196
|
end
|
192
197
|
|
193
|
-
def apply_default_conditions(join_association)
|
194
|
-
reflection = join_association.reflection
|
195
|
-
default_scope = join_association.active_record.scoped
|
196
|
-
default_conditions = default_scope.arel.where_clauses
|
197
|
-
if default_conditions.any?
|
198
|
-
reflection.options[:conditions] = default_conditions
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
198
|
end
|
203
199
|
end
|
204
200
|
end
|
@@ -90,8 +90,8 @@ module Ransack
|
|
90
90
|
#
|
91
91
|
def join_sources
|
92
92
|
base = Arel::SelectManager.new(@object.engine, @object.table)
|
93
|
-
|
94
|
-
|
93
|
+
@object.joins_values.each do |assoc|
|
94
|
+
next unless assoc.is_a?(JoinDependency::JoinAssociation)
|
95
95
|
assoc.join_to(base)
|
96
96
|
end
|
97
97
|
base.join_sources
|
@@ -151,7 +151,7 @@ module Ransack
|
|
151
151
|
Constants::STRING_JOIN
|
152
152
|
when Hash, Symbol, Array
|
153
153
|
Constants::ASSOCIATION_JOIN
|
154
|
-
when
|
154
|
+
when JoinDependency::JoinAssociation
|
155
155
|
Constants::STASHED_JOIN
|
156
156
|
when Arel::Nodes::Join
|
157
157
|
Constants::JOIN_NODE
|
@@ -196,23 +196,19 @@ module Ransack
|
|
196
196
|
:build, Polyamorous::Join.new(name, @join_type, klass), parent
|
197
197
|
)
|
198
198
|
found_association = @join_dependency.join_associations.last
|
199
|
-
|
199
|
+
|
200
|
+
default_conditions = found_association.active_record.scoped.arel.constraints
|
201
|
+
if default_conditions.any?
|
202
|
+
and_default_conditions = "AND #{default_conditions.reduce(&:and).to_sql}"
|
203
|
+
end
|
204
|
+
|
200
205
|
# Leverage the stashed association functionality in AR
|
201
|
-
@object = @object.joins(found_association)
|
206
|
+
@object = @object.joins(found_association).joins(and_default_conditions)
|
202
207
|
end
|
203
208
|
|
204
209
|
found_association
|
205
210
|
end
|
206
211
|
|
207
|
-
def apply_default_conditions(join_association)
|
208
|
-
reflection = join_association.reflection
|
209
|
-
default_scope = join_association.active_record.scoped
|
210
|
-
default_conditions = default_scope.arel.where_clauses
|
211
|
-
if default_conditions.any?
|
212
|
-
reflection.options[:conditions] = default_conditions
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
212
|
end
|
217
213
|
end
|
218
214
|
end
|
@@ -35,7 +35,7 @@ module Ransack
|
|
35
35
|
def format_predicate(predicate)
|
36
36
|
predicate.tap do
|
37
37
|
if casted_array_with_in_predicate?(predicate)
|
38
|
-
predicate.right[0] = predicate.right[0]
|
38
|
+
predicate.right[0] = format_values_for(predicate.right[0])
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
@@ -47,12 +47,9 @@ module Ransack
|
|
47
47
|
predicate.right[0].val.is_a?(Array)
|
48
48
|
end
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
Arel::Nodes.build_quoted(value)
|
54
|
-
else
|
55
|
-
value
|
50
|
+
def format_values_for(predicate)
|
51
|
+
predicate.val.map do |value|
|
52
|
+
value.is_a?(String) ? Arel::Nodes.build_quoted(value) : value
|
56
53
|
end
|
57
54
|
end
|
58
55
|
|
@@ -73,7 +73,7 @@ module Ransack
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def reflect_on_all_associations_all
|
76
|
-
reflect_on_all_associations(:belongs_to, :has_one, :has_many)
|
76
|
+
reflect_on_all_associations(:belongs_to, :has_one, :has_many, :embeds_many, :embedded_in)
|
77
77
|
end
|
78
78
|
|
79
79
|
# For overriding with a whitelist of symbols
|
@@ -87,6 +87,10 @@ module Ransack
|
|
87
87
|
[]
|
88
88
|
end
|
89
89
|
|
90
|
+
def custom_join_ast *args
|
91
|
+
[]
|
92
|
+
end
|
93
|
+
|
90
94
|
def first(*args)
|
91
95
|
if args.size == 0
|
92
96
|
super
|
@@ -21,7 +21,7 @@ module Ransack
|
|
21
21
|
|
22
22
|
def type_for(attr)
|
23
23
|
return nil unless attr && attr.valid?
|
24
|
-
name = attr.arel_attribute.name.to_s
|
24
|
+
name = attr.arel_attribute.name.to_s.split('.').last
|
25
25
|
# table = attr.arel_attribute.relation.table_name
|
26
26
|
|
27
27
|
# schema_cache = @engine.connection.schema_cache
|
@@ -38,7 +38,7 @@ module Ransack
|
|
38
38
|
|
39
39
|
name = '_id' if name == 'id'
|
40
40
|
|
41
|
-
t = object.klass.fields[name].type
|
41
|
+
t = object.klass.fields[name].try(:type) || @bind_pairs[attr.name].first.fields[name].type
|
42
42
|
|
43
43
|
t.to_s.demodulize.underscore.to_sym
|
44
44
|
end
|
@@ -114,10 +114,10 @@ module Ransack
|
|
114
114
|
segments.pop) && segments.size > 0 && !found_assoc do
|
115
115
|
assoc, klass = unpolymorphize_association(segments.join('_'))
|
116
116
|
if found_assoc = get_association(assoc, parent)
|
117
|
-
join = build_or_find_association(found_assoc.name, parent, klass)
|
118
117
|
parent, attr_name = get_parent_and_attribute_name(
|
119
|
-
remainder.join('_'),
|
118
|
+
remainder.join('_'), found_assoc.klass
|
120
119
|
)
|
120
|
+
attr_name = "#{segments.join('_')}.#{attr_name}"
|
121
121
|
end
|
122
122
|
end
|
123
123
|
end
|
data/lib/ransack/context.rb
CHANGED
@@ -1,12 +1,5 @@
|
|
1
1
|
require 'ransack/visitor'
|
2
|
-
|
3
|
-
if defined?(::ActiveRecord::Base)
|
4
|
-
require 'ransack/adapters/active_record/ransack/visitor'
|
5
|
-
end
|
6
|
-
|
7
|
-
if defined?(::Mongoid)
|
8
|
-
require 'ransack/adapters/mongoid/ransack/visitor'
|
9
|
-
end
|
2
|
+
Ransack::Adapters.require_context
|
10
3
|
|
11
4
|
module Ransack
|
12
5
|
class Context
|
@@ -15,8 +15,7 @@ module Ransack
|
|
15
15
|
elsif record.is_a?(Array) &&
|
16
16
|
(search = record.detect { |o| o.is_a?(Ransack::Search) })
|
17
17
|
options[:url] ||= polymorphic_path(
|
18
|
-
record
|
19
|
-
format: options.delete(:format)
|
18
|
+
options_for(record), format: options.delete(:format)
|
20
19
|
)
|
21
20
|
else
|
22
21
|
raise ArgumentError,
|
@@ -24,13 +23,9 @@ module Ransack
|
|
24
23
|
end
|
25
24
|
options[:html] ||= {}
|
26
25
|
html_options = {
|
27
|
-
:
|
28
|
-
|
29
|
-
|
30
|
-
:id => options[:id].present? ?
|
31
|
-
"#{options[:id]}" :
|
32
|
-
"#{search.klass.to_s.underscore}_search",
|
33
|
-
:method => :get
|
26
|
+
class: html_option_for(options[:class], search),
|
27
|
+
id: html_option_for(options[:id], search),
|
28
|
+
method: :get
|
34
29
|
}
|
35
30
|
options[:as] ||= Ransack.options[:search_key]
|
36
31
|
options[:html].reverse_merge!(html_options)
|
@@ -54,6 +49,26 @@ module Ransack
|
|
54
49
|
|
55
50
|
private
|
56
51
|
|
52
|
+
def options_for(record)
|
53
|
+
record.map &method(:parse_record)
|
54
|
+
end
|
55
|
+
|
56
|
+
def parse_record(object)
|
57
|
+
if object.is_a?(Ransack::Search)
|
58
|
+
object.klass
|
59
|
+
else
|
60
|
+
object
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def html_option_for(option, search)
|
65
|
+
if option.present?
|
66
|
+
option.to_s
|
67
|
+
else
|
68
|
+
"#{search.klass.to_s.underscore}_search"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
57
72
|
def extract_search_and_routing_proxy(search)
|
58
73
|
if search.is_a? Array
|
59
74
|
[search.second, search.first]
|
@@ -75,14 +90,12 @@ module Ransack
|
|
75
90
|
@search = search
|
76
91
|
@params = params
|
77
92
|
@field = attribute.to_s
|
78
|
-
sort_fields
|
93
|
+
@sort_fields = extract_sort_fields_and_mutate_args!(args).compact
|
79
94
|
@current_dir = existing_sort_direction
|
80
95
|
@label_text = extract_label_and_mutate_args!(args)
|
81
96
|
@options = extract_options_and_mutate_args!(args)
|
82
97
|
@hide_indicator = @options.delete :hide_indicator
|
83
98
|
@default_order = @options.delete :default_order
|
84
|
-
@sort_params = build_sort(sort_fields)
|
85
|
-
@sort_params = @sort_params.first if @sort_params.size == 1
|
86
99
|
end
|
87
100
|
|
88
101
|
def name
|
@@ -100,10 +113,10 @@ module Ransack
|
|
100
113
|
|
101
114
|
def html_options(args)
|
102
115
|
html_options = extract_options_and_mutate_args!(args)
|
103
|
-
html_options.merge(
|
104
|
-
[[Constants::SORT_LINK, @current_dir], html_options[:class]]
|
105
|
-
|
106
|
-
|
116
|
+
html_options.merge(
|
117
|
+
class: [[Constants::SORT_LINK, @current_dir], html_options[:class]]
|
118
|
+
.compact.join(Constants::SPACE)
|
119
|
+
)
|
107
120
|
end
|
108
121
|
|
109
122
|
private
|
@@ -120,7 +133,7 @@ module Ransack
|
|
120
133
|
if args.first.is_a? String
|
121
134
|
args.shift
|
122
135
|
else
|
123
|
-
Translate.attribute(@field, :
|
136
|
+
Translate.attribute(@field, context: @search.context)
|
124
137
|
end
|
125
138
|
end
|
126
139
|
|
@@ -133,16 +146,25 @@ module Ransack
|
|
133
146
|
end
|
134
147
|
|
135
148
|
def search_and_sort_params
|
136
|
-
search_params.merge(:
|
149
|
+
search_params.merge(s: sort_params)
|
137
150
|
end
|
138
151
|
|
139
152
|
def search_params
|
140
153
|
@params[@search.context.search_key].presence || {}
|
141
154
|
end
|
142
155
|
|
143
|
-
def
|
156
|
+
def sort_params
|
157
|
+
sort_array = recursive_sort_params_build(@sort_fields)
|
158
|
+
if sort_array.size == 1
|
159
|
+
sort_array.first
|
160
|
+
else
|
161
|
+
sort_array
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def recursive_sort_params_build(fields)
|
144
166
|
return [] if fields.empty?
|
145
|
-
[parse_sort(fields[0])] +
|
167
|
+
[parse_sort(fields[0])] + recursive_sort_params_build(fields.drop 1)
|
146
168
|
end
|
147
169
|
|
148
170
|
def parse_sort(field)
|
@@ -154,8 +176,7 @@ module Ransack
|
|
154
176
|
end
|
155
177
|
|
156
178
|
def detect_previous_sort_direction_and_invert_it(attr_name)
|
157
|
-
sort_dir = existing_sort_direction(attr_name)
|
158
|
-
if sort_dir
|
179
|
+
if sort_dir = existing_sort_direction(attr_name)
|
159
180
|
direction_text(sort_dir)
|
160
181
|
else
|
161
182
|
default_sort_order(attr_name) || Constants::ASC
|
@@ -169,7 +190,11 @@ module Ransack
|
|
169
190
|
end
|
170
191
|
|
171
192
|
def default_sort_order(attr_name)
|
172
|
-
Hash === @default_order
|
193
|
+
if Hash === @default_order
|
194
|
+
@default_order[attr_name]
|
195
|
+
else
|
196
|
+
@default_order
|
197
|
+
end
|
173
198
|
end
|
174
199
|
|
175
200
|
def order_indicator
|
@@ -0,0 +1,70 @@
|
|
1
|
+
de:
|
2
|
+
ransack:
|
3
|
+
search: "suchen"
|
4
|
+
predicate: "Eigenschaft"
|
5
|
+
and: "und"
|
6
|
+
or: "oder"
|
7
|
+
any: "beliebige"
|
8
|
+
all: "alle"
|
9
|
+
combinator: "Kombinator"
|
10
|
+
attribute: "Attribut"
|
11
|
+
value: "Wert"
|
12
|
+
condition: "Bedingung"
|
13
|
+
sort: "sortieren"
|
14
|
+
asc: "aufsteigend"
|
15
|
+
desc: "absteigend"
|
16
|
+
predicates:
|
17
|
+
eq: "gleicht"
|
18
|
+
eq_any: "gleicht beliebigen"
|
19
|
+
eq_all: "gleicht allen"
|
20
|
+
not_eq: "ungleich"
|
21
|
+
not_eq_any: "ungleich beliebigen"
|
22
|
+
not_eq_all: "ungleich allen"
|
23
|
+
matches: "entspricht"
|
24
|
+
matches_any: "stimmt überein mit einem beliebigen"
|
25
|
+
matches_all: "stimmt mit allen überein"
|
26
|
+
does_not_match: "stimmt nicht überein"
|
27
|
+
does_not_match_any: "erfüllt ein beliebiger/s nicht"
|
28
|
+
does_not_match_all: "stimmt nicht mit allen überein"
|
29
|
+
lt: "kleiner als"
|
30
|
+
lt_any: "kleiner als ein beliebiger/s"
|
31
|
+
lt_all: "kleiner als alle als alle"
|
32
|
+
lteq: "kleiner oder gleich"
|
33
|
+
lteq_any: "kleiner oder gleich beliebige"
|
34
|
+
lteq_all: "kleiner oder gleich allen"
|
35
|
+
gt: "größer als"
|
36
|
+
gt_any: "größer als ein beliebiger/s"
|
37
|
+
gt_all: "größer als alle"
|
38
|
+
gteq: "größer oder gleich"
|
39
|
+
gteq_any: "größer oder gleich als ein beliebiger/s"
|
40
|
+
gteq_all: "größer oder gleich alle"
|
41
|
+
in: "in"
|
42
|
+
in_any: "ist nicht in einem beliebigen"
|
43
|
+
in_all: "in allen"
|
44
|
+
not_in: "nicht in"
|
45
|
+
not_in_any: "nicht in beliebige"
|
46
|
+
not_in_all: "nicht in allen"
|
47
|
+
cont: "enthält"
|
48
|
+
cont_any: "enthält beliebige"
|
49
|
+
cont_all: "enthält alle"
|
50
|
+
not_cont: "enthält nicht"
|
51
|
+
not_cont_any: "enthält ein beliebiger/s nicht"
|
52
|
+
not_cont_all: "enthält keine/s"
|
53
|
+
start: "beginnt mit"
|
54
|
+
start_any: "beginnt mit beliebigen"
|
55
|
+
start_all: "beginnt mit allen"
|
56
|
+
not_start: "beginnt nicht mit"
|
57
|
+
not_start_any: "beginnt nicht mit beliebigen"
|
58
|
+
not_start_all: "beginnt nicht mit allen"
|
59
|
+
end: "endet mit"
|
60
|
+
end_any: "endet mit beliebigen"
|
61
|
+
end_all: "endet mit allen"
|
62
|
+
not_end: "endet nicht mit"
|
63
|
+
not_end_any: "endet nicht mit beliebigen"
|
64
|
+
not_end_all: "endet nicht mit allen"
|
65
|
+
'true': "ist wahr"
|
66
|
+
'false': "ist falsch"
|
67
|
+
present: "ist vorhanden"
|
68
|
+
blank: "ist leer"
|
69
|
+
'null': "ist null"
|
70
|
+
not_null: "ist nicht null"
|
data/lib/ransack/nodes.rb
CHANGED
@@ -3,7 +3,6 @@ require 'ransack/nodes/node'
|
|
3
3
|
require 'ransack/nodes/attribute'
|
4
4
|
require 'ransack/nodes/value'
|
5
5
|
require 'ransack/nodes/condition'
|
6
|
-
|
7
|
-
require 'ransack/adapters/mongoid/ransack/nodes/condition' if defined?(::Mongoid)
|
6
|
+
Ransack::Adapters.require_nodes
|
8
7
|
require 'ransack/nodes/sort'
|
9
|
-
require 'ransack/nodes/grouping'
|
8
|
+
require 'ransack/nodes/grouping'
|
@@ -9,7 +9,7 @@ module Ransack
|
|
9
9
|
|
10
10
|
class << self
|
11
11
|
def extract(context, key, values)
|
12
|
-
attributes, predicate = extract_attributes_and_predicate(key)
|
12
|
+
attributes, predicate = extract_attributes_and_predicate(key, context)
|
13
13
|
if attributes.size > 0 && predicate
|
14
14
|
combinator = key.match(/_(or|and)_/) ? $1 : nil
|
15
15
|
condition = self.new(context)
|
@@ -31,14 +31,18 @@ module Ransack
|
|
31
31
|
|
32
32
|
private
|
33
33
|
|
34
|
-
def extract_attributes_and_predicate(key)
|
34
|
+
def extract_attributes_and_predicate(key, context = nil)
|
35
35
|
str = key.dup
|
36
36
|
name = Predicate.detect_and_strip_from_string!(str)
|
37
37
|
predicate = Predicate.named(name)
|
38
38
|
unless predicate || Ransack.options[:ignore_unknown_conditions]
|
39
39
|
raise ArgumentError, "No valid predicate for #{key}"
|
40
40
|
end
|
41
|
-
|
41
|
+
if context.present? && context.attribute_method?(str)
|
42
|
+
attributes = [str]
|
43
|
+
else
|
44
|
+
attributes = str.split(/_and_|_or_/)
|
45
|
+
end
|
42
46
|
[attributes, predicate]
|
43
47
|
end
|
44
48
|
end
|
data/lib/ransack/search.rb
CHANGED
@@ -1,14 +1,6 @@
|
|
1
1
|
require 'ransack/nodes'
|
2
2
|
require 'ransack/context'
|
3
|
-
|
4
|
-
if defined?(::ActiveRecord::Base)
|
5
|
-
require 'ransack/adapters/active_record/ransack/context'
|
6
|
-
end
|
7
|
-
|
8
|
-
if defined?(::Mongoid)
|
9
|
-
require 'ransack/adapters/mongoid/ransack/context'
|
10
|
-
end
|
11
|
-
|
3
|
+
Ransack::Adapters.require_search
|
12
4
|
require 'ransack/naming'
|
13
5
|
|
14
6
|
module Ransack
|
data/lib/ransack/version.rb
CHANGED
data/ransack.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.authors = ["Ernie Miller", "Ryan Bigg", "Jon Atack"]
|
10
10
|
s.email = ["ernie@erniemiller.org", "radarlistener@gmail.com", "jonnyatack@gmail.com"]
|
11
11
|
s.homepage = "https://github.com/activerecord-hackery/ransack"
|
12
|
-
s.summary = %q{Object-based searching for
|
12
|
+
s.summary = %q{Object-based searching for Active Record and Mongoid (currently).}
|
13
13
|
s.description = %q{Ransack is the successor to the MetaSearch gem. It improves and expands upon MetaSearch's functionality, but does not have a 100%-compatible API.}
|
14
14
|
s.required_ruby_version = '>= 1.9'
|
15
15
|
s.license = 'MIT'
|
@@ -21,16 +21,15 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.add_dependency 'activesupport', '>= 3.0'
|
22
22
|
s.add_dependency 'i18n'
|
23
23
|
s.add_dependency 'polyamorous', '~> 1.2'
|
24
|
-
s.add_development_dependency 'rspec', '~> 2
|
24
|
+
s.add_development_dependency 'rspec', '~> 2'
|
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
28
|
s.add_development_dependency 'pg'
|
29
|
-
s.add_development_dependency 'mysql2', '0.3.
|
29
|
+
s.add_development_dependency 'mysql2', '0.3.18'
|
30
30
|
s.add_development_dependency 'pry', '0.9.12.2'
|
31
31
|
|
32
|
-
s.files = `git ls-files
|
33
|
-
.split("\n")
|
32
|
+
s.files = `git ls-files`.split("\n")
|
34
33
|
|
35
34
|
s.test_files = `git ls-files -- {test,spec,features}/*`
|
36
35
|
.split("\n")
|
@@ -25,48 +25,48 @@ module Ransack
|
|
25
25
|
|
26
26
|
it "applies true scopes" do
|
27
27
|
s = Person.ransack('active' => true)
|
28
|
-
s.result.to_sql.
|
28
|
+
expect(s.result.to_sql).to (include 'active = 1')
|
29
29
|
end
|
30
30
|
|
31
31
|
it "applies stringy true scopes" do
|
32
32
|
s = Person.ransack('active' => 'true')
|
33
|
-
s.result.to_sql.
|
33
|
+
expect(s.result.to_sql).to (include 'active = 1')
|
34
34
|
end
|
35
35
|
|
36
36
|
it "applies stringy boolean scopes with true value in an array" do
|
37
37
|
s = Person.ransack('of_age' => ['true'])
|
38
|
-
s.result.to_sql.
|
38
|
+
expect(s.result.to_sql).to (include 'age >= 18')
|
39
39
|
end
|
40
40
|
|
41
41
|
it "applies stringy boolean scopes with false value in an array" do
|
42
42
|
s = Person.ransack('of_age' => ['false'])
|
43
|
-
s.result.to_sql.
|
43
|
+
expect(s.result.to_sql).to (include 'age < 18')
|
44
44
|
end
|
45
45
|
|
46
46
|
it "ignores unlisted scopes" do
|
47
47
|
s = Person.ransack('restricted' => true)
|
48
|
-
s.result.to_sql.
|
48
|
+
expect(s.result.to_sql).to_not (include 'restricted')
|
49
49
|
end
|
50
50
|
|
51
51
|
it "ignores false scopes" do
|
52
52
|
s = Person.ransack('active' => false)
|
53
|
-
s.result.to_sql.
|
53
|
+
expect(s.result.to_sql).not_to (include 'active')
|
54
54
|
end
|
55
55
|
|
56
56
|
it "ignores stringy false scopes" do
|
57
57
|
s = Person.ransack('active' => 'false')
|
58
|
-
s.result.to_sql.
|
58
|
+
expect(s.result.to_sql).to_not (include 'active')
|
59
59
|
end
|
60
60
|
|
61
61
|
it "passes values to scopes" do
|
62
62
|
s = Person.ransack('over_age' => 18)
|
63
|
-
s.result.to_sql.
|
63
|
+
expect(s.result.to_sql).to (include 'age > 18')
|
64
64
|
end
|
65
65
|
|
66
66
|
it "chains scopes" do
|
67
67
|
s = Person.ransack('over_age' => 18, 'active' => true)
|
68
|
-
s.result.to_sql.
|
69
|
-
s.result.to_sql.
|
68
|
+
expect(s.result.to_sql).to (include 'age > 18')
|
69
|
+
expect(s.result.to_sql).to (include 'active = 1')
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
@@ -145,6 +145,9 @@ module Ransack
|
|
145
145
|
end
|
146
146
|
|
147
147
|
it "should function correctly with a multi-parameter attribute" do
|
148
|
+
::ActiveRecord::Base.default_timezone = :utc
|
149
|
+
Time.zone = 'UTC'
|
150
|
+
|
148
151
|
date = Date.current
|
149
152
|
s = Person.ransack(
|
150
153
|
{ "created_at_gteq(1i)" => date.year,
|
@@ -228,14 +231,9 @@ module Ransack
|
|
228
231
|
end
|
229
232
|
|
230
233
|
it "should function correctly when an attribute name has 'and' in it" do
|
231
|
-
# FIXME: this test does not pass!
|
232
234
|
p = Person.create!(:terms_and_conditions => true)
|
233
235
|
s = Person.ransack(:terms_and_conditions_eq => true)
|
234
|
-
|
235
|
-
puts "
|
236
|
-
FIXME: Search not detecting the `terms_and_conditions` attribute in
|
237
|
-
base_spec.rb, line 178: #{s.result.to_sql}"
|
238
|
-
# expect(s.result.to_a).to eq [p]
|
236
|
+
expect(s.result.to_a).to eq [p]
|
239
237
|
end
|
240
238
|
|
241
239
|
it 'allows sort by "only_sort" field' do
|
@@ -9,10 +9,11 @@ module Ransack
|
|
9
9
|
describe Context do
|
10
10
|
subject { Context.new(Person) }
|
11
11
|
|
12
|
-
if AR_version >=
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
if AR_version >= '3.1'
|
13
|
+
it 'has an Active Record alias tracker method' do
|
14
|
+
expect(subject.alias_tracker)
|
15
|
+
.to be_an ::ActiveRecord::Associations::AliasTracker
|
16
|
+
end
|
16
17
|
end
|
17
18
|
|
18
19
|
describe '#relation_for' do
|
@@ -15,37 +15,37 @@ module Ransack
|
|
15
15
|
describe '#attribute_method?' do
|
16
16
|
context 'for attributes of the context' do
|
17
17
|
it 'is true' do
|
18
|
-
expect(subject.attribute_method?('name')).to
|
18
|
+
expect(subject.attribute_method?('name')).to be true
|
19
19
|
end
|
20
20
|
|
21
21
|
context "when the attribute contains '_and_'" do
|
22
22
|
it 'is true' do
|
23
|
-
expect(subject.attribute_method?('terms_and_conditions')).to
|
23
|
+
expect(subject.attribute_method?('terms_and_conditions')).to be true
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
context "when the attribute contains '_or_'" do
|
28
28
|
it 'is true' do
|
29
|
-
expect(subject.attribute_method?('true_or_false')).to
|
29
|
+
expect(subject.attribute_method?('true_or_false')).to be true
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
context "when the attribute ends with '_start'" do
|
34
34
|
it 'is true' do
|
35
|
-
expect(subject.attribute_method?('life_start')).to
|
35
|
+
expect(subject.attribute_method?('life_start')).to be true
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
context "when the attribute ends with '_end'" do
|
40
40
|
it 'is true' do
|
41
|
-
expect(subject.attribute_method?('stop_end')).to
|
41
|
+
expect(subject.attribute_method?('stop_end')).to be true
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
context 'for unknown attributes' do
|
47
47
|
it 'is false' do
|
48
|
-
expect(subject.attribute_method?('not_an_attribute')).to
|
48
|
+
expect(subject.attribute_method?('not_an_attribute')).to be false
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
data/spec/ransack/search_spec.rb
CHANGED
@@ -93,9 +93,10 @@ module Ransack
|
|
93
93
|
expect(condition.value).to eq 'Ernie'
|
94
94
|
end
|
95
95
|
|
96
|
-
it 'preserves default scope conditions for associations' do
|
97
|
-
search = Search.new(Person,
|
96
|
+
it 'preserves default scope and conditions for associations' do
|
97
|
+
search = Search.new(Person, published_articles_title_eq: 'Test')
|
98
98
|
expect(search.result.to_sql).to include 'default_scope'
|
99
|
+
expect(search.result.to_sql).to include 'published'
|
99
100
|
end
|
100
101
|
|
101
102
|
it 'discards empty conditions' do
|
data/spec/support/schema.rb
CHANGED
@@ -33,6 +33,11 @@ class Person < ActiveRecord::Base
|
|
33
33
|
belongs_to :parent, :class_name => 'Person', :foreign_key => :parent_id
|
34
34
|
has_many :children, :class_name => 'Person', :foreign_key => :parent_id
|
35
35
|
has_many :articles
|
36
|
+
if ActiveRecord::VERSION::MAJOR == 3
|
37
|
+
has_many :published_articles, conditions: { published: true }, class_name: "Article"
|
38
|
+
else
|
39
|
+
has_many :published_articles, ->{ where(published: true) }, class_name: "Article"
|
40
|
+
end
|
36
41
|
has_many :comments
|
37
42
|
has_many :authored_article_comments, :through => :articles,
|
38
43
|
:source => :comments, :foreign_key => :person_id
|
@@ -171,6 +176,7 @@ module Schema
|
|
171
176
|
t.string :title
|
172
177
|
t.text :subject_header
|
173
178
|
t.text :body
|
179
|
+
t.boolean :published, default: true
|
174
180
|
end
|
175
181
|
|
176
182
|
create_table :comments, :force => true do |t|
|
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.
|
4
|
+
version: 1.7.0
|
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-
|
13
|
+
date: 2015-08-20 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: actionpack
|
@@ -88,14 +88,14 @@ dependencies:
|
|
88
88
|
requirements:
|
89
89
|
- - "~>"
|
90
90
|
- !ruby/object:Gem::Version
|
91
|
-
version: 2
|
91
|
+
version: '2'
|
92
92
|
type: :development
|
93
93
|
prerelease: false
|
94
94
|
version_requirements: !ruby/object:Gem::Requirement
|
95
95
|
requirements:
|
96
96
|
- - "~>"
|
97
97
|
- !ruby/object:Gem::Version
|
98
|
-
version: 2
|
98
|
+
version: '2'
|
99
99
|
- !ruby/object:Gem::Dependency
|
100
100
|
name: machinist
|
101
101
|
requirement: !ruby/object:Gem::Requirement
|
@@ -158,14 +158,14 @@ dependencies:
|
|
158
158
|
requirements:
|
159
159
|
- - '='
|
160
160
|
- !ruby/object:Gem::Version
|
161
|
-
version: 0.3.
|
161
|
+
version: 0.3.18
|
162
162
|
type: :development
|
163
163
|
prerelease: false
|
164
164
|
version_requirements: !ruby/object:Gem::Requirement
|
165
165
|
requirements:
|
166
166
|
- - '='
|
167
167
|
- !ruby/object:Gem::Version
|
168
|
-
version: 0.3.
|
168
|
+
version: 0.3.18
|
169
169
|
- !ruby/object:Gem::Dependency
|
170
170
|
name: pry
|
171
171
|
requirement: !ruby/object:Gem::Requirement
|
@@ -199,6 +199,7 @@ files:
|
|
199
199
|
- README.md
|
200
200
|
- Rakefile
|
201
201
|
- lib/ransack.rb
|
202
|
+
- lib/ransack/adapters.rb
|
202
203
|
- lib/ransack/adapters/active_record.rb
|
203
204
|
- lib/ransack/adapters/active_record/3.0/compat.rb
|
204
205
|
- lib/ransack/adapters/active_record/3.0/context.rb
|
@@ -233,6 +234,7 @@ files:
|
|
233
234
|
- lib/ransack/helpers/form_builder.rb
|
234
235
|
- lib/ransack/helpers/form_helper.rb
|
235
236
|
- lib/ransack/locale/cs.yml
|
237
|
+
- lib/ransack/locale/de.yml
|
236
238
|
- lib/ransack/locale/en.yml
|
237
239
|
- lib/ransack/locale/es.yml
|
238
240
|
- lib/ransack/locale/fr.yml
|
@@ -310,10 +312,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
310
312
|
version: '0'
|
311
313
|
requirements: []
|
312
314
|
rubyforge_project: ransack
|
313
|
-
rubygems_version: 2.4.
|
315
|
+
rubygems_version: 2.4.8
|
314
316
|
signing_key:
|
315
317
|
specification_version: 4
|
316
|
-
summary: Object-based searching for
|
318
|
+
summary: Object-based searching for Active Record and Mongoid (currently).
|
317
319
|
test_files:
|
318
320
|
- spec/blueprints/articles.rb
|
319
321
|
- spec/blueprints/comments.rb
|