Commit 99d2379b authored by Eugenia Grieff's avatar Eugenia Grieff

Add test examples for system notes

- Tree reorder service should create system
notes when new parent is set
parent f46565b4
...@@ -49,7 +49,7 @@ RSpec.describe 'Updating an epic tree' do ...@@ -49,7 +49,7 @@ RSpec.describe 'Updating an epic tree' do
end end
end end
context 'when epic feature is enabled' do context 'when epics and subepics features are enabled' do
before do before do
stub_licensed_features(epics: true, subepics: true) stub_licensed_features(epics: true, subepics: true)
end end
......
...@@ -66,7 +66,7 @@ RSpec.describe Epics::TreeReorderService do ...@@ -66,7 +66,7 @@ RSpec.describe Epics::TreeReorderService do
context 'when user does have permission to admin the base epic' do context 'when user does have permission to admin the base epic' do
before do before do
group.add_developer(user) group.add_reporter(user)
end end
context 'when relative_position is not valid' do context 'when relative_position is not valid' do
...@@ -102,6 +102,10 @@ RSpec.describe Epics::TreeReorderService do ...@@ -102,6 +102,10 @@ RSpec.describe Epics::TreeReorderService do
it 'updates the parent' do it 'updates the parent' do
expect { subject }.to change { tree_object_2.reload.epic }.from(epic1).to(epic) expect { subject }.to change { tree_object_2.reload.epic }.from(epic1).to(epic)
end end
it 'creates system notes' do
expect { subject }.to change { Note.system.count }.by(3)
end
end end
context 'when object being moved is from another epic' do context 'when object being moved is from another epic' do
...@@ -207,6 +211,10 @@ RSpec.describe Epics::TreeReorderService do ...@@ -207,6 +211,10 @@ RSpec.describe Epics::TreeReorderService do
expect(tree_object_1.reload.relative_position).to be > tree_object_2.reload.relative_position expect(tree_object_1.reload.relative_position).to be > tree_object_2.reload.relative_position
end end
it 'creates system notes' do
expect { subject }.to change { Note.system.count }.by(3)
end
end end
end end
end end
...@@ -215,6 +223,17 @@ RSpec.describe Epics::TreeReorderService do ...@@ -215,6 +223,17 @@ RSpec.describe Epics::TreeReorderService do
let!(:tree_object_1) { epic1 } let!(:tree_object_1) { epic1 }
let!(:tree_object_2) { epic2 } let!(:tree_object_2) { epic2 }
context 'when subepics feature is disabled' do
let(:new_parent_id) { GitlabSchema.id_from_object(epic) }
before do
stub_licensed_features(epics: true, subepics: false)
end
it_behaves_like 'error for the tree update', 'You don\'t have permissions to move the objects.'
end
context 'when subepics feature is enabled' do
before do before do
stub_licensed_features(epics: true, subepics: true) stub_licensed_features(epics: true, subepics: true)
end end
...@@ -231,6 +250,16 @@ RSpec.describe Epics::TreeReorderService do ...@@ -231,6 +250,16 @@ RSpec.describe Epics::TreeReorderService do
it_behaves_like 'error for the tree update', 'You don\'t have permissions to move the objects.' it_behaves_like 'error for the tree update', 'You don\'t have permissions to move the objects.'
end end
context 'when user does not have permissions to admin the previous parent links' do
let(:new_parent_id) { GitlabSchema.id_from_object(epic) }
before do
group.add_guest(user)
end
it_behaves_like 'error for the tree update', 'You don\'t have permissions to move the objects.'
end
context 'when there is some other error with the new parent' do context 'when there is some other error with the new parent' do
let(:other_group) { create(:group) } let(:other_group) { create(:group) }
let(:new_parent_id) { GitlabSchema.id_from_object(epic) } let(:new_parent_id) { GitlabSchema.id_from_object(epic) }
...@@ -252,6 +281,8 @@ RSpec.describe Epics::TreeReorderService do ...@@ -252,6 +281,8 @@ RSpec.describe Epics::TreeReorderService do
it_behaves_like 'error for the tree update', 'You don\'t have permissions to move the objects.' it_behaves_like 'error for the tree update', 'You don\'t have permissions to move the objects.'
end end
context 'when user '
context 'when the reordered epics are not subepics of the base epic' do context 'when the reordered epics are not subepics of the base epic' do
let(:another_group) { create(:group) } let(:another_group) { create(:group) }
let(:another_epic) { create(:epic, group: another_group) } let(:another_epic) { create(:epic, group: another_group) }
...@@ -264,19 +295,6 @@ RSpec.describe Epics::TreeReorderService do ...@@ -264,19 +295,6 @@ RSpec.describe Epics::TreeReorderService do
it_behaves_like 'error for the tree update', 'You don\'t have permissions to move the objects.' it_behaves_like 'error for the tree update', 'You don\'t have permissions to move the objects.'
end end
context 'when new parent is another epic and subepics feature is disabled' do
let(:other_epic) { create(:epic, group: group) }
let(:new_parent_id) { GitlabSchema.id_from_object(epic) }
let(:epic3) { create(:epic, parent: other_epic, group: group) }
let(:tree_object_2) { epic3 }
before do
stub_licensed_features(epics: true, subepics: false)
end
it_behaves_like 'error for the tree update', 'You don\'t have permissions to move the objects.'
end
context 'when moving is successful' do context 'when moving is successful' do
it 'updates the links relative positions' do it 'updates the links relative positions' do
subject subject
...@@ -304,7 +322,7 @@ RSpec.describe Epics::TreeReorderService do ...@@ -304,7 +322,7 @@ RSpec.describe Epics::TreeReorderService do
let(:epic3) { create(:epic, parent: other_epic, group: group) } let(:epic3) { create(:epic, parent: other_epic, group: group) }
let(:tree_object_2) { epic3 } let(:tree_object_2) { epic3 }
it 'updates the relative positions and parent_id' do it 'updates the relative positions' do
subject subject
expect(tree_object_1.reload.relative_position).to be > tree_object_2.reload.relative_position expect(tree_object_1.reload.relative_position).to be > tree_object_2.reload.relative_position
...@@ -313,6 +331,11 @@ RSpec.describe Epics::TreeReorderService do ...@@ -313,6 +331,11 @@ RSpec.describe Epics::TreeReorderService do
it 'updates the parent' do it 'updates the parent' do
expect { subject }.to change { tree_object_2.reload.parent }.from(other_epic).to(epic) expect { subject }.to change { tree_object_2.reload.parent }.from(other_epic).to(epic)
end end
it 'creates system notes' do
expect { subject }.to change { Note.system.count }.by(2)
end
end
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment