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 ...@@ -26,6 +26,7 @@ FactoryBot.modify do
timestamp = Time.now timestamp = Time.now
import_state.last_update_at = timestamp import_state.last_update_at = timestamp
import_state.last_update_started_at = timestamp import_state.last_update_started_at = timestamp
import_state.last_successful_update_at = timestamp
when :failed when :failed
import_state.last_update_at = Time.now import_state.last_update_at = Time.now
end end
......
...@@ -2,48 +2,15 @@ ...@@ -2,48 +2,15 @@
FactoryBot.modify do FactoryBot.modify do
factory :project 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 trait :import_hard_failed do
import_status { :failed } import_status { :failed }
last_update_at { Time.now - 1.minute }
retry_count { Gitlab::Mirror::MAX_RETRY + 1 }
end
trait :disabled_mirror do after(:create) do |project, evaluator|
mirror { false } project.import_state.update!(
import_url { generate(:url) } retry_count: Gitlab::Mirror::MAX_RETRY + 1,
mirror_user_id { creator_id } last_update_at: Time.now - 1.minute
)
end
end end
trait :mirror do trait :mirror do
......
...@@ -5,12 +5,18 @@ require 'spec_helper' ...@@ -5,12 +5,18 @@ require 'spec_helper'
RSpec.describe 'shared/_mirror_status.html.haml' do RSpec.describe 'shared/_mirror_status.html.haml' do
include ApplicationHelper include ApplicationHelper
context 'when mirror has not updated yet' do let(:project) { create(:project, :mirror, import_state: import_state) }
it 'does not render anything' do
@project = create(:project, :mirror) 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' render 'shared/mirror_status'
expect(rendered).to be_empty expect(rendered).to be_empty
...@@ -18,11 +24,9 @@ RSpec.describe 'shared/_mirror_status.html.haml' do ...@@ -18,11 +24,9 @@ RSpec.describe 'shared/_mirror_status.html.haml' do
end end
context 'when mirror successful' do context 'when mirror successful' do
it 'renders success message' do let(:import_state) { create(:import_state, :finished) }
@project = create(:project, :mirror, :import_finished)
sign_in(@project.owner)
it 'renders success message' do
render 'shared/mirror_status' render 'shared/mirror_status'
expect(rendered).to have_content("Pull mirroring updated") expect(rendered).to have_content("Pull mirroring updated")
...@@ -30,11 +34,7 @@ RSpec.describe 'shared/_mirror_status.html.haml' do ...@@ -30,11 +34,7 @@ RSpec.describe 'shared/_mirror_status.html.haml' do
end end
context 'when mirror failed' do context 'when mirror failed' do
before do let(:import_state) { create(:import_state, :failed) }
@project = create(:project, :mirror, :import_failed)
sign_in(@project.owner)
end
it 'renders failure message' do it 'renders failure message' do
render 'shared/mirror_status', raw_message: true render 'shared/mirror_status', raw_message: true
...@@ -50,9 +50,9 @@ RSpec.describe 'shared/_mirror_status.html.haml' do ...@@ -50,9 +50,9 @@ RSpec.describe 'shared/_mirror_status.html.haml' do
end end
context 'with a previous successful update' do context 'with a previous successful update' do
it 'renders failure message' do let(:import_state) { create(:import_state, :failed, last_successful_update_at: Time.now - 1.minute) }
@project.import_state.last_successful_update_at = Time.now - 1.minute
it 'renders failure message' do
render 'shared/mirror_status', raw_message: true render 'shared/mirror_status', raw_message: true
expect(rendered).to have_content("Last successful update") expect(rendered).to have_content("Last successful update")
...@@ -60,9 +60,9 @@ RSpec.describe 'shared/_mirror_status.html.haml' do ...@@ -60,9 +60,9 @@ RSpec.describe 'shared/_mirror_status.html.haml' do
end end
context 'with a hard failed mirror' do context 'with a hard failed mirror' do
it 'renders hard failed message' do let(:import_state) { create(:import_state, :failed, retry_count: Gitlab::Mirror::MAX_RETRY + 1) }
@project.import_state.retry_count = Gitlab::Mirror::MAX_RETRY + 1
it 'renders hard failed message' do
render 'shared/mirror_status', raw_message: true 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.") 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