searchable-by 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +14 -14
- data/lib/searchable_by.rb +2 -2
- data/searchable-by.gemspec +1 -1
- data/spec/searchable_by_spec.rb +13 -12
- data/spec/spec_helper.rb +17 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21e09cdcdb1a9bebd3df6bb7a28d4f4cfc566a478b757390ea7f71445f195edd
|
4
|
+
data.tar.gz: 3bad5ea302c2c46bceee3a966b298799c133d1c2db0ffecf6a4bd38bf5393ccc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be511c786fae03cf6f37f392bc122446101ddb7dee1ed7af52bd1d21b92e4512d8493687baa9fa842aef5460f1b6d750f83f7ad9e54b30a2c74a42a8b14971b7
|
7
|
+
data.tar.gz: 8029a6c09870555dcf1d9235127ae1d8312e1cb226b93cf7428176f74efee991235158b2faf12b2b0dd7b7a83f7cfc705ffdfa9e2bb032edbcc8a65a6a0e2bd3
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
searchable-by (0.5.
|
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.
|
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.
|
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.
|
39
|
+
rspec-core (3.8.2)
|
40
40
|
rspec-support (~> 3.8.0)
|
41
|
-
rspec-expectations (3.8.
|
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.
|
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.
|
48
|
-
rubocop (0.
|
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.
|
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.
|
55
|
-
rubocop-performance (1.
|
56
|
-
rubocop (>= 0.
|
57
|
-
ruby-progressbar (1.10.
|
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.
|
62
|
+
unicode-display_width (1.6.0)
|
63
63
|
|
64
64
|
PLATFORMS
|
65
65
|
ruby
|
data/lib/searchable_by.rb
CHANGED
@@ -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
|
|
data/searchable-by.gemspec
CHANGED
data/spec/searchable_by_spec.rb
CHANGED
@@ -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(
|
7
|
-
expect(Post.search_by('').count).to eq(
|
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(
|
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[
|
27
|
-
expect(Post.search_by('bOb').pluck(:title)).to match_array(%w[
|
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
|
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 -
|
36
|
-
expect(Post.search_by('+alice "
|
37
|
-
expect(Post.search_by('bob -"
|
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: '
|
42
|
-
expect(Post.where(title: '
|
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[:
|
47
|
+
expect(Post.search_by(POSTS[:ab].id.to_s).count).to eq(1)
|
47
48
|
end
|
48
49
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -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 :
|
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
|
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 {
|
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
|
-
|
45
|
-
|
46
|
-
|
47
|
+
USERS = {
|
48
|
+
a: User.create!(name: 'Alice'),
|
49
|
+
b: User.create!(name: 'Bob'),
|
47
50
|
}.freeze
|
48
51
|
|
49
52
|
POSTS = {
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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.
|
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-
|
11
|
+
date: 2019-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|