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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ebdc7756338ed85d56d22c0e350930651f3776f75bcf027f27a95a994b7e3955
4
- data.tar.gz: 9f56f6e8b3fb01533ce3e938cd9fb32476970789baf6e6d9a0752e21c125f71d
3
+ metadata.gz: 3d50fc64d55fb96b64906163d2f2e88f253974e8aeb0653307795fcab40eb636
4
+ data.tar.gz: 86184be05de8b457dbe709c89c4938aa35f600adf5cd1c20d38819a1ba933b86
5
5
  SHA512:
6
- metadata.gz: c570e77317b1b19d28edb11e9b8d3fe34c08d81f0ddf929efd043da51bda078c60139bc4f27c5e62c31c0fbd5a1b8e21245ec8aae03ebcc2b163d0f5e7570e22
7
- data.tar.gz: 3d1b6708a2c114271ea733fd245f73ed5be1c577d2140d2a46107dd81a082e5ac9111a8e06151aa185b31c490af1d7f2feb5fd9b7527661b525faa4c48d724f9
6
+ metadata.gz: abc70826323ea53b7966a415d78f18a64a10e004e9e6e08687c6118ebcd60964a5732691706c3d2d52aea05d919d9154484c57517a4882b4f9056518bf8ab4f3
7
+ data.tar.gz: 47c56ea7175559e06bbde1c830f6dc8437279cfb6639446babc6d2b731a86037c815fb8664f4fba64f6832cac33168a6e6f86cf79275cc410eec1b0cce17fb72
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
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
+
4
8
  Version 1.2.2:
5
9
 
6
10
  * Fix table name for namespaced models #70
@@ -12,7 +12,7 @@ module SearchCop
12
12
  end
13
13
 
14
14
  def associations
15
- all_associations - [query_info.model.table_name.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
@@ -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.table_name, column]
58
+ table, attribute = column.to_s =~ /\./ ? column.to_s.split(".") : [model.name.tableize, column]
59
59
 
60
60
  "#{table}.#{attribute}"
61
61
  end
@@ -1,3 +1,3 @@
1
1
  module SearchCop
2
- VERSION = "1.2.2"
2
+ VERSION = "1.2.3"
3
3
  end
@@ -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 SomeNamespace
81
- class Product < ActiveRecord::Base
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, :description
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.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
@@ -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