ransack 1.8.7 → 1.8.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a68f79e9c101613e0af4423267942f4d38007d19
4
- data.tar.gz: ae51bdebc41d71f0902c29aeafd570e8057ad59b
2
+ SHA256:
3
+ metadata.gz: f61f4b16a29defa380a26e7c29e3470bb61eb98fee71fb2b506b1b7c377f4995
4
+ data.tar.gz: a08063d09eae00edf1f62dfdcb9df19db195fded6d951a0ddb6ff0dd63885095
5
5
  SHA512:
6
- metadata.gz: 39361cd28cb1002386b506a28c4a4065448bb82c23bb3d989c7038ffa33dba628d170f8a2daca58ed3665707de833fe9f8d325884be8a1812dbc07c6e7abce8a
7
- data.tar.gz: 1d71cb39bd5524cb9c53313cbd6abf971f248b0c5978b376d3049bfb5ab684e7b6937c7785d0033ba534c52e700559c1c3faa093f368952743e5dd7d41db4f87
6
+ metadata.gz: 7075b5593e9931a4f5df153e04e2069dbb3b7e65f6463941b5dcfed0abfe6c5eba685b6db246755a98c8268e412d8088855495d14badcb75630c9c9eec86bb81
7
+ data.tar.gz: 5243186d40445ea7e1087cf1e655139718eca9089b3de1a52780b4aee71a200f7ac241d27c93821703bbe17872f05e740f12669be8cf129d3f1869967f04e2e2
@@ -3,10 +3,8 @@ language: ruby
3
3
  sudo: false
4
4
 
5
5
  rvm:
6
- - 2.3.3
7
- - 2.2.6
8
- - 2.1.10
9
- - 2.0
6
+ - 2.5
7
+ - 2.2
10
8
 
11
9
  env:
12
10
  - RAILS=5-2-stable DB=sqlite3
@@ -21,79 +19,6 @@ env:
21
19
  - RAILS=4-2-stable DB=mysql
22
20
  - RAILS=4-2-stable DB=postgres
23
21
 
24
- - RAILS=4-1-stable DB=sqlite3
25
- - RAILS=4-1-stable DB=mysql
26
- - RAILS=4-1-stable DB=postgres
27
-
28
- - RAILS=4-0-stable DB=sqlite3
29
- - RAILS=4-0-stable DB=mysql
30
- - RAILS=4-0-stable DB=postgres
31
-
32
- - RAILS=3-2-stable DB=sqlite
33
- - RAILS=3-2-stable DB=mysql
34
- - RAILS=3-2-stable DB=postgres
35
-
36
- - RAILS=3-1-stable DB=sqlite
37
- - RAILS=3-1-stable DB=mysql
38
- - RAILS=3-1-stable DB=postgres
39
-
40
- matrix:
41
- exclude:
42
- - rvm: 2.1.10
43
- env: RAILS=5-2-stable DB=sqlite3
44
- - rvm: 2.1.10
45
- env: RAILS=5-2-stable DB=mysql
46
- - rvm: 2.1.10
47
- env: RAILS=5-2-stable DB=postgres
48
-
49
- - rvm: 2.1.10
50
- env: RAILS=5-0-stable DB=sqlite3
51
- - rvm: 2.1.10
52
- env: RAILS=5-0-stable DB=mysql
53
- - rvm: 2.1.10
54
- env: RAILS=5-0-stable DB=postgres
55
-
56
- - rvm: 2.0
57
- env: RAILS=5-2-stable DB=sqlite3
58
- - rvm: 2.0
59
- env: RAILS=5-2-stable DB=mysql
60
- - rvm: 2.0
61
- env: RAILS=5-2-stable DB=postgres
62
-
63
- - rvm: 2.0
64
- env: RAILS=5-0-stable DB=sqlite3
65
- - rvm: 2.0
66
- env: RAILS=5-0-stable DB=mysql
67
- - rvm: 2.0
68
- env: RAILS=5-0-stable DB=postgres
69
-
70
- - rvm: 2.0
71
- env: RAILS=4-2-stable DB=sqlite3
72
- - rvm: 2.0
73
- env: RAILS=4-2-stable DB=mysql
74
- - rvm: 2.0
75
- env: RAILS=4-2-stable DB=postgres
76
-
77
- include:
78
- - rvm: 2.3.3
79
- env: RAILS=master DB=sqlite3
80
- - rvm: 2.3.3
81
- env: RAILS=master DB=mysql
82
- - rvm: 2.3.3
83
- env: RAILS=master DB=postgres
84
-
85
- - rvm: 2.2.6
86
- env: RAILS=master DB=sqlite3
87
- - rvm: 2.2.6
88
- env: RAILS=master DB=mysql
89
- - rvm: 2.2.6
90
- env: RAILS=master DB=postgres
91
-
92
- allow_failures:
93
- - env: RAILS=master DB=sqlite3
94
- - env: RAILS=master DB=mysql
95
- - env: RAILS=master DB=postgres
96
-
97
22
  before_script:
