searchable-by 0.5.1 → 0.5.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c1c5cfdea465a6a9ff73159a062558c5475889d27e0119e81212bb8bb37bbc1
4
- data.tar.gz: c77c158c890b37b67d1243c93b4d5c982731b55fb48d284ecc404de58142da26
3
+ metadata.gz: 21e09cdcdb1a9bebd3df6bb7a28d4f4cfc566a478b757390ea7f71445f195edd
4
+ data.tar.gz: 3bad5ea302c2c46bceee3a966b298799c133d1c2db0ffecf6a4bd38bf5393ccc
5
5
  SHA512:
6
- metadata.gz: 1ba79022ae7056fc1cd6f6ef7af109ed6e0a7228601241ac2bc8f501818b6f487a6fd929f77bc3ce0dba9956b879def3dc705159c3696246d4653e3197f3d71f
7
- data.tar.gz: c023dff5eb1bb4685dcfe7d10b7164242a090a930189ccc1b336c6de3437ab05d1de0dc90d13f52412e8e15b16a0a1386d5dacb289b208e00eefca5eab0cc2f7
6
+ metadata.gz: be511c786fae03cf6f37f392bc122446101ddb7dee1ed7af52bd1d21b92e4512d8493687baa9fa842aef5460f1b6d750f83f7ad9e54b30a2c74a42a8b14971b7
7
+ data.tar.gz: 8029a6c09870555dcf1d9235127ae1d8312e1cb226b93cf7428176f74efee991235158b2faf12b2b0dd7b7a83f7cfc705ffdfa9e2bb032edbcc8a65a6a0e2bd3
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- searchable-by (0.5.1)
4
+ searchable-by (0.5.2)
5
5
  activerecord
6
6
  activesupport
7
7
 
@@ -25,41 +25,41 @@ GEM
25
25
  diff-lcs (1.3)
26
26
  i18n (1.6.0)
27
27
  concurrent-ruby (~> 1.0)
28
- jaro_winkler (1.5.2)
28
+ jaro_winkler (1.5.3)
29
29
  minitest (5.11.3)
30
30
  parallel (1.17.0)
31
31
  parser (2.6.3.0)
32
32
  ast (~> 2.4.0)
33
33
  rainbow (3.0.0)
34
- rake (12.3.2)
34
+ rake (12.3.3)
35
35
  rspec (3.8.0)
36
36
  rspec-core (~> 3.8.0)
37
37
  rspec-expectations (~> 3.8.0)
38
38
  rspec-mocks (~> 3.8.0)
39
- rspec-core (3.8.0)
39
+ rspec-core (3.8.2)
40
40
  rspec-support (~> 3.8.0)
41
- rspec-expectations (3.8.3)
41
+ rspec-expectations (3.8.4)
42
42
  diff-lcs (>= 1.2.0, < 2.0)
43
43
  rspec-support (~> 3.8.0)
44
- rspec-mocks (3.8.0)
44
+ rspec-mocks (3.8.1)
45
45
  diff-lcs (>= 1.2.0, < 2.0)
46
46
  rspec-support (~> 3.8.0)
47
- rspec-support (3.8.0)
48
- rubocop (0.68.1)
47
+ rspec-support (3.8.2)
48
+ rubocop (0.73.0)
49
49
  jaro_winkler (~> 1.5.1)
50
50
  parallel (~> 1.10)
51
- parser (>= 2.5, != 2.5.1.1)
51
+ parser (>= 2.6)
52
52
  rainbow (>= 2.2.2, < 4.0)
53
53
  ruby-progressbar (~> 1.7)
54
- unicode-display_width (>= 1.4.0, < 1.6)
55
- rubocop-performance (1.2.0)
56
- rubocop (>= 0.68.0)
57
- ruby-progressbar (1.10.0)
54
+ unicode-display_width (>= 1.4.0, < 1.7)
55
+ rubocop-performance (1.4.0)
56
+ rubocop (>= 0.71.0)
57
+ ruby-progressbar (1.10.1)
58
58
  sqlite3 (1.4.1)
