Commit 6c7a4bea authored by Fabio Pitino's avatar Fabio Pitino

Merge branch 'id-remove-redundant-callback-in-factory' into 'master'

Remove unused traits from EE project factory

See merge request gitlab-org/gitlab!40194
parents 8d1287d4 8ed72955
......@@ -26,6 +26,7 @@ FactoryBot.modify do
timestamp = Time.now
import_state.last_update_at = timestamp
import_state.last_update_started_at = timestamp
import_state.last_successful_update_at = timestamp
when :failed
import_state.last_update_at = Time.now
end
......
......@@ -2,48 +2,15 @@
FactoryBot.modify do
factory :project do
transient do
last_update_at { nil }
last_successful_update_at { nil }
retry_count { 0 }
end
after(:create) do |project, evaluator|
import_state = project.import_state
if import_state
import_state.last_successful_update_at = evaluator.last_successful_update_at
import_state.retry_count = evaluator.retry_count
case import_state.status.to_sym
when :scheduled
import_state.last_update_scheduled_at = Time.now
when :started
import_state.last_update_started_at = Time.now
when :finished
timestamp = evaluator.last_update_at || Time.now
import_state.last_update_at = timestamp
import_state.last_successful_update_at = timestamp
when :failed
import_state.last_update_at = evaluator.last_update_at || Time.now
end
import_state.save!
end
end
trait :import_none do
import_status { :none }
end
trait :import_hard_failed do
import_status { :failed }
last_update_at { Time.now - 1.minute }
retry_count { Gitlab::Mirror::MAX_RETRY + 1 }
end
trait :disabled_mirror do
mirror { false }
import_url { generate(:url) }
mirror_user_id { creator_id }
after(:create) do |project, evaluator|
project.import_state.update!(
retry_count: Gitlab::Mirror::MAX_RETRY + 1,
last_update_at: Time.now - 1.minute
)
end
end
trait :mirror do
......
......@@ -5,12 +5,18 @@ require 'spec_helper'
RSpec.describe 'shared/_mirror_status.html.haml' do
include ApplicationHelper
context 'when mirror has not updated yet' do
it 'does not render anything' do
@project = create(:project, :mirror)
let(:project) { create(:project, :mirror, import_state: import_state) }
before do
@project = project # for the view
sign_in(project.owner)
end
sign_in(@project.owner)
context 'when mirror has not updated yet' do
let(:import_state) { create(:import_state) }
it 'does not render anything' do
render 'shared/mirror_status'
expect(rendered).to be_empty
......@@ -18,11 +24,9 @@ RSpec.describe 'shared/_mirror_status.html.haml' do
end
context 'when mirror successful' do
it 'renders success message' do
@project = create(:project, :mirror, :import_finished)
sign_in(@project.owner)
let(:import_state) { create(:import_state, :finished) }
it 'renders success message' do
render 'shared/mirror_status'
expect(rendered).to have_content("Pull mirroring updated")
......@@ -30,11 +34,7 @@ RSpec.describe 'shared/_mirror_status.html.haml' do
end
context 'when mirror failed' do
before do
@project = create(:project, :mirror, :import_failed)
sign_in(@project.owner)
end
let(:import_state) { create(:import_state, :failed) }
it 'renders failure message' do
render 'shared/mirror_status', raw_message: true
......@@ -50,9 +50,9 @@ RSpec.describe 'shared/_mirror_status.html.haml' do
end
context 'with a previous successful update' do
it 'renders failure message' do
@project.import_state.last_successful_update_at = Time.now - 1.minute
let(:import_state) { create(:import_state, :failed, last_successful_update_at: Time.now - 1.minute) }
it 'renders failure message' do
render 'shared/mirror_status', raw_message: true
expect(rendered).to have_content("Last successful update")
......@@ -60,9 +60,9 @@ RSpec.describe 'shared/_mirror_status.html.haml' do
end
context 'with a hard failed mirror' do
it 'renders hard failed message' do
@project.import_state.retry_count = Gitlab::Mirror::MAX_RETRY + 1
let(:import_state) { create(:import_state, :failed, retry_count: Gitlab::Mirror::MAX_RETRY + 1) }
it 'renders hard failed message' do
render 'shared/mirror_status', raw_message: true
expect(rendered).to have_content("Repository mirroring has been paused due to too many failed attempts, and can be resumed by a project maintainer.")
......
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