search_cop 1.2.0 → 1.2.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 +11 -3
- data/.rubocop.yml +6 -0
- data/CHANGELOG.md +13 -0
- data/gemfiles/rails7.gemfile +13 -0
- data/lib/search_cop/query_builder.rb +1 -1
- data/lib/search_cop/version.rb +1 -1
- data/search_cop.gemspec +0 -1
- data/test/search_cop_test.rb +29 -0
- data/test/test_helper.rb +31 -0
- metadata +8 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d50fc64d55fb96b64906163d2f2e88f253974e8aeb0653307795fcab40eb636
|
4
|
+
data.tar.gz: 86184be05de8b457dbe709c89c4938aa35f600adf5cd1c20d38819a1ba933b86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abc70826323ea53b7966a415d78f18a64a10e004e9e6e08687c6118ebcd60964a5732691706c3d2d52aea05d919d9154484c57517a4882b4f9056518bf8ab4f3
|
7
|
+
data.tar.gz: 47c56ea7175559e06bbde1c830f6dc8437279cfb6639446babc6d2b731a86037c815fb8664f4fba64f6832cac33168a6e6f86cf79275cc410eec1b0cce17fb72
|
data/.github/workflows/test.yml
CHANGED
@@ -4,10 +4,18 @@ jobs:
|
|
4
4
|
build:
|
5
5
|
runs-on: ubuntu-latest
|
6
6
|
strategy:
|
7
|
+
fail-fast: false
|
7
8
|
matrix:
|
8
|
-
ruby: ["2.
|
9
|
-
rails: ["rails5", "rails6"]
|
9
|
+
ruby: ["2.6", "2.7", "3.0", "3.1"]
|
10
|
+
rails: ["rails5", "rails6", "rails7"]
|
10
11
|
database: ["sqlite", "postgres", "mysql"]
|
12
|
+
exclude:
|
13
|
+
- ruby: "3.0"
|
14
|
+
rails: "rails5"
|
15
|
+
- ruby: "3.1"
|
16
|
+
rails: "rails5"
|
17
|
+
- ruby: "2.6"
|
18
|
+
rails: "rails7"
|
11
19
|
services:
|
12
20
|
postgres:
|
13
21
|
image: postgres
|
@@ -27,7 +35,7 @@ jobs:
|
|
27
35
|
- 3306:3306
|
28
36
|
steps:
|
29
37
|
- uses: actions/checkout@v1
|
30
|
-
- uses:
|
38
|
+
- uses: ruby/setup-ruby@v1
|
31
39
|
with:
|
32
40
|
ruby-version: ${{ matrix.ruby }}
|
33
41
|
- name: test
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,19 @@
|
|
1
1
|
|
2
2
|
# Changelog
|
3
3
|
|
4
|
+
Version 1.2.3:
|
5
|
+
|
6
|
+
* Fix table name for namespaced and inherited models #70 #67
|
7
|
+
|
8
|
+
Version 1.2.2:
|
9
|
+
|
10
|
+
* Fix table name for namespaced models #70
|
11
|
+
|
12
|
+
Version 1.2.1:
|
13
|
+
|
14
|
+
* Fix use of `table_name` to work with inherited models
|
15
|
+
* Fix linter, add ruby 3 and rails 7 to ci pipeline
|
16
|
+
|
4
17
|
Version 1.2.0:
|
5
18
|
|
6
19
|
* Added support for disabling the right wildcard
|
data/lib/search_cop/version.rb
CHANGED
data/search_cop.gemspec
CHANGED
@@ -14,7 +14,6 @@ Gem::Specification.new do |spec|
|
|
14
14
|
|
15
15
|
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
16
16
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
17
|
spec.require_paths = ["lib"]
|
19
18
|
|
20
19
|
spec.add_dependency "treetop"
|
data/test/search_cop_test.rb
CHANGED
@@ -61,6 +61,35 @@ class SearchCopTest < SearchCop::TestCase
|
|
61
61
|
refute_includes results, rejected
|
62
62
|
end
|
63
63
|
|
64
|
+
def test_inherited_model
|
65
|
+
expected = create(:available_product, comments: [create(:comment, user: create(:user, username: "Expected"))])
|
66
|
+
rejected = create(:available_product, comments: [create(:comment, user: create(:user, username: "Rejected"))])
|
67
|
+
|
68
|
+
results = AvailableProduct.search("user: Expected")
|
69
|
+
assert_includes results, expected
|
70
|
+
refute_includes results, rejected
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_namespaced_model
|
74
|
+
expected = create(:blog_post, title: "Expected")
|
75
|
+
rejected = create(:blog_post, title: "Rejected")
|
76
|
+
|
77
|
+
results = Blog::Post.search("Expected")
|
78
|
+
|
79
|
+
assert_includes results, expected
|
80
|
+
refute_includes results, rejected
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_namespaced_model_with_associations
|
84
|
+
expected = create(:blog_post, user: create(:user, username: "Expected"))
|
85
|
+
rejected = create(:blog_post, user: create(:user, username: "Rejected"))
|
86
|
+
|
87
|
+
results = Blog::Post.search("user:Expected")
|
88
|
+
|
89
|
+
assert_includes results, expected
|
90
|
+
refute_includes results, rejected
|
91
|
+
end
|
92
|
+
|
64
93
|
def test_multiple
|
65
94
|
product = create(:product, comments: [create(:comment, title: "Title", message: "Message")])
|
66
95
|
|
data/test/test_helper.rb
CHANGED
@@ -77,10 +77,34 @@ class Product < ActiveRecord::Base
|
|
77
77
|
belongs_to :user
|
78
78
|
end
|
79
79
|
|
80
|
+
module Blog
|
81
|
+
class Post < ActiveRecord::Base
|
82
|
+
include SearchCop
|
83
|
+
|
84
|
+
belongs_to :user
|
85
|
+
|
86
|
+
search_scope :search do
|
87
|
+
attributes :title, :content
|
88
|
+
attributes user: ["user.username"]
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
class AvailableProduct < Product
|
94
|
+
default_scope { where(available: true) }
|
95
|
+
end
|
96
|
+
|
80
97
|
FactoryBot.define do
|
81
98
|
factory :product do
|
82
99
|
end
|
83
100
|
|
101
|
+
factory :blog_post, class: Blog::Post do
|
102
|
+
end
|
103
|
+
|
104
|
+
factory :available_product do
|
105
|
+
available { true }
|
106
|
+
end
|
107
|
+
|
84
108
|
factory :comment do
|
85
109
|
end
|
86
110
|
|
@@ -89,6 +113,7 @@ FactoryBot.define do
|
|
89
113
|
end
|
90
114
|
|
91
115
|
ActiveRecord::Base.connection.execute "DROP TABLE IF EXISTS products"
|
116
|
+
ActiveRecord::Base.connection.execute "DROP TABLE IF EXISTS posts"
|
92
117
|
ActiveRecord::Base.connection.execute "DROP TABLE IF EXISTS comments"
|
93
118
|
ActiveRecord::Base.connection.execute "DROP TABLE IF EXISTS users"
|
94
119
|
|
@@ -105,6 +130,12 @@ ActiveRecord::Base.connection.create_table :products do |t|
|
|
105
130
|
t.string :notice
|
106
131
|
end
|
107
132
|
|
133
|
+
ActiveRecord::Base.connection.create_table :posts do |t|
|
134
|
+
t.references :user
|
135
|
+
t.string :title
|
136
|
+
t.text :content
|
137
|
+
end
|
138
|
+
|
108
139
|
ActiveRecord::Base.connection.create_table :comments do |t|
|
109
140
|
t.references :product
|
110
141
|
t.references :user
|
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.2.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Vetter
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: treetop
|
@@ -128,6 +128,7 @@ files:
|
|
128
128
|
- docker-compose.yml
|
129
129
|
- gemfiles/rails5.gemfile
|
130
130
|
- gemfiles/rails6.gemfile
|
131
|
+
- gemfiles/rails7.gemfile
|
131
132
|
- lib/search_cop.rb
|
132
133
|
- lib/search_cop/grammar_parser.rb
|
133
134
|
- lib/search_cop/hash_parser.rb
|
@@ -167,7 +168,7 @@ homepage: https://github.com/mrkamel/search_cop
|
|
167
168
|
licenses:
|
168
169
|
- MIT
|
169
170
|
metadata: {}
|
170
|
-
post_install_message:
|
171
|
+
post_install_message:
|
171
172
|
rdoc_options: []
|
172
173
|
require_paths:
|
173
174
|
- lib
|
@@ -182,27 +183,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
182
183
|
- !ruby/object:Gem::Version
|
183
184
|
version: '0'
|
184
185
|
requirements: []
|
185
|
-
rubygems_version: 3.
|
186
|
-
signing_key:
|
186
|
+
rubygems_version: 3.3.3
|
187
|
+
signing_key:
|
187
188
|
specification_version: 4
|
188
189
|
summary: Easily perform complex search engine like fulltext queries on your ActiveRecord
|
189
190
|
models
|
190
|
-
test_files:
|
191
|
-
- test/and_test.rb
|
192
|
-
- test/boolean_test.rb
|
193
|
-
- test/database.yml
|
194
|
-
- test/date_test.rb
|
195
|
-
- test/datetime_test.rb
|
196
|
-
- test/default_operator_test.rb
|
197
|
-
- test/error_test.rb
|
198
|
-
- test/float_test.rb
|
199
|
-
- test/fulltext_test.rb
|
200
|
-
- test/hash_test.rb
|
201
|
-
- test/integer_test.rb
|
202
|
-
- test/not_test.rb
|
203
|
-
- test/or_test.rb
|
204
|
-
- test/scope_test.rb
|
205
|
-
- test/search_cop_test.rb
|
206
|
-
- test/string_test.rb
|
207
|
-
- test/test_helper.rb
|
208
|
-
- test/visitor_test.rb
|
191
|
+
test_files: []
|