searchable-by 0.7.1 → 0.7.2

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
2
  SHA256:
3
- metadata.gz: a91aa1b24f6ea20f4568629c1d6cc4010c2a6754932ad1251500a702c2f79165
4
- data.tar.gz: bbe553d775212b8bb0c076fac08fe10ed7912931a150b3c93c6becd7fa298e7d
3
+ metadata.gz: 0e4e441547e362a7212dd9d706a46b3f99501295ef996e1c053aac336bd3ad8e
4
+ data.tar.gz: 34532895f83d269d8e8feefab72c7df489cd436cb2b7edb63d5a0f449407bfd4
5
5
  SHA512:
6
- metadata.gz: 958e8ebc7f8ee60f4531f75fdf5780f667986985f0392af3a303ad0f82f3a810e2bd8aa23171b25ee9d906a111cc4be8cd95a83b9c302f3fe55390e95112835d
7
- data.tar.gz: 393536f83f00c301b2a2bcf9ae10a158f6ddd9cb642170c893e68d9d1c8bb967131de058c48414f20111c1a5cecf7c0eb98240028e9858a2c788918e38fd3642
6
+ metadata.gz: aad7ba2ceb7972367e635d8f0c93e356421b1adb012d4803fc1b7aecf3b4a661fbf4381e9a71a6d0b96e972810dda5bf28efe1e6d00ef955a89569a46202f9e5
7
+ data.tar.gz: ee7b3e43c8d8f89847bd9d61de69c85817ac99d250ad2d49f9850d8d10c1b2e9ba1315ce2dafab77c19652168371a1d3ecd8d95939383692a88eb8878ea13c0a
@@ -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@v2
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
@@ -1,2 +1,8 @@
1
1
  source 'http://rubygems.org'
2
2
  gemspec
3
+
4
+ gem 'rake'
5
+ gem 'rspec'
6
+ gem 'rubocop'
7
+ gem 'rubocop-bsm'
8
+ gem 'sqlite3'
data/Gemfile.lock CHANGED
@@ -1,76 +1,83 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- searchable-by (0.7.1)
4
+ searchable-by (0.7.2)
5
5
  activerecord
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- activemodel (7.0.2.3)
11
- activesupport (= 7.0.2.3)
12
- activerecord (7.0.2.3)
13
- activemodel (= 7.0.2.3)
14
- activesupport (= 7.0.2.3)
15
- activesupport (7.0.2.3)
10
+ activemodel (7.0.4.2)
11
+ activesupport (= 7.0.4.2)
12
+ activerecord (7.0.4.2)
13
+ activemodel (= 7.0.4.2)
14
+ activesupport (= 7.0.4.2)
15
+ activesupport (7.0.4.2)
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.1.9)
21
+ concurrent-ruby (1.2.0)
22
22
  diff-lcs (1.5.0)
23
- i18n (1.10.0)
23
+ i18n (1.12.0)
24
24
  concurrent-ruby (~> 1.0)
25
- minitest (5.15.0)
26
- parallel (1.21.0)
27
- parser (3.1.1.0)
25
+ json (2.6.3)
26
+ mini_portile2 (2.8.1)
27
+ minitest (5.17.0)
28
+ parallel (1.22.1)
29
+ parser (3.2.0.0)
28
30
  ast (~> 2.4.1)
29
31
  rainbow (3.1.1)
30
32
  rake (13.0.6)
31
- regexp_parser (2.2.1)
33
+ regexp_parser (2.6.2)
32
34
  rexml (3.2.5)
33
- rspec (3.11.0)
34
- rspec-core (~> 3.11.0)
35
- rspec-expectations (~> 3.11.0)
36
- rspec-mocks (~> 3.11.0)
37
- rspec-core (3.11.0)
38
- rspec-support (~> 3.11.0)
39
- rspec-expectations (3.11.0)
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.0)
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.11.0)
42
- rspec-mocks (3.11.0)
43
+ rspec-support (~> 3.12.0)
44
+ rspec-mocks (3.12.3)
43
45
  diff-lcs (>= 1.2.0, < 2.0)
