scoped_search 2.6.2 → 2.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/scoped_search/query_builder.rb +1 -1
- data/lib/scoped_search/version.rb +1 -1
- data/spec/integration/relation_querying_spec.rb +41 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06da166bed055eddce7ceffc6866cf09f339e881
|
4
|
+
data.tar.gz: 50ef26f62b672dd9fc887c47386c43caa6585f77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 156b20573d8e35001ca7272a48f756a787b03b1845c002379a73a2f0298823eccd5a58e4395f22ef07aec00626e2184484164d890f301a72f7affc3b1f9d9819
|
7
|
+
data.tar.gz: 4ddf5b25a5fe7b5a3daad3e1d0ff7cddb5f1e309689953b2f7acc53edfd63364461d89e7a179bd3b93c49055ae7885ebaf0a51d9f6a5dddd57f0264454f9af9c
|
@@ -356,7 +356,7 @@ module ScopedSearch
|
|
356
356
|
def reflection_conditions(reflection)
|
357
357
|
return unless reflection
|
358
358
|
conditions = reflection.options[:conditions]
|
359
|
-
conditions ||= "#{reflection.options[:source]}_type = '#{reflection.
|
359
|
+
conditions ||= "#{reflection.options[:source]}_type = '#{reflection.options[:source_type]}'" if reflection.options[:source] && reflection.options[:source_type]
|
360
360
|
conditions ||= "#{reflection.try(:foreign_type)} = '#{reflection.klass}'" if reflection.options[:polymorphic]
|
361
361
|
" AND #{conditions}" if conditions
|
362
362
|
end
|
@@ -240,7 +240,10 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
|
|
240
240
|
# The class on which to call search_for
|
241
241
|
class Koo < ActiveRecord::Base
|
242
242
|
has_many :mars
|
243
|
-
|
243
|
+
# having the source option here is not needed for the statement correctness.
|
244
|
+
# It is here to fail the code introduced in 2.6.2 that wrongly detected source instead of source_type
|
245
|
+
# as an indication for a polymorphic relation.
|
246
|
+
has_many :bazs, :through => :mars, :source => :baz
|
244
247
|
|
245
248
|
scoped_search :in => :bazs, :on => :related
|
246
249
|
end
|
@@ -282,48 +285,72 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
|
|
282
285
|
# Create some tables
|
283
286
|
ActiveRecord::Migration.create_table(:taggables) { |t| t.integer :taggable_id; t.string :taggable_type; t.integer :tag_id }
|
284
287
|
ActiveRecord::Migration.create_table(:dogs) { |t| t.string :related }
|
288
|
+
ActiveRecord::Migration.create_table(:cats) { |t| t.string :related }
|
285
289
|
ActiveRecord::Migration.create_table(:tags) { |t| t.string :foo }
|
286
290
|
|
287
291
|
# The related classes
|
288
292
|
class Taggable < ActiveRecord::Base; belongs_to :tag; belongs_to :taggable, :polymorphic => true; end
|
289
|
-
|
293
|
+
|
294
|
+
class Tag < ActiveRecord::Base
|
295
|
+
has_many :taggables
|
296
|
+
has_many :dogs, :through => :taggables, :source => :taggable, :source_type => 'Dog'
|
297
|
+
|
298
|
+
scoped_search :in => :dogs, :on => :related, :rename => :dog
|
299
|
+
end
|
290
300
|
|
291
301
|
# The class on which to call search_for
|
292
302
|
class Dog < ActiveRecord::Base
|
293
|
-
has_many :
|
294
|
-
has_many :tags, :through => :
|
303
|
+
has_many :taggables, :as => :taggable
|
304
|
+
has_many :tags, :through => :taggables
|
295
305
|
|
296
306
|
scoped_search :in => :tags, :on => :foo
|
297
307
|
end
|
298
308
|
|
309
|
+
class Cat < ActiveRecord::Base
|
310
|
+
has_many :taggables, :as => :taggable
|
311
|
+
has_many :tags, :through => :taggables
|
312
|
+
end
|
313
|
+
|
299
314
|
@tag_1 = Tag.create!(:foo => 'foo')
|
300
315
|
@tag_2 = Tag.create!(:foo => 'foo too')
|
301
316
|
@tag_3 = Tag.create!(:foo => 'foo three')
|
302
317
|
|
303
|
-
@
|
304
|
-
@
|
318
|
+
@dog_1 = Dog.create(:related => 'baz')
|
319
|
+
@dog_2 = Dog.create(:related => 'baz too!')
|
320
|
+
@cat_1 = Cat.create(:related => 'mitzi')
|
305
321
|
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
322
|
+
Taggable.create!(:tag => @tag_1, :taggable => @dog_1, :taggable_type => 'Dog' )
|
323
|
+
Taggable.create!(:tag => @tag_1)
|
324
|
+
Taggable.create!(:tag => @tag_2, :taggable => @dog_1 , :taggable_type => 'Dog')
|
325
|
+
Taggable.create!(:tag => @tag_2, :taggable => @dog_2 , :taggable_type => 'Dog')
|
326
|
+
Taggable.create!(:tag => @tag_3, :taggable => @dog_2 , :taggable_type => 'Dog')
|
327
|
+
Taggable.create!(:tag => @tag_2, :taggable => @cat_1 , :taggable_type => 'Cat')
|
328
|
+
Taggable.create!(:tag => @tag_3)
|
312
329
|
end
|
313
330
|
|
314
331
|
after do
|
315
332
|
ActiveRecord::Migration.drop_table(:dogs)
|
316
333
|
ActiveRecord::Migration.drop_table(:taggables)
|
317
334
|
ActiveRecord::Migration.drop_table(:tags)
|
335
|
+
ActiveRecord::Migration.drop_table(:cats)
|
318
336
|
end
|
319
337
|
|
320
|
-
it "should find the two records that are related to a
|
338
|
+
it "should find the two records that are related to a tag that contains foo record" do
|
321
339
|
Dog.search_for('foo').should have(2).items
|
322
340
|
end
|
323
341
|
|
324
|
-
it "should find
|
342
|
+
it "should find one records that is related to both tags" do
|
325
343
|
Dog.search_for('foo=foo AND foo="foo too"').should have(1).items
|
326
344
|
end
|
345
|
+
|
346
|
+
it "should find the two tags that are related to a dog record" do
|
347
|
+
Tag.search_for('dog=baz').should have(2).items
|
348
|
+
end
|
349
|
+
|
350
|
+
it "should find the 3 tags that are related to dogs record" do
|
351
|
+
Tag.search_for('baz').should have(3).items
|
352
|
+
end
|
353
|
+
|
327
354
|
end
|
328
355
|
end
|
329
356
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scoped_search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.6.
|
4
|
+
version: 2.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Amos Benari
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-02-
|
13
|
+
date: 2014-02-12 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|