diff options
Diffstat (limited to 'spec/models/project_import_state_spec.rb')
-rw-r--r-- | spec/models/project_import_state_spec.rb | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/spec/models/project_import_state_spec.rb b/spec/models/project_import_state_spec.rb index f6e398bd23c..db79185d759 100644 --- a/spec/models/project_import_state_spec.rb +++ b/spec/models/project_import_state_spec.rb @@ -156,7 +156,7 @@ RSpec.describe ProjectImportState, type: :model do project.import_state.finish end - it 'does not qneueue housekeeping when project does not have a valid import type' do + it 'does not enqueue housekeeping when project does not have a valid import type' do project = create(:project, :import_started, import_type: nil) expect(Projects::AfterImportWorker).not_to receive(:perform_async) @@ -164,6 +164,43 @@ RSpec.describe ProjectImportState, type: :model do project.import_state.finish end end + + context 'state transition: [:none, :scheduled, :started] => [:canceled]' do + it 'updates the import status' do + import_state = create(:import_state, :none) + expect { import_state.cancel } + .to change { import_state.status } + .from('none').to('canceled') + end + + it 'unsets the JID' do + import_state = create(:import_state, :started, jid: '123') + + expect(Gitlab::SidekiqStatus) + .to receive(:unset) + .with('123') + .and_call_original + + import_state.cancel! + + expect(import_state.jid).to be_nil + end + + it 'removes import data' do + import_data = ProjectImportData.new(data: { 'test' => 'some data' }) + project = create(:project, :import_scheduled, import_data: import_data) + + expect(project) + .to receive(:remove_import_data) + .and_call_original + + expect do + project.import_state.cancel + project.reload + end.to change { project.import_data } + .from(import_data).to(nil) + end + end end describe 'clearing `jid` after finish', :clean_gitlab_redis_cache do @@ -178,7 +215,7 @@ RSpec.describe ProjectImportState, type: :model do end end - context 'with an JID' do + context 'with a JID' do it 'unsets the JID' do import_state = create(:import_state, :started, jid: '123') |