acts_as_recursive_tree 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +321 -0
- data/CHANGELOG.md +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +175 -0
- data/Rakefile +15 -0
- data/acts_as_recursive_tree.gemspec +30 -0
- data/lib/acts_as_recursive_tree/acts_macro.rb +28 -0
- data/lib/acts_as_recursive_tree/associations.rb +25 -0
- data/lib/acts_as_recursive_tree/builders/ancestors.rb +17 -0
- data/lib/acts_as_recursive_tree/builders/descendants.rb +9 -0
- data/lib/acts_as_recursive_tree/builders/leaves.rb +26 -0
- data/lib/acts_as_recursive_tree/builders/relation_builder.rb +121 -0
- data/lib/acts_as_recursive_tree/builders.rb +13 -0
- data/lib/acts_as_recursive_tree/model.rb +125 -0
- data/lib/acts_as_recursive_tree/options/depth_condition.rb +48 -0
- data/lib/acts_as_recursive_tree/options/query_options.rb +21 -0
- data/lib/acts_as_recursive_tree/options/values.rb +77 -0
- data/lib/acts_as_recursive_tree/options.rb +9 -0
- data/lib/acts_as_recursive_tree/railtie.rb +9 -0
- data/lib/acts_as_recursive_tree/scopes.rb +16 -0
- data/lib/acts_as_recursive_tree/version.rb +3 -0
- data/lib/acts_as_recursive_tree.rb +14 -0
- data/spec/builders_spec.rb +136 -0
- data/spec/db/database.rb +22 -0
- data/spec/db/database.yml +12 -0
- data/spec/db/models.rb +37 -0
- data/spec/db/schema.rb +34 -0
- data/spec/model/location_spec.rb +55 -0
- data/spec/model/node_spec.rb +129 -0
- data/spec/model/relation_spec.rb +63 -0
- data/spec/spec_helper.rb +119 -0
- data/spec/values_spec.rb +86 -0
- metadata +182 -0
data/spec/db/models.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
ActiveRecord::Base.class_exec do
|
2
|
+
extend ActsAsRecursiveTree::ActsMacro
|
3
|
+
end
|
4
|
+
|
5
|
+
class Node < ActiveRecord::Base
|
6
|
+
acts_as_tree
|
7
|
+
has_one :node_info
|
8
|
+
end
|
9
|
+
|
10
|
+
class NodeInfo < ActiveRecord::Base
|
11
|
+
belongs_to :node
|
12
|
+
end
|
13
|
+
|
14
|
+
class NodeWithPolymorphicParent < ActiveRecord::Base
|
15
|
+
acts_as_tree parent_key: :other_id, parent_type_column: :other_type
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
class NodeWithOtherParentKey < ActiveRecord::Base
|
20
|
+
acts_as_tree parent_key: :other_id
|
21
|
+
end
|
22
|
+
|
23
|
+
class Location < ActiveRecord::Base
|
24
|
+
acts_as_tree
|
25
|
+
end
|
26
|
+
|
27
|
+
class Building < Location
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
class Floor < Location
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
class Room < Location
|
36
|
+
|
37
|
+
end
|
data/spec/db/schema.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
ActiveRecord::Schema.define(:version => 0) do
|
4
|
+
|
5
|
+
create_table :nodes do |t|
|
6
|
+
t.integer :parent_id
|
7
|
+
t.string :name
|
8
|
+
t.boolean :active, default: true
|
9
|
+
end
|
10
|
+
|
11
|
+
add_foreign_key(:nodes, :nodes, column: :parent_id)
|
12
|
+
|
13
|
+
create_table :node_infos do |t|
|
14
|
+
t.belongs_to :node
|
15
|
+
t.string :status
|
16
|
+
end
|
17
|
+
|
18
|
+
create_table :node_with_other_parent_keys do |t|
|
19
|
+
t.integer :other_id
|
20
|
+
end
|
21
|
+
|
22
|
+
create_table :node_with_polymorphic_parents do |t|
|
23
|
+
t.integer :other_id
|
24
|
+
t.string :other_type
|
25
|
+
end
|
26
|
+
|
27
|
+
create_table :locations do |t|
|
28
|
+
t.integer :parent_id
|
29
|
+
t.string :name
|
30
|
+
t.string :type
|
31
|
+
end
|
32
|
+
|
33
|
+
add_foreign_key(:locations, :locations, column: :parent_id)
|
34
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Location do
|
4
|
+
before do
|
5
|
+
@building = Building.create!(name: 'big house')
|
6
|
+
|
7
|
+
1.upto(5) do |index|
|
8
|
+
floor = Floor.create!(name: "#{index}. Floor")
|
9
|
+
|
10
|
+
@building.children << floor
|
11
|
+
|
12
|
+
1.upto(5) do |index_room|
|
13
|
+
|
14
|
+
floor.children << Room.create!(name: "#{index_room}. Room")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'building' do
|
20
|
+
it 'has 30 descendants' do
|
21
|
+
expect(@building.descendants.count).to eq(5 + (5 * 5))
|
22
|
+
end
|
23
|
+
|
24
|
+
context '::descendants_of' do
|
25
|
+
|
26
|
+
context 'with Room' do
|
27
|
+
let(:rooms) { Room.descendants_of(@building) }
|
28
|
+
|
29
|
+
it 'should have 25 rooms' do
|
30
|
+
expect(rooms.count).to eq(25)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should all be of type Room' do
|
34
|
+
expect(rooms.all).to all(be_an(Room))
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'with Floor' do
|
40
|
+
let(:floors) { Floor.descendants_of(@building) }
|
41
|
+
|
42
|
+
it 'should have 5 Floors' do
|
43
|
+
expect(floors.count).to eq(5)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should all be of type Floor' do
|
47
|
+
expect(floors.all).to all(be_an(Floor))
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Node do
|
4
|
+
|
5
|
+
def create_tree(max_level, current_level = 0, node = nil)
|
6
|
+
|
7
|
+
if node.nil?
|
8
|
+
node = Node.create!(name: 'root')
|
9
|
+
end
|
10
|
+
|
11
|
+
1.upto(max_level - current_level) do |index|
|
12
|
+
child = node.children.create!(name: "child #{index} - level #{current_level}")
|
13
|
+
create_tree(max_level, current_level + 1, child)
|
14
|
+
end
|
15
|
+
|
16
|
+
node
|
17
|
+
end
|
18
|
+
|
19
|
+
before do
|
20
|
+
@root = create_tree(3)
|
21
|
+
@child = @root.children.first
|
22
|
+
end
|
23
|
+
|
24
|
+
context '#children' do
|
25
|
+
it 'should have 3 children' do
|
26
|
+
expect(@root.children.count).to eql(3)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should not include root node ' do
|
30
|
+
expect(@root.children).to_not include(@root)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
context '#descendants' do
|
36
|
+
|
37
|
+
it 'should have 15 descendants' do
|
38
|
+
expect(@root.descendants.count).to eql(3 + (3 * 2) + (3 * 2 * 1))
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should not include root' do
|
42
|
+
expect(@root.descendants).to_not include(@root)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
context '#self_and_descendants' do
|
46
|
+
|
47
|
+
it 'should have 15 descendants and self' do
|
48
|
+
expect(@root.self_and_descendants.count).to eql(@root.descendants.count + 1)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should include self' do
|
52
|
+
expect(@root.self_and_descendants.all).to include(@root)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context '#root?' do
|
57
|
+
|
58
|
+
it 'should be true for root node' do
|
59
|
+
expect(@root.root?).to be_truthy
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should be false for children' do
|
63
|
+
expect(@child.root?).to be_falsey
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
context '#leaf?' do
|
69
|
+
|
70
|
+
it 'should be false for root node' do
|
71
|
+
expect(@root.leaf?).to be_falsey
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should be true for children' do
|
75
|
+
expect(@root.leaves.first.leaf?).to be_truthy
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
context '#leaves' do
|
82
|
+
it 'should have 6 leaves' do
|
83
|
+
expect(@root.leaves.count).to eql(6)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe 'child' do
|
88
|
+
|
89
|
+
it 'should have root as parent' do
|
90
|
+
expect(@child.parent).to eql(@root)
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should have 1 ancestor' do
|
94
|
+
expect(@child.ancestors.count).to eql(1)
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'should have root as only ancestor' do
|
98
|
+
expect(@child.ancestors.first).to eql(@root)
|
99
|
+
end
|
100
|
+
|
101
|
+
it '#root should return root' do
|
102
|
+
expect(@child.root).to eql(@root)
|
103
|
+
end
|
104
|
+
|
105
|
+
it '#root? should be false' do
|
106
|
+
expect(@child.root?).to be false
|
107
|
+
end
|
108
|
+
|
109
|
+
it '#leaf? should be false' do
|
110
|
+
expect(@child.leaf?).to be false
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
describe 'scopes' do
|
116
|
+
|
117
|
+
context 'roots' do
|
118
|
+
|
119
|
+
it 'has only one root node' do
|
120
|
+
expect(Node.roots.count).to eql(1)
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'is the @root node' do
|
124
|
+
expect(Node.roots.first).to eql(@root)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Relation' do
|
4
|
+
|
5
|
+
def create_tree(max_level, current_level: 0, node: nil, stop_at: nil)
|
6
|
+
|
7
|
+
if node.nil?
|
8
|
+
node = Node.create!(name: 'root')
|
9
|
+
end
|
10
|
+
|
11
|
+
1.upto(max_level - current_level) do |index|
|
12
|
+
child = node.children.create!(name: "child #{index} - level #{current_level}", active: stop_at > current_level)
|
13
|
+
child.create_node_info(status: stop_at > current_level ? 'foo' : 'bar')
|
14
|
+
create_tree(max_level, current_level: current_level + 1, node: child, stop_at: stop_at)
|
15
|
+
end
|
16
|
+
|
17
|
+
node
|
18
|
+
end
|
19
|
+
|
20
|
+
before do
|
21
|
+
@root = create_tree(4, stop_at: 2)
|
22
|
+
@child = @root.children.first
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'descendants' do
|
26
|
+
|
27
|
+
it 'works with simple relation' do
|
28
|
+
desc = @root.descendants { |opts| opts.condition = Node.where(active: true) }
|
29
|
+
desc.all.each do |node|
|
30
|
+
expect(node.active).to be_truthy
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'works with joins relation' do
|
35
|
+
desc = @root.descendants { |opts| opts.condition = Node.joins(:node_info).where.not(node_infos: { status: 'bar' }) }
|
36
|
+
desc.all.each do |node|
|
37
|
+
expect(node.node_info.status).to eql('foo')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'ancestors' do
|
43
|
+
|
44
|
+
it 'works with simple relation' do
|
45
|
+
ancestors = @root.leaves.first.ancestors { |opts| opts.condition = Node.where(active: false) }.to_a
|
46
|
+
|
47
|
+
ancestors.each do |node|
|
48
|
+
expect(node.active).to be_falsey
|
49
|
+
end
|
50
|
+
|
51
|
+
expect(ancestors).to_not include(@root)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'works with joins relation' do
|
55
|
+
ancestors = @root.leaves.first.ancestors { |opts| opts.condition = Node.joins(:node_info).where.not(node_infos: { status: 'foo' }) }
|
56
|
+
ancestors.all.each do |node|
|
57
|
+
expect(node.node_info.status).to eql('bar')
|
58
|
+
end
|
59
|
+
expect(ancestors).to_not include(@root)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
|
2
|
+
|
3
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
|
4
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
5
|
+
require 'active_record'
|
6
|
+
|
7
|
+
require 'acts_as_recursive_tree'
|
8
|
+
require_relative 'db/database'
|
9
|
+
|
10
|
+
require 'database_cleaner'
|
11
|
+
|
12
|
+
|
13
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
14
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
15
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
16
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
17
|
+
# files.
|
18
|
+
#
|
19
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
20
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
21
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
22
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
23
|
+
# a separate helper file that requires the additional dependencies and performs
|
24
|
+
# the additional setup, and require it from the spec files that actually need
|
25
|
+
# it.
|
26
|
+
#
|
27
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
28
|
+
# users commonly want.
|
29
|
+
#
|
30
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
31
|
+
RSpec.configure do |config|
|
32
|
+
# rspec-expectations config goes here. You can use an alternate
|
33
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
34
|
+
# assertions if you prefer.
|
35
|
+
config.expect_with :rspec do |expectations|
|
36
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
37
|
+
# and `failure_message` of custom matchers include text for helper methods
|
38
|
+
# defined using `chain`, e.g.:
|
39
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
40
|
+
# # => "be bigger than 2 and smaller than 4"
|
41
|
+
# ...rather than:
|
42
|
+
# # => "be bigger than 2"
|
43
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
44
|
+
end
|
45
|
+
|
46
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
47
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
48
|
+
config.mock_with :rspec do |mocks|
|
49
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
50
|
+
# a real object. This is generally recommended, and will default to
|
51
|
+
# `true` in RSpec 4.
|
52
|
+
mocks.verify_partial_doubles = true
|
53
|
+
end
|
54
|
+
|
55
|
+
# The settings below are suggested to provide a good initial experience
|
56
|
+
# with RSpec, but feel free to customize to your heart's content.
|
57
|
+
=begin
|
58
|
+
# These two settings work together to allow you to limit a spec run
|
59
|
+
# to individual examples or groups you care about by tagging them with
|
60
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
61
|
+
# get run.
|
62
|
+
config.filter_run :focus
|
63
|
+
config.run_all_when_everything_filtered = true
|
64
|
+
|
65
|
+
# Allows RSpec to persist some state between runs in order to support
|
66
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
67
|
+
# you configure your source control system to ignore this file.
|
68
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
69
|
+
|
70
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
71
|
+
# recommended. For more details, see:
|
72
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
73
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
74
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
75
|
+
config.disable_monkey_patching!
|
76
|
+
|
77
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
78
|
+
# be too noisy due to issues in dependencies.
|
79
|
+
config.warnings = true
|
80
|
+
|
81
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
82
|
+
# file, and it's useful to allow more verbose output when running an
|
83
|
+
# individual spec file.
|
84
|
+
if config.files_to_run.one?
|
85
|
+
# Use the documentation formatter for detailed output,
|
86
|
+
# unless a formatter has already been configured
|
87
|
+
# (e.g. via a command-line flag).
|
88
|
+
config.default_formatter = 'doc'
|
89
|
+
end
|
90
|
+
|
91
|
+
# Print the 10 slowest examples and example groups at the
|
92
|
+
# end of the spec run, to help surface which specs are running
|
93
|
+
# particularly slow.
|
94
|
+
config.profile_examples = 10
|
95
|
+
|
96
|
+
# Run specs in random order to surface order dependencies. If you find an
|
97
|
+
# order dependency and want to debug it, you can fix the order by providing
|
98
|
+
# the seed, which is printed after each run.
|
99
|
+
# --seed 1234
|
100
|
+
config.order = :random
|
101
|
+
|
102
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
103
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
104
|
+
# test failures related to randomization by passing the same `--seed` value
|
105
|
+
# as the one that triggered the failure.
|
106
|
+
Kernel.srand config.seed
|
107
|
+
=end
|
108
|
+
|
109
|
+
config.before(:suite) do
|
110
|
+
DatabaseCleaner.strategy = :transaction
|
111
|
+
DatabaseCleaner.clean_with(:truncation)
|
112
|
+
end
|
113
|
+
|
114
|
+
config.around(:each) do |example|
|
115
|
+
DatabaseCleaner.cleaning do
|
116
|
+
example.run
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
data/spec/values_spec.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'single values' do
|
4
|
+
subject(:value) { described_class.create(single_value) }
|
5
|
+
|
6
|
+
it { is_expected.to be_a ActsAsRecursiveTree::Options::Values::SingleValue }
|
7
|
+
|
8
|
+
it 'should apply_to' do
|
9
|
+
expect(value.apply_to(attribute).to_sql).to end_with " = #{single_value}"
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should apply_negated_to' do
|
13
|
+
expect(value.apply_negated_to(attribute).to_sql).to end_with " != #{single_value}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe ActsAsRecursiveTree::Options::Values do
|
18
|
+
let(:table) { Arel::Table.new('test_table') }
|
19
|
+
let(:attribute) { table['test_attr'] }
|
20
|
+
|
21
|
+
context 'invalid agurment' do
|
22
|
+
it 'should raise exception' do
|
23
|
+
expect{described_class.create(nil)}.to raise_exception /is not supported/
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'single value' do
|
28
|
+
let(:single_value) { 3 }
|
29
|
+
|
30
|
+
it_behaves_like 'single values' do
|
31
|
+
let(:value_obj) { single_value }
|
32
|
+
end
|
33
|
+
|
34
|
+
it_behaves_like 'single values' do
|
35
|
+
let(:value_obj) { Node.new(id: single_value) }
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'multi value' do
|
41
|
+
context 'Array' do
|
42
|
+
let(:array) { [1, 2, 3] }
|
43
|
+
subject(:value) { described_class.create(array) }
|
44
|
+
|
45
|
+
it { is_expected.to be_a ActsAsRecursiveTree::Options::Values::MultiValue }
|
46
|
+
|
47
|
+
it 'should apply_to' do
|
48
|
+
expect(value.apply_to(attribute).to_sql).to end_with " IN (#{array.join(', ')})"
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should apply_negated_to' do
|
52
|
+
expect(value.apply_negated_to(attribute).to_sql).to end_with " NOT IN (#{array.join(', ')})"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'Range' do
|
57
|
+
let(:range) { 1..3 }
|
58
|
+
subject(:value) { described_class.create(range) }
|
59
|
+
|
60
|
+
it { is_expected.to be_a ActsAsRecursiveTree::Options::Values::MultiValue }
|
61
|
+
|
62
|
+
it 'should apply_to' do
|
63
|
+
expect(value.apply_to(attribute).to_sql).to end_with "BETWEEN #{range.begin} AND #{range.end}"
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should apply_negated_to' do
|
67
|
+
expect(value.apply_negated_to(attribute).to_sql).to match /< #{range.begin} OR.* > #{range.end}/
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'Relation' do
|
72
|
+
let(:relation) { Node.where(name: 'test') }
|
73
|
+
subject(:value) { described_class.create(relation, OpenStruct.new(primary_key: :id)) }
|
74
|
+
|
75
|
+
it { is_expected.to be_a ActsAsRecursiveTree::Options::Values::Relation }
|
76
|
+
|
77
|
+
it 'should apply_to' do
|
78
|
+
expect(value.apply_to(attribute).to_sql).to match /IN \(SELECT.*\)/
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'should apply_negated_to' do
|
82
|
+
expect(value.apply_negated_to(attribute).to_sql).to match /NOT IN \(SELECT.*\)/
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
metadata
ADDED
@@ -0,0 +1,182 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acts_as_recursive_tree
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Wolfgang Wedelich-John
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.0.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 6.0.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 5.0.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 6.0.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bundler
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.7'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.7'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: database_cleaner
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.5.0
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 1.5.0
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rake
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '10.0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '10.0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rspec-rails
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 3.5.0
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 3.5.0
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: sqlite3
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 1.3.10
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 1.3.10
|
103
|
+
description: "\n This is a ruby gem that provides drop in replacement for acts_as_tree
|
104
|
+
but makes use of SQL recursive statement. Be sure to have a DBMS that supports recursive
|
105
|
+
queries when using this gem (e.g. PostgreSQL or SQLite). "
|
106
|
+
email:
|
107
|
+
- wolfgang.wedelich@1und1.de
|
108
|
+
executables: []
|
109
|
+
extensions: []
|
110
|
+
extra_rdoc_files: []
|
111
|
+
files:
|
112
|
+
- ".gitignore"
|
113
|
+
- ".rspec"
|
114
|
+
- ".rubocop.yml"
|
115
|
+
- ".rubocop_todo.yml"
|
116
|
+
- CHANGELOG.md
|
117
|
+
- Gemfile
|
118
|
+
- LICENSE.txt
|
119
|
+
- README.md
|
120
|
+
- Rakefile
|
121
|
+
- acts_as_recursive_tree.gemspec
|
122
|
+
- lib/acts_as_recursive_tree.rb
|
123
|
+
- lib/acts_as_recursive_tree/acts_macro.rb
|
124
|
+
- lib/acts_as_recursive_tree/associations.rb
|
125
|
+
- lib/acts_as_recursive_tree/builders.rb
|
126
|
+
- lib/acts_as_recursive_tree/builders/ancestors.rb
|
127
|
+
- lib/acts_as_recursive_tree/builders/descendants.rb
|
128
|
+
- lib/acts_as_recursive_tree/builders/leaves.rb
|
129
|
+
- lib/acts_as_recursive_tree/builders/relation_builder.rb
|
130
|
+
- lib/acts_as_recursive_tree/model.rb
|
131
|
+
- lib/acts_as_recursive_tree/options.rb
|
132
|
+
- lib/acts_as_recursive_tree/options/depth_condition.rb
|
133
|
+
- lib/acts_as_recursive_tree/options/query_options.rb
|
134
|
+
- lib/acts_as_recursive_tree/options/values.rb
|
135
|
+
- lib/acts_as_recursive_tree/railtie.rb
|
136
|
+
- lib/acts_as_recursive_tree/scopes.rb
|
137
|
+
- lib/acts_as_recursive_tree/version.rb
|
138
|
+
- spec/builders_spec.rb
|
139
|
+
- spec/db/database.rb
|
140
|
+
- spec/db/database.yml
|
141
|
+
- spec/db/models.rb
|
142
|
+
- spec/db/schema.rb
|
143
|
+
- spec/model/location_spec.rb
|
144
|
+
- spec/model/node_spec.rb
|
145
|
+
- spec/model/relation_spec.rb
|
146
|
+
- spec/spec_helper.rb
|
147
|
+
- spec/values_spec.rb
|
148
|
+
homepage: https://github.com/1and1/acts_as_recursive_tree
|
149
|
+
licenses:
|
150
|
+
- MIT
|
151
|
+
metadata: {}
|
152
|
+
post_install_message:
|
153
|
+
rdoc_options: []
|
154
|
+
require_paths:
|
155
|
+
- lib
|
156
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - ">="
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: 2.0.0
|
161
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
requirements: []
|
167
|
+
rubyforge_project:
|
168
|
+
rubygems_version: 2.6.14
|
169
|
+
signing_key:
|
170
|
+
specification_version: 4
|
171
|
+
summary: Drop in replacement for acts_as_tree but using recursive queries
|
172
|
+
test_files:
|
173
|
+
- spec/builders_spec.rb
|
174
|
+
- spec/db/database.rb
|
175
|
+
- spec/db/database.yml
|
176
|
+
- spec/db/models.rb
|
177
|
+
- spec/db/schema.rb
|
178
|
+
- spec/model/location_spec.rb
|
179
|
+
- spec/model/node_spec.rb
|
180
|
+
- spec/model/relation_spec.rb
|
181
|
+
- spec/spec_helper.rb
|
182
|
+
- spec/values_spec.rb
|