searchable-by 0.7.0 → 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: e3c6177e1001a078408b9466190f08df81a8dc812724903650ecd4a1b267fa09
4
- data.tar.gz: 8c08713658466f75b21cac681a4dcce20bef6dc1544c4d7a935bb1eb285f54ea
3
+ metadata.gz: 0e4e441547e362a7212dd9d706a46b3f99501295ef996e1c053aac336bd3ad8e
4
+ data.tar.gz: 34532895f83d269d8e8feefab72c7df489cd436cb2b7edb63d5a0f449407bfd4
5
5
  SHA512:
6
- metadata.gz: f384f6380a8124c6a8a5f1591d54b14cbce6def8766cbe0271f43f023c98d0a6622f99f0ac22d7537b497ea59ea10ff7412b005729159d6d3cbc78908c00e8a6
7
- data.tar.gz: ae93c1ce199d6a6315d579346ddff7c04dd1673782c85c130d9c17def56aa94d1873cb44333a53937d789e76683436641fd4187f1b26fd89327079d9857aefe7
6
+ metadata.gz: aad7ba2ceb7972367e635d8f0c93e356421b1adb012d4803fc1b7aecf3b4a661fbf4381e9a71a6d0b96e972810dda5bf28efe1e6d00ef955a89569a46202f9e5
7
+ data.tar.gz: ee7b3e43c8d8f89847bd9d61de69c85817ac99d250ad2d49f9850d8d10c1b2e9ba1315ce2dafab77c19652168371a1d3ecd8d95939383692a88eb8878ea13c0a
@@ -11,9 +11,12 @@ jobs:
11
11
  runs-on: ubuntu-latest
12
12
  strategy:
13
13
  matrix:
14
- ruby-version: ["2.6", "2.7", "3.0"]
14
+ ruby-version: ["2.7", "3.0", "3.1", "3.2"]
15
+ gemfiles: ["Gemfile", "Gemfile.rails6"]
16
+ env:
17
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
15
18
  steps:
16
- - uses: actions/checkout@v2
19
+ - uses: actions/checkout@v3
17
20
  - uses: ruby/setup-ruby@v1
18
21
  with:
19
22
  ruby-version: ${{ matrix.ruby-version }}
data/.rubocop.yml CHANGED
@@ -6,7 +6,7 @@ inherit_mode:
6
6
  - Exclude
7
7
 
8
8
  AllCops:
9
- TargetRubyVersion: "2.6"
9
+ TargetRubyVersion: "2.7"
10
10
 
11
11
  Naming/FileName:
12
12
  Exclude:
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,79 +1,83 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- searchable-by (0.7.0)
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 (6.1.4)
11
- activesupport (= 6.1.4)
12
- activerecord (6.1.4)
13
- activemodel (= 6.1.4)
14
- activesupport (= 6.1.4)
15
- activesupport (6.1.4)
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
- zeitwerk (~> 2.3)
21
20
  ast (2.4.2)
22
- concurrent-ruby (1.1.9)
23
- diff-lcs (1.4.4)
24
- i18n (1.8.10)
21
+ concurrent-ruby (1.2.0)
22
+ diff-lcs (1.5.0)
23
+ i18n (1.12.0)
25
24
  concurrent-ruby (~> 1.0)
26
- minitest (5.14.4)
27
- parallel (1.20.1)
28
- parser (3.0.2.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)
29
30
  ast (~> 2.4.1)
30
- rainbow (3.0.0)
31
+ rainbow (3.1.1)
31
32
  rake (13.0.6)
32
- regexp_parser (2.1.1)
33
+ regexp_parser (2.6.2)
33
34
  rexml (3.2.5)
