scoped_search 4.1.0 → 4.1.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
  SHA1:
3
- metadata.gz: 3b15c18415944dcdf767c8ab154ac00186290c2b
4
- data.tar.gz: ca8384a89a6887ae0335b02fe7d8e0341654c063
3
+ metadata.gz: ed2cb536ff3e9eb2ae79adb69c0d16deded93503
4
+ data.tar.gz: d71fcf06f4526cca6f0f74c674b700c63cc53710
5
5
  SHA512:
6
- metadata.gz: 3534f6ce7a7c2d0edc4c3d5ca1fe5c43bf21ef51491861d298da837dcb949d86a237df26680f1273a9f8ec88a0bf6b139efd8e801747e9c994435628f66dd343
7
- data.tar.gz: 7fedaf4f620b8f77b5dd3594a77810f51632ac7a8d0d5ac33ea946c34ae4b085eb85ca7502ebe2c8955b93d1f9c5940ba76422ef180fe4177709d1290878d13e
6
+ metadata.gz: 574ce08bfd3a7e6910c52b814c5c0b977e6de7675a80dc53b971915e2fe4619a9e82453dcdafa547d66ff9a6464737a0b26e935ebd4f2f78121ff0061a5096b2
7
+ data.tar.gz: 0adcf62f38857c13dd4e49c835b4cfe33821ddf273f5e190ccd557b279ca49512d35700a05549ca9b8eb2c332e73c0ae501daa7fbbccb10da4b5b8720f30429a
@@ -8,6 +8,11 @@ Please add an entry to the "Unreleased changes" section in your pull requests.
8
8
 
9
9
  *Nothing yet*
10
10
 
