|
1 | | -# frozen_string_literal: true |
2 | 1 |
|
3 | | -require 'spec_helper' |
4 | | - |
5 | | -shared_context 'setup with enforced ordering' do |
| 2 | +RSpec.shared_context 'setup with enforced ordering' do |
6 | 3 | let(:ordering) { false } |
7 | 4 | include_context 'base_setup' do |
8 | 5 | let(:proc) { ->(config) { config.ensure_ordering! } } |
9 | 6 | end |
10 | 7 | end |
11 | 8 |
|
12 | | -shared_context 'base_setup' do |
| 9 | +RSpec.shared_context 'base_setup' do |
13 | 10 | subject(:query) { builder.build.to_sql } |
14 | 11 |
|
15 | 12 | let(:model_id) { 1 } |
|
21 | 18 | end |
22 | 19 | end |
23 | 20 |
|
24 | | -shared_examples 'basic recursive examples' do |
| 21 | +RSpec.shared_examples 'basic recursive examples' do |
25 | 22 | it { is_expected.to start_with "SELECT \"#{model_class.table_name}\".* FROM \"#{model_class.table_name}\"" } |
26 | 23 |
|
27 | 24 | it { is_expected.to match(/WHERE "#{model_class.table_name}"."#{model_class.primary_key}" = #{model_id}/) } |
|
35 | 32 | } |
36 | 33 | end |
37 | 34 |
|
38 | | -shared_examples 'build recursive query' do |
| 35 | +RSpec.shared_examples 'build recursive query' do |
39 | 36 | context 'simple id' do |
40 | 37 | context 'with simple class' do |
41 | 38 | include_context 'base_setup' do |
|
67 | 64 | end |
68 | 65 | end |
69 | 66 |
|
70 | | -shared_examples 'ancestor query' do |
| 67 | +RSpec.shared_examples 'ancestor query' do |
71 | 68 | include_context 'base_setup' |
72 | 69 |
|
73 | 70 | it { is_expected.to match(/"#{builder.travers_loc_table.name}"."#{model_class._recursive_tree_config.parent_key}" = "#{model_class.table_name}"."#{model_class.primary_key}"/) } |
74 | 71 | end |
75 | 72 |
|
76 | | -shared_examples 'descendant query' do |
| 73 | +RSpec.shared_examples 'descendant query' do |
77 | 74 | include_context 'base_setup' |
78 | 75 |
|
79 | 76 | it { is_expected.to match(/"#{model_class.table_name}"."#{model_class._recursive_tree_config.parent_key}" = "#{builder.travers_loc_table.name}"."#{model_class.primary_key}"/) } |
80 | 77 | it { is_expected.to match(/#{Regexp.escape(builder.travers_loc_table.project(builder.travers_loc_table[model_class.primary_key]).to_sql)}/) } |
81 | 78 | end |
82 | 79 |
|
83 | | -shared_context 'context with ordering' do |
| 80 | +RSpec.shared_context 'context with ordering' do |
84 | 81 | include_context 'base_setup' do |
85 | 82 | it_behaves_like 'with ordering' |
86 | 83 | end |
87 | 84 | end |
88 | 85 |
|
89 | | -shared_context 'context without ordering' do |
| 86 | +RSpec.shared_context 'context without ordering' do |
90 | 87 | include_context 'base_setup' do |
91 | 88 | it_behaves_like 'without ordering' |
92 | 89 | end |
93 | 90 | end |
94 | 91 |
|
95 | | -shared_examples 'with ordering' do |
| 92 | +RSpec.shared_examples 'with ordering' do |
96 | 93 | it { is_expected.to match(/ORDER BY #{Regexp.escape(builder.recursive_temp_table[model_class._recursive_tree_config.depth_column].asc.to_sql)}/) } |
97 | 94 | end |
98 | 95 |
|
99 | | -shared_examples 'without ordering' do |
| 96 | +RSpec.shared_examples 'without ordering' do |
100 | 97 | it { is_expected.not_to match(/ORDER BY/) } |
101 | 98 | end |
102 | | - |
103 | | -describe ActsAsRecursiveTree::Builders::Descendants do |
104 | | - context 'basic' do |
105 | | - it_behaves_like 'build recursive query' |
106 | | - it_behaves_like 'descendant query' |
107 | | - include_context 'context without ordering' |
108 | | - end |
109 | | - |
110 | | - context 'with options' do |
111 | | - include_context 'setup with enforced ordering' do |
112 | | - let(:ordering) { true } |
113 | | - it_behaves_like 'with ordering' |
114 | | - end |
115 | | - end |
116 | | -end |
117 | | - |
118 | | -describe ActsAsRecursiveTree::Builders::Ancestors do |
119 | | - context 'basic' do |
120 | | - it_behaves_like 'build recursive query' |
121 | | - it_behaves_like 'ancestor query' |
122 | | - include_context 'context with ordering' |
123 | | - end |
124 | | - |
125 | | - context 'with options' do |
126 | | - include_context 'setup with enforced ordering' do |
127 | | - it_behaves_like 'with ordering' |
128 | | - end |
129 | | - end |
130 | | -end |
131 | | - |
132 | | -describe ActsAsRecursiveTree::Builders::Leaves do |
133 | | - context 'basic' do |
134 | | - it_behaves_like 'build recursive query' |
135 | | - it_behaves_like 'descendant query' |
136 | | - include_context 'context without ordering' |
137 | | - end |
138 | | - |
139 | | - context 'with options' do |
140 | | - include_context 'setup with enforced ordering' do |
141 | | - let(:ordering) { true } |
142 | | - it_behaves_like 'without ordering' |
143 | | - end |
144 | | - end |
145 | | -end |
0 commit comments