44
- rspec-support (~> 3.11.0)
45
- rspec-support (3.11.0)
46
- rubocop (1.26.0)
46
+ rspec-support (~> 3.12.0)
47
+ rspec-support (3.12.0)
48
+ rubocop (1.44.1)
49
+ json (~> 2.3)
47
50
  parallel (~> 1.10)
48
- parser (>= 3.1.0.0)
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.16.0, < 2.0)
54
+ rexml (>= 3.2.5, < 4.0)
55
+ rubocop-ast (>= 1.24.1, < 2.0)
53
56
  ruby-progressbar (~> 1.7)
54
- unicode-display_width (>= 1.4.0, < 3.0)
55
- rubocop-ast (1.16.0)
57
+ unicode-display_width (>= 2.4.0, < 3.0)
58
+ rubocop-ast (1.24.1)
56
59
  parser (>= 3.1.1.0)
57
- rubocop-bsm (0.6.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-performance (1.13.3)
65
+ rubocop-capybara (2.17.0)
66
+ rubocop (~> 1.41)
67
+ rubocop-performance (1.15.2)
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.9.0)
68
- rubocop (~> 1.19)
72
+ rubocop-rspec (2.18.1)
73
+ rubocop (~> 1.33)
74
+ rubocop-capybara (~> 2.17)
69
75
  ruby-progressbar (1.11.0)
70
- sqlite3 (1.4.2)
71
- tzinfo (2.0.4)
76
+ sqlite3 (1.6.0)
77
+ mini_portile2 (~> 2.8.0)
78
+ tzinfo (2.0.6)
72
79
  concurrent-ruby (~> 1.0)
73
- unicode-display_width (2.1.0)
80
+ unicode-display_width (2.4.2)
74
81
 
75
82
  PLATFORMS
76
83
  ruby
data/Gemfile.rails6 CHANGED
@@ -2,3 +2,8 @@ source 'https://rubygems.org'
2
2
  gemspec
3
3
 
4
4
  gem 'activerecord', '~> 6.1'
5
+ gem 'rake'
6
+ gem 'rspec'
7
+ gem 'rubocop'
8
+ gem 'rubocop-bsm'
9
+ gem 'sqlite3'
data/Gemfile.rails6.lock CHANGED
@@ -1,78 +1,83 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- searchable-by (0.7.1)
4
+ searchable-by (0.7.2)
5
5
  activerecord
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activemodel (6.1.4.7)
11
- activesupport (= 6.1.4.7)
12
- activerecord (6.1.4.7)
13
- activemodel (= 6.1.4.7)
14
- activesupport (= 6.1.4.7)
15
- activesupport (6.1.4.7)
10
+ activemodel (6.1.7.2)
11
+ activesupport (= 6.1.7.2)
12
+ activerecord (6.1.7.2)
13
+ activemodel (= 6.1.7.2)
14
+ activesupport (= 6.1.7.2)
15
+ activesupport (6.1.7.2)
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.1.9)
22
+ concurrent-ruby (1.2.0)
23
23
  diff-lcs (1.5.0)
24
- i18n (1.10.0)
24
+ i18n (1.12.0)
25
25
  concurrent-ruby (~> 1.0)
26
- minitest (5.15.0)
27
- parallel (1.21.0)
28
- parser (3.1.1.0)
26
+ json (2.6.3)
27
+ minitest (5.17.0)
28
+ parallel (1.22.1)
29
+ parser (3.2.0.0)
29
30
  ast (~> 2.4.1)
30
31
  rainbow (3.1.1)
31
32
  rake (13.0.6)
32
- regexp_parser (2.2.1)
33
+ regexp_parser (2.6.2)
33
34
  rexml (3.2.5)