34
- rspec (3.10.0)
35
- rspec-core (~> 3.10.0)
36
- rspec-expectations (~> 3.10.0)
37
- rspec-mocks (~> 3.10.0)
38
- rspec-core (3.10.1)
39
- rspec-support (~> 3.10.0)
40
- rspec-expectations (3.10.1)
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.10.0)
43
- rspec-mocks (3.10.2)
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.10.0)
46
- rspec-support (3.10.2)
47
- rubocop (1.18.3)
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.0.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.7.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.7.0)
57
- parser (>= 3.0.1.1)
58
- rubocop-bsm (0.6.0)
57
+ unicode-display_width (>= 2.4.0, < 3.0)
58
+ rubocop-ast (1.24.1)
59
+ parser (>= 3.1.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-performance (1.11.4)
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.4.0)
69
- rubocop (~> 1.0)
70
- rubocop-ast (>= 1.1.0)
72
+ rubocop-rspec (2.18.1)
73
+ rubocop (~> 1.33)
74
+ rubocop-capybara (~> 2.17)
71
75
  ruby-progressbar (1.11.0)
72
- sqlite3 (1.4.2)
73
- tzinfo (2.0.4)
76
+ sqlite3 (1.6.0)
77
+ mini_portile2 (~> 2.8.0)
78
+ tzinfo (2.0.6)
74
79
  concurrent-ruby (~> 1.0)
75
- unicode-display_width (2.0.0)
76
- zeitwerk (2.4.2)
80
+ unicode-display_width (2.4.2)
77
81
 
78
82
  PLATFORMS
79
83
  ruby
@@ -88,4 +92,4 @@ DEPENDENCIES
88
92
  sqlite3
89
93
 
90
94
  BUNDLED WITH
91
- 2.2.21
95
+ 2.3.9
data/Gemfile.rails6 ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ gem 'activerecord', '~> 6.1'
5
+ gem 'rake'
6
+ gem 'rspec'
7
+ gem 'rubocop'
8
+ gem 'rubocop-bsm'
9
+ gem 'sqlite3'
@@ -0,0 +1,96 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ searchable-by (0.7.2)
5
+ activerecord
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
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
+ concurrent-ruby (~> 1.0, >= 1.0.2)
17
+ i18n (>= 1.6, < 2)
18
+ minitest (>= 5.1)
19
+ tzinfo (~> 2.0)
20
+ zeitwerk (~> 2.3)
21
+ ast (2.4.2)
22
+ concurrent-ruby (1.2.0)
23
+ diff-lcs (1.5.0)
24
+ i18n (1.12.0)
25
+ concurrent-ruby (~> 1.0)
26
+ json (2.6.3)
27
+ minitest (5.17.0)
28
+ parallel (1.22.1)
29
+ parser (3.2.0.0)
30
+ ast (~> 2.4.1)
31
+ rainbow (3.1.1)
32
+ rake (13.0.6)
33
+ regexp_parser (2.6.2)
34
+ rexml (3.2.5)
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)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.12.0)
44
+ rspec-mocks (3.12.3)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.12.0)
47
+ rspec-support (3.12.0)
48
+ rubocop (1.44.1)
49
+ json (~> 2.3)
50
+ parallel (~> 1.10)
51
+ parser (>= 3.2.0.0)
52
+ rainbow (>= 2.2.2, < 4.0)
53
+ regexp_parser (>= 1.8, < 3.0)
54
+ rexml (>= 3.2.5, < 4.0)
55
+ rubocop-ast (>= 1.24.1, < 2.0)
56
+ ruby-progressbar (~> 1.7)
57
+ unicode-display_width (>= 2.4.0, < 3.0)
58
+ rubocop-ast (1.24.1)
59
+ parser (>= 3.1.1.0)
60
+ rubocop-bsm (0.6.1)
61
+ rubocop (~> 1.0)
62
+ rubocop-performance
63
+ rubocop-rake
64
+ rubocop-rspec
65
+ rubocop-capybara (2.17.0)
66
+ rubocop (~> 1.41)
67
+ rubocop-performance (1.15.2)
68
+ rubocop (>= 1.7.0, < 2.0)
69
+ rubocop-ast (>= 0.4.0)
70
+ rubocop-rake (0.6.0)
71
+ rubocop (~> 1.0)
72
+ rubocop-rspec (2.18.1)
73
+ rubocop (~> 1.33)
74
+ rubocop-capybara (~> 2.17)
75
+ ruby-progressbar (1.11.0)
76
+ sqlite3 (1.6.0-x86_64-linux)
77
+ tzinfo (2.0.6)
78
+ concurrent-ruby (~> 1.0)
79
+ unicode-display_width (2.4.2)
80
+ zeitwerk (2.6.6)
81
+
82
+ PLATFORMS
83
+ x86_64-linux
84
+
85
+ DEPENDENCIES
86
+ activerecord (~> 6.1)
87
+ bundler
88
+ rake
89
+ rspec
90
+ rubocop
91
+ rubocop-bsm
92
+ searchable-by!
93
+ sqlite3
94
+
95
+ BUNDLED WITH
96
+ 2.3.9
@@ -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.0'
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,15 +9,12 @@ 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
- s.required_ruby_version = '>= 2.6'
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'
17
+ s.metadata = {
18
+ 'rubygems_mfa_required' => 'true',
19
+ }
23
20
  end
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.0
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: 2021-08-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
@@ -120,6 +50,8 @@ files:
120
50
  - ".rubocop.yml"
