search_cop 1.2.1 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 07623ce75206a9b6b4455141697c09782649b05f1073ec27c965a7a4fdf2862a
4
- data.tar.gz: 5adef700f6a6514d0d1de0b1f17958d03ecacc0a0f83df57de5aff480bc96da5
3
+ metadata.gz: ebdc7756338ed85d56d22c0e350930651f3776f75bcf027f27a95a994b7e3955
4
+ data.tar.gz: 9f56f6e8b3fb01533ce3e938cd9fb32476970789baf6e6d9a0752e21c125f71d
5
5
  SHA512:
6
- metadata.gz: fbe73b6ec59b87263d9bfd7d4740618deab1dd7d4867dcb39a864e75db8614f08beed34518477791dd3d66f10ee8461a1282a3d81d35ee17b2a7de26d8c995cf
7
- data.tar.gz: c131ea06253e994bc5550570708cc5dc973b5392ca208020de08c3384153492c0bc9820438fc0d32c596ec46f27c9982b445d98b80363a89764b6461a4a35706
6
+ metadata.gz: c570e77317b1b19d28edb11e9b8d3fe34c08d81f0ddf929efd043da51bda078c60139bc4f27c5e62c31c0fbd5a1b8e21245ec8aae03ebcc2b163d0f5e7570e22
7
+ data.tar.gz: 3d1b6708a2c114271ea733fd245f73ed5be1c577d2140d2a46107dd81a082e5ac9111a8e06151aa185b31c490af1d7f2feb5fd9b7527661b525faa4c48d724f9
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
 
2
2
  # Changelog
3
3
 
4
+ Version 1.2.2:
5
+
6
+ * Fix table name for namespaced models #70
7
+
4
8
  Version 1.2.1:
5
9
 
6
10
  * Fix use of `table_name` to work with inherited models
@@ -55,7 +55,7 @@ module SearchCop
55
55
  def attributes_hash(hash)
56
56
  hash.each do |key, value|
57
57
  reflection.attributes[key.to_s] = Array(value).collect do |column|
58
- table, attribute = column.to_s =~ /\./ ? column.to_s.split(".") : [model.name.tableize, column]
58
+ table, attribute = column.to_s =~ /\./ ? column.to_s.split(".") : [model.table_name, column]
59
59
 
60
60
  "#{table}.#{attribute}"
61
61
  end
@@ -1,3 +1,3 @@
1
1
  module SearchCop
2
- VERSION = "1.2.1"
2
+ VERSION = "1.2.2"
3
3
  end
@@ -0,0 +1,23 @@
1
+ require File.expand_path("test_helper", __dir__)
2
+
3
+ class NamespaceTest < SearchCop::TestCase
4
+ def test_model_namespace
5
+ expected = create(:product, title: "Expected")
6
+ rejected = create(:product, title: "Rejected")
7
+
8
+ results = SomeNamespace::Product.search("Expected")
9
+
10
+ assert_includes results.map(&:id), expected.id
11
+ refute_includes results.map(&:id), rejected.id
12
+ end
13
+
14
+ def test_model_namespace_with_associations
15
+ expected = create(:product, user: create(:user, username: "Expected"))
16
+ rejected = create(:product, user: create(:user, username: "Rejected"))
17
+
18
+ results = SomeNamespace::Product.search("user:Expected")
19
+
20
+ assert_includes results.map(&:id), expected.id
21
+ refute_includes results.map(&:id), rejected.id
22
+ end
23
+ end
data/test/test_helper.rb CHANGED
@@ -77,6 +77,19 @@ class Product < ActiveRecord::Base
77
77
  belongs_to :user
78
78
  end
79
79
 
80
+ module SomeNamespace
81
+ class Product < ActiveRecord::Base
82
+ include SearchCop
83
+
84
+ belongs_to :user
85
+
86
+ search_scope :search do
87
+ attributes :title, :description
88
+ attributes user: ["user.username"]
89
+ end
90
+ end
91
+ end
92
+
80
93
  class AvailableProduct < Product
81
94
  default_scope { where(available: true) }
82
95
  end
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.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Vetter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-08 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
@@ -157,6 +157,7 @@ files:
157
157
  - test/fulltext_test.rb
158
158
  - test/hash_test.rb
159
159
  - test/integer_test.rb
160
+ - test/namespace_test.rb
160
161
  - test/not_test.rb
161
162
  - test/or_test.rb
162
163
  - test/scope_test.rb