scoped_search 4.3.0 → 4.3.1
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2413a0e2075ccff25188af0a579df4b8cfde593f38ab801b99bd7379b2344c8b
|
4
|
+
data.tar.gz: edc1ec5d32cc2b410fdf9938e49aca0cfba46807850491c3ee6bba28642dfc5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a31a5e76daac85ca7b36cff7fdf38a377258401f38da13fb789afb1d6ca55e01331ce88c78136e7bc4efc64704e59460de267b50bfd8dc47e479c881e2b84b7
|
7
|
+
data.tar.gz: 87d273283f63fbc83afb0ab29f163a5625f0fc074c551c5220f004eb902c43a407973bf5470395c90442666ff14e1a69b1b0e7b8aba653c997d180da969429ee
|
data/CHANGELOG.rdoc
CHANGED
@@ -6,6 +6,9 @@ Please add an entry to the "Unreleased changes" section in your pull requests.
|
|
6
6
|
|
7
7
|
=== Unreleased changes
|
8
8
|
|
9
|
+
=== Version 4.3.1
|
10
|
+
- Autocomplete now offers only relevant options available through scopes set on associations (#233)
|
11
|
+
|
9
12
|
=== Version 4.3.0
|
10
13
|
|
11
14
|
- Prevent scoped_search from modifying an empty string on newer rubies (#229)
|
@@ -207,6 +207,7 @@ module ScopedSearch
|
|
207
207
|
|
208
208
|
def complete_value_from_db(field, special_values, val)
|
209
209
|
count = 20 - special_values.count
|
210
|
+
|
210
211
|
completer_scope(field)
|
211
212
|
.where(@options[:value_filter])
|
212
213
|
.where(value_conditions(field.quoted_field, val))
|
@@ -224,7 +225,9 @@ module ScopedSearch
|
|
224
225
|
|
225
226
|
if field.klass != field.definition.klass
|
226
227
|
reflection = field.definition.reflection_by_name(field.definition.klass, field.relation)
|
227
|
-
|
228
|
+
sub_scope = reflection.active_record.joins(reflection.name)
|
229
|
+
sub_scope = sub_scope.select("#{field.klass.table_name}.#{field.klass.primary_key}")
|
230
|
+
scope = scope.where(field.klass.primary_key => sub_scope)
|
228
231
|
end
|
229
232
|
|
230
233
|
scope.respond_to?(:reorder) ? scope.reorder(Arel.sql(field.quoted_field)) : scope.scoped(:order => field.quoted_field)
|
@@ -45,6 +45,16 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
|
|
45
45
|
t.integer :foo_id
|
46
46
|
end
|
47
47
|
|
48
|
+
ActiveRecord::Migration.create_table(:asds, :force => true) do |t|
|
49
|
+
t.integer :baz_id
|
50
|
+
t.string :string
|
51
|
+
end
|
52
|
+
|
53
|
+
ActiveRecord::Migration.create_table(:qwes, :force => true) do |t|
|
54
|
+
t.integer :asd_id
|
55
|
+
t.string :string
|
56
|
+
end
|
57
|
+
|
48
58
|
class ::Bar < ActiveRecord::Base
|
49
59
|
belongs_to :foo
|
50
60
|
end
|
@@ -71,34 +81,61 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
|
|
71
81
|
|
72
82
|
class ::Baz < ActiveRecord::Base
|
73
83
|
belongs_to :foo, -> { where(string: 'foo') }
|
84
|
+
has_one :asd, -> { where(string: 'foo') }
|
85
|
+
has_one :qwe, through: :asd
|
74
86
|
|
75
|
-
scoped_search :on => :string, :relation => :foo, :complete_value => true
|
87
|
+
scoped_search :on => :string, :relation => :foo, :complete_value => true, :rename => 'foos.string'.to_sym
|
88
|
+
scoped_search :on => :string, :relation => :asd, :complete_value => true, :rename => 'asds.string'.to_sym
|
89
|
+
scoped_search :on => :string, :relation => :qwe, :complete_value => true, :rename => 'qwes.string'.to_sym
|
76
90
|
end
|
77
91
|
|
78
92
|
class ::Infoo < ::Foo
|
79
93
|
end
|
80
94
|
|
95
|
+
class ::Asd < ActiveRecord::Base
|
96
|
+
belongs_to :baz
|
97
|
+
has_one :qwe
|
98
|
+
end
|
99
|
+
|
100
|
+
class ::Qwe < ActiveRecord::Base
|
101
|
+
belongs_to :asd
|
102
|
+
end
|
103
|
+
|
81
104
|
@qux_1 = Qux.create!()
|
82
105
|
@qux_2 = Qux.create!()
|
83
106
|
@foo_1 = Foo.create!(:string => 'foo', :another => 'temp 1', :explicit => 'baz', :int => 9 , :date => 'February 8, 2011' , :unindexed => 10, :qux => @qux_1)
|
84
107
|
@foo_2 = Foo.create!(:string => 'foo', :another => 'temp 2', :explicit => 'baz', :int => 10 , :date => 'February 8, 2011' , :unindexed => 10, :qux => @qux_2)
|
85
|
-
Foo.create!(:string => 'bar', :another => 'temp "2"', :explicit => 'baz', :int => 22 , :date => 'February 10, 2011', :unindexed => 10)
|
108
|
+
@foo_3 = Foo.create!(:string => 'bar', :another => 'temp "2"', :explicit => 'baz', :int => 22 , :date => 'February 10, 2011', :unindexed => 10)
|
86
109
|
Foo.create!(:string => 'baz', :another => nil, :explicit => nil , :int => nil, :date => nil , :unindexed => nil)
|
87
110
|
20.times { Foo.create!(:explicit => "aaa") }
|
88
111
|
|
112
|
+
@baz_1 = Baz.create!(:foo => @foo_1)
|
113
|
+
@baz_2 = Baz.create!(:foo => @foo_2)
|
114
|
+
Baz.create!(:foo => @foo_3)
|
115
|
+
|
89
116
|
Bar.create!(:related => 'lala', :foo => @foo_1)
|
90
117
|
Bar.create!(:related => 'another lala', :foo => @foo_1)
|
118
|
+
|
119
|
+
@asd_1 = Asd.create!(:string => 'foo', :baz => @baz_1)
|
120
|
+
@asd_2 = Asd.create!(:string => 'bar', :baz => @baz_2)
|
121
|
+
Qwe.create!(:asd => @asd_1, :string => 'qwe1')
|
122
|
+
Qwe.create!(:asd => @asd_2, :string => 'qwe2')
|
91
123
|
end
|
92
124
|
|
93
125
|
after(:all) do
|
94
126
|
ActiveRecord::Migration.drop_table(:foos)
|
95
127
|
ActiveRecord::Migration.drop_table(:bars)
|
96
128
|
ActiveRecord::Migration.drop_table(:bazs)
|
129
|
+
ActiveRecord::Migration.drop_table(:asds)
|
130
|
+
ActiveRecord::Migration.drop_table(:qwes)
|
97
131
|
|
98
132
|
Object.send :remove_const, :Foo
|
99
133
|
Object.send :remove_const, :Bar
|
100
134
|
Object.send :remove_const, :Baz
|
135
|
+
Object.send :remove_const, :Qux
|
101
136
|
Object.send :remove_const, :Infoo
|
137
|
+
Object.send :remove_const, :Asd
|
138
|
+
Object.send :remove_const, :Qwe
|
102
139
|
|
103
140
|
ScopedSearch::RSpec::Database.close_connection
|
104
141
|
end
|
@@ -282,7 +319,11 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
|
|
282
319
|
|
283
320
|
context 'autocompleting with scopes' do
|
284
321
|
it 'should honor the scope' do
|
285
|
-
|
322
|
+
Baz.complete_for('foos.string =').should == ['foos.string = "foo"']
|
323
|
+
end
|
324
|
+
|
325
|
+
it 'should honor scope on the through relation' do
|
326
|
+
Baz.complete_for('qwes.string =').should == ['qwes.string = "qwe1"']
|
286
327
|
end
|
287
328
|
end
|
288
329
|
end
|
@@ -249,13 +249,13 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
|
|
249
249
|
before do
|
250
250
|
|
251
251
|
# Create some tables
|
252
|
-
ActiveRecord::Migration.create_table(:mars) { |t| t.integer :koo_id; t.integer :
|
253
|
-
ActiveRecord::Migration.create_table(:
|
252
|
+
ActiveRecord::Migration.create_table(:mars) { |t| t.integer :koo_id; t.integer :zab_id }
|
253
|
+
ActiveRecord::Migration.create_table(:zabs) { |t| t.string :related }
|
254
254
|
ActiveRecord::Migration.create_table(:koos) { |t| t.string :foo }
|
255
255
|
|
256
256
|
# The related classes
|
257
|
-
class Mar < ActiveRecord::Base; belongs_to :
|
258
|
-
class
|
257
|
+
class Mar < ActiveRecord::Base; belongs_to :zab; belongs_to :koo; end
|
258
|
+
class Zab < ActiveRecord::Base; has_many :mars; end
|
259
259
|
|
260
260
|
# The class on which to call search_for
|
261
261
|
class Koo < ActiveRecord::Base
|
@@ -263,38 +263,38 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
|
|
263
263
|
# having the source option here is not needed for the statement correctness.
|
264
264
|
# It is here to fail the code introduced in 2.6.2 that wrongly detected source instead of source_type
|
265
265
|
# as an indication for a polymorphic relation.
|
266
|
-
has_many :
|
266
|
+
has_many :zabs, :through => :mars, :source => :zab
|
267
267
|
|
268
|
-
scoped_search :relation => :
|
268
|
+
scoped_search :relation => :zabs, :on => :related
|
269
269
|
end
|
270
270
|
|
271
271
|
@koo_1 = Koo.create!(:foo => 'foo')
|
272
272
|
@koo_2 = Koo.create!(:foo => 'foo too')
|
273
273
|
@koo_3 = Koo.create!(:foo => 'foo three')
|
274
274
|
|
275
|
-
@
|
276
|
-
@
|
275
|
+
@zab_1 = Zab.create(:related => 'zab')
|
276
|
+
@zab_2 = Zab.create(:related => 'zab too!')
|
277
277
|
|
278
|
-
@bar_1 = Mar.create!(:koo => @koo_1, :
|
278
|
+
@bar_1 = Mar.create!(:koo => @koo_1, :zab => @zab_1)
|
279
279
|
@bar_2 = Mar.create!(:koo => @koo_1)
|
280
|
-
@bar_3 = Mar.create!(:koo => @koo_2, :
|
281
|
-
@bar_3 = Mar.create!(:koo => @koo_2, :
|
282
|
-
@bar_3 = Mar.create!(:koo => @koo_2, :
|
280
|
+
@bar_3 = Mar.create!(:koo => @koo_2, :zab => @zab_1)
|
281
|
+
@bar_3 = Mar.create!(:koo => @koo_2, :zab => @zab_2)
|
282
|
+
@bar_3 = Mar.create!(:koo => @koo_2, :zab => @zab_2)
|
283
283
|
@bar_4 = Mar.create!(:koo => @koo_3)
|
284
284
|
end
|
285
285
|
|
286
286
|
after do
|
287
|
-
ActiveRecord::Migration.drop_table(:
|
287
|
+
ActiveRecord::Migration.drop_table(:zabs)
|
288
288
|
ActiveRecord::Migration.drop_table(:mars)
|
289
289
|
ActiveRecord::Migration.drop_table(:koos)
|
290
290
|
end
|
291
291
|
|
292
|
-
it "should find the two records that are related to a
|
293
|
-
Koo.search_for('
|
292
|
+
it "should find the two records that are related to a zab record" do
|
293
|
+
Koo.search_for('zab').length.should == 2
|
294
294
|
end
|
295
295
|
|
296
|
-
it "should find the two records that are related to a
|
297
|
-
Koo.search_for('related=
|
296
|
+
it "should find the two records that are related to a zab record" do
|
297
|
+
Koo.search_for('related=zab AND related="zab too!"').length.should == 1
|
298
298
|
end
|
299
299
|
end
|
300
300
|
|
@@ -303,27 +303,27 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
|
|
303
303
|
before do
|
304
304
|
|
305
305
|
# Create some tables
|
306
|
-
ActiveRecord::Migration.create_table(:zars) { |t| t.integer :
|
307
|
-
ActiveRecord::Migration.create_table(:
|
306
|
+
ActiveRecord::Migration.create_table(:zars) { |t| t.integer :zab_id }
|
307
|
+
ActiveRecord::Migration.create_table(:zabs) { |t| t.string :related }
|
308
308
|
ActiveRecord::Migration.create_table(:zoos) { |t| t.integer :zar_id; t.string :foo }
|
309
309
|
|
310
310
|
# The related classes
|
311
|
-
class Zar < ActiveRecord::Base; belongs_to :
|
312
|
-
class
|
311
|
+
class Zar < ActiveRecord::Base; belongs_to :zab; has_many :zoos; end
|
312
|
+
class Zab < ActiveRecord::Base; has_many :zars; end
|
313
313
|
|
314
314
|
# The class on which to call search_for
|
315
315
|
class Zoo < ActiveRecord::Base
|
316
316
|
belongs_to :zar
|
317
|
-
has_many :
|
317
|
+
has_many :zabs, :through => :zar
|
318
318
|
|
319
|
-
scoped_search :relation => :
|
319
|
+
scoped_search :relation => :zabs, :on => :related
|
320
320
|
end
|
321
321
|
|
322
|
-
|
323
|
-
|
322
|
+
zab_1 = Zab.create(:related => 'zab')
|
323
|
+
zab_2 = Zab.create(:related => 'zab too!')
|
324
324
|
|
325
|
-
zar_1 = Zar.create!( :
|
326
|
-
zar_2 = Zar.create!( :
|
325
|
+
zar_1 = Zar.create!( :zab => zab_1)
|
326
|
+
zar_2 = Zar.create!( :zab => zab_2)
|
327
327
|
|
328
328
|
Zoo.create!(:zar => zar_1, :foo => 'foo')
|
329
329
|
Zoo.create!(:zar => zar_1, :foo => 'foo too')
|
@@ -331,17 +331,17 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
|
|
331
331
|
end
|
332
332
|
|
333
333
|
after do
|
334
|
-
ActiveRecord::Migration.drop_table(:
|
334
|
+
ActiveRecord::Migration.drop_table(:zabs)
|
335
335
|
ActiveRecord::Migration.drop_table(:zars)
|
336
336
|
ActiveRecord::Migration.drop_table(:zoos)
|
337
337
|
end
|
338
338
|
|
339
|
-
it "should find the three records that are related to a
|
340
|
-
Zoo.search_for('
|
339
|
+
it "should find the three records that are related to a zab record" do
|
340
|
+
Zoo.search_for('zab').length.should == 3
|
341
341
|
end
|
342
342
|
|
343
|
-
it "should find no records that are related to a
|
344
|
-
Zoo.search_for('related=
|
343
|
+
it "should find no records that are related to a zab record" do
|
344
|
+
Zoo.search_for('related=zab AND related="zab too!"').length.should == 0
|
345
345
|
end
|
346
346
|
end
|
347
347
|
|
@@ -392,8 +392,8 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
|
|
392
392
|
@tag_2 = Tag.create!(:foo => 'foo too')
|
393
393
|
@tag_3 = Tag.create!(:foo => 'foo three')
|
394
394
|
|
395
|
-
@dog_1 = Dog.create(:related => '
|
396
|
-
@dog_2 = Dog.create(:related => '
|
395
|
+
@dog_1 = Dog.create(:related => 'zab')
|
396
|
+
@dog_2 = Dog.create(:related => 'zab too!')
|
397
397
|
@cat_1 = Cat.create(:related => 'mitzi')
|
398
398
|
|
399
399
|
@owner_1 = Owner.create(:name => 'Fred', :dogs => [@dog_1])
|
@@ -429,11 +429,11 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
|
|
429
429
|
end
|
430
430
|
|
431
431
|
it "should find the two tags that are related to a dog record" do
|
432
|
-
Tag.search_for('dog=
|
432
|
+
Tag.search_for('dog=zab').length.should == 2
|
433
433
|
end
|
434
434
|
|
435
435
|
it "should find the 3 tags that are related to dogs record" do
|
436
|
-
Tag.search_for('
|
436
|
+
Tag.search_for('zab').length.should == 3
|
437
437
|
end
|
438
438
|
end
|
439
439
|
|
@@ -547,22 +547,22 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
|
|
547
547
|
before do
|
548
548
|
|
549
549
|
# Create some tables with namespaces
|
550
|
-
ActiveRecord::Migration.create_table(:zan_mars) { |t| t.integer :koo_id; t.integer :
|
551
|
-
ActiveRecord::Migration.create_table(:
|
550
|
+
ActiveRecord::Migration.create_table(:zan_mars) { |t| t.integer :koo_id; t.integer :zab_id }
|
551
|
+
ActiveRecord::Migration.create_table(:zan_zabs) { |t| t.string :related }
|
552
552
|
ActiveRecord::Migration.create_table(:zan_koos) { |t| t.string :foo }
|
553
553
|
|
554
554
|
# The related classes
|
555
|
-
module Zan; class Mar < ActiveRecord::Base; belongs_to :
|
556
|
-
module Zan; class
|
555
|
+
module Zan; class Mar < ActiveRecord::Base; belongs_to :zab; belongs_to :koo; self.table_name = "zan_mars"; end; end
|
556
|
+
module Zan; class Zab < ActiveRecord::Base; has_many :mars; self.table_name = "zan_zabs"; end; end
|
557
557
|
|
558
558
|
# The class on which to call search_for
|
559
559
|
module Zan
|
560
560
|
class Koo < ActiveRecord::Base
|
561
561
|
has_many :mars, :class_name => "Zan::Mar"
|
562
|
-
has_many :
|
562
|
+
has_many :zabs, :through => :mars
|
563
563
|
self.table_name = "zan_koos"
|
564
564
|
|
565
|
-
scoped_search :relation => :
|
565
|
+
scoped_search :relation => :zabs, :on => :related
|
566
566
|
end
|
567
567
|
end
|
568
568
|
|
@@ -570,29 +570,29 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
|
|
570
570
|
@koo_2 = Zan::Koo.create!(:foo => 'foo too')
|
571
571
|
@koo_3 = Zan::Koo.create!(:foo => 'foo three')
|
572
572
|
|
573
|
-
@
|
574
|
-
@
|
573
|
+
@zab_1 = Zan::Zab.create(:related => 'zab')
|
574
|
+
@zab_2 = Zan::Zab.create(:related => 'zab too!')
|
575
575
|
|
576
|
-
@bar_1 = Zan::Mar.create!(:koo => @koo_1, :
|
576
|
+
@bar_1 = Zan::Mar.create!(:koo => @koo_1, :zab => @zab_1)
|
577
577
|
@bar_2 = Zan::Mar.create!(:koo => @koo_1)
|
578
|
-
@bar_3 = Zan::Mar.create!(:koo => @koo_2, :
|
579
|
-
@bar_3 = Zan::Mar.create!(:koo => @koo_2, :
|
580
|
-
@bar_3 = Zan::Mar.create!(:koo => @koo_2, :
|
578
|
+
@bar_3 = Zan::Mar.create!(:koo => @koo_2, :zab => @zab_1)
|
579
|
+
@bar_3 = Zan::Mar.create!(:koo => @koo_2, :zab => @zab_2)
|
580
|
+
@bar_3 = Zan::Mar.create!(:koo => @koo_2, :zab => @zab_2)
|
581
581
|
@bar_4 = Zan::Mar.create!(:koo => @koo_3)
|
582
582
|
end
|
583
583
|
|
584
584
|
after do
|
585
|
-
ActiveRecord::Migration.drop_table(:
|
585
|
+
ActiveRecord::Migration.drop_table(:zan_zabs)
|
586
586
|
ActiveRecord::Migration.drop_table(:zan_mars)
|
587
587
|
ActiveRecord::Migration.drop_table(:zan_koos)
|
588
588
|
end
|
589
589
|
|
590
|
-
it "should find the two records that are related to a
|
591
|
-
Zan::Koo.search_for('
|
590
|
+
it "should find the two records that are related to a zab record" do
|
591
|
+
Zan::Koo.search_for('zab').length.should == 2
|
592
592
|
end
|
593
593
|
|
594
|
-
it "should find the one record that is related to two
|
595
|
-
Zan::Koo.search_for('related=
|
594
|
+
it "should find the one record that is related to two zab records" do
|
595
|
+
Zan::Koo.search_for('related=zab AND related="zab too!"').length.should == 1
|
596
596
|
end
|
597
597
|
end
|
598
598
|
|
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scoped_search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.3.
|
4
|
+
version: 4.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Amos Benari
|
8
8
|
- Willem van Bergen
|
9
9
|
- Wes Hays
|
10
|
+
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date:
|
13
|
+
date: 2025-09-30 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: activerecord
|
@@ -141,10 +142,10 @@ email:
|
|
141
142
|
executables: []
|
142
143
|
extensions: []
|
143
144
|
extra_rdoc_files:
|
145
|
+
- README.rdoc
|
144
146
|
- CHANGELOG.rdoc
|
145
147
|
- CONTRIBUTING.rdoc
|
146
148
|
- LICENSE
|
147
|
-
- README.rdoc
|
148
149
|
files:
|
149
150
|
- ".github/workflows/ruby.yml"
|
150
151
|
- ".gitignore"
|
@@ -213,6 +214,7 @@ homepage: https://github.com/wvanbergen/scoped_search/wiki
|
|
213
214
|
licenses:
|
214
215
|
- MIT
|
215
216
|
metadata: {}
|
217
|
+
post_install_message:
|
216
218
|
rdoc_options:
|
217
219
|
- "--title"
|
218
220
|
- scoped_search
|
@@ -233,7 +235,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
233
235
|
- !ruby/object:Gem::Version
|
234
236
|
version: '0'
|
235
237
|
requirements: []
|
236
|
-
rubygems_version: 3.
|
238
|
+
rubygems_version: 3.0.3.1
|
239
|
+
signing_key:
|
237
240
|
specification_version: 4
|
238
241
|
summary: Easily search you ActiveRecord models with a simple query language using
|
239
242
|
a named scope
|