59
59
  thread_safe (0.3.6)
60
60
  tzinfo (1.2.5)
61
61
  thread_safe (~> 0.1)
62
- unicode-display_width (1.5.0)
62
+ unicode-display_width (1.6.0)
63
63
 
64
64
  PLATFORMS
65
65
  ruby
@@ -73,7 +73,7 @@ module ActiveRecord
73
73
  case column.type
74
74
  when :int, :integer
75
75
  begin
76
- column.node.eq(Integer(value))
76
+ column.node.not_eq(nil).and(column.node.eq(Integer(value)))
77
77
  rescue ArgumentError
78
78
  nil
79
79
  end
@@ -81,7 +81,7 @@ module ActiveRecord
81
81
  value = value.dup
82
82
  value.gsub!('%', '\%')
83
83
  value.gsub!('_', '\_')
84
- column.node.matches("%#{value}%")
84
+ column.node.not_eq(nil).and(column.node.matches("%#{value}%"))
85
85
  end
86
86
  end
87
87
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'searchable-by'
3
- s.version = '0.5.1'
3
+ s.version = '0.5.2'
4
4
  s.authors = ['Dimitrij Denissenko']
5
5
  s.email = ['dimitrij@blacksquaremedia.com']
6
6
  s.summary = 'Generate search scopes'
@@ -3,13 +3,13 @@ require 'spec_helper'
3
3
  describe ActiveRecord::SearchableBy do
4
4
 
5
5
  it 'should ignore bad inputs' do
6
- expect(Post.search_by(nil).count).to eq(4)
7
- expect(Post.search_by('').count).to eq(4)
6
+ expect(Post.search_by(nil).count).to eq(5)
7
+ expect(Post.search_by('').count).to eq(5)
8
8
  end
9
9
 
10
10
  it 'should configure correctly' do
11
11
  expect(AbstractModel._searchable_by_config.columns.size).to eq(1)
12
- expect(Post._searchable_by_config.columns.size).to eq(4)
12
+ expect(Post._searchable_by_config.columns.size).to eq(5)
13
13
  end
14
14
 
15
15
  it 'should generate SQL' do
@@ -23,26 +23,27 @@ describe ActiveRecord::SearchableBy do
23
23
  end
24
24
 
25
25
  it 'should search' do
26
- expect(Post.search_by('ALICE').pluck(:title)).to match_array(%w[titla title])
27
- expect(Post.search_by('bOb').pluck(:title)).to match_array(%w[titlo titlu])
26
+ expect(Post.search_by('ALICE').pluck(:title)).to match_array(%w[a1 a2 ab])
27
+ expect(Post.search_by('bOb').pluck(:title)).to match_array(%w[b1 b2 ab])
28
28
  end
29
29
 
30
30
  it 'should search across multiple words' do
31
- expect(Post.search_by('ALICE title').pluck(:title)).to match_array(%w[title])
31
+ expect(Post.search_by('ALICE your').pluck(:title)).to match_array(%w[a2])
32
32
  end
33
33
 
34
34
  it 'should support search markers' do
35
- expect(Post.search_by('aLiCe -title').pluck(:title)).to match_array(%w[titla])
36
- expect(Post.search_by('+alice "pie recipe"').pluck(:title)).to match_array(%w[title])
37
- expect(Post.search_by('bob -"piu recipe"').pluck(:title)).to match_array(%w[titlo])
35
+ expect(Post.search_by('aLiCe -your').pluck(:title)).to match_array(%w[a1 ab])
36
+ expect(Post.search_by('+alice "your recipe"').pluck(:title)).to match_array(%w[a2])
37
+ expect(Post.search_by('bob -"her recipe"').pluck(:title)).to match_array(%w[b2 ab])
38
+ expect(Post.search_by('bob +"her recipe"').pluck(:title)).to match_array(%w[b1])
38
39
  end
