ransack 2.1.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +32 -22
- data/CHANGELOG.md +60 -1
- data/CONTRIBUTING.md +11 -6
- data/Gemfile +21 -17
- data/README.md +56 -29
- data/lib/polyamorous/{activerecord_5.2.1_ruby_2 → activerecord_5.2_ruby_2}/join_association.rb +2 -9
- data/lib/polyamorous/{activerecord_5.2.1_ruby_2 → activerecord_5.2_ruby_2}/join_dependency.rb +25 -3
- data/lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb +11 -0
- data/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb +1 -0
- data/lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb +80 -0
- data/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb +1 -0
- data/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb +74 -0
- data/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb +93 -0
- data/lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb +1 -0
- data/lib/{polyamorous.rb → polyamorous/polyamorous.rb} +3 -3
- data/lib/ransack.rb +2 -2
- data/lib/ransack/adapters/active_record/base.rb +1 -0
- data/lib/ransack/adapters/active_record/context.rb +60 -68
- data/lib/ransack/adapters/active_record/ransack/constants.rb +17 -2
- data/lib/ransack/adapters/active_record/ransack/context.rb +2 -6
- data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +12 -5
- data/lib/ransack/adapters/active_record/ransack/translate.rb +1 -1
- data/lib/ransack/constants.rb +2 -3
- data/lib/ransack/context.rb +19 -18
- data/lib/ransack/helpers/form_builder.rb +5 -11
- data/lib/ransack/helpers/form_helper.rb +1 -1
- data/lib/ransack/locale/ar.yml +70 -0
- data/lib/ransack/locale/az.yml +1 -1
- data/lib/ransack/locale/ca.yml +70 -0
- data/lib/ransack/locale/es.yml +22 -22
- data/lib/ransack/locale/fa.yml +70 -0
- data/lib/ransack/locale/fi.yml +71 -0
- data/lib/ransack/locale/sk.yml +70 -0
- data/lib/ransack/locale/zh-CN.yml +12 -12
- data/lib/ransack/nodes/condition.rb +8 -0
- data/lib/ransack/nodes/grouping.rb +1 -1
- data/lib/ransack/predicate.rb +2 -1
- data/lib/ransack/search.rb +1 -0
- data/lib/ransack/translate.rb +115 -115
- data/lib/ransack/version.rb +1 -1
- data/ransack.gemspec +5 -21
- data/spec/helpers/polyamorous_helper.rb +3 -8
- data/spec/{ransack → polyamorous}/join_association_spec.rb +7 -0
- data/spec/{ransack → polyamorous}/join_dependency_spec.rb +18 -7
- data/spec/{ransack → polyamorous}/join_spec.rb +0 -0
- data/spec/ransack/adapters/active_record/base_spec.rb +8 -8
- data/spec/ransack/adapters/active_record/context_spec.rb +60 -17
- data/spec/ransack/helpers/form_helper_spec.rb +51 -51
- data/spec/ransack/predicate_spec.rb +54 -2
- data/spec/ransack/search_spec.rb +78 -13
- data/spec/spec_helper.rb +4 -0
- data/spec/support/schema.rb +13 -2
- metadata +29 -136
- data/lib/polyamorous/activerecord_5.0_ruby_2/join_association.rb +0 -2
- data/lib/polyamorous/activerecord_5.0_ruby_2/join_dependency.rb +0 -2
- data/lib/polyamorous/activerecord_5.1_ruby_2/join_association.rb +0 -32
- data/lib/polyamorous/activerecord_5.1_ruby_2/join_dependency.rb +0 -112
- data/lib/polyamorous/activerecord_5.2.0_ruby_2/join_association.rb +0 -32
- data/lib/polyamorous/activerecord_5.2.0_ruby_2/join_dependency.rb +0 -113
data/lib/ransack/version.rb
CHANGED
data/ransack.gemspec
CHANGED
@@ -11,31 +11,15 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.homepage = "https://github.com/activerecord-hackery/ransack"
|
12
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
|
-
s.required_ruby_version = '>=
|
14
|
+
s.required_ruby_version = '>= 2.3'
|
15
15
|
s.license = 'MIT'
|
16
16
|
|
17
|
-
s.
|
18
|
-
|
19
|
-
s.add_dependency 'actionpack', '>= 5.0'
|
20
|
-
s.add_dependency 'activerecord', '>= 5.0'
|
21
|
-
s.add_dependency 'activesupport', '>= 5.0'
|
17
|
+
s.add_dependency 'activerecord', '>= 5.2.4'
|
18
|
+
s.add_dependency 'activesupport', '>= 5.2.4'
|
22
19
|
s.add_dependency 'i18n'
|
23
|
-
s.add_development_dependency 'rspec', '~> 3'
|
24
|
-
s.add_development_dependency 'machinist', '~> 1.0.6'
|
25
|
-
s.add_development_dependency 'faker', '~> 0.9.5'
|
26
|
-
s.add_development_dependency 'sqlite3', '~> 1.3.3'
|
27
|
-
s.add_development_dependency 'pg', '~> 0.21'
|
28
|
-
s.add_development_dependency 'mysql2', '0.3.20'
|
29
|
-
s.add_development_dependency 'pry', '0.10'
|
30
20
|
|
31
21
|
s.files = `git ls-files`.split("\n")
|
32
|
-
|
33
|
-
s.
|
34
|
-
.split("\n")
|
35
|
-
|
36
|
-
s.executables = `git ls-files -- bin/*`
|
37
|
-
.split("\n")
|
38
|
-
.map { |f| File.basename(f) }
|
39
|
-
|
22
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
23
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
40
24
|
s.require_paths = ["lib"]
|
41
25
|
end
|
@@ -3,18 +3,13 @@ module PolyamorousHelper
|
|
3
3
|
Polyamorous::JoinAssociation.new reflection, children, klass
|
4
4
|
end
|
5
5
|
|
6
|
-
if ActiveRecord::
|
6
|
+
if ActiveRecord.version >= ::Gem::Version.new("6.0.0.rc1")
|
7
7
|
def new_join_dependency(klass, associations = {})
|
8
|
-
Polyamorous::JoinDependency.new klass, klass.arel_table, associations
|
9
|
-
end
|
10
|
-
elsif ActiveRecord::VERSION::STRING == "5.2.0"
|
11
|
-
def new_join_dependency(klass, associations = {})
|
12
|
-
alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(klass.connection, klass.table_name, [])
|
13
|
-
Polyamorous::JoinDependency.new klass, klass.arel_table, associations, alias_tracker
|
8
|
+
Polyamorous::JoinDependency.new klass, klass.arel_table, associations, Polyamorous::InnerJoin
|
14
9
|
end
|
15
10
|
else
|
16
11
|
def new_join_dependency(klass, associations = {})
|
17
|
-
Polyamorous::JoinDependency.new klass,
|
12
|
+
Polyamorous::JoinDependency.new klass, klass.arel_table, associations
|
18
13
|
end
|
19
14
|
end
|
20
15
|
|
@@ -10,6 +10,13 @@ module Polyamorous
|
|
10
10
|
new_join_association(reflection, parent.children, Article)
|
11
11
|
}
|
12
12
|
|
13
|
+
subject { new_join_association(reflection, parent.children, Person) }
|
14
|
+
|
15
|
+
it 'respects polymorphism on equality test' do
|
16
|
+
expect(subject).to eq new_join_association(reflection, parent.children, Person)
|
17
|
+
expect(subject).not_to eq new_join_association(reflection, parent.children, Article)
|
18
|
+
end
|
19
|
+
|
13
20
|
it 'leaves the orginal reflection intact for thread safety' do
|
14
21
|
reflection.instance_variable_set(:@klass, Article)
|
15
22
|
join_association
|
@@ -8,8 +8,8 @@ module Polyamorous
|
|
8
8
|
|
9
9
|
specify { expect(subject.send(:join_root).drop(1).size)
|
10
10
|
.to eq(2) }
|
11
|
-
specify { expect(subject.send(:join_root).drop(1).map(&:join_type))
|
12
|
-
.to
|
11
|
+
specify { expect(subject.send(:join_root).drop(1).map(&:join_type).uniq)
|
12
|
+
.to eq [Polyamorous::InnerJoin] }
|
13
13
|
end
|
14
14
|
|
15
15
|
context 'with has_many :through association' do
|
@@ -38,8 +38,8 @@ module Polyamorous
|
|
38
38
|
.to eq 2 }
|
39
39
|
specify { expect(subject.send(:join_root).drop(1).map(&:join_type))
|
40
40
|
.to eq [Polyamorous::OuterJoin, Polyamorous::OuterJoin] }
|
41
|
-
specify { expect(subject.send(:join_root).drop(1).map(&:join_type))
|
42
|
-
.to
|
41
|
+
specify { expect(subject.send(:join_root).drop(1).map(&:join_type).uniq)
|
42
|
+
.to eq [Polyamorous::OuterJoin] }
|
43
43
|
end
|
44
44
|
|
45
45
|
context 'with polymorphic belongs_to join' do
|
@@ -59,8 +59,19 @@ module Polyamorous
|
|
59
59
|
|
60
60
|
specify { expect(subject.send(:join_root).drop(1).size)
|
61
61
|
.to eq 2 }
|
62
|
-
specify { expect(subject.send(:join_root).drop(1).map(&:join_type))
|
63
|
-
.to
|
62
|
+
specify { expect(subject.send(:join_root).drop(1).map(&:join_type).uniq)
|
63
|
+
.to eq [Polyamorous::InnerJoin] }
|
64
|
+
specify { expect(subject.send(:join_root).drop(1).first.table_name)
|
65
|
+
.to eq 'people' }
|
66
|
+
specify { expect(subject.send(:join_root).drop(1)[1].table_name)
|
67
|
+
.to eq 'comments' }
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'with polymorphic belongs_to join and nested join' do
|
71
|
+
subject { new_join_dependency Note,
|
72
|
+
new_join(:notable, :outer, Person) => :comments }
|
73
|
+
specify { expect(subject.send(:join_root).drop(1).size).to eq 2 }
|
74
|
+
specify { expect(subject.send(:join_root).drop(1).map(&:join_type)).to eq [Polyamorous::OuterJoin, Polyamorous::InnerJoin] }
|
64
75
|
specify { expect(subject.send(:join_root).drop(1).first.table_name)
|
65
76
|
.to eq 'people' }
|
66
77
|
specify { expect(subject.send(:join_root).drop(1)[1].table_name)
|
@@ -68,7 +79,7 @@ module Polyamorous
|
|
68
79
|
end
|
69
80
|
|
70
81
|
context '#left_outer_join in Rails 5 overrides join type specified',
|
71
|
-
if: ActiveRecord::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MINOR < 2 do
|
82
|
+
if: ActiveRecord::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MAJOR < 6 && ActiveRecord::VERSION::MINOR < 2 do
|
72
83
|
|
73
84
|
let(:join_type_class) do
|
74
85
|
new_join_dependency(
|
File without changes
|
@@ -143,14 +143,12 @@ module Ransack
|
|
143
143
|
it 'removes redundant joins from top query' do
|
144
144
|
s = Article.ransack(tags_name_not_eq: "Fantasy")
|
145
145
|
sql = s.result.to_sql
|
146
|
-
|
147
146
|
expect(sql).to_not include('LEFT OUTER JOIN')
|
148
147
|
end
|
149
148
|
|
150
149
|
it 'handles != for single values' do
|
151
150
|
s = Article.ransack(tags_name_not_eq: "Fantasy")
|
152
151
|
articles = s.result.to_a
|
153
|
-
|
154
152
|
expect(articles).to include marco
|
155
153
|
expect(articles).to_not include arthur
|
156
154
|
end
|
@@ -267,10 +265,12 @@ module Ransack
|
|
267
265
|
# end
|
268
266
|
|
269
267
|
it 'creates ransack attributes' do
|
268
|
+
person = Person.create!(name: 'Aric Smith')
|
269
|
+
|
270
270
|
s = Person.ransack(reversed_name_eq: 'htimS cirA')
|
271
271
|
expect(s.result.size).to eq(1)
|
272
272
|
|
273
|
-
expect(s.result.first).to eq
|
273
|
+
expect(s.result.first).to eq person
|
274
274
|
end
|
275
275
|
|
276
276
|
it 'can be accessed through associations' do
|
@@ -584,31 +584,31 @@ module Ransack
|
|
584
584
|
|
585
585
|
context 'case insensitive sorting' do
|
586
586
|
it 'allows sort by desc' do
|
587
|
-
search = Person.
|
587
|
+
search = Person.ransack(sorts: ['name_case_insensitive desc'])
|
588
588
|
expect(search.result.to_sql).to match /ORDER BY LOWER(.*) DESC/
|
589
589
|
end
|
590
590
|
|
591
591
|
it 'allows sort by asc' do
|
592
|
-
search = Person.
|
592
|
+
search = Person.ransack(sorts: ['name_case_insensitive asc'])
|
593
593
|
expect(search.result.to_sql).to match /ORDER BY LOWER(.*) ASC/
|
594
594
|
end
|
595
595
|
end
|
596
596
|
|
597
597
|
context 'regular sorting' do
|
598
598
|
it 'allows sort by desc' do
|
599
|
-
search = Person.
|
599
|
+
search = Person.ransack(sorts: ['name desc'])
|
600
600
|
expect(search.result.to_sql).to match /ORDER BY .* DESC/
|
601
601
|
end
|
602
602
|
|
603
603
|
it 'allows sort by asc' do
|
604
|
-
search = Person.
|
604
|
+
search = Person.ransack(sorts: ['name asc'])
|
605
605
|
expect(search.result.to_sql).to match /ORDER BY .* ASC/
|
606
606
|
end
|
607
607
|
end
|
608
608
|
|
609
609
|
context 'sorting by a scope' do
|
610
610
|
it 'applies the correct scope' do
|
611
|
-
search = Person.
|
611
|
+
search = Person.ransack(sorts: ['reverse_name asc'])
|
612
612
|
expect(search.result.to_sql).to include("ORDER BY REVERSE(name) ASC")
|
613
613
|
end
|
614
614
|
end
|
@@ -40,6 +40,66 @@ module Ransack
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
+
describe '#build_correlated_subquery' do
|
44
|
+
it 'build correlated subquery for Root STI model' do
|
45
|
+
search = Search.new(Person, { articles_title_not_eq: 'some_title' }, context: subject)
|
46
|
+
attribute = search.conditions.first.attributes.first
|
47
|
+
constraints = subject.build_correlated_subquery(attribute.parent).constraints
|
48
|
+
constraint = constraints.first
|
49
|
+
|
50
|
+
expect(constraints.length).to eql 1
|
51
|
+
expect(constraint.left.name).to eql 'person_id'
|
52
|
+
expect(constraint.left.relation.name).to eql 'articles'
|
53
|
+
expect(constraint.right.name).to eql 'id'
|
54
|
+
expect(constraint.right.relation.name).to eql 'people'
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'build correlated subquery for Child STI model when predicate is not_eq' do
|
58
|
+
search = Search.new(Person, { story_articles_title_not_eq: 'some_title' }, context: subject)
|
59
|
+
attribute = search.conditions.first.attributes.first
|
60
|
+
constraints = subject.build_correlated_subquery(attribute.parent).constraints
|
61
|
+
constraint = constraints.first
|
62
|
+
|
63
|
+
expect(constraints.length).to eql 1
|
64
|
+
expect(constraint.left.relation.name).to eql 'articles'
|
65
|
+
expect(constraint.left.name).to eql 'person_id'
|
66
|
+
expect(constraint.right.relation.name).to eql 'people'
|
67
|
+
expect(constraint.right.name).to eql 'id'
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'build correlated subquery for Child STI model when predicate is eq' do
|
71
|
+
search = Search.new(Person, { story_articles_title_not_eq: 'some_title' }, context: subject)
|
72
|
+
attribute = search.conditions.first.attributes.first
|
73
|
+
constraints = subject.build_correlated_subquery(attribute.parent).constraints
|
74
|
+
constraint = constraints.first
|
75
|
+
|
76
|
+
expect(constraints.length).to eql 1
|
77
|
+
expect(constraint.left.relation.name).to eql 'articles'
|
78
|
+
expect(constraint.left.name).to eql 'person_id'
|
79
|
+
expect(constraint.right.relation.name).to eql 'people'
|
80
|
+
expect(constraint.right.name).to eql 'id'
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'build correlated subquery for multiple conditions (default scope)' do
|
84
|
+
search = Search.new(Person, { comments_body_not_eq: 'some_title'})
|
85
|
+
|
86
|
+
# Was
|
87
|
+
# SELECT "people".* FROM "people" WHERE "people"."id" NOT IN (
|
88
|
+
# SELECT "comments"."disabled" FROM "comments"
|
89
|
+
# WHERE "comments"."disabled" = "people"."id"
|
90
|
+
# AND NOT ("comments"."body" != 'some_title')
|
91
|
+
# ) ORDER BY "people"."id" DESC
|
92
|
+
# Should Be
|
93
|
+
# SELECT "people".* FROM "people" WHERE "people"."id" NOT IN (
|
94
|
+
# SELECT "comments"."person_id" FROM "comments"
|
95
|
+
# WHERE "comments"."person_id" = "people"."id"
|
96
|
+
# AND NOT ("comments"."body" != 'some_title')
|
97
|
+
# ) ORDER BY "people"."id" DESC
|
98
|
+
|
99
|
+
expect(search.result.to_sql).to match /.comments.\..person_id. = .people.\..id./
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
43
103
|
describe 'sharing context across searches' do
|
44
104
|
let(:shared_context) { Context.for(Person) }
|
45
105
|
|
@@ -50,23 +110,6 @@ module Ransack
|
|
50
110
|
context: shared_context)
|
51
111
|
end
|
52
112
|
|
53
|
-
describe '#join_associations', if: AR_version <= '4.0' do
|
54
|
-
it 'returns dependent join associations for all searches run
|
55
|
-
against the context' do
|
56
|
-
parents, children = shared_context.join_associations
|
57
|
-
|
58
|
-
expect(children.aliased_table_name).to eq "children_people"
|
59
|
-
expect(parents.aliased_table_name).to eq "parents_people"
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'can be rejoined to execute a valid query' do
|
63
|
-
parents, children = shared_context.join_associations
|
64
|
-
|
65
|
-
expect { Person.joins(parents).joins(children).to_a }
|
66
|
-
.to_not raise_error
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
113
|
describe '#join_sources' do
|
71
114
|
it 'returns dependent arel join nodes for all searches run against
|
72
115
|
the context' do
|
@@ -25,7 +25,7 @@ module Ransack
|
|
25
25
|
describe '#sort_link with default search_key' do
|
26
26
|
subject { @controller.view_context
|
27
27
|
.sort_link(
|
28
|
-
[:main_app, Person.
|
28
|
+
[:main_app, Person.ransack(sorts: ['name desc'])],
|
29
29
|
:name,
|
30
30
|
controller: 'people'
|
31
31
|
)
|
@@ -38,7 +38,7 @@ module Ransack
|
|
38
38
|
describe '#sort_url with default search_key' do
|
39
39
|
subject { @controller.view_context
|
40
40
|
.sort_url(
|
41
|
-
[:main_app, Person.
|
41
|
+
[:main_app, Person.ransack(sorts: ['name desc'])],
|
42
42
|
:name,
|
43
43
|
controller: 'people'
|
44
44
|
)
|
@@ -49,7 +49,7 @@ module Ransack
|
|
49
49
|
describe '#sort_link with default search_key defined as symbol' do
|
50
50
|
subject { @controller.view_context
|
51
51
|
.sort_link(
|
52
|
-
Person.
|
52
|
+
Person.ransack({ sorts: ['name desc'] }, search_key: :people_search),
|
53
53
|
:name, controller: 'people'
|
54
54
|
)
|
55
55
|
}
|
@@ -59,7 +59,7 @@ module Ransack
|
|
59
59
|
describe '#sort_url with default search_key defined as symbol' do
|
60
60
|
subject { @controller.view_context
|
61
61
|
.sort_url(
|
62
|
-
Person.
|
62
|
+
Person.ransack({ sorts: ['name desc'] }, search_key: :people_search),
|
63
63
|
:name, controller: 'people'
|
64
64
|
)
|
65
65
|
}
|
@@ -69,7 +69,7 @@ module Ransack
|
|
69
69
|
describe '#sort_link desc through association table defined as symbol' do
|
70
70
|
subject { @controller.view_context
|
71
71
|
.sort_link(
|
72
|
-
Person.
|
72
|
+
Person.ransack({ sorts: 'comments_body asc' }),
|
73
73
|
:comments_body,
|
74
74
|
controller: 'people'
|
75
75
|
)
|
@@ -82,7 +82,7 @@ module Ransack
|
|
82
82
|
describe '#sort_url desc through association table defined as symbol' do
|
83
83
|
subject { @controller.view_context
|
84
84
|
.sort_url(
|
85
|
-
Person.
|
85
|
+
Person.ransack({ sorts: 'comments_body asc' }),
|
86
86
|
:comments_body,
|
87
87
|
controller: 'people'
|
88
88
|
)
|
@@ -93,7 +93,7 @@ module Ransack
|
|
93
93
|
describe '#sort_link through association table defined as a string' do
|
94
94
|
subject { @controller.view_context
|
95
95
|
.sort_link(
|
96
|
-
Person.
|
96
|
+
Person.ransack({ sorts: 'comments.body desc' }),
|
97
97
|
'comments.body',
|
98
98
|
controller: 'people'
|
99
99
|
)
|
@@ -106,7 +106,7 @@ module Ransack
|
|
106
106
|
describe '#sort_url through association table defined as a string' do
|
107
107
|
subject { @controller.view_context
|
108
108
|
.sort_url(
|
109
|
-
Person.
|
109
|
+
Person.ransack({ sorts: 'comments.body desc' }),
|
110
110
|
'comments.body',
|
111
111
|
controller: 'people'
|
112
112
|
)
|
@@ -119,7 +119,7 @@ module Ransack
|
|
119
119
|
specify {
|
120
120
|
expect { @controller.view_context
|
121
121
|
.sort_link(
|
122
|
-
Person.
|
122
|
+
Person.ransack(@controller.view_context.params[:q]),
|
123
123
|
:name,
|
124
124
|
controller: 'people'
|
125
125
|
)
|
@@ -132,7 +132,7 @@ module Ransack
|
|
132
132
|
specify {
|
133
133
|
expect { @controller.view_context
|
134
134
|
.sort_url(
|
135
|
-
Person.
|
135
|
+
Person.ransack(@controller.view_context.params[:q]),
|
136
136
|
:name,
|
137
137
|
controller: 'people'
|
138
138
|
)
|
@@ -143,7 +143,7 @@ module Ransack
|
|
143
143
|
describe '#sort_link with search_key defined as a string' do
|
144
144
|
subject { @controller.view_context
|
145
145
|
.sort_link(
|
146
|
-
Person.
|
146
|
+
Person.ransack(
|
147
147
|
{ sorts: ['name desc'] }, search_key: 'people_search'
|
148
148
|
),
|
149
149
|
:name,
|
@@ -156,7 +156,7 @@ module Ransack
|
|
156
156
|
describe '#sort_link with default_order defined with a string key' do
|
157
157
|
subject { @controller.view_context
|
158
158
|
.sort_link(
|
159
|
-
[:main_app, Person.
|
159
|
+
[:main_app, Person.ransack()],
|
160
160
|
:name,
|
161
161
|
controller: 'people',
|
162
162
|
default_order: 'desc'
|
@@ -168,7 +168,7 @@ module Ransack
|
|
168
168
|
describe '#sort_url with default_order defined with a string key' do
|
169
169
|
subject { @controller.view_context
|
170
170
|
.sort_url(
|
171
|
-
[:main_app, Person.
|
171
|
+
[:main_app, Person.ransack()],
|
172
172
|
:name,
|
173
173
|
controller: 'people',
|
174
174
|
default_order: 'desc'
|
@@ -180,7 +180,7 @@ module Ransack
|
|
180
180
|
describe '#sort_link with multiple search_keys defined as an array' do
|
181
181
|
subject { @controller.view_context
|
182
182
|
.sort_link(
|
183
|
-
[:main_app, Person.
|
183
|
+
[:main_app, Person.ransack(sorts: ['name desc', 'email asc'])],
|
184
184
|
:name, [:name, 'email DESC'],
|
185
185
|
controller: 'people'
|
186
186
|
)
|
@@ -196,7 +196,7 @@ module Ransack
|
|
196
196
|
describe '#sort_url with multiple search_keys defined as an array' do
|
197
197
|
subject { @controller.view_context
|
198
198
|
.sort_url(
|
199
|
-
[:main_app, Person.
|
199
|
+
[:main_app, Person.ransack(sorts: ['name desc', 'email asc'])],
|
200
200
|
:name, [:name, 'email DESC'],
|
201
201
|
controller: 'people'
|
202
202
|
)
|
@@ -210,7 +210,7 @@ module Ransack
|
|
210
210
|
describe '#sort_link with multiple search_keys does not break on nil values & ignores them' do
|
211
211
|
subject { @controller.view_context
|
212
212
|
.sort_link(
|
213
|
-
[:main_app, Person.
|
213
|
+
[:main_app, Person.ransack(sorts: ['name desc', nil, 'email', nil])],
|
214
214
|
:name, [nil, :name, nil, 'email DESC', nil],
|
215
215
|
controller: 'people'
|
216
216
|
)
|
@@ -226,7 +226,7 @@ module Ransack
|
|
226
226
|
describe '#sort_url with multiple search_keys does not break on nil values & ignores them' do
|
227
227
|
subject { @controller.view_context
|
228
228
|
.sort_url(
|
229
|
-
[:main_app, Person.
|
229
|
+
[:main_app, Person.ransack(sorts: ['name desc', nil, 'email', nil])],
|
230
230
|
:name, [nil, :name, nil, 'email DESC', nil],
|
231
231
|
controller: 'people'
|
232
232
|
)
|
@@ -240,7 +240,7 @@ module Ransack
|
|
240
240
|
describe '#sort_link with multiple search_keys should allow a label to be specified' do
|
241
241
|
subject { @controller.view_context
|
242
242
|
.sort_link(
|
243
|
-
[:main_app, Person.
|
243
|
+
[:main_app, Person.ransack(sorts: ['name desc', 'email asc'])],
|
244
244
|
:name, [:name, 'email DESC'],
|
245
245
|
'Property Name',
|
246
246
|
controller: 'people'
|
@@ -252,7 +252,7 @@ module Ransack
|
|
252
252
|
describe '#sort_link with multiple search_keys should flip multiple fields specified without a direction' do
|
253
253
|
subject { @controller.view_context
|
254
254
|
.sort_link(
|
255
|
-
[:main_app, Person.
|
255
|
+
[:main_app, Person.ransack(sorts: ['name desc', 'email asc'])],
|
256
256
|
:name, [:name, :email],
|
257
257
|
controller: 'people'
|
258
258
|
)
|
@@ -268,7 +268,7 @@ module Ransack
|
|
268
268
|
describe '#sort_url with multiple search_keys should flip multiple fields specified without a direction' do
|
269
269
|
subject { @controller.view_context
|
270
270
|
.sort_url(
|
271
|
-
[:main_app, Person.
|
271
|
+
[:main_app, Person.ransack(sorts: ['name desc', 'email asc'])],
|
272
272
|
:name, [:name, :email],
|
273
273
|
controller: 'people'
|
274
274
|
)
|
@@ -282,7 +282,7 @@ module Ransack
|
|
282
282
|
describe '#sort_link with multiple search_keys and default_order specified as a string' do
|
283
283
|
subject { @controller.view_context
|
284
284
|
.sort_link(
|
285
|
-
[:main_app, Person.
|
285
|
+
[:main_app, Person.ransack()],
|
286
286
|
:name, [:name, :email],
|
287
287
|
controller: 'people',
|
288
288
|
default_order: 'desc'
|
@@ -299,7 +299,7 @@ module Ransack
|
|
299
299
|
describe '#sort_url with multiple search_keys and default_order specified as a string' do
|
300
300
|
subject { @controller.view_context
|
301
301
|
.sort_url(
|
302
|
-
[:main_app, Person.
|
302
|
+
[:main_app, Person.ransack()],
|
303
303
|
:name, [:name, :email],
|
304
304
|
controller: 'people',
|
305
305
|
default_order: 'desc'
|
@@ -314,7 +314,7 @@ module Ransack
|
|
314
314
|
describe '#sort_link with multiple search_keys and default_order specified as a symbol' do
|
315
315
|
subject { @controller.view_context
|
316
316
|
.sort_link(
|
317
|
-
[:main_app, Person.
|
317
|
+
[:main_app, Person.ransack()],
|
318
318
|
:name, [:name, :email],
|
319
319
|
controller: 'people',
|
320
320
|
default_order: :desc
|
@@ -331,7 +331,7 @@ module Ransack
|
|
331
331
|
describe '#sort_url with multiple search_keys and default_order specified as a symbol' do
|
332
332
|
subject { @controller.view_context
|
333
333
|
.sort_url(
|
334
|
-
[:main_app, Person.
|
334
|
+
[:main_app, Person.ransack],
|
335
335
|
:name, [:name, :email],
|
336
336
|
controller: 'people',
|
337
337
|
default_order: :desc
|
@@ -346,7 +346,7 @@ module Ransack
|
|
346
346
|
describe '#sort_link with multiple search_keys should allow multiple default_orders to be specified' do
|
347
347
|
subject { @controller.view_context
|
348
348
|
.sort_link(
|
349
|
-
[:main_app, Person.
|
349
|
+
[:main_app, Person.ransack],
|
350
350
|
:name, [:name, :email],
|
351
351
|
controller: 'people',
|
352
352
|
default_order: { name: 'desc', email: 'asc' }
|
@@ -363,7 +363,7 @@ module Ransack
|
|
363
363
|
describe '#sort_url with multiple search_keys should allow multiple default_orders to be specified' do
|
364
364
|
subject { @controller.view_context
|
365
365
|
.sort_url(
|
366
|
-
[:main_app, Person.
|
366
|
+
[:main_app, Person.ransack],
|
367
367
|
:name, [:name, :email],
|
368
368
|
controller: 'people',
|
369
369
|
default_order: { name: 'desc', email: 'asc' }
|
@@ -378,7 +378,7 @@ module Ransack
|
|
378
378
|
describe '#sort_link with multiple search_keys with multiple default_orders should not override a specified order' do
|
379
379
|
subject { @controller.view_context
|
380
380
|
.sort_link(
|
381
|
-
[:main_app, Person.
|
381
|
+
[:main_app, Person.ransack],
|
382
382
|
:name, [:name, 'email desc'],
|
383
383
|
controller: 'people',
|
384
384
|
default_order: { name: 'desc', email: 'asc' }
|
@@ -395,7 +395,7 @@ module Ransack
|
|
395
395
|
describe '#sort_url with multiple search_keys with multiple default_orders should not override a specified order' do
|
396
396
|
subject { @controller.view_context
|
397
397
|
.sort_url(
|
398
|
-
[:main_app, Person.
|
398
|
+
[:main_app, Person.ransack],
|
399
399
|
:name, [:name, 'email desc'],
|
400
400
|
controller: 'people',
|
401
401
|
default_order: { name: 'desc', email: 'asc' }
|
@@ -410,7 +410,7 @@ module Ransack
|
|
410
410
|
describe "#sort_link on polymorphic association should preserve association model name case" do
|
411
411
|
subject { @controller.view_context
|
412
412
|
.sort_link(
|
413
|
-
[:main_app, Note.
|
413
|
+
[:main_app, Note.ransack],
|
414
414
|
:notable_of_Person_type_name, "Notable",
|
415
415
|
controller: 'notes'
|
416
416
|
)
|
@@ -423,7 +423,7 @@ module Ransack
|
|
423
423
|
describe "#sort_url on polymorphic association should preserve association model name case" do
|
424
424
|
subject { @controller.view_context
|
425
425
|
.sort_link(
|
426
|
-
[:main_app, Note.
|
426
|
+
[:main_app, Note.ransack],
|
427
427
|
:notable_of_Person_type_name, "Notable",
|
428
428
|
controller: 'notes'
|
429
429
|
)
|
@@ -439,7 +439,7 @@ module Ransack
|
|
439
439
|
|
440
440
|
subject {
|
441
441
|
@controller.view_context.sort_link(
|
442
|
-
Person.
|
442
|
+
Person.ransack(
|
443
443
|
{ sorts: ['name desc'] },
|
444
444
|
search_key: 'people_search'
|
445
445
|
),
|
@@ -457,7 +457,7 @@ module Ransack
|
|
457
457
|
|
458
458
|
subject {
|
459
459
|
@controller.view_context.sort_url(
|
460
|
-
Person.
|
460
|
+
Person.ransack(
|
461
461
|
{ sorts: ['name desc'] },
|
462
462
|
search_key: 'people_search'
|
463
463
|
),
|
@@ -473,7 +473,7 @@ module Ransack
|
|
473
473
|
if: ::ActiveRecord::VERSION::MAJOR > 3 do
|
474
474
|
|
475
475
|
describe 'with symbol q:, #sort_link should include search params' do
|
476
|
-
subject { @controller.view_context.sort_link(Person.
|
476
|
+
subject { @controller.view_context.sort_link(Person.ransack, :name) }
|
477
477
|
let(:params) { ActionController::Parameters.new(
|
478
478
|
{ :q => { name_eq: 'TEST' }, controller: 'people' }
|
479
479
|
) }
|
@@ -488,7 +488,7 @@ module Ransack
|
|
488
488
|
end
|
489
489
|
|
490
490
|
describe 'with symbol q:, #sort_url should include search params' do
|
491
|
-
subject { @controller.view_context.sort_url(Person.
|
491
|
+
subject { @controller.view_context.sort_url(Person.ransack, :name) }
|
492
492
|
let(:params) { ActionController::Parameters.new(
|
493
493
|
{ :q => { name_eq: 'TEST' }, controller: 'people' }
|
494
494
|
) }
|
@@ -503,7 +503,7 @@ module Ransack
|
|
503
503
|
end
|
504
504
|
|
505
505
|
describe "with string 'q', #sort_link should include search params" do
|
506
|
-
subject { @controller.view_context.sort_link(Person.
|
506
|
+
subject { @controller.view_context.sort_link(Person.ransack, :name) }
|
507
507
|
let(:params) {
|
508
508
|
ActionController::Parameters.new(
|
509
509
|
{ 'q' => { name_eq: 'Test2' }, controller: 'people' }
|
@@ -519,7 +519,7 @@ module Ransack
|
|
519
519
|
end
|
520
520
|
|
521
521
|
describe "with string 'q', #sort_url should include search params" do
|
522
|
-
subject { @controller.view_context.sort_url(Person.
|
522
|
+
subject { @controller.view_context.sort_url(Person.ransack, :name) }
|
523
523
|
let(:params) {
|
524
524
|
ActionController::Parameters.new(
|
525
525
|
{ 'q' => { name_eq: 'Test2' }, controller: 'people' }
|
@@ -539,7 +539,7 @@ module Ransack
|
|
539
539
|
describe '#sort_link with hide order indicator set to true' do
|
540
540
|
subject { @controller.view_context
|
541
541
|
.sort_link(
|
542
|
-
[:main_app, Person.
|
542
|
+
[:main_app, Person.ransack(sorts: ['name desc'])],
|
543
543
|
:name,
|
544
544
|
controller: 'people',
|
545
545
|
hide_indicator: true
|
@@ -552,7 +552,7 @@ module Ransack
|
|
552
552
|
describe '#sort_link with hide order indicator set to false' do
|
553
553
|
subject { @controller.view_context
|
554
554
|
.sort_link(
|
555
|
-
[:main_app, Person.
|
555
|
+
[:main_app, Person.ransack(sorts: ['name desc'])],
|
556
556
|
:name,
|
557
557
|
controller: 'people',
|
558
558
|
hide_indicator: false
|
@@ -572,7 +572,7 @@ module Ransack
|
|
572
572
|
|
573
573
|
subject { @controller.view_context
|
574
574
|
.sort_link(
|
575
|
-
[:main_app, Person.
|
575
|
+
[:main_app, Person.ransack(sorts: ['name desc'])],
|
576
576
|
:name,
|
577
577
|
controller: 'people',
|
578
578
|
hide_indicator: false
|
@@ -593,7 +593,7 @@ module Ransack
|
|
593
593
|
|
594
594
|
subject { @controller.view_context
|
595
595
|
.sort_link(
|
596
|
-
[:main_app, Person.
|
596
|
+
[:main_app, Person.ransack(sorts: ['name asc'])],
|
597
597
|
:name,
|
598
598
|
controller: 'people',
|
599
599
|
hide_indicator: false
|
@@ -614,7 +614,7 @@ module Ransack
|
|
614
614
|
|
615
615
|
subject { @controller.view_context
|
616
616
|
.sort_link(
|
617
|
-
[:main_app, Person.
|
617
|
+
[:main_app, Person.ransack(sorts: ['name desc'])],
|
618
618
|
:name,
|
619
619
|
controller: 'people'
|
620
620
|
)
|
@@ -630,7 +630,7 @@ module Ransack
|
|
630
630
|
|
631
631
|
subject { @controller.view_context
|
632
632
|
.sort_link(
|
633
|
-
[:main_app, Person.
|
633
|
+
[:main_app, Person.ransack(sorts: ['name desc'])],
|
634
634
|
:name,
|
635
635
|
controller: 'people'
|
636
636
|
)
|
@@ -655,7 +655,7 @@ module Ransack
|
|
655
655
|
|
656
656
|
subject { @controller.view_context
|
657
657
|
.sort_link(
|
658
|
-
[:main_app, Person.
|
658
|
+
[:main_app, Person.ransack],
|
659
659
|
:name,
|
660
660
|
controller: 'people'
|
661
661
|
)
|
@@ -681,7 +681,7 @@ module Ransack
|
|
681
681
|
|
682
682
|
subject { @controller.view_context
|
683
683
|
.sort_link(
|
684
|
-
[:main_app, Person.
|
684
|
+
[:main_app, Person.ransack(sorts: ['name desc'])],
|
685
685
|
:name,
|
686
686
|
controller: 'people'
|
687
687
|
)
|
@@ -707,7 +707,7 @@ module Ransack
|
|
707
707
|
|
708
708
|
subject { @controller.view_context
|
709
709
|
.sort_link(
|
710
|
-
[:main_app, Person.
|
710
|
+
[:main_app, Person.ransack(sorts: ['name desc'])],
|
711
711
|
:name,
|
712
712
|
controller: 'people'
|
713
713
|
)
|
@@ -719,7 +719,7 @@ module Ransack
|
|
719
719
|
describe '#sort_link with a block' do
|
720
720
|
subject { @controller.view_context
|
721
721
|
.sort_link(
|
722
|
-
[:main_app, Person.
|
722
|
+
[:main_app, Person.ransack(sorts: ['name desc'])],
|
723
723
|
:name,
|
724
724
|
controller: 'people'
|
725
725
|
) { 'Block label' }
|
@@ -729,14 +729,14 @@ module Ransack
|
|
729
729
|
|
730
730
|
describe '#search_form_for with default format' do
|
731
731
|
subject { @controller.view_context
|
732
|
-
.search_form_for(Person.
|
732
|
+
.search_form_for(Person.ransack) {} }
|
733
733
|
it { should match /action="\/people"/ }
|
734
734
|
end
|
735
735
|
|
736
736
|
describe '#search_form_for with pdf format' do
|
737
737
|
subject {
|
738
738
|
@controller.view_context
|
739
|
-
.search_form_for(Person.
|
739
|
+
.search_form_for(Person.ransack, format: :pdf) {}
|
740
740
|
}
|
741
741
|
it { should match /action="\/people.pdf"/ }
|
742
742
|
end
|
@@ -744,7 +744,7 @@ module Ransack
|
|
744
744
|
describe '#search_form_for with json format' do
|
745
745
|
subject {
|
746
746
|
@controller.view_context
|
747
|
-
.search_form_for(Person.
|
747
|
+
.search_form_for(Person.ransack, format: :json) {}
|
748
748
|
}
|
749
749
|
it { should match /action="\/people.json"/ }
|
750
750
|
end
|
@@ -752,7 +752,7 @@ module Ransack
|
|
752
752
|
describe '#search_form_for with an array of routes' do
|
753
753
|
subject {
|
754
754
|
@controller.view_context
|
755
|
-
.search_form_for([:admin, Comment.
|
755
|
+
.search_form_for([:admin, Comment.ransack]) {}
|
756
756
|
}
|
757
757
|
it { should match /action="\/admin\/comments"/ }
|
758
758
|
end
|
@@ -763,7 +763,7 @@ module Ransack
|
|
763
763
|
end
|
764
764
|
subject {
|
765
765
|
@controller.view_context
|
766
|
-
.search_form_for(Person.
|
766
|
+
.search_form_for(Person.ransack) { |f| f.text_field :name_eq }
|
767
767
|
}
|
768
768
|
it { should match /example_name_eq/ }
|
769
769
|
end
|