34
- rspec (3.11.0)
35
- rspec-core (~> 3.11.0)
36
- rspec-expectations (~> 3.11.0)
37
- rspec-mocks (~> 3.11.0)
38
- rspec-core (3.11.0)
39
- rspec-support (~> 3.11.0)
40
- rspec-expectations (3.11.0)
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.0)
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.11.0)
43
- rspec-mocks (3.11.0)
43
+ rspec-support (~> 3.12.0)
44
+ rspec-mocks (3.12.3)
44
45
  diff-lcs (>= 1.2.0, < 2.0)
45
- rspec-support (~> 3.11.0)
46
- rspec-support (3.11.0)
47
- rubocop (1.26.0)
46
+ rspec-support (~> 3.12.0)
47
+ rspec-support (3.12.0)
48
+ rubocop (1.44.1)
49
+ json (~> 2.3)
48
50
  parallel (~> 1.10)
49
- parser (>= 3.1.0.0)
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.16.0, < 2.0)
54
+ rexml (>= 3.2.5, < 4.0)
55
+ rubocop-ast (>= 1.24.1, < 2.0)
54
56
  ruby-progressbar (~> 1.7)
55
- unicode-display_width (>= 1.4.0, < 3.0)
56
- rubocop-ast (1.16.0)
57
+ unicode-display_width (>= 2.4.0, < 3.0)
58
+ rubocop-ast (1.24.1)
57
59
  parser (>= 3.1.1.0)
58
- rubocop-bsm (0.6.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-performance (1.13.3)
65
+ rubocop-capybara (2.17.0)
66
+ rubocop (~> 1.41)
67
+ rubocop-performance (1.15.2)
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.9.0)
69
- rubocop (~> 1.19)
72
+ rubocop-rspec (2.18.1)
73
+ rubocop (~> 1.33)
74
+ rubocop-capybara (~> 2.17)
70
75
  ruby-progressbar (1.11.0)
71
- sqlite3 (1.4.2)
72
- tzinfo (2.0.4)
76
+ sqlite3 (1.6.0-x86_64-linux)
77
+ tzinfo (2.0.6)
73
78
  concurrent-ruby (~> 1.0)
74
- unicode-display_width (2.1.0)
75
- zeitwerk (2.5.4)
79
+ unicode-display_width (2.4.2)
80
+ zeitwerk (2.6.6)
76
81
 
77
82
  PLATFORMS
78
83
  x86_64-linux
@@ -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!(/([\-+]?)"+([^"]*)"+/) do |_|
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
@@ -10,4 +10,4 @@ module SearchableBy
10
10
  Value = Struct.new(:term, :negate, :phrase)
11
11
  end
12
12
 
13
- ActiveRecord::Base.extend SearchableBy::Concern if defined?(::ActiveRecord::Base)
13
+ ActiveRecord::Base.extend SearchableBy::Concern if defined?(ActiveRecord::Base)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'searchable-by'
3
- s.version = '0.7.1'
3
+ s.version = '0.7.2'
4
4
  s.authors = ['Dimitrij Denissenko']
5
5
  s.email = ['dimitrij@blacksquaremedia.com']
6
6
  s.summary = 'Generate search scopes'
@@ -9,17 +9,11 @@ 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
16
  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
17
  s.metadata = {
24
18
  'rubygems_mfa_required' => 'true',
25
19
  }
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.1
4
+ version: 0.7.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: 2022-03-11 00:00:00.000000000 Z
11
+ date: 2023-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -38,76 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
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
41
  description: ActiveRecord plugin
112
42
  email:
113
43
  - dimitrij@blacksquaremedia.com
@@ -133,9 +63,6 @@ files:
133
63
  - lib/searchable_by/profiles.rb
134
64
  - lib/searchable_by/util.rb
135
65
  - searchable-by.gemspec
136
- - spec/searchable_by/util_spec.rb
137
- - spec/searchable_by_spec.rb
138
- - spec/spec_helper.rb
139
66
  homepage: https://github.com/bsm/sortable-by
140
67
  licenses:
141
68
  - Apache-2.0
@@ -160,7 +87,4 @@ rubygems_version: 3.3.3
160
87
  signing_key:
161
88
  specification_version: 4
162
89
  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
90
+ 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
@@ -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