scoped_search 2.6.2 → 2.6.3

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
  SHA1:
3
- metadata.gz: 37c27d6c6a3311a013c5bcaa5558f3d91f7c4443
4
- data.tar.gz: f0d713611729611a6d2f0f990982873dad65bb82
3
+ metadata.gz: 06da166bed055eddce7ceffc6866cf09f339e881
4
+ data.tar.gz: 50ef26f62b672dd9fc887c47386c43caa6585f77
5
5
  SHA512:
6
- metadata.gz: 5826b9fe779a5c48da50101a6dc7c52ba756bed745f99d463adeada1f23a1484e127d36ea122a9249f85050597133748655db51900d40160bf9c81a154975ae2
7
- data.tar.gz: 6a0a37aeb76ca59e10c07c3e57ac51480dc34e7ef52586026d9db75741da70619fd327061b459ed527e206725b68e47fb0b4c5b012464f13aea8c48a1a053e90
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.klass}'" if reflection.options[:source]
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
@@ -1,3 +1,3 @@
1
1
  module ScopedSearch
2
- VERSION = "2.6.2"
2
+ VERSION = "2.6.3"
3
3
  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
- has_many :bazs, :through => :mars
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
- class Tag < ActiveRecord::Base; has_many :taggables; end
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 :taggable, :as => :taggable
294
- has_many :tags, :through => :taggable
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
- @taggable_1 = Dog.create(:related => 'baz')
304
- @taggable_2 = Dog.create(:related => 'baz too!')
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
- @bar_1 = Taggable.create!(:tag => @tag_1, :taggable => @taggable_1, :taggable_type => 'Dog' )
307
- @bar_2 = Taggable.create!(:tag => @tag_1)
308
- @bar_3 = Taggable.create!(:tag => @tag_2, :taggable => @taggable_1 , :taggable_type => 'Dog')
309
- @bar_3 = Taggable.create!(:tag => @tag_2, :taggable => @taggable_2 , :taggable_type => 'Dog')
310
- @bar_3 = Taggable.create!(:tag => @tag_2, :taggable => @taggable_2 , :taggable_type => 'Dog')
311
- @bar_4 = Taggable.create!(:tag => @tag_3)
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 baz record" do
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 the two records that are related to a baz record" do
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.2
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-10 00:00:00.000000000 Z
13
+ date: 2014-02-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord