search_cop 1.1.0 → 1.2.0
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 +42 -0
- data/.rubocop.yml +128 -0
- data/CHANGELOG.md +14 -9
- data/Gemfile +4 -5
- data/README.md +11 -1
- data/Rakefile +0 -1
- data/docker-compose.yml +8 -1
- data/gemfiles/{5.1.gemfile → rails5.gemfile} +2 -2
- data/gemfiles/rails6.gemfile +13 -0
- data/lib/search_cop.rb +5 -23
- data/lib/search_cop/grammar_parser.rb +1 -3
- data/lib/search_cop/hash_parser.rb +19 -19
- data/lib/search_cop/helpers.rb +15 -0
- data/lib/search_cop/query_builder.rb +0 -2
- data/lib/search_cop/query_info.rb +0 -2
- data/lib/search_cop/search_scope.rb +2 -4
- data/lib/search_cop/version.rb +1 -1
- data/lib/search_cop/visitors.rb +0 -2
- data/lib/search_cop/visitors/mysql.rb +4 -2
- data/lib/search_cop/visitors/postgres.rb +5 -3
- data/lib/search_cop/visitors/visitor.rb +5 -3
- data/lib/search_cop_grammar.rb +1 -3
- data/lib/search_cop_grammar/attributes.rb +45 -34
- data/lib/search_cop_grammar/nodes.rb +0 -2
- data/search_cop.gemspec +8 -8
- data/test/and_test.rb +6 -8
- data/test/boolean_test.rb +7 -9
- data/test/database.yml +2 -1
- data/test/date_test.rb +14 -16
- data/test/datetime_test.rb +15 -17
- data/test/default_operator_test.rb +14 -10
- data/test/error_test.rb +2 -4
- data/test/float_test.rb +9 -11
- data/test/fulltext_test.rb +6 -8
- data/test/hash_test.rb +32 -34
- data/test/integer_test.rb +9 -11
- data/test/not_test.rb +6 -8
- data/test/or_test.rb +8 -10
- data/test/scope_test.rb +11 -13
- data/test/search_cop_test.rb +32 -34
- data/test/string_test.rb +67 -19
- data/test/test_helper.rb +13 -15
- data/test/visitor_test.rb +4 -6
- metadata +28 -13
- data/.travis.yml +0 -34
- data/gemfiles/4.2.gemfile +0 -13
data/test/test_helper.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
require "search_cop"
|
3
2
|
|
4
3
|
begin
|
@@ -18,7 +17,7 @@ require "yaml"
|
|
18
17
|
|
19
18
|
DATABASE = ENV["DATABASE"] || "sqlite"
|
20
19
|
|
21
|
-
ActiveRecord::Base.establish_connection YAML.load_file(File.expand_path("
|
20
|
+
ActiveRecord::Base.establish_connection YAML.load_file(File.expand_path("database.yml", __dir__))[DATABASE]
|
22
21
|
|
23
22
|
class User < ActiveRecord::Base; end
|
24
23
|
|
@@ -28,7 +27,7 @@ class Comment < ActiveRecord::Base
|
|
28
27
|
belongs_to :user
|
29
28
|
|
30
29
|
search_scope :search do
|
31
|
-
attributes :
|
30
|
+
attributes user: "user.username"
|
32
31
|
attributes :title, :message
|
33
32
|
end
|
34
33
|
end
|
@@ -38,19 +37,19 @@ class Product < ActiveRecord::Base
|
|
38
37
|
|
39
38
|
search_scope :search do
|
40
39
|
attributes :title, :description, :brand, :notice, :stock, :price, :created_at, :created_on, :available
|
41
|
-
attributes :
|
42
|
-
attributes :
|
40
|
+
attributes comment: ["comments.title", "comments.message"], user: ["users.username", "users_products.username"]
|
41
|
+
attributes primary: [:title, :description]
|
43
42
|
|
44
|
-
aliases :
|
43
|
+
aliases users_products: :user
|
45
44
|
|
46
45
|
if DATABASE != "sqlite"
|
47
|
-
options :title, :
|
48
|
-
options :description, :
|
49
|
-
options :comment, :
|
46
|
+
options :title, type: :fulltext, coalesce: true
|
47
|
+
options :description, type: :fulltext, coalesce: true
|
48
|
+
options :comment, type: :fulltext, coalesce: true
|
50
49
|
end
|
51
50
|
|
52
51
|
if DATABASE == "postgres"
|
53
|
-
options :title, :
|
52
|
+
options :title, dictionary: "english"
|
54
53
|
end
|
55
54
|
|
56
55
|
generator :custom_eq do |column_name, raw_value|
|
@@ -62,10 +61,10 @@ class Product < ActiveRecord::Base
|
|
62
61
|
scope { joins "LEFT OUTER JOIN users users_products ON users_products.id = products.user_id" }
|
63
62
|
|
64
63
|
attributes :title, :description
|
65
|
-
attributes :
|
64
|
+
attributes user: "users_products.username"
|
66
65
|
|
67
|
-
options :title, :
|
68
|
-
aliases :
|
66
|
+
options :title, default: true
|
67
|
+
aliases users_products: User
|
69
68
|
end
|
70
69
|
|
71
70
|
search_scope :search_multi_columns do
|
@@ -73,7 +72,7 @@ class Product < ActiveRecord::Base
|
|
73
72
|
end
|
74
73
|
|
75
74
|
has_many :comments
|
76
|
-
has_many :users, :
|
75
|
+
has_many :users, through: :comments
|
77
76
|
|
78
77
|
belongs_to :user
|
79
78
|
end
|
@@ -173,4 +172,3 @@ class SearchCop::TestCase
|
|
173
172
|
ActiveRecord::Base.connection.quote object
|
174
173
|
end
|
175
174
|
end
|
176
|
-
|
data/test/visitor_test.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
require File.expand_path("../test_helper", __FILE__)
|
1
|
+
require File.expand_path("test_helper", __dir__)
|
3
2
|
|
4
3
|
class VisitorTest < SearchCop::TestCase
|
5
4
|
def test_and
|
@@ -53,8 +52,8 @@ class VisitorTest < SearchCop::TestCase
|
|
53
52
|
def test_matches
|
54
53
|
node = SearchCopGrammar::Attributes::String.new(Product, "products", "notice").matches("Notice")
|
55
54
|
|
56
|
-
assert_equal("(#{quote_table_name "products"}.#{quote_column_name "notice"} IS NOT NULL AND #{quote_table_name "products"}.#{quote_column_name "notice"} LIKE #{quote "%Notice%"})", SearchCop::Visitors::Visitor.new(ActiveRecord::Base.connection).visit(node)) if ENV["DATABASE"] != "postgres"
|
57
|
-
assert_equal("(#{quote_table_name "products"}.#{quote_column_name "notice"} IS NOT NULL AND #{quote_table_name "products"}.#{quote_column_name "notice"} ILIKE #{quote "%Notice%"})", SearchCop::Visitors::Visitor.new(ActiveRecord::Base.connection).visit(node)) if ENV["DATABASE"] == "postgres"
|
55
|
+
assert_equal("(#{quote_table_name "products"}.#{quote_column_name "notice"} IS NOT NULL AND #{quote_table_name "products"}.#{quote_column_name "notice"} LIKE #{quote "%Notice%"} ESCAPE #{quote "\\"})", SearchCop::Visitors::Visitor.new(ActiveRecord::Base.connection).visit(node)) if ENV["DATABASE"] != "postgres"
|
56
|
+
assert_equal("(#{quote_table_name "products"}.#{quote_column_name "notice"} IS NOT NULL AND #{quote_table_name "products"}.#{quote_column_name "notice"} ILIKE #{quote "%Notice%"} ESCAPE #{quote "\\"})", SearchCop::Visitors::Visitor.new(ActiveRecord::Base.connection).visit(node)) if ENV["DATABASE"] == "postgres"
|
58
57
|
end
|
59
58
|
|
60
59
|
def test_not
|
@@ -99,7 +98,7 @@ class VisitorTest < SearchCop::TestCase
|
|
99
98
|
end
|
100
99
|
|
101
100
|
def test_generator
|
102
|
-
generator =
|
101
|
+
generator = lambda do |column_name, value|
|
103
102
|
"#{column_name} = #{quote value}"
|
104
103
|
end
|
105
104
|
node = SearchCopGrammar::Attributes::Collection.new(SearchCop::QueryInfo.new(Product, Product.search_scopes[:search]), "title").generator(generator, "value").optimize!
|
@@ -107,4 +106,3 @@ class VisitorTest < SearchCop::TestCase
|
|
107
106
|
assert_equal "#{quote_table_name "products"}.#{quote_column_name "title"} = 'value'", SearchCop::Visitors::Visitor.new(ActiveRecord::Base.connection).visit(node)
|
108
107
|
end
|
109
108
|
end
|
110
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: search_cop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Vetter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: treetop
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activerecord
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.0.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.0.0
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,7 +53,7 @@ dependencies:
|
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
56
|
+
name: factory_bot
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - ">="
|
@@ -53,21 +67,21 @@ dependencies:
|
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: minitest
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - ">="
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
75
|
+
version: '0'
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
80
|
- - ">="
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
84
|
+
name: rake
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
87
|
- - ">="
|
@@ -81,7 +95,7 @@ dependencies:
|
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
98
|
+
name: rubocop
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
101
|
- - ">="
|
@@ -101,8 +115,9 @@ executables: []
|
|
101
115
|
extensions: []
|
102
116
|
extra_rdoc_files: []
|
103
117
|
files:
|
118
|
+
- ".github/workflows/test.yml"
|
104
119
|
- ".gitignore"
|
105
|
-
- ".
|
120
|
+
- ".rubocop.yml"
|
106
121
|
- CHANGELOG.md
|
107
122
|
- CONTRIBUTING.md
|
108
123
|
- Gemfile
|
@@ -111,11 +126,12 @@ files:
|
|
111
126
|
- README.md
|
112
127
|
- Rakefile
|
113
128
|
- docker-compose.yml
|
114
|
-
- gemfiles/
|
115
|
-
- gemfiles/
|
129
|
+
- gemfiles/rails5.gemfile
|
130
|
+
- gemfiles/rails6.gemfile
|
116
131
|
- lib/search_cop.rb
|
117
132
|
- lib/search_cop/grammar_parser.rb
|
118
133
|
- lib/search_cop/hash_parser.rb
|
134
|
+
- lib/search_cop/helpers.rb
|
119
135
|
- lib/search_cop/query_builder.rb
|
120
136
|
- lib/search_cop/query_info.rb
|
121
137
|
- lib/search_cop/search_scope.rb
|
@@ -166,8 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
182
|
- !ruby/object:Gem::Version
|
167
183
|
version: '0'
|
168
184
|
requirements: []
|
169
|
-
|
170
|
-
rubygems_version: 2.7.3
|
185
|
+
rubygems_version: 3.0.3
|
171
186
|
signing_key:
|
172
187
|
specification_version: 4
|
173
188
|
summary: Easily perform complex search engine like fulltext queries on your ActiveRecord
|
data/.travis.yml
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
|
2
|
-
services:
|
3
|
-
- postgresql
|
4
|
-
- mysql
|
5
|
-
|
6
|
-
before_script:
|
7
|
-
- mysql -e 'create database search_cop;'
|
8
|
-
- psql -c "create user search_cop password 'secret';" -U postgres
|
9
|
-
- psql -c 'create database search_cop owner search_cop;' -U postgres
|
10
|
-
|
11
|
-
matrix:
|
12
|
-
include:
|
13
|
-
- rvm: ruby-head
|
14
|
-
gemfile: gemfiles/4.2.gemfile
|
15
|
-
env: DATABASE=sqlite
|
16
|
-
- rvm: ruby-head
|
17
|
-
gemfile: gemfiles/4.2.gemfile
|
18
|
-
env: DATABASE=mysql
|
19
|
-
- rvm: ruby-head
|
20
|
-
gemfile: gemfiles/5.1.gemfile
|
21
|
-
env: DATABASE=mysql
|
22
|
-
- rvm: ruby-head
|
23
|
-
gemfile: gemfiles/4.2.gemfile
|
24
|
-
env: DATABASE=postgres
|
25
|
-
- rvm: ruby-head
|
26
|
-
gemfile: gemfiles/5.1.gemfile
|
27
|
-
env: DATABASE=postgres
|
28
|
-
|
29
|
-
install:
|
30
|
-
- "travis_retry bundle install"
|
31
|
-
|
32
|
-
script: "rake test --trace"
|
33
|
-
sudo: false
|
34
|
-
|
data/gemfiles/4.2.gemfile
DELETED