98
23
  - mysql -e 'create database ransack collate utf8_general_ci;'
99
24
  - mysql -e 'use ransack;show variables like "%character%";show variables like "%collation%";'
@@ -1,5 +1,29 @@
1
1
  # Change Log
2
2
 
3
+ ## Version 1.8.8 - 2018-03-16
4
+ * Fix multiple database support
5
+ PR [#893](https://github.com/activerecord-hackery/ransack/pull/893)
6
+
7
+ * Updated Dutch translations
8
+ PR [#887](https://github.com/activerecord-hackery/ransack/pull/887)
9
+
10
+ * Fixed no method error 'asc' for Rails 4.2
11
+ PR [#885](https://github.com/activerecord-hackery/ransack/pull/885)
12
+
13
+
14
+ ## Version 1.8.7 - 2018-02-05
15
+
16
+ * Rails 5.2 support
17
+ PR [#868](https://github.com/activerecord-hackery/ransack/pull/868)
18
+
19
+ * Lock pg gem to 0.21 to support older releases
20
+
21
+ * Warnings cleanup
22
+ PR [#867](https://github.com/activerecord-hackery/ransack/pull/867)
23
+
24
+ * Wildcard escaping
25
+ PR [#866]
26
+
3
27
  ## Version 1.8.6 - 2018-01-23
4
28
 
5
29
  ### Added
@@ -75,6 +75,15 @@ Here's a quick guide:
75
75
  $ DB=pg bundle exec rake spec (`DB=postgres` & `DB=postgresql` work too)
76
76
  $ DB=mysql bundle exec rake spec
77
77
 
78
+ For Postgres and MySQL, databases are expected to exist, called 'ransack'. To create use these commands (assuming OS X and Homebrew):
79
+
80
+ ### Postgres
81
+ $ createdb ransack
82
+
83
+ ### MySQL
84
+ $ mysql -u root
85
+ mysql> create database ransack;
86
+
78
87
  To run only the tests in a particular file: `rspec <path/to/filename>`
79
88
 
80
89
  $ rspec spec/ransack/search_spec.rb
data/README.md CHANGED
@@ -27,13 +27,11 @@ 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.8.2).](https://github.com/activerecord-hackery/ransack/tree/v1.8.2)
30
+ [View documentation for the last release (1.8.8).](https://github.com/activerecord-hackery/ransack/tree/v1.8.8)
31
31
 
32
32
  ## Getting started
33
33
 
34
- Ransack is compatible with Rails 3, 4 and 5 on Ruby 1.9 and later.
35
- JRuby 9 ought to work as well (see
36
- [this](https://github.com/activerecord-hackery/polyamorous/issues/17)).
34
+ Ransack is compatible with Rails 4.2 and 5.0, 5.1 and 5.2 on Ruby 2.2 and later.
37
35
  If you are using Ruby 1.8 or an earlier JRuby and run into compatibility
38
36
  issues, you can use an earlier version of Ransack, say, up to 1.3.0.
39
37
 
@@ -412,28 +410,60 @@ query parameters in your URLs.
412
410
 
413
411
  List of all possible predicates
414
412
 
415
- * `*_eq` - equal
416
- * `*_not_eq` - not equal
417
- * `*_matches` - matches with `LIKE`, e.g. `q[email_matches]=%@gmail.com`
418
- * Also: `*_does_not_match`, `*_matches_any`, `*_matches_all`, `*_does_not_match_any`, `*_does_not_match_all`
419
- * `*_lt` - less than
420
- * `*_lteq` - less than or equal
421
- * `*_gt` - greater than
422
- * `*_gteq` - greater than or equal
423
- * `*_present` - not null and not empty, e.g. `q[name_present]=1` (SQL: `col is not null AND col != ''`)
424
- * `*_blank` - is null or empty. (SQL: `col is null OR col = ''`)
425
- * `*_null`, `*_not_null` - is null, is not null
426
- * `*_in` - match any values in array, e.g. `q[name_in][]=Alice&q[name_in][]=Bob`
427
- * `*_not_in` - match none of values in array
428
- * `*_lt_any`, `*_lteq_any`, `*_gt_any`, `*_gteq_any` - Compare to list of values, at least positive. (SQL: `col > value1 OR col > value2`)
429
- * `*_matches_any`, `*_does_not_match_any` - same as above but with `LIKE`
430
- * `*_lt_all`, `*_lteq_all`, `*_gt_all`, `*_gteq_all` - Compare to list of values, all positive. (SQL: `col > value1 AND col > value2`)
431
- * `*_matches_all`, `*_does_not_match_all` - same as above but with `LIKE`
432
- * `*_not_eq_all` - none of values in a set
433
- * `*_start`, `*_not_start`, `*_start_any`, `*_start_all`, `*_not_start_any`, `*_not_start_all` - start with, (SQL: `col LIKE 'value%'`)
434
- * `*_end`, `*_not_end`, `*_end_any`, `*_end_all`, `*_not_end_any`, `*_not_end_all` - end with, (SQL: `col LIKE '%value'`)
435
- * `*_cont`, `*_cont_any`, `*_cont_all`, `*_not_cont`, `*_not_cont_any`, `*_not_cont_all` - contains value, using `LIKE`
436
- * `*_true`, `*_false` - is true and is false
413
+
414
+ | Predicate | Description | Notes |
415
+ | ------------- | ------------- |-------- |
416
+ | `*_eq` | equal | |
417
+ | `*_not_eq` | not equal | |
418
+ | `*_matches` | matches with `LIKE` | e.g. `q[email_matches]=%@gmail.com`|
419
+ | `*_does_not_match` | does not match with `LIKE` | |
420
+ | `*_matches_any` | Matches any | |
421
+ | `*_matches_all` | Matches all | |
422
+ | `*_does_not_match_any` | Does not match any | |
423
+ | `*_does_not_match_all` | Does not match all | |
424
+ | `*_lt` | less than | |
425
+ | `*_lteq` | less than or equal | |
426
+ | `*_gt` | greater than | |
427
+ | `*_gteq` | greater than or equal | |
428
+ | `*_present` | not null and not empty | e.g. `q[name_present]=1` (SQL: `col is not null AND col != ''`) |
429
+ | `*_blank` | is null or empty. | (SQL: `col is null OR col = ''`) |
430
+ | `*_null` | is null | |
431
+ | `*_not_null` | is not null | |
432
+ | `*_in` | match any values in array | e.g. `q[name_in][]=Alice&q[name_in][]=Bob` |
433
+ | `*_not_in` | match none of values in array | |
434
+ | `*_lt_any` | Less than any | SQL: `col < value1 OR col < value2` |
435
+ | `*_lteq_any` | Less than or equal to any | |
436
+ | `*_gt_any` | Greater than any | |
437
+ | `*_gteq_any` | Greater than or equal to any | |
438
+ | `*_matches_any` | `*_does_not_match_any` | same as above but with `LIKE` |
439
+ | `*_lt_all` | Less than all | SQL: `col < value1 AND col < value2` |
440
+ | `*_lteq_all` | Less than or equal to all | |
441
+ | `*_gt_all` | Greater than all | |
442
+ | `*_gteq_all` | Greater than or equal to all | |
443
+ | `*_matches_all` | Matches all | same as above but with `LIKE` |
444
+ | `*_does_not_match_all` | Does not match all | |
445
+ | `*_not_eq_all` | none of values in a set | |
446
+ | `*_start` | Starts with | SQL: `col LIKE 'value%'` |
447
+ | `*_not_start` | Does not start with | |
448
+ | `*_start_any` | Starts with any of | |
449
+ | `*_start_all` | Starts with all of | |
450
+ | `*_not_start_any` | Does not start with any of | |
451
+ | `*_not_start_all` | Does not start with all of | |
452
+ | `*_end` | Ends with | SQL: `col LIKE '%value'` |
453
+ | `*_not_end` | Does not end with | |
454
+ | `*_end_any` | Ends with any of | |
455
+ | `*_end_all` | Ends with all of | |
456
+ | `*_not_end_any` | | |
457
+ | `*_not_end_all` | | |
458
+ | `*_cont` | Contains value | uses `LIKE` |
459
+ | `*_cont_any` | Contains any of | |
460
+ | `*_cont_all` | Contains all of | |
461
+ | `*_not_cont` | Does not contain |
462
+ | `*_not_cont_any` | Does not contain any of | |
463
+ | `*_not_cont_all` | Does not contain all of | |
464
+ | `*_true` | is true | |
465
+ | `*_false` | is false | |
466
+
437
467
 
438
468
  (See full list: https://github.com/activerecord-hackery/ransack/blob/master/lib/ransack/locale/en.yml#L15 and [wiki](https://github.com/activerecord-hackery/ransack/wiki/Basic-Searching))
439
469
 
@@ -10,6 +10,8 @@ module Ransack
10
10
  ActiveRecordAdapter.new
11
11
  elsif defined?(::Mongoid)
12
12
  MongoidAdapter.new
13
+ else
14
+ raise "Unsupported adapter"
13
15
  end
14
16
  end
15
17
 
@@ -27,11 +27,11 @@ module Ransack
27
27
  return nil unless attr && attr.valid?
28
28
  name = attr.arel_attribute.name.to_s
29
29
  table = attr.arel_attribute.relation.table_name
30
- schema_cache = ::ActiveRecord::Base.connection.schema_cache
30
+ schema_cache = self.klass.connection.schema_cache
31
31
  unless schema_cache.send(database_table_exists?, table)
32
32
  raise "No table named #{table} exists."
33
33
  end
34
- schema_cache.columns_hash(table)[name].type
34
+ attr.klass.columns.find { |column| column.name == name }.type
35
35
  end
36
36
 
37
37
  def evaluate(search, opts = {})
@@ -251,7 +251,10 @@ module Ransack
251
251
  # Checkout active_record/relation/query_methods.rb +build_joins+ for
252
252
  # reference. Lots of duplicated code maybe we can avoid it
253
253
  def build_joins(relation)
254
- buckets = relation.joins_values.group_by do |join|
254
+ buckets = relation.joins_values
255
+ buckets += relation.left_outer_joins_values if ::ActiveRecord::VERSION::MAJOR >= 5
256
+
257
+ buckets = buckets.group_by do |join|
255
258
  case join
256
259
  when String
257
260
  :string_join
@@ -287,10 +290,10 @@ module Ransack
287
290
  join_dependency.send(:alias_tracker).aliases[join.left.name.downcase] = 1
288
291
  end
289
292
  else
290
- alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(::ActiveRecord::Base.connection, relation.table.name, join_list)
293
+ alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, relation.table.name, join_list)
291
294
  join_dependency = JoinDependency.new(relation.klass, relation.table, association_joins, alias_tracker)
292
295
  join_nodes.each do |join|
293
- join_dependency.alias_tracker.aliases[join.left.name.downcase] = 1
296
+ join_dependency.send(:alias_tracker).aliases[join.left.name.downcase] = 1
294
297
  end
295
298
  end
296
299
 
@@ -330,7 +333,7 @@ module Ransack
330
333
  )
331
334
  found_association = jd.join_root.children.last
332
335
  else
333
- alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(::ActiveRecord::Base.connection, parent.table.name, [])
336
+ alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, parent.table.name, [])
334
337
  jd = JoinDependency.new(
335
338
  parent.base_klass,
336
339
  parent.base_klass.arel_table,
@@ -20,5 +20,24 @@ module Ransack
20
20
  end
21
21
  end
22
22
 
23
+ def visit_Ransack_Nodes_Sort(object)
24
+ return unless object.valid?
25
+ if object.attr.is_a?(Arel::Attributes::Attribute)
26
+ object.attr.send(object.dir)
27
+ else
28
+ ordered(object)
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def ordered(object)
35
+ case object.dir
36
+ when 'asc'.freeze
37
+ Arel::Nodes::Ascending.new(object.attr)
38
+ when 'desc'.freeze
39
+ Arel::Nodes::Descending.new(object.attr)
40
+ end
41
+ end
23
42
  end
24
43
  end
@@ -35,9 +35,9 @@ nl:
35
35
  gt: "groter dan"
36
36
  gt_any: "groter dan enig"
37
37
  gt_all: "groter dan alle"
38
- gteq: "groter dan or equal to"
39
- gteq_any: "groter dan or equal to enig"
40
- gteq_all: "groter dan or equal to alle"
38
+ gteq: "groter dan of gelijk aan"
39
+ gteq_any: "groter dan of gelijk aan enig"
40
+ gteq_all: "groter dan of gelijk aan alle"
41
41
  in: "in"
42
42
  in_any: "in enig"
43
43
  in_all: "in alle"
@@ -64,7 +64,7 @@ nl:
64
64
  not_end_all: "eindigt niet met alle"
65
65
  'true': "is waar"
66
66
  'false': "is niet waar"
67
- present: "is present"
67
+ present: "is aanwezig"
68
68
  blank: "is afwezig"
69
69
  'null': "is null"
70
70
  not_null: "is niet null"
@@ -1,3 +1,3 @@
1
1
  module Ransack
2
- VERSION = '1.8.7'
2
+ VERSION = '1.8.8'
3
3
  end
@@ -40,10 +40,6 @@ module Ransack
40
40
  end
41
41
  end
42
42
 
43
- def visit_Ransack_Nodes_Sort(object)
44
- object.attr.send(object.dir) if object.valid?
45
- end
46
-
47
43
  def quoted?(object)
48
44
  raise "not implemented"
49
45
  end
@@ -57,6 +53,5 @@ module Ransack
57
53
  klass.name.gsub(Constants::TWO_COLONS, Constants::UNDERSCORE)
58
54
  }"
59
55
  end
60
-
61
56
  end
62
57
  end
@@ -18,6 +18,13 @@ module Ransack
18
18
  expect(subject.object).to be_an ::ActiveRecord::Relation
19
19
  end
20
20
 
21
+ context "multiple database connection" do
22
+ it "does not raise error" do
23
+ expect { Person.ransack(name_cont: "test") }.not_to raise_error
24
+ expect { SubDB::OperationHistory.ransack(people_id_eq: 1) }.not_to raise_error
25
+ end
26
+ end
27
+
21
28
  context 'with scopes' do
22
29
  before do
23
30
  allow(Person)
@@ -505,6 +512,7 @@ module Ransack
505
512
  )
506
513
  end
507
514
 
515
+
508
516
  it 'should allow passing ransacker arguments to a ransacker' do
509
517
  s = Person.ransack(
510
518
  c: [{
@@ -544,6 +552,30 @@ module Ransack
544
552
  /BETWEEN 2 AND 6 GROUP BY articles.person_id \) DESC/
545
553
  )
546
554
  end
555
+
556
+ context 'case insensitive sorting' do
557
+ it 'allows sort by desc' do
558
+ search = Person.search(sorts: ['name_case_insensitive desc'])
559
+ expect(search.result.to_sql).to match /ORDER BY LOWER(.*) DESC/
560
+ end
561
+
562
+ it 'allows sort by asc' do
563
+ search = Person.search(sorts: ['name_case_insensitive asc'])
564
+ expect(search.result.to_sql).to match /ORDER BY LOWER(.*) ASC/
565
+ end
566
+ end
567
+
568
+ context 'regular sorting' do
569
+ it 'allows sort by desc' do
570
+ search = Person.search(sorts: ['name desc'])
571
+ expect(search.result.to_sql).to match /ORDER BY .* DESC/
572
+ end
573
+
574
+ it 'allows sort by asc' do
575
+ search = Person.search(sorts: ['name asc'])
576
+ expect(search.result.to_sql).to match /ORDER BY .* ASC/
577
+ end
578
+ end
547
579
  end
548
580
 
549
581
  describe '#ransackable_attributes' do
@@ -37,6 +37,7 @@ RSpec.configure do |config|
37
37
  line = '=' * message.length
38
38
  puts line, message, line
39
39
  Schema.create
40
+ SubDB::Schema.create
40
41
  end
41
42
 
42
43
  config.before(:all) { Sham.reset(:before_all) }
@@ -92,10 +92,15 @@ class Person < ActiveRecord::Base
92
92
  )
93
93
  end
94
94
 
95
+
95
96
  ransacker :sql_literal_id do
96
97
  Arel.sql('people.id')
97
98
  end
98
99
 
100
+ ransacker :name_case_insensitive, type: :string do
101
+ arel_table[:name].lower
102
+ end
103
+
99
104
  ransacker :with_arguments, args: [:parent, :ransacker_args] do |parent, args|
100
105
  min, max = args
101
106
  query = <<-SQL
@@ -110,6 +115,7 @@ class Person < ActiveRecord::Base
110
115
  Arel.sql(query)
111
116
  end
112
117
 
118
+
113
119
  def self.ransackable_attributes(auth_object = nil)
114
120
  if auth_object == :admin
115
121
  super - ['only_sort']
@@ -255,3 +261,30 @@ module Schema
255
261
  )
256
262
  end
257
263
  end
264
+
265
+ module SubDB
266
+ class Base < ActiveRecord::Base
267
+ self.abstract_class = true
268
+ establish_connection(
269
+ adapter: 'sqlite3',
270
+ database: ':memory:'
271
+ )
272
+ end
273
+
274
+ class OperationHistory < Base
275
+ end
276
+
277
+ module Schema
278
+ def self.create
279
+ s = ::ActiveRecord::Schema.new
280
+ s.instance_variable_set(:@connection, SubDB::Base.connection)
281
+ s.verbose = false
282
+ s.define({}) do
283
+ create_table :operation_histories, force: true do |t|
284
+ t.string :operation_type
285
+ t.integer :people_id
286
+ end
287
+ end
288
+ end
289
+ end
290
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ransack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.7
4
+ version: 1.8.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ernie Miller
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2018-02-05 00:00:00.000000000 Z
14
+ date: 2018-03-17 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: actionpack
@@ -321,7 +321,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
321
321
  version: '0'
322
322
  requirements: []
323
323
  rubyforge_project: ransack
324
- rubygems_version: 2.6.13
324
+ rubygems_version: 2.7.3
325
325
  signing_key:
326
326
  specification_version: 4
327
327
  summary: Object-based searching for Active Record and Mongoid (currently).