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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8cb7e91b305057b2ea3df0c96643f8cd2cc726583f2362db9d576ef128826a75
4
- data.tar.gz: 419ee38ec698795d478f7749486e63b533c9cc497057aa820b5627b343cbdeb4
3
+ metadata.gz: 3d50fc64d55fb96b64906163d2f2e88f253974e8aeb0653307795fcab40eb636
4
+ data.tar.gz: 86184be05de8b457dbe709c89c4938aa35f600adf5cd1c20d38819a1ba933b86
5
5
  SHA512:
6
- metadata.gz: 19b765a13b9a21a5b798b60618253729b4a8c1279babe47644d5c030b93b09c87706138ab11cd5bfd9daee757d8d04bff95fc1bc3ce50c5f6f7399aaaabc09d1
7
- data.tar.gz: a65e72e3d6e5500b986bb312c45dbbd00432419b344765c71387432dd127efd5eb463cd42f71c3e405913a66b8d45201b9d909b9e66da17bf28f11ea3b7aa5c8
6
+ metadata.gz: abc70826323ea53b7966a415d78f18a64a10e004e9e6e08687c6118ebcd60964a5732691706c3d2d52aea05d919d9154484c57517a4882b4f9056518bf8ab4f3
7
+ data.tar.gz: 47c56ea7175559e06bbde1c830f6dc8437279cfb6639446babc6d2b731a86037c815fb8664f4fba64f6832cac33168a6e6f86cf79275cc410eec1b0cce17fb72
@@ -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.5", "2.6", "2.7"]
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: actions/setup-ruby@v1
38
+ - uses: ruby/setup-ruby@v1
31
39
  with:
32
40
  ruby-version: ${{ matrix.ruby }}
33
41
  - name: test
data/.rubocop.yml CHANGED
@@ -1,6 +1,12 @@
1
1
  AllCops:
2
2
  NewCops: enable
3
3
 
4
+ Gemspec/RequireMFA:
5
+ Enabled: false
6
+
7
+ Style/FetchEnvVar:
8
+ Enabled: false
9
+
4
10
  Gemspec/RequiredRubyVersion:
5
11
  Enabled: false
6
12
 
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
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 7.0"
6
+
7
+ platforms :ruby do
8
+ gem "mysql2"
9
+ gem "pg"
10
+ gem "sqlite3"
11
+ end
12
+
13
+ gemspec path: "../"
@@ -12,7 +12,7 @@ module SearchCop
12
12
  end
13
13
 
14
14
  def associations
15
- all_associations - [query_info.model.name.tableize.to_sym]
15
+ all_associations - [query_info.model.name.tableize.to_sym] - [query_info.model.table_name.to_sym]
16
16
  end
17
17
 
18
18
  private
@@ -1,3 +1,3 @@
1
1
  module SearchCop
2
- VERSION = "1.2.0"
2
+ VERSION = "1.2.3"
3
3
  end
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"
@@ -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.0
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: 2021-05-13 00:00:00.000000000 Z
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.0.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: []