search_cop 1.2.2 → 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/CHANGELOG.md +4 -0
- data/lib/search_cop/query_builder.rb +1 -1
- data/lib/search_cop/search_scope.rb +1 -1
- data/lib/search_cop/version.rb +1 -1
- data/test/search_cop_test.rb +20 -0
- data/test/test_helper.rb +13 -3
- metadata +1 -2
- data/test/namespace_test.rb +0 -23
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/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.name.tableize, column]
|
59
59
|
|
60
60
|
"#{table}.#{attribute}"
|
61
61
|
end
|
data/lib/search_cop/version.rb
CHANGED
data/test/search_cop_test.rb
CHANGED
@@ -70,6 +70,26 @@ class SearchCopTest < SearchCop::TestCase
|
|
70
70
|
refute_includes results, rejected
|
71
71
|
end
|
72
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
|
+
|
73
93
|
def test_multiple
|
74
94
|
product = create(:product, comments: [create(:comment, title: "Title", message: "Message")])
|
75
95
|
|
data/test/test_helper.rb
CHANGED
@@ -77,14 +77,14 @@ class Product < ActiveRecord::Base
|
|
77
77
|
belongs_to :user
|
78
78
|
end
|
79
79
|
|
80
|
-
module
|
81
|
-
class
|
80
|
+
module Blog
|
81
|
+
class Post < ActiveRecord::Base
|
82
82
|
include SearchCop
|
83
83
|
|
84
84
|
belongs_to :user
|
85
85
|
|
86
86
|
search_scope :search do
|
87
|
-
attributes :title, :
|
87
|
+
attributes :title, :content
|
88
88
|
attributes user: ["user.username"]
|
89
89
|
end
|
90
90
|
end
|
@@ -98,6 +98,9 @@ FactoryBot.define do
|
|
98
98
|
factory :product do
|
99
99
|
end
|
100
100
|
|
101
|
+
factory :blog_post, class: Blog::Post do
|
102
|
+
end
|
103
|
+
|
101
104
|
factory :available_product do
|
102
105
|
available { true }
|
103
106
|
end
|
@@ -110,6 +113,7 @@ FactoryBot.define do
|
|
110
113
|
end
|
111
114
|
|
112
115
|
ActiveRecord::Base.connection.execute "DROP TABLE IF EXISTS products"
|
116
|
+
ActiveRecord::Base.connection.execute "DROP TABLE IF EXISTS posts"
|
113
117
|
ActiveRecord::Base.connection.execute "DROP TABLE IF EXISTS comments"
|
114
118
|
ActiveRecord::Base.connection.execute "DROP TABLE IF EXISTS users"
|
115
119
|
|
@@ -126,6 +130,12 @@ ActiveRecord::Base.connection.create_table :products do |t|
|
|
126
130
|
t.string :notice
|
127
131
|
end
|
128
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
|
+
|
129
139
|
ActiveRecord::Base.connection.create_table :comments do |t|
|
130
140
|
t.references :product
|
131
141
|
t.references :user
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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
|
@@ -157,7 +157,6 @@ files:
|
|
157
157
|
- test/fulltext_test.rb
|
158
158
|
- test/hash_test.rb
|
159
159
|
- test/integer_test.rb
|
160
|
-
- test/namespace_test.rb
|
161
160
|
- test/not_test.rb
|
162
161
|
- test/or_test.rb
|
163
162
|
- test/scope_test.rb
|
data/test/namespace_test.rb
DELETED
@@ -1,23 +0,0 @@
|
|
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
|