Commit bc510c29 authored by Tiago Botelho's avatar Tiago Botelho

adds test suite for feature

parent d4273e2b
......@@ -7,7 +7,7 @@ module MirrorHelper
def mirror_sync_time_options
Gitlab::Mirror.sync_time_options.select do |key, value|
value < current_application_settings.minimum_mirror_sync_time
value >= current_application_settings.minimum_mirror_sync_time
end
end
end
......@@ -47,7 +47,7 @@
= render "shared/mirror_trigger_builds_setting", f: f
.form-group
= f.label :sync_time, "Synchronization time", class: "label-light append-bottom-0"
= f.select :sync_time, options_for_select(mirror_sync_time_options, @project.sync_time), {}, class: 'form-control'
= f.select :sync_time, options_for_select(mirror_sync_time_options, @project.sync_time), {}, class: 'form-control project-mirror-sync-time'
.col-sm-12
%hr
.col-lg-3
......@@ -82,7 +82,7 @@
= render "instructions"
.form-group
= rm_form.label :sync_time, "Synchronization time", class: "label-light append-bottom-0"
= rm_form.select :sync_time, options_for_select(mirror_sync_time_options, @remote_mirror.sync_time), {}, class: 'form-control'
= rm_form.select :sync_time, options_for_select(mirror_sync_time_options, @remote_mirror.sync_time), {}, class: 'form-control remote-mirror-sync-time'
.col-sm-12.text-center
%hr
= f.submit 'Save changes', class: 'btn btn-create', name: 'update_remote_mirror'
......@@ -34,9 +34,9 @@ module Gitlab
update_all_mirrors_worker_job = Sidekiq::Cron::Job.find("update_all_mirrors_worker")
update_all_remote_mirrors_worker_job = Sidekiq::Cron::Job.find("update_all_remote_mirrors_worker")
if update_all_mirrors_worker && update_all_remote_mirrors_worker
update_all_mirrors_worker.destroy
update_all_remote_mirrors_worker.destroy
if update_all_mirrors_worker_job && update_all_remote_mirrors_worker_job
update_all_mirrors_worker_job.destroy
update_all_remote_mirrors_worker_job.destroy
end
Sidekiq::Cron::Job.create(
......
......@@ -8,15 +8,54 @@ feature 'Project mirror', feature: true do
before do
project.team << [user, :master]
login_as user
visit namespace_project_mirror_path(project.namespace, project)
end
describe 'pressing "Update now"' do
before { visit namespace_project_mirror_path(project.namespace, project) }
it 'returns with the project updating (job enqueued)' do
Sidekiq::Testing.fake! { click_link('Update Now') }
expect(page).to have_content('Updating')
end
end
describe 'synchronization times' do
describe 'daily minimum mirror sync_time' do
before do
stub_application_setting(minimum_mirror_sync_time: Gitlab::Mirror::DAILY)
visit namespace_project_mirror_path(project.namespace, project)
end
it 'shows the correct selector options' do
expect(page).to have_selector('.project-mirror-sync-time > option', count: 1)
expect(page).to have_selector('.remote-mirror-sync-time > option', count: 1)
end
end
describe 'hourly minimum mirror sync_time' do
before do
stub_application_setting(minimum_mirror_sync_time: Gitlab::Mirror::HOURLY)
visit namespace_project_mirror_path(project.namespace, project)
end
it 'shows the correct selector options' do
expect(page).to have_selector('.project-mirror-sync-time > option', count: 2)
expect(page).to have_selector('.remote-mirror-sync-time > option', count: 2)
end
end
describe 'fifteen minimum mirror sync_time' do
before do
stub_application_setting(minimum_mirror_sync_time: Gitlab::Mirror::FIFTEEN)
visit namespace_project_mirror_path(project.namespace, project)
end
it 'shows the correct selector options' do
expect(page).to have_selector('.project-mirror-sync-time > option', count: 3)
expect(page).to have_selector('.remote-mirror-sync-time > option', count: 3)
end
end
end
end
end
......@@ -20,6 +20,12 @@ describe ApplicationSetting, models: true do
it { is_expected.to allow_value(https).for(:after_sign_out_path) }
it { is_expected.not_to allow_value(ftp).for(:after_sign_out_path) }
it { is_expected.to allow_value(Gitlab::Mirror::FIFTEEN).for(:minimum_mirror_sync_time) }
it { is_expected.to allow_value(Gitlab::Mirror::HOURLY).for(:minimum_mirror_sync_time) }
it { is_expected.to allow_value(Gitlab::Mirror::DAILY).for(:minimum_mirror_sync_time) }
it { is_expected.not_to allow_value(nil).for(:minimum_mirror_sync_time) }
it { is_expected.not_to allow_value(61).for(:minimum_mirror_sync_time) }
describe 'disabled_oauth_sign_in_sources validations' do
before do
allow(Devise).to receive(:omniauth_providers).and_return([:github])
......@@ -41,6 +47,24 @@ describe ApplicationSetting, models: true do
subject { setting }
end
context "update minimum_mirror_cron_jobs" do
let(:daily_cron) { Gitlab::Mirror::SYNC_TIME_TO_CRON[Gitlab::Mirror::DAILY] }
let(:hourly_cron) { Gitlab::Mirror::SYNC_TIME_TO_CRON[Gitlab::Mirror::HOURLY] }
before do
Gitlab::Mirror.configure_cron_jobs!
allow_any_instance_of(Gitlab::CurrentSettings).to receive(:current_application_settings).and_return(setting)
end
it "changes update_all_mirrors_worker cron" do
expect { setting.update_attributes(minimum_mirror_sync_time: Gitlab::Mirror::DAILY) }.to change { Sidekiq::Cron::Job.find("update_all_mirrors_worker").cron }.from(hourly_cron).to(daily_cron)
end
it "changes update_all_remote_mirrors_worker cron" do
expect { setting.update_attributes(minimum_mirror_sync_time: Gitlab::Mirror::DAILY) }.to change { Sidekiq::Cron::Job.find("update_all_remote_mirrors_worker").cron }.from(hourly_cron).to(daily_cron)
end
end
# Upgraded databases will have this sort of content
context 'repository_storages is a String, not an Array' do
before { setting.__send__(:raw_write_attribute, :repository_storages, 'default') }
......
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