search_cop 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/search_cop/search_scope.rb +1 -1
- data/lib/search_cop/version.rb +1 -1
- data/test/namespace_test.rb +23 -0
- data/test/test_helper.rb +13 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebdc7756338ed85d56d22c0e350930651f3776f75bcf027f27a95a994b7e3955
|
4
|
+
data.tar.gz: 9f56f6e8b3fb01533ce3e938cd9fb32476970789baf6e6d9a0752e21c125f71d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c570e77317b1b19d28edb11e9b8d3fe34c08d81f0ddf929efd043da51bda078c60139bc4f27c5e62c31c0fbd5a1b8e21245ec8aae03ebcc2b163d0f5e7570e22
|
7
|
+
data.tar.gz: 3d1b6708a2c114271ea733fd245f73ed5be1c577d2140d2a46107dd81a082e5ac9111a8e06151aa185b31c490af1d7f2feb5fd9b7527661b525faa4c48d724f9
|
data/CHANGELOG.md
CHANGED
@@ -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.
|
58
|
+
table, attribute = column.to_s =~ /\./ ? column.to_s.split(".") : [model.table_name, column]
|
59
59
|
|
60
60
|
"#{table}.#{attribute}"
|
61
61
|
end
|
data/lib/search_cop/version.rb
CHANGED
@@ -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.
|
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-
|
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
|