|
1 | | -RSpec.shared_context 'setup with enforced ordering' do |
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +RSpec.shared_context 'with enforced ordering setup' do |
2 | 4 | let(:ordering) { false } |
3 | | - include_context 'base_setup' do |
| 5 | + include_context 'with base_setup' do |
4 | 6 | let(:proc) { ->(config) { config.ensure_ordering! } } |
5 | 7 | end |
6 | 8 | end |
7 | 9 |
|
8 | | -RSpec.shared_context 'base_setup' do |
| 10 | +RSpec.shared_context 'with base_setup' do |
9 | 11 | subject(:query) { builder.build.to_sql } |
10 | 12 |
|
11 | 13 | let(:model_id) { 1 } |
|
32 | 34 | end |
33 | 35 |
|
34 | 36 | RSpec.shared_examples 'build recursive query' do |
35 | | - context 'simple id' do |
| 37 | + context 'with simple id' do |
36 | 38 | context 'with simple class' do |
37 | | - include_context 'base_setup' do |
| 39 | + include_context 'with base_setup' do |
38 | 40 | let(:model_class) { Node } |
39 | 41 | it_behaves_like 'basic recursive examples' |
40 | 42 | end |
41 | 43 | end |
42 | 44 |
|
43 | 45 | context 'with class with different parent key' do |
44 | | - include_context 'base_setup' do |
| 46 | + include_context 'with base_setup' do |
45 | 47 | let(:model_class) { NodeWithOtherParentKey } |
46 | 48 | it_behaves_like 'basic recursive examples' |
47 | 49 | end |
48 | 50 | end |
49 | 51 |
|
50 | 52 | context 'with Subclass' do |
51 | | - include_context 'base_setup' do |
| 53 | + include_context 'with base_setup' do |
52 | 54 | let(:model_class) { Floor } |
53 | 55 | it_behaves_like 'basic recursive examples' |
54 | 56 | end |
55 | 57 | end |
56 | 58 |
|
57 | 59 | context 'with polymorphic parent relation' do |
58 | | - include_context 'base_setup' do |
| 60 | + include_context 'with base_setup' do |
59 | 61 | let(:model_class) { NodeWithPolymorphicParent } |
60 | 62 | it_behaves_like 'basic recursive examples' |
61 | 63 | end |
|
64 | 66 | end |
65 | 67 |
|
66 | 68 | RSpec.shared_examples 'ancestor query' do |
67 | | - include_context 'base_setup' |
| 69 | + include_context 'with base_setup' |
68 | 70 |
|
69 | 71 | 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}"/) } |
70 | 72 | end |
71 | 73 |
|
72 | 74 | RSpec.shared_examples 'descendant query' do |
73 | | - include_context 'base_setup' |
| 75 | + include_context 'with base_setup' |
74 | 76 |
|
75 | 77 | 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}"/) } |
76 | 78 | it { is_expected.to match(/#{Regexp.escape(builder.travers_loc_table.project(builder.travers_loc_table[model_class.primary_key]).to_sql)}/) } |
77 | 79 | end |
78 | 80 |
|
79 | | -RSpec.shared_context 'context with ordering' do |
80 | | - include_context 'base_setup' do |
81 | | - it_behaves_like 'with ordering' |
| 81 | +RSpec.shared_context 'with ordering' do |
| 82 | + include_context 'with base_setup' do |
| 83 | + it_behaves_like 'is adding ordering' |
82 | 84 | end |
83 | 85 | end |
84 | 86 |
|
85 | | -RSpec.shared_context 'context without ordering' do |
86 | | - include_context 'base_setup' do |
87 | | - it_behaves_like 'without ordering' |
| 87 | +RSpec.shared_context 'without ordering' do |
| 88 | + include_context 'with base_setup' do |
| 89 | + it_behaves_like 'not adding ordering' |
88 | 90 | end |
89 | 91 | end |
90 | 92 |
|
91 | | -RSpec.shared_examples 'with ordering' do |
| 93 | +RSpec.shared_examples 'is adding ordering' do |
92 | 94 | it { is_expected.to match(/ORDER BY #{Regexp.escape(builder.recursive_temp_table[model_class._recursive_tree_config.depth_column].asc.to_sql)}/) } |
93 | 95 | end |
94 | 96 |
|
95 | | -RSpec.shared_examples 'without ordering' do |
| 97 | +RSpec.shared_examples 'not adding ordering' do |
96 | 98 | it { is_expected.not_to match(/ORDER BY/) } |
97 | 99 | end |
0 commit comments