11
+ === Version 4.1.1
12
+
13
+ - Bugfix related to quoting when building autocomplete queries for date fields (#167)
14
+ - Bugfix related to using polymorphic relations (#168)
15
+
11
16
  === Version 4.1.0
12
17
 
13
18
  - Add support for ActiveRecord and ActionView 5.1
@@ -236,7 +236,7 @@ module ScopedSearch
236
236
  options << 5.days.ago.strftime('%A')
237
237
  options << '"6 days ago"'
238
238
  options << 7.days.ago.strftime('"%b %d,%Y"')
239
- options << '2 weeks from now'
239
+ options << '"2 weeks from now"'
240
240
  options
241
241
  end
242
242
 
@@ -262,6 +262,7 @@ module ScopedSearch
262
262
  def has_many_through_join(field)
263
263
  many_class = field.definition.klass
264
264
  through = definition.reflection_by_name(many_class, field.relation).options[:through]
265
+
265
266
  connection = many_class.connection
266
267
 
267
268
  # table names
@@ -269,9 +270,10 @@ module ScopedSearch
269
270
  many_table_name = many_class.table_name
270
271
  middle_table_name = definition.reflection_by_name(many_class, through).klass.table_name
271
272
 
272
- # primary and foreign keys + optional condition for the many to middle join
273
+ # primary and foreign keys + optional conditions for the joins
273
274
  pk1, fk1 = field.reflection_keys(definition.reflection_by_name(many_class, through))
274
- condition1 = field.reflection_conditions(definition.reflection_by_name(field.klass, middle_table_name))
275
+ condition_many_to_middle = field.reflection_conditions(definition.reflection_by_name(field.klass, many_table_name))
276
+ condition_middle_to_end = field.reflection_conditions(definition.reflection_by_name(field.klass, middle_table_name))
275
277
 
276
278
  # primary and foreign keys + optional condition for the endpoint to middle join
277
279
  middle_table_association = find_has_many_through_association(field, through) || middle_table_name
@@ -281,7 +283,7 @@ module ScopedSearch
281
283
  <<-SQL
282
284
  #{connection.quote_table_name(many_table_name)}
283
285
  INNER JOIN #{connection.quote_table_name(middle_table_name)}
284
- ON #{connection.quote_table_name(many_table_name)}.#{connection.quote_column_name(pk1)} = #{connection.quote_table_name(middle_table_name)}.#{connection.quote_column_name(fk1)} #{condition1}
286
+ ON #{connection.quote_table_name(many_table_name)}.#{connection.quote_column_name(pk1)} = #{connection.quote_table_name(middle_table_name)}.#{connection.quote_column_name(fk1)} #{condition_many_to_middle} #{condition_middle_to_end}
285
287
  INNER JOIN #{connection.quote_table_name(endpoint_table_name)}
286
288
  ON #{connection.quote_table_name(middle_table_name)}.#{connection.quote_column_name(fk2)} = #{connection.quote_table_name(endpoint_table_name)}.#{connection.quote_column_name(pk2)} #{condition2}
287
289
  SQL
@@ -1,3 +1,3 @@
1
1
  module ScopedSearch
2
- VERSION = "4.1.0"
2
+ VERSION = "4.1.1"
3
3
  end
@@ -479,11 +479,11 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
479
479
  ActiveRecord::Migration.create_table(:user_groups) { |t| t.integer :user_id; t.integer :group_id }
480
480
  ActiveRecord::Migration.create_table(:conflicts) { |t| t.integer :group_id; t.integer :user_id }
481
481
  ActiveRecord::Migration.create_table(:groups) { |t| t.string :related; t.integer :user_id }
482
- ActiveRecord::Migration.create_table(:users) { |t| t.string :foo }
482
+ ActiveRecord::Migration.create_table(:users) { |t| t.string :foo; t.string :user_type }
483
483
 
484
484
  # The related classes
485
485
  class UserGroup < ActiveRecord::Base; belongs_to :user; belongs_to :group; end
486
- class Conflict < ActiveRecord::Base; belongs_to :user; belongs_to :group; end
486
+ class Conflict < ActiveRecord::Base; belongs_to :user, :polymorphic => true; belongs_to :group; end
487
487
  class Group < ActiveRecord::Base
488
488
  has_many :user_groups
489
489
  has_many :users, :through => :conflicts, :source_type => 'User', :source => :user
@@ -497,9 +497,9 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
497
497
  scoped_search :relation => :groups, :on => :related
498
498
  end
499
499
 
500
- @user_1 = User.create!(:foo => 'foo')
501
- @user_2 = User.create!(:foo => 'foo too')
502
- @user_3 = User.create!(:foo => 'foo three')
500
+ @user_1 = User.create!(:foo => 'foo', :user_type => 'User')
501
+ @user_2 = User.create!(:foo => 'foo too', :user_type => 'User')
502
+ @user_3 = User.create!(:foo => 'foo three', :user_type => 'User')
503
503
 
504
504
  @group_1 = Group.create(:related => 'value')
505
505
  @group_2 = Group.create(:related => 'value too!')
@@ -524,7 +524,6 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
524
524
  end
525
525
  end
526
526
 
527
-
528
527
  context 'querying a :has_many => :through relation with modules' do
529
528
 
530
529
  before do
@@ -578,5 +577,63 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
578
577
  Zan::Koo.search_for('related=baz AND related="baz too!"').length.should == 1
579
578
  end
580
579
  end
580
+
581
+ context 'querying a :has_many => :through with polymorphism' do
582
+ before do
583
+ ActiveRecord::Migration.create_table(:subnets) { |t| t.string :name }
584
+ ActiveRecord::Migration.create_table(:taxable_taxonomies) { |t| t.integer :taxable_id; t.integer :taxonomy_id; t.string :taxable_type }
585
+ ActiveRecord::Migration.create_table(:taxonomies) { |t| t.string :type; t.string :name }
586
+
587
+ class Subnet < ActiveRecord::Base
588
+ has_many :taxable_taxonomies, :as => :taxable
589
+ has_many :locations, -> { where(:type => 'Location') }, :through => :taxable_taxonomies, :source => :taxonomy
590
+ has_many :organizations, -> { where(:type => 'Organization') }, :through => :taxable_taxonomies, :source => :taxonomy
591
+
592
+ scoped_search :relation => :locations, :on => :id, :rename => :location_id
593
+ scoped_search :relation => :organizations, :on => :id, :rename => :organization_id
594
+ end
595
+
596
+ class TaxableTaxonomy < ActiveRecord::Base
597
+ belongs_to :taxonomy
598
+ belongs_to :taxable, :polymorphic => true
599
+ end
600
+
601
+ class Taxonomy < ActiveRecord::Base
602
+ has_many :taxable_taxonomies
603
+ has_many :subnets, :through => :taxable_taxonomies, :source => :taxable, :source_type => 'Subnet'
604
+ end
605
+
606
+ class Organization < Taxonomy; end
607
+ class Location < Taxonomy; end
608
+
609
+ @loc_a = Location.create!(:name => 'Location A')
610
+ @loc_b = Location.create!(:name => 'Location B')
611
+ @org_a = Organization.create!(:name => 'Organization A')
612
+ @org_b = Organization.create!(:name => 'Organization B')
613
+
614
+ @subnet_a = Subnet.create!(:name => 'Subnet A')
615
+ @subnet_b = Subnet.create!(:name => 'Subnet B')
616
+
617
+
618
+ TaxableTaxonomy.create!(:taxable_id => @subnet_a.id, :taxonomy_id => @loc_a.id, :taxable_type => 'Subnet')
619
+ TaxableTaxonomy.create!(:taxable_id => @subnet_b.id, :taxonomy_id => @loc_b.id, :taxable_type => 'Subnet')
620
+ TaxableTaxonomy.create!(:taxable_id => @subnet_a.id, :taxonomy_id => @org_a.id, :taxable_type => 'Subnet')
621
+ TaxableTaxonomy.create!(:taxable_id => @subnet_b.id, :taxonomy_id => @loc_b.id, :taxable_type => 'Subnet')
622
+ end
623
+
624
+ after do
625
+ ActiveRecord::Migration.drop_table :subnets
626
+ ActiveRecord::Migration.drop_table :taxable_taxonomies
627
+ ActiveRecord::Migration.drop_table :taxonomies
628
+ end
629
+
630
+ it "should find the records based on location id" do
631
+ Subnet.search_for("location_id = #{@loc_a.id}").length.should == 1
632
+ end
633
+
634
+ it "should find the records based on organization id" do
635
+ Subnet.search_for("organization_id = #{@org_a.id}").length.should == 1
636
+ end
637
+ end
581
638
  end
582
639
  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: 4.1.0
4
+ version: 4.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amos Benari
@@ -10,48 +10,48 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-03-29 00:00:00.000000000 Z
13
+ date: 2017-09-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - ">="
19
+ - - '>='
20
20
  - !ruby/object:Gem::Version
21
21
  version: 4.2.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - ">="
26
+ - - '>='
27
27
  - !ruby/object:Gem::Version
28
28
  version: 4.2.0
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: rspec
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - "~>"
33
+ - - ~>
34
34
  - !ruby/object:Gem::Version
35
35
  version: '3.0'
36
36
  type: :development
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - "~>"
40
+ - - ~>
41
41
  - !ruby/object:Gem::Version
42
42
  version: '3.0'
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: rake
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - ">="
47
+ - - '>='
48
48
  - !ruby/object:Gem::Version
49
49
  version: '0'
50
50
  type: :development
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - ">="
54
+ - - '>='
55
55
  - !ruby/object:Gem::Version
56
56
  version: '0'
57
57
  description: |2
@@ -77,8 +77,8 @@ extra_rdoc_files:
77
77
  - CONTRIBUTING.rdoc
78
78
  - LICENSE
79
79
  files:
80
- - ".gitignore"
81
- - ".travis.yml"
80
+ - .gitignore
81
+ - .travis.yml
82
82
  - CHANGELOG.rdoc
83
83
  - CONTRIBUTING.rdoc
84
84
  - Gemfile
@@ -137,27 +137,27 @@ licenses:
137
137
  metadata: {}
138
138
  post_install_message:
139
139
  rdoc_options:
140
- - "--title"
140
+ - --title
141
141
  - scoped_search
142
- - "--main"
142
+ - --main
143
143
  - README.rdoc
144
- - "--line-numbers"
145
- - "--inline-source"
144
+ - --line-numbers
145
+ - --inline-source
146
146
  require_paths:
147
147
  - lib
148
148
  required_ruby_version: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ">="
150
+ - - '>='
151
151
  - !ruby/object:Gem::Version
152
152
  version: 2.0.0
153
153
  required_rubygems_version: !ruby/object:Gem::Requirement
154
154
  requirements:
155
- - - ">="
155
+ - - '>='
156
156
  - !ruby/object:Gem::Version
157
157
  version: '0'
158
158
  requirements: []
159
159
  rubyforge_project:
160
- rubygems_version: 2.6.8
160
+ rubygems_version: 2.0.14.1
161
161
  signing_key:
162
162
  specification_version: 4
163
163
  summary: Easily search you ActiveRecord models with a simple query language using