activerecord-hierarchical_query 0.1.4 → 0.1.5

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: fb06a2b6a2d1c5e9d77bdcae7bcd93fc648a1d0f
4
- data.tar.gz: 0a88b8b0bb779d4bab7395b02818574c7b2559dd
3
+ metadata.gz: 1549f26e6ece270b3daacb073b2a817bfd1af1fa
4
+ data.tar.gz: 8138b6f92c03fb569464026187be7a8f16d4b52d
5
5
  SHA512:
6
- metadata.gz: 4ae72dfaa66ce34d6a83967367afcf4d5b74883e77da4bc0b909c82d0a4fab442cd7b237e2dba8f9dc6fe6f3baa5eb2a2fbd3b297bc1481dc1a249f3110385de
7
- data.tar.gz: d40b2571939dfb11d7579f62f03da854444bdb6555638db67b9fc735b386b5b900fec7f8aaf054b5566abcf91ab8a35b5a1b38a6616e3eefd03e663917a167b1
6
+ metadata.gz: 9873c2dd645746f3d42bdcee30e77dd30e5bf0a2df2a3bb7446f978a48614feeb9b713e3c199f6c8c1a3429127f9a2851096d3bb18522faf79bff9e1065d7b62
7
+ data.tar.gz: 43272bdb02606a2b32f32b5bf282758418727fd911b98bcd0fdb8d7cdb3a4199558c1f4e96a8006511e5d11c2e5f9236dcfba9020b74d57459708e0cd8796b3b
@@ -29,7 +29,8 @@ module ActiveRecord
29
29
  @scope ||= query.
30
30
  start_with_value.
31
31
  select(columns).
32
- except(*DISALLOWED_CLAUSES)
32
+ except(*DISALLOWED_CLAUSES).
33
+ reorder(nil)
33
34
  end
34
35
 
35
36
  def columns
@@ -51,4 +52,4 @@ module ActiveRecord
51
52
  end # class NonRecursiveTerm
52
53
  end
53
54
  end
54
- end
55
+ end
@@ -25,7 +25,7 @@ module ActiveRecord
25
25
 
26
26
  private
27
27
  def scope
28
- @scope ||= query.child_scope_value.select(columns)
28
+ @scope ||= query.child_scope_value.select(columns).reorder(nil)
29
29
  end
30
30
 
31
31
  def columns
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module HierarchicalQuery
3
- VERSION = '0.1.4'
3
+ VERSION = '0.1.5'
4
4
  end
5
5
  end
@@ -330,4 +330,22 @@ describe ActiveRecord::HierarchicalQuery do
330
330
  expect(result).to include(article)
331
331
  end
332
332
  end
333
+
334
+ describe 'Models with default scope' do
335
+ let!(:scoped_root) { ModelWithDefaultScope.create!(name: '9. Root') }
336
+ let!(:scoped_child_1) { ModelWithDefaultScope.create!(name: '8. Child', parent: scoped_root) }
337
+ let!(:scoped_child_2) { ModelWithDefaultScope.create!(name: '7. Child', parent: scoped_root) }
338
+
339
+ subject(:result) {
340
+ ModelWithDefaultScope.join_recursive do |query|
341
+ query
342
+ .connect_by(id: :parent_id)
343
+ .start_with(id: scoped_root.id)
344
+ end
345
+ }
346
+
347
+ it 'applies default scope to outer query without affecting recursive terms' do
348
+ expect(result).to eq [scoped_child_2, scoped_child_1, scoped_root]
349
+ end
350
+ end
333
351
  end
data/spec/schema.rb CHANGED
@@ -13,4 +13,9 @@ ActiveRecord::Schema.define(version: 0) do
13
13
  t.column :category_id, :integer
14
14
  t.column :title, :string
15
15
  end
16
+
17
+ create_table :model_with_default_scopes, force: true do |t|
18
+ t.column :parent_id, :integer
19
+ t.column :name, :string
20
+ end
16
21
  end
@@ -42,3 +42,9 @@ end
42
42
  class Article < ActiveRecord::Base
43
43
  belongs_to :category
44
44
  end
45
+
46
+ class ModelWithDefaultScope < ActiveRecord::Base
47
+ belongs_to :parent, class_name: 'ModelWithDefaultScope'
48
+
49
+ default_scope -> { order('name ASC') }
50
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-hierarchical_query
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexei Mikhailov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-15 00:00:00.000000000 Z
11
+ date: 2016-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord