Skip to content

Commit a128467

Browse files
committed
Test cleanup
1 parent 8e1049f commit a128467

File tree

9 files changed

+80
-74
lines changed

9 files changed

+80
-74
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
RSpec.describe ActsAsRecursiveTree::Builders::Ancestors do
6+
context 'basic' do
7+
it_behaves_like 'build recursive query'
8+
it_behaves_like 'ancestor query'
9+
include_context 'context with ordering'
10+
end
11+
12+
context 'with options' do
13+
include_context 'setup with enforced ordering' do
14+
it_behaves_like 'with ordering'
15+
end
16+
end
17+
end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
RSpec.describe ActsAsRecursiveTree::Builders::Descendants do
6+
context 'basic' do
7+
it_behaves_like 'build recursive query'
8+
it_behaves_like 'descendant query'
9+
include_context 'context without ordering'
10+
end
11+
12+
context 'with options' do
13+
include_context 'setup with enforced ordering' do
14+
let(:ordering) { true }
15+
it_behaves_like 'with ordering'
16+
end
17+
end
18+
end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
RSpec.describe ActsAsRecursiveTree::Builders::Leaves do
6+
context 'basic' do
7+
it_behaves_like 'build recursive query'
8+
it_behaves_like 'descendant query'
9+
include_context 'context without ordering'
10+
end
11+
12+
context 'with options' do
13+
include_context 'setup with enforced ordering' do
14+
let(:ordering) { true }
15+
it_behaves_like 'without ordering'
16+
end
17+
end
18+
end

spec/values_spec.rb renamed to spec/acts_as_recursive_tree/options/values_spec.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22

33
require 'spec_helper'
44

5-
shared_examples 'single values' do
6-
subject(:value) { described_class.create(single_value) }
5+
RSpec.describe ActsAsRecursiveTree::Options::Values do
6+
shared_examples 'single values' do
7+
subject(:value) { described_class.create(single_value) }
78

8-
it { is_expected.to be_a ActsAsRecursiveTree::Options::Values::SingleValue }
9+
it { is_expected.to be_a described_class::SingleValue }
910

10-
it 'apply_toes' do
11-
expect(value.apply_to(attribute).to_sql).to end_with " = #{single_value}"
12-
end
11+
it 'apply_toes' do
12+
expect(value.apply_to(attribute).to_sql).to end_with " = #{single_value}"
13+
end
1314

14-
it 'apply_negated_toes' do
15-
expect(value.apply_negated_to(attribute).to_sql).to end_with " != #{single_value}"
15+
it 'apply_negated_toes' do
16+
expect(value.apply_negated_to(attribute).to_sql).to end_with " != #{single_value}"
17+
end
1618
end
17-
end
1819

19-
describe ActsAsRecursiveTree::Options::Values do
2020
let(:table) { Arel::Table.new('test_table') }
2121
let(:attribute) { table['test_attr'] }
2222

@@ -44,7 +44,7 @@
4444

4545
let(:array) { [1, 2, 3] }
4646

47-
it { is_expected.to be_a ActsAsRecursiveTree::Options::Values::MultiValue }
47+
it { is_expected.to be_a described_class::MultiValue }
4848

4949
it 'apply_toes' do
5050
expect(value.apply_to(attribute).to_sql).to end_with " IN (#{array.join(', ')})"
@@ -60,7 +60,7 @@
6060

6161
let(:range) { 1..3 }
6262

63-
it { is_expected.to be_a ActsAsRecursiveTree::Options::Values::RangeValue }
63+
it { is_expected.to be_a described_class::RangeValue }
6464

6565
it 'apply_toes' do
6666
expect(value.apply_to(attribute).to_sql).to end_with "BETWEEN #{range.begin} AND #{range.end}"
@@ -83,7 +83,7 @@ def self.primary_key
8383
end
8484
end
8585

86-
it { is_expected.to be_a ActsAsRecursiveTree::Options::Values::Relation }
86+
it { is_expected.to be_a described_class::Relation }
8787