39
40
 
40
41
  it 'should search within scopes' do
41
- expect(Post.where(title: 'title').search_by('ALICE').pluck(:title)).to match_array(%w[title])
42
- expect(Post.where(title: 'title').search_by('bOb').pluck(:title)).to match_array(%w[])
42
+ expect(Post.where(title: 'a1').search_by('ALICE').pluck(:title)).to match_array(%w[a1])
43
+ expect(Post.where(title: 'a1').search_by('bOb').pluck(:title)).to match_array(%w[])
43
44
  end
44
45
 
45
46
  it 'should search integers' do
46
- expect(Post.search_by(POSTS[:alice1].id.to_s).count).to eq(1)
47
+ expect(Post.search_by(POSTS[:ab].id.to_s).count).to eq(1)
47
48
  end
48
49
  end
@@ -6,11 +6,12 @@ ActiveRecord::Base.configurations['test'] = { 'adapter' => 'sqlite3', 'database'
6
6
  ActiveRecord::Base.establish_connection :test
7
7
 
8
8
  ActiveRecord::Base.connection.instance_eval do
9
- create_table :authors do |t|
9
+ create_table :users do |t|
10
10
  t.string :name
11
11
  end
12
12
  create_table :posts do |t|
13
13
  t.integer :author_id, null: false
14
+ t.integer :reviewer_id
14
15
  t.string :title
15
16
  t.text :body
16
17
  end
@@ -24,31 +25,34 @@ class AbstractModel < ActiveRecord::Base
24
25
  end
25
26
  end
26
27
 
27
- class Author < AbstractModel
28
- has_many :posts
28
+ class User < AbstractModel
29
+ has_many :posts, foreign_key: :author_id
29
30
  end
30
31
 
31
32
  class Post < AbstractModel
32
- belongs_to :author
33
+ belongs_to :author, class_name: 'User'
34
+ belongs_to :reviewer, class_name: 'User'
33
35
 
34
36
  searchable_by do
35
37
  column :title, :body
36
- column { Author.arel_table[:name] }
38
+ column { User.arel_table[:name] }
39
+ column { User.arel_table.alias('reviewers_posts')[:name] }
37
40
 
38
41
  scope do
39
- joins(:author)
42
+ joins(:author).left_outer_joins(:reviewer)
40
43
  end
41
44
  end
42
45
  end
43
46
 
44
- AUTHORS = {
45
- alice: Author.create!(name: 'Alice'),
46
- bob: Author.create!(name: 'Bob'),
47
+ USERS = {
48
+ a: User.create!(name: 'Alice'),
49
+ b: User.create!(name: 'Bob'),
47
50
  }.freeze
48
51
 
49
52
  POSTS = {
50
- alice1: AUTHORS[:alice].posts.create!(title: 'titla', body: 'my pia recipe '),
51
- alice2: AUTHORS[:alice].posts.create!(title: 'title', body: 'your pie recipe'),
52
- bob1: AUTHORS[:bob].posts.create!(title: 'titlo', body: 'her pio recipe'),
53
- bob2: AUTHORS[:bob].posts.create!(title: 'titlu', body: 'our piu recipe'),
53
+ a1: USERS[:a].posts.create!(title: 'a1', body: 'my recipe '),
54
+ a2: USERS[:a].posts.create!(title: 'a2', body: 'your recipe'),
55
+ b1: USERS[:b].posts.create!(title: 'b1', body: 'her recipe'),
56
+ b2: USERS[:b].posts.create!(title: 'b2', body: 'our recipe'),
57
+ ab: USERS[:a].posts.create!(title: 'ab', reviewer: USERS[:b], body: 'their recipe'),
54
58
  }.freeze
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: searchable-by
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitrij Denissenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-10 00:00:00.000000000 Z
11
+ date: 2019-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord