searchable-by 0.7.1 → 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +2 -2
- data/Gemfile +6 -0
- data/Gemfile.lock +46 -40
- data/Gemfile.rails6 +5 -0
- data/Gemfile.rails6.lock +45 -41
- data/lib/searchable_by/util.rb +1 -1
- data/lib/searchable_by.rb +1 -1
- data/searchable-by.gemspec +1 -8
- metadata +4 -94
- data/spec/searchable_by/util_spec.rb +0 -36
- data/spec/searchable_by_spec.rb +0 -107
- data/spec/spec_helper.rb +0 -71
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c281721470fe15890260c41f17094fc836d049b10e1771b0ad1beda82b2408e
|
4
|
+
data.tar.gz: 287a4c13fc98808660319e0415c852ff492f4467098731e3379b8a68e52bd2f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe6861ab7d50ddc1151f287ec3f9fbf3e052566f0b999f9179e699bc25bca5f50a5120fabc7a8ec9cb2be764e24be5eea09cd709145a90a167b8b5f0cd4ffefa
|
7
|
+
data.tar.gz: 47e232a71e1669c7c70185ad405d8cd89fbddedffc6131b2dbed1c2e31fe040b0bd06d271522721ab418765f3b376a6765e41215cbe51a7459749349376a1978
|
data/.github/workflows/test.yml
CHANGED
@@ -11,12 +11,12 @@ jobs:
|
|
11
11
|
runs-on: ubuntu-latest
|
12
12
|
strategy:
|
13
13
|
matrix:
|
14
|
-
ruby-version: ["2.7", "3.0", "3.1"]
|
14
|
+
ruby-version: ["2.7", "3.0", "3.1", "3.2"]
|
15
15
|
gemfiles: ["Gemfile", "Gemfile.rails6"]
|
16
16
|
env:
|
17
17
|
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
18
18
|
steps:
|
19
|
-
- uses: actions/checkout@
|
19
|
+
- uses: actions/checkout@v3
|
20
20
|
- uses: ruby/setup-ruby@v1
|
21
21
|
with:
|
22
22
|
ruby-version: ${{ matrix.ruby-version }}
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,82 +1,88 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
searchable-by (0.7.
|
4
|
+
searchable-by (0.7.3)
|
5
5
|
activerecord
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activemodel (7.0.
|
11
|
-
activesupport (= 7.0.
|
12
|
-
activerecord (7.0.
|
13
|
-
activemodel (= 7.0.
|
14
|
-
activesupport (= 7.0.
|
15
|
-
activesupport (7.0.
|
10
|
+
activemodel (7.0.4.3)
|
11
|
+
activesupport (= 7.0.4.3)
|
12
|
+
activerecord (7.0.4.3)
|
13
|
+
activemodel (= 7.0.4.3)
|
14
|
+
activesupport (= 7.0.4.3)
|
15
|
+
activesupport (7.0.4.3)
|
16
16
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
17
|
i18n (>= 1.6, < 2)
|
18
18
|
minitest (>= 5.1)
|
19
19
|
tzinfo (~> 2.0)
|
20
20
|
ast (2.4.2)
|
21
|
-
concurrent-ruby (1.
|
21
|
+
concurrent-ruby (1.2.2)
|
22
22
|
diff-lcs (1.5.0)
|
23
|
-
i18n (1.
|
23
|
+
i18n (1.12.0)
|
24
24
|
concurrent-ruby (~> 1.0)
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
json (2.6.3)
|
26
|
+
mini_portile2 (2.8.1)
|
27
|
+
minitest (5.18.0)
|
28
|
+
parallel (1.22.1)
|
29
|
+
parser (3.2.1.1)
|
28
30
|
ast (~> 2.4.1)
|
29
31
|
rainbow (3.1.1)
|
30
32
|
rake (13.0.6)
|
31
|
-
regexp_parser (2.
|
33
|
+
regexp_parser (2.7.0)
|
32
34
|
rexml (3.2.5)
|
33
|
-
rspec (3.
|
34
|
-
rspec-core (~> 3.
|
35
|
-
rspec-expectations (~> 3.
|
36
|
-
rspec-mocks (~> 3.
|
37
|
-
rspec-core (3.
|
38
|
-
rspec-support (~> 3.
|
39
|
-
rspec-expectations (3.
|
35
|
+
rspec (3.12.0)
|
36
|
+
rspec-core (~> 3.12.0)
|
37
|
+
rspec-expectations (~> 3.12.0)
|
38
|
+
rspec-mocks (~> 3.12.0)
|
39
|
+
rspec-core (3.12.1)
|
40
|
+
rspec-support (~> 3.12.0)
|
41
|
+
rspec-expectations (3.12.2)
|
40
42
|
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
-
rspec-support (~> 3.
|
42
|
-
rspec-mocks (3.
|
43
|
+
rspec-support (~> 3.12.0)
|
44
|
+
rspec-mocks (3.12.4)
|
43
45
|
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
-
rspec-support (~> 3.
|
45
|
-
rspec-support (3.
|
46
|
-
rubocop (1.
|
46
|
+
rspec-support (~> 3.12.0)
|
47
|
+
rspec-support (3.12.0)
|
48
|
+
rubocop (1.48.1)
|
49
|
+
json (~> 2.3)
|
47
50
|
parallel (~> 1.10)
|
48
|
-
parser (>= 3.
|
51
|
+
parser (>= 3.2.0.0)
|
49
52
|
rainbow (>= 2.2.2, < 4.0)
|
50
53
|
regexp_parser (>= 1.8, < 3.0)
|
51
|
-
rexml
|
52
|
-
rubocop-ast (>= 1.
|
54
|
+
rexml (>= 3.2.5, < 4.0)
|
55
|
+
rubocop-ast (>= 1.26.0, < 2.0)
|
53
56
|
ruby-progressbar (~> 1.7)
|
54
|
-
unicode-display_width (>=
|
55
|
-
rubocop-ast (1.
|
56
|
-
parser (>= 3.
|
57
|
-
rubocop-bsm (0.6.
|
57
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
58
|
+
rubocop-ast (1.27.0)
|
59
|
+
parser (>= 3.2.1.0)
|
60
|
+
rubocop-bsm (0.6.1)
|
58
61
|
rubocop (~> 1.0)
|
59
62
|
rubocop-performance
|
60
63
|
rubocop-rake
|
61
64
|
rubocop-rspec
|
62
|
-
rubocop-
|
65
|
+
rubocop-capybara (2.17.1)
|
66
|
+
rubocop (~> 1.41)
|
67
|
+
rubocop-performance (1.16.0)
|
63
68
|
rubocop (>= 1.7.0, < 2.0)
|
64
69
|
rubocop-ast (>= 0.4.0)
|
65
70
|
rubocop-rake (0.6.0)
|
66
71
|
rubocop (~> 1.0)
|
67
|
-
rubocop-rspec (2.
|
68
|
-
rubocop (~> 1.
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
+
rubocop-rspec (2.19.0)
|
73
|
+
rubocop (~> 1.33)
|
74
|
+
rubocop-capybara (~> 2.17)
|
75
|
+
ruby-progressbar (1.13.0)
|
76
|
+
sqlite3 (1.6.1)
|
77
|
+
mini_portile2 (~> 2.8.0)
|
78
|
+
tzinfo (2.0.6)
|
72
79
|
concurrent-ruby (~> 1.0)
|
73
|
-
unicode-display_width (2.
|
80
|
+
unicode-display_width (2.4.2)
|
74
81
|
|
75
82
|
PLATFORMS
|
76
83
|
ruby
|
77
84
|
|
78
85
|
DEPENDENCIES
|
79
|
-
bundler
|
80
86
|
rake
|
81
87
|
rspec
|
82
88
|
rubocop
|
data/Gemfile.rails6
CHANGED
data/Gemfile.rails6.lock
CHANGED
@@ -1,85 +1,89 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
searchable-by (0.7.
|
4
|
+
searchable-by (0.7.3)
|
5
5
|
activerecord
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activemodel (6.1.
|
11
|
-
activesupport (= 6.1.
|
12
|
-
activerecord (6.1.
|
13
|
-
activemodel (= 6.1.
|
14
|
-
activesupport (= 6.1.
|
15
|
-
activesupport (6.1.
|
10
|
+
activemodel (6.1.7.3)
|
11
|
+
activesupport (= 6.1.7.3)
|
12
|
+
activerecord (6.1.7.3)
|
13
|
+
activemodel (= 6.1.7.3)
|
14
|
+
activesupport (= 6.1.7.3)
|
15
|
+
activesupport (6.1.7.3)
|
16
16
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
17
|
i18n (>= 1.6, < 2)
|
18
18
|
minitest (>= 5.1)
|
19
19
|
tzinfo (~> 2.0)
|
20
20
|
zeitwerk (~> 2.3)
|
21
21
|
ast (2.4.2)
|
22
|
-
concurrent-ruby (1.
|
22
|
+
concurrent-ruby (1.2.2)
|
23
23
|
diff-lcs (1.5.0)
|
24
|
-
i18n (1.
|
24
|
+
i18n (1.12.0)
|
25
25
|
concurrent-ruby (~> 1.0)
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
json (2.6.3)
|
27
|
+
minitest (5.18.0)
|
28
|
+
parallel (1.22.1)
|
29
|
+
parser (3.2.1.1)
|
29
30
|
ast (~> 2.4.1)
|
30
31
|
rainbow (3.1.1)
|
31
32
|
rake (13.0.6)
|
32
|
-
regexp_parser (2.
|
33
|
+
regexp_parser (2.7.0)
|
33
34
|
rexml (3.2.5)
|
34
|
-
rspec (3.
|
35
|
-
rspec-core (~> 3.
|
36
|
-
rspec-expectations (~> 3.
|
37
|
-
rspec-mocks (~> 3.
|
38
|
-
rspec-core (3.
|
39
|
-
rspec-support (~> 3.
|
40
|
-
rspec-expectations (3.
|
35
|
+
rspec (3.12.0)
|
36
|
+
rspec-core (~> 3.12.0)
|
37
|
+
rspec-expectations (~> 3.12.0)
|
38
|
+
rspec-mocks (~> 3.12.0)
|
39
|
+
rspec-core (3.12.1)
|
40
|
+
rspec-support (~> 3.12.0)
|
41
|
+
rspec-expectations (3.12.2)
|
41
42
|
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
-
rspec-support (~> 3.
|
43
|
-
rspec-mocks (3.
|
43
|
+
rspec-support (~> 3.12.0)
|
44
|
+
rspec-mocks (3.12.4)
|
44
45
|
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
-
rspec-support (~> 3.
|
46
|
-
rspec-support (3.
|
47
|
-
rubocop (1.
|
46
|
+
rspec-support (~> 3.12.0)
|
47
|
+
rspec-support (3.12.0)
|
48
|
+
rubocop (1.48.1)
|
49
|
+
json (~> 2.3)
|
48
50
|
parallel (~> 1.10)
|
49
|
-
parser (>= 3.
|
51
|
+
parser (>= 3.2.0.0)
|
50
52
|
rainbow (>= 2.2.2, < 4.0)
|
51
53
|
regexp_parser (>= 1.8, < 3.0)
|
52
|
-
rexml
|
53
|
-
rubocop-ast (>= 1.
|
54
|
+
rexml (>= 3.2.5, < 4.0)
|
55
|
+
rubocop-ast (>= 1.26.0, < 2.0)
|
54
56
|
ruby-progressbar (~> 1.7)
|
55
|
-
unicode-display_width (>=
|
56
|
-
rubocop-ast (1.
|
57
|
-
parser (>= 3.
|
58
|
-
rubocop-bsm (0.6.
|
57
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
58
|
+
rubocop-ast (1.27.0)
|
59
|
+
parser (>= 3.2.1.0)
|
60
|
+
rubocop-bsm (0.6.1)
|
59
61
|
rubocop (~> 1.0)
|
60
62
|
rubocop-performance
|
61
63
|
rubocop-rake
|
62
64
|
rubocop-rspec
|
63
|
-
rubocop-
|
65
|
+
rubocop-capybara (2.17.1)
|
66
|
+
rubocop (~> 1.41)
|
67
|
+
rubocop-performance (1.16.0)
|
64
68
|
rubocop (>= 1.7.0, < 2.0)
|
65
69
|
rubocop-ast (>= 0.4.0)
|
66
70
|
rubocop-rake (0.6.0)
|
67
71
|
rubocop (~> 1.0)
|
68
|
-
rubocop-rspec (2.
|
69
|
-
rubocop (~> 1.
|
70
|
-
|
71
|
-
|
72
|
-
|
72
|
+
rubocop-rspec (2.19.0)
|
73
|
+
rubocop (~> 1.33)
|
74
|
+
rubocop-capybara (~> 2.17)
|
75
|
+
ruby-progressbar (1.13.0)
|
76
|
+
sqlite3 (1.6.1-x86_64-linux)
|
77
|
+
tzinfo (2.0.6)
|
73
78
|
concurrent-ruby (~> 1.0)
|
74
|
-
unicode-display_width (2.
|
75
|
-
zeitwerk (2.
|
79
|
+
unicode-display_width (2.4.2)
|
80
|
+
zeitwerk (2.6.7)
|
76
81
|
|
77
82
|
PLATFORMS
|
78
83
|
x86_64-linux
|
79
84
|
|
80
85
|
DEPENDENCIES
|
81
86
|
activerecord (~> 6.1)
|
82
|
-
bundler
|
83
87
|
rake
|
84
88
|
rspec
|
85
89
|
rubocop
|
data/lib/searchable_by/util.rb
CHANGED
@@ -6,7 +6,7 @@ module SearchableBy
|
|
6
6
|
|
7
7
|
# capture any phrases inside double quotes
|
8
8
|
# exclude from search if preceded by '-'
|
9
|
-
query.gsub!(/([
|
9
|
+
query.gsub!(/([-+]?)"+([^"]*)"+/) do |_|
|
10
10
|
term = Regexp.last_match(2)
|
11
11
|
negate = Regexp.last_match(1) == '-'
|
12
12
|
|
data/lib/searchable_by.rb
CHANGED
data/searchable-by.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'searchable-by'
|
3
|
-
s.version = '0.7.
|
3
|
+
s.version = '0.7.3'
|
4
4
|
s.authors = ['Dimitrij Denissenko']
|
5
5
|
s.email = ['dimitrij@blacksquaremedia.com']
|
6
6
|
s.summary = 'Generate search scopes'
|
@@ -9,17 +9,10 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.license = 'Apache-2.0'
|
10
10
|
|
11
11
|
s.files = `git ls-files -z`.split("\x0").reject {|f| f.start_with?('spec/') }
|
12
|
-
s.test_files = `git ls-files -z -- spec/*`.split("\x0")
|
13
12
|
s.require_paths = ['lib']
|
14
13
|
s.required_ruby_version = '>= 2.7'
|
15
14
|
|
16
15
|
s.add_dependency 'activerecord'
|
17
|
-
s.add_development_dependency 'bundler'
|
18
|
-
s.add_development_dependency 'rake'
|
19
|
-
s.add_development_dependency 'rspec'
|
20
|
-
s.add_development_dependency 'rubocop'
|
21
|
-
s.add_development_dependency 'rubocop-bsm'
|
22
|
-
s.add_development_dependency 'sqlite3'
|
23
16
|
s.metadata = {
|
24
17
|
'rubygems_mfa_required' => 'true',
|
25
18
|
}
|
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.7.
|
4
|
+
version: 0.7.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimitrij Denissenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -24,90 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: bundler
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rspec
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rubocop
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rubocop-bsm
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: sqlite3
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
27
|
description: ActiveRecord plugin
|
112
28
|
email:
|
113
29
|
- dimitrij@blacksquaremedia.com
|
@@ -133,9 +49,6 @@ files:
|
|
133
49
|
- lib/searchable_by/profiles.rb
|
134
50
|
- lib/searchable_by/util.rb
|
135
51
|
- searchable-by.gemspec
|
136
|
-
- spec/searchable_by/util_spec.rb
|
137
|
-
- spec/searchable_by_spec.rb
|
138
|
-
- spec/spec_helper.rb
|
139
52
|
homepage: https://github.com/bsm/sortable-by
|
140
53
|
licenses:
|
141
54
|
- Apache-2.0
|
@@ -156,11 +69,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
69
|
- !ruby/object:Gem::Version
|
157
70
|
version: '0'
|
158
71
|
requirements: []
|
159
|
-
rubygems_version: 3.
|
72
|
+
rubygems_version: 3.4.9
|
160
73
|
signing_key:
|
161
74
|
specification_version: 4
|
162
75
|
summary: Generate search scopes
|
163
|
-
test_files:
|
164
|
-
- spec/searchable_by/util_spec.rb
|
165
|
-
- spec/searchable_by_spec.rb
|
166
|
-
- spec/spec_helper.rb
|
76
|
+
test_files: []
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe SearchableBy::Util do
|
4
|
-
context 'with norm_values' do
|
5
|
-
def norm(str, **opts)
|
6
|
-
described_class.norm_values(str, **opts).each_with_object({}) do |val, acc|
|
7
|
-
acc[val.term] = val.negate
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'tokenises strings' do
|
12
|
-
expect(norm(nil)).to eq({})
|
13
|
-
expect(norm('""')).to eq({})
|
14
|
-
expect(norm('-+""')).to eq({})
|
15
|
-
expect(norm('simple words')).to eq('simple' => false, 'words' => false)
|
16
|
-
expect(norm(" with \t spaces\n")).to eq('with' => false, 'spaces' => false)
|
17
|
-
expect(norm('with with duplicates with')).to eq('with' => false, 'duplicates' => false)
|
18
|
-
expect(norm('with "full term"')).to eq('full term' => false, 'with' => false)
|
19
|
-
expect(norm('"""odd double quotes around"""')).to eq('odd double quotes around' => false)
|
20
|
-
expect(norm('""even double quotes around""')).to eq('even double quotes around' => false)
|
21
|
-
expect(norm('with\'apostrophe')).to eq("with'apostrophe" => false)
|
22
|
-
expect(norm('with -minus')).to eq('minus' => true, 'with' => false)
|
23
|
-
expect(norm('with +plus')).to eq('plus' => false, 'with' => false)
|
24
|
-
expect(norm('with-minus')).to eq('with-minus' => false)
|
25
|
-
expect(norm('with+plus')).to eq('with+plus' => false)
|
26
|
-
expect(norm('with -"minus before"')).to eq('minus before' => true, 'with' => false)
|
27
|
-
expect(norm('with "-minus within"')).to eq('-minus within' => false, 'with' => false)
|
28
|
-
expect(norm('with +"plus before"')).to eq('plus before' => false, 'with' => false)
|
29
|
-
expect(norm('with "+plus within"')).to eq('+plus within' => false, 'with' => false)
|
30
|
-
expect(norm('+plus "in other term"')).to eq('in other term' => false, 'plus' => false)
|
31
|
-
expect(norm('with_blank \'\'')).to eq('with_blank' => false, '\'\'' => false)
|
32
|
-
expect(norm('with_blank_doubles ""')).to eq('with_blank_doubles' => false)
|
33
|
-
expect(norm('with min length', min_length: 4)).to eq('length' => false, 'with' => false)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
data/spec/searchable_by_spec.rb
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe SearchableBy do
|
4
|
-
it 'ignores bad inputs' do
|
5
|
-
expect(Post.search_by(nil).count).to eq(5)
|
6
|
-
expect(Post.search_by('').count).to eq(5)
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'configures correctly' do
|
10
|
-
expect(AbstractModel._searchable_by_profiles[:default].columns.size).to eq(1)
|
11
|
-
expect(Post._searchable_by_profiles[:default].columns.size).to eq(6)
|
12
|
-
expect(User._searchable_by_profiles[:default].min_length).to eq(3)
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'generates SQL' do
|
16
|
-
sql = Post.search_by('123').to_sql
|
17
|
-
expect(sql).to include(%("posts"."id" IS NOT NULL AND "posts"."id" = 123))
|
18
|
-
expect(sql).to include(%("posts"."title" IS NOT NULL AND "posts"."title" LIKE '123%'))
|
19
|
-
expect(sql).to include(%("posts"."body" IS NOT NULL AND "posts"."body" LIKE '%123%'))
|
20
|
-
expect(sql).to include(%("users"."name" IS NOT NULL AND LOWER("users"."name") = '123'))
|
21
|
-
|
22
|
-
sql = Post.search_by('foo%bar').to_sql
|
23
|
-
expect(sql).not_to include(%("posts"."id"))
|
24
|
-
expect(sql).to include(%("posts"."title" LIKE 'foo\\%bar%'))
|
25
|
-
expect(sql).to include(%("posts"."body" LIKE '%foo\\%bar%'))
|
26
|
-
|
27
|
-
sql = User.search_by('uni*dom').to_sql
|
28
|
-
expect(sql).to include(%("users"."country" LIKE 'uni%dom'))
|
29
|
-
expect(sql).to include(%("users"."bio" LIKE '%uni*dom%'))
|
30
|
-
|
31
|
-
sql = User.search_by('"uni * dom"').to_sql
|
32
|
-
expect(sql).to include(%("users"."country" LIKE 'uni % dom'))
|
33
|
-
expect(sql).to include(%("users"."bio" LIKE '%uni * dom%'))
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'searches' do
|
37
|
-
expect(Post.search_by('ALICE').pluck(:title)).to match_array(%w[ax1 ax2 ab1])
|
38
|
-
expect(Post.search_by('bOb').pluck(:title)).to match_array(%w[bx1 bx2 ab1])
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'searches across multiple words' do
|
42
|
-
expect(Post.search_by('ALICE your').pluck(:title)).to match_array(%w[ax2])
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'supports search markers' do
|
46
|
-
expect(Post.search_by('aLiCe -your').pluck(:title)).to match_array(%w[ax1 ab1])
|
47
|
-
expect(Post.search_by('+alice "your recipe"').pluck(:title)).to match_array(%w[ax2])
|
48
|
-
expect(Post.search_by('bob -"her recipe"').pluck(:title)).to match_array(%w[bx2 ab1])
|
49
|
-
expect(Post.search_by('bob +"her recipe"').pluck(:title)).to match_array(%w[bx1])
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'respects match options' do
|
53
|
-
# name uses match: :exact
|
54
|
-
expect(Post.search_by('alice').pluck(:title)).to match_array(%w[ax1 ax2 ab1])
|
55
|
-
expect(Post.search_by('ali').pluck(:title)).to be_empty
|
56
|
-
expect(Post.search_by('lice').pluck(:title)).to be_empty
|
57
|
-
expect(Post.search_by('li').pluck(:title)).to be_empty
|
58
|
-
|
59
|
-
# title uses match: :prefix
|
60
|
-
expect(Post.search_by('ax').pluck(:title)).to match_array(%w[ax1 ax2])
|
61
|
-
expect(Post.search_by('bx').pluck(:title)).to match_array(%w[bx1 bx2])
|
62
|
-
expect(Post.search_by('ab').pluck(:title)).to match_array(%w[ab1])
|
63
|
-
expect(Post.search_by('ba').pluck(:title)).to be_empty
|
64
|
-
|
65
|
-
# title uses match_phrase: :exact
|
66
|
-
expect(Post.search_by('"ab"').pluck(:title)).to be_empty
|
67
|
-
expect(Post.search_by('"ab1"').pluck(:title)).to match_array(%w[ab1])
|
68
|
-
|
69
|
-
# country uses match: :full in combination with wildcard: '*'
|
70
|
-
expect(Post.search_by('*kingdom').pluck(:title)).to match_array(%w[ax1 ax2 ab1])
|
71
|
-
|
72
|
-
# body uses match: :all (default)
|
73
|
-
expect(Post.search_by('recip').pluck(:title)).to match_array(%w[ax1 ax2 bx1 bx2 ab1])
|
74
|
-
end
|
75
|
-
|
76
|
-
it 'supports min term length in context' do
|
77
|
-
# values are discarded - too short for bio
|
78
|
-
expect(User.search_by('+be')).to match_array(USERS.values_at(:a, :b))
|
79
|
-
expect(User.search_by('is')).to match_array(USERS.values_at(:a, :b))
|
80
|
-
|
81
|
-
# value is used to scope
|
82
|
-
expect(User.search_by('ear')).to match_array(USERS.values_at(:a))
|
83
|
-
|
84
|
-
# one used, one discarded
|
85
|
-
expect(User.search_by('beard is')).to match_array(USERS.values_at(:a))
|
86
|
-
end
|
87
|
-
|
88
|
-
it 'searches within scopes' do
|
89
|
-
expect(Post.where(title: 'ax1').search_by('ALICE').pluck(:title)).to match_array(%w[ax1])
|
90
|
-
expect(Post.where(title: 'ax1').search_by('bOb').pluck(:title)).to be_empty
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'searches integers' do
|
94
|
-
expect(Post.search_by(POSTS[:ab1].id.to_s).count).to eq(1)
|
95
|
-
end
|
96
|
-
|
97
|
-
it 'supports wildcards' do
|
98
|
-
expect(User.search_by('*uni*dom')).to match_array(USERS.values_at(:a))
|
99
|
-
expect(User.search_by('*uni*o*')).to match_array(USERS.values_at(:a, :b))
|
100
|
-
expect(User.search_by('*uni*of*dom')).to be_empty
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'supports profiles' do
|
104
|
-
expect(User.search_by('king', profile: :country_only)).to match_array(USERS.values_at(:a))
|
105
|
-
expect(User.search_by('Norris', profile: :country_only)).to be_empty
|
106
|
-
end
|
107
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
ENV['RACK_ENV'] ||= 'test'
|
2
|
-
require 'searchable-by'
|
3
|
-
require 'rspec'
|
4
|
-
|
5
|
-
ActiveRecord::Base.configurations = { 'test' => { 'adapter' => 'sqlite3', 'database' => ':memory:' } }
|
6
|
-
ActiveRecord::Base.establish_connection :test
|
7
|
-
|
8
|
-
ActiveRecord::Base.connection.instance_eval do
|
9
|
-
create_table :users do |t|
|
10
|
-
t.string :name
|
11
|
-
t.string :bio
|
12
|
-
t.string :country
|
13
|
-
end
|
14
|
-
create_table :posts do |t|
|
15
|
-
t.integer :author_id, null: false
|
16
|
-
t.integer :reviewer_id
|
17
|
-
t.string :title
|
18
|
-
t.text :body
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
class AbstractModel < ActiveRecord::Base
|
23
|
-
self.abstract_class = true
|
24
|
-
|
25
|
-
searchable_by do
|
26
|
-
column :id, type: :integer
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
class User < AbstractModel
|
31
|
-
has_many :posts, foreign_key: :author_id
|
32
|
-
|
33
|
-
searchable_by min_length: 3 do
|
34
|
-
column :bio
|
35
|
-
column :country, wildcard: '*', match: :exact
|
36
|
-
end
|
37
|
-
|
38
|
-
searchable_by :country_only do
|
39
|
-
column :country
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
class Post < AbstractModel
|
44
|
-
belongs_to :author, class_name: 'User'
|
45
|
-
belongs_to :reviewer, class_name: 'User'
|
46
|
-
|
47
|
-
searchable_by do
|
48
|
-
column :title, match: :prefix, match_phrase: :exact
|
49
|
-
column :body
|
50
|
-
column proc { User.arel_table[:name] }, match: :exact
|
51
|
-
column proc { User.arel_table[:country] }, wildcard: '*', match: :exact
|
52
|
-
column { User.arel_table.alias('reviewers_posts')[:name] }
|
53
|
-
|
54
|
-
scope do
|
55
|
-
joins(:author).left_outer_joins(:reviewer)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
USERS = {
|
61
|
-
a: User.create!(name: 'Alice', bio: "Chuck Norris' beard is immutable.", country: 'United Kingdom'),
|
62
|
-
b: User.create!(name: 'Bob', bio: 'Chuck Norris can divide by zero.', country: 'United States of America'),
|
63
|
-
}.freeze
|
64
|
-
|
65
|
-
POSTS = {
|
66
|
-
ax1: USERS[:a].posts.create!(title: 'ax1', body: 'my recipe '),
|
67
|
-
ax2: USERS[:a].posts.create!(title: 'ax2', body: 'your recipe'),
|
68
|
-
bx1: USERS[:b].posts.create!(title: 'bx1', body: 'her recipe'),
|
69
|
-
bx2: USERS[:b].posts.create!(title: 'bx2', body: 'our recipe'),
|
70
|
-
ab1: USERS[:a].posts.create!(title: 'ab1', reviewer: USERS[:b], body: 'their recipe'),
|
71
|
-
}.freeze
|