ransack 1.6.3 → 1.6.4
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 +0 -1
- data/CHANGELOG.md +22 -0
- data/README.md +4 -2
- data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +1 -0
- data/lib/ransack/helpers/form_builder.rb +23 -4
- data/lib/ransack/nodes/attribute.rb +3 -2
- data/lib/ransack/nodes/condition.rb +1 -1
- data/lib/ransack/translate.rb +2 -1
- data/lib/ransack/version.rb +1 -1
- data/spec/ransack/adapters/active_record/base_spec.rb +56 -29
- data/spec/ransack/nodes/grouping_spec.rb +0 -1
- data/spec/ransack/predicate_spec.rb +34 -11
- data/spec/support/schema.rb +17 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 954c9a11f9682b9e3fe5689c40d56d1978c24bb9
|
4
|
+
data.tar.gz: 58f30b75616e213c3afc8a91f92c8a940b4ac837
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bcbd765da64c6a1919651d7e8544ee74eedf95d69c69b0e777fffc5ebc624fe6312ae6ef88f4789dcaa54a622787f5f67804bdcfd07025163cae71b6100c0fbd
|
7
|
+
data.tar.gz: 876abe7e9d6faf89b99b64e993645add3d1c64bca934c4066c5b97790c46401ed581df97b8ffdc98685a9fd7fd5d4885196374e7a2d9ac5c581a0caba10725bc
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## Version 1.6.4 - 2015-03-20
|
4
|
+
|
5
|
+
* ActionView patch to maintain compatibility with Rails 4.2.1 released today.
|
6
|
+
|
7
|
+
*Jon Atack*
|
8
|
+
|
9
|
+
* Enable scoping I18n by 'ransack.models'
|
10
|
+
([#514](https://github.com/activerecord-hackery/ransack/pull/514)).
|
11
|
+
|
12
|
+
*nagyt234*
|
13
|
+
|
14
|
+
* Add ransacker arguments
|
15
|
+
([#513](https://github.com/activerecord-hackery/ransack/pull/513)).
|
16
|
+
|
17
|
+
*Denis Tataurov*, *Jon Atack*
|
18
|
+
|
3
19
|
## Version 1.6.3 - 2015-01-21
|
4
20
|
|
5
21
|
* Fix a regression
|
@@ -11,6 +27,12 @@
|
|
11
27
|
|
12
28
|
*Nate Berkopec*, *Jon Atack*
|
13
29
|
|
30
|
+
* Update travis-ci to no longer test Rails 3.1 with Ruby 2.2 and speed up the test matrix.
|
31
|
+
|
32
|
+
* Refactor Nodes::Condition.
|
33
|
+
|
34
|
+
*Jon Atack*
|
35
|
+
|
14
36
|
|
15
37
|
## Version 1.6.2 - 2015-01-14
|
16
38
|
|
data/README.md
CHANGED
@@ -27,8 +27,8 @@ instead.
|
|
27
27
|
If you're viewing this at
|
28
28
|
[github.com/activerecord-hackery/ransack](https://github.com/activerecord-hackery/ransack),
|
29
29
|
you're reading the documentation for the master branch with the latest features.
|
30
|
-
[View documentation for the last release (1.6.
|
31
|
-
(https://github.com/activerecord-hackery/ransack/tree/v1.6.
|
30
|
+
[View documentation for the last release (1.6.4).]
|
31
|
+
(https://github.com/activerecord-hackery/ransack/tree/v1.6.4)
|
32
32
|
|
33
33
|
## Getting started
|
34
34
|
|
@@ -632,6 +632,8 @@ en:
|
|
632
632
|
end: ends with
|
633
633
|
gt: greater than
|
634
634
|
lt: less than
|
635
|
+
models:
|
636
|
+
person: Passanger
|
635
637
|
attributes:
|
636
638
|
person:
|
637
639
|
name: Full Name
|
@@ -1,17 +1,36 @@
|
|
1
1
|
require 'action_view'
|
2
2
|
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
# TODO: Find a better way to solve this.
|
3
|
+
# Monkey-patching, avert your eyes!
|
4
|
+
# TODO: Find a better way to solve these two issues:
|
7
5
|
#
|
8
6
|
module ActionView::Helpers::Tags
|
7
|
+
|
8
|
+
# This patch is needed since this Rails commit:
|
9
|
+
# https://github.com/rails/rails/commit/c1a118a
|
10
|
+
#
|
9
11
|
class Base
|
10
12
|
private
|
11
13
|
def value(object)
|
12
14
|
object.send @method_name if object # use send instead of public_send
|
13
15
|
end
|
14
16
|
end
|
17
|
+
|
18
|
+
# This patch is needed for Rails 4.2.1 and 5.0.0 since these commits:
|
19
|
+
#
|
20
|
+
# Rails 4.2:
|
21
|
+
# https://github.com/rails/rails/commits/4-2-stable/actionview/lib/action_view/helpers/tags/translator.rb
|
22
|
+
# https://github.com/rails/rails/commits/4-2-stable/actionview/lib/action_view/helpers/tags/placeholderable.rb
|
23
|
+
#
|
24
|
+
# Rails master:
|
25
|
+
# https://github.com/rails/rails/commits/master/actionview/lib/action_view/helpers/tags/translator.rb
|
26
|
+
# https://github.com/rails/rails/commits/master/actionview/lib/action_view/helpers/tags/placeholderable.rb
|
27
|
+
#
|
28
|
+
class Translator
|
29
|
+
def i18n_default
|
30
|
+
return '' unless model
|
31
|
+
["#{model}.#{method_and_value}".to_sym, ""]
|
32
|
+
end
|
33
|
+
end
|
15
34
|
end
|
16
35
|
|
17
36
|
RANSACK_FORM_BUILDER = 'RANSACK_FORM_BUILDER'.freeze
|
@@ -3,14 +3,15 @@ module Ransack
|
|
3
3
|
class Attribute < Node
|
4
4
|
include Bindable
|
5
5
|
|
6
|
-
attr_reader :name
|
6
|
+
attr_reader :name, :ransacker_args
|
7
7
|
|
8
8
|
delegate :blank?, :present?, :==, :to => :name
|
9
9
|
delegate :engine, :to => :context
|
10
10
|
|
11
|
-
def initialize(context, name = nil)
|
11
|
+
def initialize(context, name = nil, ransacker_args = [])
|
12
12
|
super(context)
|
13
13
|
self.name = name unless name.blank?
|
14
|
+
@ransacker_args = ransacker_args
|
14
15
|
end
|
15
16
|
|
16
17
|
def name=(name)
|
data/lib/ransack/translate.rb
CHANGED
@@ -59,7 +59,8 @@ module Ransack
|
|
59
59
|
|
60
60
|
defaults =
|
61
61
|
if key.blank?
|
62
|
-
[:"
|
62
|
+
[:"ransack.models.#{i18n_key(context.klass)}",
|
63
|
+
:"#{context.klass.i18n_scope}.models.#{i18n_key(context.klass)}"]
|
63
64
|
else
|
64
65
|
[:"ransack.associations.#{i18n_key(context.klass)}.#{key}"]
|
65
66
|
end
|
data/lib/ransack/version.rb
CHANGED
@@ -24,49 +24,49 @@ module Ransack
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it "applies true scopes" do
|
27
|
-
|
28
|
-
|
27
|
+
s = Person.ransack('active' => true)
|
28
|
+
s.result.to_sql.should include "active = 1"
|
29
29
|
end
|
30
30
|
|
31
31
|
it "applies stringy true scopes" do
|
32
|
-
|
33
|
-
|
32
|
+
s = Person.ransack('active' => 'true')
|
33
|
+
s.result.to_sql.should include "active = 1"
|
34
34
|
end
|
35
35
|
|
36
36
|
it "applies stringy boolean scopes with true value in an array" do
|
37
|
-
|
38
|
-
|
37
|
+
s = Person.ransack('of_age' => ['true'])
|
38
|
+
s.result.to_sql.should include "age >= 18"
|
39
39
|
end
|
40
40
|
|
41
41
|
it "applies stringy boolean scopes with false value in an array" do
|
42
|
-
|
43
|
-
|
42
|
+
s = Person.ransack('of_age' => ['false'])
|
43
|
+
s.result.to_sql.should include "age < 18"
|
44
44
|
end
|
45
45
|
|
46
46
|
it "ignores unlisted scopes" do
|
47
|
-
|
48
|
-
|
47
|
+
s = Person.ransack('restricted' => true)
|
48
|
+
s.result.to_sql.should_not include "restricted"
|
49
49
|
end
|
50
50
|
|
51
51
|
it "ignores false scopes" do
|
52
|
-
|
53
|
-
|
52
|
+
s = Person.ransack('active' => false)
|
53
|
+
s.result.to_sql.should_not include "active"
|
54
54
|
end
|
55
55
|
|
56
56
|
it "ignores stringy false scopes" do
|
57
|
-
|
58
|
-
|
57
|
+
s = Person.ransack('active' => 'false')
|
58
|
+
s.result.to_sql.should_not include "active"
|
59
59
|
end
|
60
60
|
|
61
61
|
it "passes values to scopes" do
|
62
|
-
|
63
|
-
|
62
|
+
s = Person.ransack('over_age' => 18)
|
63
|
+
s.result.to_sql.should include "age > 18"
|
64
64
|
end
|
65
65
|
|
66
66
|
it "chains scopes" do
|
67
|
-
|
68
|
-
|
69
|
-
|
67
|
+
s = Person.ransack('over_age' => 18, 'active' => true)
|
68
|
+
s.result.to_sql.should include "age > 18"
|
69
|
+
s.result.to_sql.should include "active = 1"
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
@@ -80,14 +80,6 @@ module Ransack
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
-
context "search on an `in` predicate with an array" do
|
84
|
-
it "should function correctly when passing an array of ids" do
|
85
|
-
array = Person.all.map(&:id)
|
86
|
-
s = Person.ransack(id_in: array)
|
87
|
-
expect(s.result.count).to eq array.size
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
83
|
describe '#ransacker' do
|
92
84
|
# For infix tests
|
93
85
|
def self.sane_adapter?
|
@@ -181,17 +173,32 @@ module Ransack
|
|
181
173
|
expect(s.result.to_a).to eq [p]
|
182
174
|
end
|
183
175
|
|
184
|
-
context "
|
176
|
+
context "searching on an `in` predicate with a ransacker" do
|
185
177
|
it "should function correctly when passing an array of ids" do
|
186
178
|
s = Person.ransack(array_users_in: true)
|
187
179
|
expect(s.result.count).to be > 0
|
188
180
|
end
|
189
181
|
|
190
182
|
it "should function correctly when passing an array of strings" do
|
191
|
-
|
183
|
+
Person.create!(name: Person.first.id.to_s)
|
192
184
|
s = Person.ransack(array_names_in: true)
|
193
185
|
expect(s.result.count).to be > 0
|
194
186
|
end
|
187
|
+
|
188
|
+
it 'should function correctly with an Arel SqlLiteral' do
|
189
|
+
s = Person.ransack(sql_literal_id_in: 1)
|
190
|
+
expect(s.result.count).to be 1
|
191
|
+
s = Person.ransack(sql_literal_id_in: ['2', 4, '5', 8])
|
192
|
+
expect(s.result.count).to be 4
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
context "search on an `in` predicate with an array" do
|
197
|
+
it "should function correctly when passing an array of ids" do
|
198
|
+
array = Person.all.map(&:id)
|
199
|
+
s = Person.ransack(id_in: array)
|
200
|
+
expect(s.result.count).to eq array.size
|
201
|
+
end
|
195
202
|
end
|
196
203
|
|
197
204
|
it "should function correctly when an attribute name ends with '_start'" do
|
@@ -306,6 +313,26 @@ module Ransack
|
|
306
313
|
quote_column_name("only_admin")} = 'htimS cirA'/
|
307
314
|
)
|
308
315
|
end
|
316
|
+
|
317
|
+
it 'should allow passing ransacker arguments to a ransacker' do
|
318
|
+
s = Person.ransack(
|
319
|
+
c: [{
|
320
|
+
a: {
|
321
|
+
'0' => {
|
322
|
+
name: 'with_passed_arguments', ransacker_args: [10, 100]
|
323
|
+
}
|
324
|
+
},
|
325
|
+
p: 'cont',
|
326
|
+
v: ['Rails has been released']
|
327
|
+
}]
|
328
|
+
)
|
329
|
+
expect(s.result.to_sql).to match(
|
330
|
+
/CHAR_LENGTH\(articles.body\) BETWEEN 10 AND 100/
|
331
|
+
)
|
332
|
+
expect(s.result.to_sql).to match(
|
333
|
+
/LIKE \'\%Rails has been released\%\'/
|
334
|
+
)
|
335
|
+
end
|
309
336
|
end
|
310
337
|
|
311
338
|
describe '#ransackable_attributes' do
|
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Ransack
|
4
|
+
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE'].to_set
|
5
|
+
FALSE_VALUES = [false, 0, '0', 'f', 'F', 'false', 'FALSE'].to_set
|
6
|
+
|
4
7
|
describe Predicate do
|
5
8
|
|
6
9
|
before do
|
@@ -20,18 +23,12 @@ module Ransack
|
|
20
23
|
end
|
21
24
|
|
22
25
|
describe 'eq' do
|
23
|
-
it 'generates an equality condition for boolean true' do
|
24
|
-
|
25
|
-
field = "#{quote_table_name("people")}.#{quote_column_name("awesome")}"
|
26
|
-
expect(@s.result.to_sql).to match /#{field} = #{
|
27
|
-
ActiveRecord::Base.connection.quoted_true}/
|
26
|
+
it 'generates an equality condition for boolean true values' do
|
27
|
+
test_boolean_equality_for(true)
|
28
28
|
end
|
29
29
|
|
30
|
-
it 'generates an equality condition for boolean false' do
|
31
|
-
|
32
|
-
field = "#{quote_table_name("people")}.#{quote_column_name("awesome")}"
|
33
|
-
expect(@s.result.to_sql).to match /#{field} = #{
|
34
|
-
ActiveRecord::Base.connection.quoted_false}/
|
30
|
+
it 'generates an equality condition for boolean false values' do
|
31
|
+
test_boolean_equality_for(false)
|
35
32
|
end
|
36
33
|
|
37
34
|
it 'does not generate a condition for nil' do
|
@@ -361,5 +358,31 @@ module Ransack
|
|
361
358
|
expect(@s.result.to_sql).to match /#{field} IS NOT NULL AND #{field} != ''/
|
362
359
|
end
|
363
360
|
end
|
364
|
-
|
361
|
+
|
362
|
+
private
|
363
|
+
|
364
|
+
def test_boolean_equality_for(boolean_value)
|
365
|
+
query = expected_query(boolean_value)
|
366
|
+
test_values_for(boolean_value).each do |value|
|
367
|
+
s = Search.new(Person, awesome_eq: value)
|
368
|
+
expect(s.result.to_sql).to match query
|
369
|
+
end
|
370
|
+
end
|
371
|
+
|
372
|
+
def test_values_for(boolean_value)
|
373
|
+
case boolean_value
|
374
|
+
when true
|
375
|
+
TRUE_VALUES
|
376
|
+
when false
|
377
|
+
FALSE_VALUES
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
def expected_query(value, attribute = 'awesome', operator = '=')
|
382
|
+
field = "#{quote_table_name("people")}.#{quote_column_name(attribute)}"
|
383
|
+
quoted_value = ActiveRecord::Base.connection.quote(value)
|
384
|
+
/#{field} #{operator} #{quoted_value}/
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
365
388
|
end
|
data/spec/support/schema.rb
CHANGED
@@ -63,6 +63,23 @@ class Person < ActiveRecord::Base
|
|
63
63
|
)
|
64
64
|
end
|
65
65
|
|
66
|
+
ransacker :sql_literal_id do
|
67
|
+
Arel.sql('people.id')
|
68
|
+
end
|
69
|
+
|
70
|
+
ransacker :with_passed_arguments, args: [:parent, :ransacker_args] do |parent, args|
|
71
|
+
min_body, max_body = args
|
72
|
+
sql = <<-SQL
|
73
|
+
(SELECT MAX(articles.title)
|
74
|
+
FROM articles
|
75
|
+
WHERE articles.person_id = people.id
|
76
|
+
AND CHAR_LENGTH(articles.body) BETWEEN #{min_body} AND #{max_body}
|
77
|
+
GROUP BY articles.person_id
|
78
|
+
)
|
79
|
+
SQL
|
80
|
+
Arel.sql(sql.squish)
|
81
|
+
end
|
82
|
+
|
66
83
|
def self.ransackable_attributes(auth_object = nil)
|
67
84
|
if auth_object == :admin
|
68
85
|
column_names + _ransackers.keys - ['only_sort']
|
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.4
|
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-03-20 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: actionpack
|
@@ -310,7 +310,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
310
310
|
version: '0'
|
311
311
|
requirements: []
|
312
312
|
rubyforge_project: ransack
|
313
|
-
rubygems_version: 2.4.
|
313
|
+
rubygems_version: 2.4.6
|
314
314
|
signing_key:
|
315
315
|
specification_version: 4
|
316
316
|
summary: Object-based searching for ActiveRecord (currently).
|