121
51
  - Gemfile
122
52
  - Gemfile.lock
53
+ - Gemfile.rails6
54
+ - Gemfile.rails6.lock
123
55
  - LICENSE
124
56
  - README.md
125
57
  - Rakefile
@@ -131,13 +63,11 @@ files:
131
63
  - lib/searchable_by/profiles.rb
132
64
  - lib/searchable_by/util.rb
133
65
  - searchable-by.gemspec
134
- - spec/searchable_by/util_spec.rb
135
- - spec/searchable_by_spec.rb
136
- - spec/spec_helper.rb
137
66
  homepage: https://github.com/bsm/sortable-by
138
67
  licenses:
139
68
  - Apache-2.0
140
- metadata: {}
69
+ metadata:
70
+ rubygems_mfa_required: 'true'
141
71
  post_install_message:
142
72
  rdoc_options: []
143
73
  require_paths:
@@ -146,18 +76,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
146
76
  requirements:
147
77
  - - ">="
148
78
  - !ruby/object:Gem::Version
149
- version: '2.6'
79
+ version: '2.7'
150
80
  required_rubygems_version: !ruby/object:Gem::Requirement
151
81
  requirements:
152
82
  - - ">="
153
83
  - !ruby/object:Gem::Version
154
84
  version: '0'
155
85
  requirements: []
156
- rubygems_version: 3.2.15
86
+ rubygems_version: 3.3.3
157
87
  signing_key:
158
88
  specification_version: 4
159
89
  summary: Generate search scopes