8888
it 'apply_toes' do
8989
expect(value.apply_to(attribute).to_sql).to match(/IN \(SELECT.*\)/)

spec/model/location_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require 'spec_helper'
44

5-
describe Location do
5+
RSpec.describe Location do
66
before do
77
@building = Building.create!(name: 'big house')
88

spec/model/node_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require 'spec_helper'
44

5-
describe Node do
5+
RSpec.describe Node do
66
include TreeMethods
77

88
before do

spec/model/relation_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require 'spec_helper'
44

5-
describe 'Relation' do
5+
RSpec.describe 'Relation' do
66
def create_tree(max_level, current_level: 0, node: nil, stop_at: nil)
77
node = Node.create!(name: 'root') if node.nil?
88

spec/spec_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
# # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
7777
# # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
7878
# # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
79-
# config.disable_monkey_patching!
79+
config.disable_monkey_patching!
8080
#
8181
# # This setting enables warnings. It's recommended, but in some cases may
8282
# # be too noisy due to issues in dependencies.
Lines changed: 10 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
# frozen_string_literal: true
21

3-
require 'spec_helper'
4-
5-
shared_context 'setup with enforced ordering' do
2+
RSpec.shared_context 'setup with enforced ordering' do
63
let(:ordering) { false }
74
include_context 'base_setup' do
85
let(:proc) { ->(config) { config.ensure_ordering! } }
96
end
107
end
118

12-
shared_context 'base_setup' do
9+
RSpec.shared_context 'base_setup' do
1310
subject(:query) { builder.build.to_sql }
1411

1512
let(:model_id) { 1 }
@@ -21,7 +18,7 @@
2118
end
2219
end
2320

24-
shared_examples 'basic recursive examples' do
21+
RSpec.shared_examples 'basic recursive examples' do
2522
it { is_expected.to start_with "SELECT \"#{model_class.table_name}\".* FROM \"#{model_class.table_name}\"" }
2623

2724
it { is_expected.to match(/WHERE "#{model_class.table_name}"."#{model_class.primary_key}" = #{model_id}/) }
@@ -35,7 +32,7 @@
3532
}
3633
end
3734

38-
shared_examples 'build recursive query' do
35+
RSpec.shared_examples 'build recursive query' do
3936
context 'simple id' do
4037
context 'with simple class' do
4138
include_context 'base_setup' do
@@ -67,79 +64,35 @@
6764
end
6865
end
6966

70-
shared_examples 'ancestor query' do
67+
RSpec.shared_examples 'ancestor query' do
7168
include_context 'base_setup'
7269

7370
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}"/) }
7471
end
7572

76-
shared_examples 'descendant query' do
73+
RSpec.shared_examples 'descendant query' do
7774
include_context 'base_setup'
7875

7976
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}"/) }
8077
it { is_expected.to match(/#{Regexp.escape(builder.travers_loc_table.project(builder.travers_loc_table[model_class.primary_key]).to_sql)}/) }
8178
end
8279

83-
shared_context 'context with ordering' do
80+
RSpec.shared_context 'context with ordering' do
8481
include_context 'base_setup' do
8582
it_behaves_like 'with ordering'
8683
end
8784
end
8885

89-
shared_context 'context without ordering' do
86+
RSpec.shared_context 'context without ordering' do
9087
include_context 'base_setup' do
9188
it_behaves_like 'without ordering'
9289
end
9390
end
9491

95-
shared_examples 'with ordering' do
92+
RSpec.shared_examples 'with ordering' do
9693
it { is_expected.to match(/ORDER BY #{Regexp.escape(builder.recursive_temp_table[model_class._recursive_tree_config.depth_column].asc.to_sql)}/) }
9794
end
9895

99-
shared_examples 'without ordering' do
96+
RSpec.shared_examples 'without ordering' do
10097
it { is_expected.not_to match(/ORDER BY/) }
10198
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

Comments
 (0)