diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-09 12:09:24 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-09 12:09:24 +0000 |
commit | a9ced7da447785c57477b3d8dbccc73a78cface1 (patch) | |
tree | 5179d27ab9d801748ee4ed1c64c985974e799812 /spec/models/project_spec.rb | |
parent | ad0265eead72a624ce7a020847db4f0f0c877e57 (diff) | |
download | gitlab-ce-a9ced7da447785c57477b3d8dbccc73a78cface1.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/project_spec.rb')
-rw-r--r-- | spec/models/project_spec.rb | 79 |
1 files changed, 35 insertions, 44 deletions
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 21c074cdce2..3c8afee4466 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -2281,38 +2281,35 @@ describe Project do end describe '#jira_import_status' do - let(:project) { create(:project, :import_started, import_type: 'jira') } + let(:project) { create(:project, import_type: 'jira') } - context 'when import_data is nil' do + context 'when no jira imports' do it 'returns none' do - expect(project.import_data).to be nil - expect(project.jira_import_status).to eq('none') + expect(project.jira_import_status).to eq('initial') end end - context 'when import_data is set' do - let(:jira_import_data) { JiraImportData.new } - let(:project) { create(:project, :import_started, import_data: jira_import_data, import_type: 'jira') } + context 'when there are jira imports' do + let(:jira_import1) { build(:jira_import_state, :finished, project: project) } + let(:jira_import2) { build(:jira_import_state, project: project) } - it 'returns none' do - expect(project.import_data.becomes(JiraImportData).force_import?).to be false - expect(project.jira_import_status).to eq('none') + before do + expect(project).to receive(:latest_jira_import).and_return(jira_import2) end - context 'when jira_force_import is true' do - let(:imported_jira_project) do - JiraImportData::JiraProjectDetails.new('xx', Time.now.strftime('%Y-%m-%d %H:%M:%S'), { user_id: 1, name: 'root' }) + context 'when latest import status is initial or jira imports are mising' do + it 'returns initial' do + expect(project.jira_import_status).to eq('initial') end + end + context 'when latest import status is scheduled' do before do - jira_import_data = project.import_data.becomes(JiraImportData) - jira_import_data << imported_jira_project - jira_import_data.force_import! + jira_import2.schedule! end - it 'returns started' do - expect(project.import_data.becomes(JiraImportData).force_import?).to be true - expect(project.jira_import_status).to eq('started') + it 'returns scheduled' do + expect(project.jira_import_status).to eq('scheduled') end end end @@ -2375,52 +2372,46 @@ describe Project do context 'jira import' do it 'schedules a jira import job' do project = create(:project, import_type: 'jira') + jira_import = create(:jira_import_state, project: project) expect(Gitlab::JiraImport::Stage::StartImportWorker).to receive(:perform_async).with(project.id).and_return(import_jid) - expect(project.add_import_job).to eq(import_jid) + + jira_import.schedule! + + expect(jira_import.jid).to eq(import_jid) end end end describe '#jira_import?' do - subject(:project) { build(:project, import_type: 'jira') } + let_it_be(:project) { build(:project, import_type: 'jira') } + let_it_be(:jira_import) { build(:jira_import_state, project: project) } - it { expect(project.jira_import?).to be true } - it { expect(project.import?).to be true } - end - - describe '#jira_force_import?' do - let(:imported_jira_project) do - JiraImportData::JiraProjectDetails.new('xx', Time.now.strftime('%Y-%m-%d %H:%M:%S'), { user_id: 1, name: 'root' }) - end - let(:jira_import_data) do - data = JiraImportData.new - data << imported_jira_project - data.force_import! - data + before do + expect(project).to receive(:jira_imports).and_return([jira_import]) end - subject(:project) { build(:project, import_type: 'jira', import_data: jira_import_data) } - - it { expect(project.jira_force_import?).to be true } + it { expect(project.jira_import?).to be true } + it { expect(project.import?).to be true } end describe '#remove_import_data' do - let(:import_data) { ProjectImportData.new(data: { 'test' => 'some data' }) } + let_it_be(:import_data) { ProjectImportData.new(data: { 'test' => 'some data' }) } context 'when jira import' do - let!(:project) { create(:project, import_type: 'jira', import_data: import_data) } + let_it_be(:project, reload: true) { create(:project, import_type: 'jira', import_data: import_data) } + let_it_be(:jira_import) { create(:jira_import_state, project: project) } - it 'does not remove import data' do + it 'does remove import data' do expect(project.mirror?).to be false expect(project.jira_import?).to be true - expect { project.remove_import_data }.not_to change { ProjectImportData.count } + expect { project.remove_import_data }.to change { ProjectImportData.count }.by(-1) end end - context 'when not mirror neither jira import' do - let(:user) { create(:user) } - let!(:project) { create(:project, import_type: 'github', import_data: import_data) } + context 'when neither a mirror nor a jira import' do + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, import_type: 'github', import_data: import_data) } it 'removes import data' do expect(project.mirror?).to be false |