160
- test_files:
161
- - spec/searchable_by/util_spec.rb
162
- - spec/searchable_by_spec.rb
163
- - 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,106 +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
- end
13
-
14
- it 'generates SQL' do
15
- sql = Post.search_by('123').to_sql
16
- expect(sql).to include(%("posts"."id" IS NOT NULL AND "posts"."id" = 123))
17
- expect(sql).to include(%("posts"."title" IS NOT NULL AND "posts"."title" LIKE '123%'))
18
- expect(sql).to include(%("posts"."body" IS NOT NULL AND "posts"."body" LIKE '%123%'))
19
- expect(sql).to include(%("users"."name" IS NOT NULL AND LOWER("users"."name") = '123'))
20
-
21
- sql = Post.search_by('foo%bar').to_sql
22
- expect(sql).not_to include(%("posts"."id"))
23
- expect(sql).to include(%("posts"."title" LIKE 'foo\\%bar%'))
24
- expect(sql).to include(%("posts"."body" LIKE '%foo\\%bar%'))
25
-
26
- sql = User.search_by('uni*dom').to_sql
27
- expect(sql).to include(%("users"."country" LIKE 'uni%dom'))
28
- expect(sql).to include(%("users"."bio" LIKE '%uni*dom%'))
29
-
30
- sql = User.search_by('"uni * dom"').to_sql
31
- expect(sql).to include(%("users"."country" LIKE 'uni % dom'))
32
- expect(sql).to include(%("users"."bio" LIKE '%uni * dom%'))
33
- end
34
-
35
- it 'searches' do
36
- expect(Post.search_by('ALICE').pluck(:title)).to match_array(%w[ax1 ax2 ab1])
37
- expect(Post.search_by('bOb').pluck(:title)).to match_array(%w[bx1 bx2 ab1])
38
- end
39
-
40
- it 'searches across multiple words' do
41
- expect(Post.search_by('ALICE your').pluck(:title)).to match_array(%w[ax2])
42
- end
43
-
44
- it 'supports search markers' do
45
- expect(Post.search_by('aLiCe -your').pluck(:title)).to match_array(%w[ax1 ab1])
46
- expect(Post.search_by('+alice "your recipe"').pluck(:title)).to match_array(%w[ax2])
47
- expect(Post.search_by('bob -"her recipe"').pluck(:title)).to match_array(%w[bx2 ab1])
48
- expect(Post.search_by('bob +"her recipe"').pluck(:title)).to match_array(%w[bx1])
49
- end
50
-
51
- it 'respects match options' do
52
- # name uses match: :exact
53
- expect(Post.search_by('alice').pluck(:title)).to match_array(%w[ax1 ax2 ab1])
54
- expect(Post.search_by('ali').pluck(:title)).to be_empty
55
- expect(Post.search_by('lice').pluck(:title)).to be_empty
56
- expect(Post.search_by('li').pluck(:title)).to be_empty
57
-
58
- # title uses match: :prefix
59
- expect(Post.search_by('ax').pluck(:title)).to match_array(%w[ax1 ax2])
60
- expect(Post.search_by('bx').pluck(:title)).to match_array(%w[bx1 bx2])
61
- expect(Post.search_by('ab').pluck(:title)).to match_array(%w[ab1])
62
- expect(Post.search_by('ba').pluck(:title)).to be_empty
63
-
64
- # title uses match_phrase: :exact
65
- expect(Post.search_by('"ab"').pluck(:title)).to be_empty
66
- expect(Post.search_by('"ab1"').pluck(:title)).to match_array(%w[ab1])
67
-
68
- # country uses match: :full in combination with wildcard: '*'
69
- expect(Post.search_by('*kingdom').pluck(:title)).to match_array(%w[ax1 ax2 ab1])
70
-
71
- # body uses match: :all (default)
72
- expect(Post.search_by('recip').pluck(:title)).to match_array(%w[ax1 ax2 bx1 bx2 ab1])
73
- end
74
-
75
- it 'supports min term length in context' do
76
- # values are discarded - too short for bio
77
- expect(User.search_by('+be')).to match_array(USERS.values_at(:a, :b))
78
- expect(User.search_by('is')).to match_array(USERS.values_at(:a, :b))
79
-
80
- # value is used to scope
81
- expect(User.search_by('ear')).to match_array(USERS.values_at(:a))
82
-
83
- # one used, one discarded
84
- expect(User.search_by('beard is')).to match_array(USERS.values_at(:a))
85
- end
86
-
87
- it 'searches within scopes' do
88
- expect(Post.where(title: 'ax1').search_by('ALICE').pluck(:title)).to match_array(%w[ax1])
89
- expect(Post.where(title: 'ax1').search_by('bOb').pluck(:title)).to be_empty
90
- end
91
-
92
- it 'searches integers' do
93
- expect(Post.search_by(POSTS[:ab1].id.to_s).count).to eq(1)
94
- end
95
-
96
- it 'supports wildcards' do
97
- expect(User.search_by('*uni*dom')).to match_array(USERS.values_at(:a))
98
- expect(User.search_by('*uni*o*')).to match_array(USERS.values_at(:a, :b))
99
- expect(User.search_by('*uni*of*dom')).to be_empty
100
- end
101
-
102
- it 'supports profiles' do
103
- expect(User.search_by('king', profile: :country_only)).to match_array(USERS.values_at(:a))
104
- expect(User.search_by('Norris', profile: :country_only)).to be_empty
105
- end
106
- 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