summaryrefslogtreecommitdiff
path: root/spec/models/concerns/group_descendant_spec.rb
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2018-04-13 18:52:28 +0200
committerBob Van Landuyt <bob@vanlanduyt.co>2018-04-18 17:15:51 +0200
commit1b0156204dd624f3645100d77f0eeed7e8b8e626 (patch)
tree1bb037e8f0b731f1c2f19b71ad4b9616fbc090f8 /spec/models/concerns/group_descendant_spec.rb
parentd8dd75ca775f66fd756e43ddd73ac75d39fc3e64 (diff)
downloadgitlab-ce-1b0156204dd624f3645100d77f0eeed7e8b8e626.tar.gz
Recover from errors when a parent is not preloaded
Diffstat (limited to 'spec/models/concerns/group_descendant_spec.rb')
-rw-r--r--spec/models/concerns/group_descendant_spec.rb17
1 files changed, 16 insertions, 1 deletions
diff --git a/spec/models/concerns/group_descendant_spec.rb b/spec/models/concerns/group_descendant_spec.rb
index c163fb01a81..28352d8c961 100644
--- a/spec/models/concerns/group_descendant_spec.rb
+++ b/spec/models/concerns/group_descendant_spec.rb
@@ -79,9 +79,24 @@ describe GroupDescendant, :nested_groups do
expect(described_class.build_hierarchy(groups)).to eq(expected_hierarchy)
end
+ it 'tracks the exception when a parent was not preloaded' do
+ expect(Gitlab::Sentry).to receive(:track_exception).and_call_original
+
+ expect { GroupDescendant.build_hierarchy([subsub_group]) }.to raise_error(ArgumentError)
+ end
+
+ it 'recovers if a parent was not reloaded by querying for the parent' do
+ expected_hierarchy = { parent => { subgroup => subsub_group } }
+
+ # this does not raise in production, so stubbing it here.
+ allow(Gitlab::Sentry).to receive(:track_exception)
+
+ expect(GroupDescendant.build_hierarchy([subsub_group])).to eq(expected_hierarchy)
+ end
+
it 'raises an error if not all elements were preloaded' do
expect { described_class.build_hierarchy([subsub_group]) }
- .to raise_error('parent was not preloaded')
+ .to raise_error(/was not preloaded/)
end
end
end