From f229290ac828d1d5743f86c5a4977168a0406365 Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Tue, 4 Apr 2017 23:43:09 +0900 Subject: [PATCH] Remove triggers_helper. Add trigger_schedule_presenter. --- app/helpers/triggers_helper.rb | 7 ----- app/models/ci/trigger_schedule.rb | 1 + .../ci/trigger_schedule_presenter.rb | 11 +++++++ .../ci/trigger_schedule_presenter_spec.rb} | 30 +++++++++++++++++-- 4 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 app/presenters/ci/trigger_schedule_presenter.rb rename spec/{helpers/triggers_helper_spec.rb => presenters/ci/trigger_schedule_presenter_spec.rb} (68%) diff --git a/app/helpers/triggers_helper.rb b/app/helpers/triggers_helper.rb index a415ac11893..a48d4475e97 100644 --- a/app/helpers/triggers_helper.rb +++ b/app/helpers/triggers_helper.rb @@ -10,11 +10,4 @@ module TriggersHelper def service_trigger_url(service) "#{Settings.gitlab.url}/api/v3/projects/#{service.project_id}/services/#{service.to_param}/trigger" end - - def real_next_run(trigger_schedule, - worker_cron: Settings.cron_jobs['trigger_schedule_worker']['cron'], - worker_time_zone: Time.zone.name) - Gitlab::Ci::CronParser.new(worker_cron, worker_time_zone) - .next_time_from(trigger_schedule.next_run_at) - end end diff --git a/app/models/ci/trigger_schedule.rb b/app/models/ci/trigger_schedule.rb index 9b1dfce969a..2cf041df8a7 100644 --- a/app/models/ci/trigger_schedule.rb +++ b/app/models/ci/trigger_schedule.rb @@ -2,6 +2,7 @@ module Ci class TriggerSchedule < ActiveRecord::Base extend Ci::Model include Importable + include Presentable acts_as_paranoid diff --git a/app/presenters/ci/trigger_schedule_presenter.rb b/app/presenters/ci/trigger_schedule_presenter.rb new file mode 100644 index 00000000000..faef6a3d66f --- /dev/null +++ b/app/presenters/ci/trigger_schedule_presenter.rb @@ -0,0 +1,11 @@ +module Ci + class TriggerSchedulePresenter < Gitlab::View::Presenter::Delegated + presents :trigger_schedule + + def real_next_run(worker_cron: Settings.cron_jobs['trigger_schedule_worker']['cron'], + worker_time_zone: Time.zone.name) + Gitlab::Ci::CronParser.new(worker_cron, worker_time_zone) + .next_time_from(next_run_at) + end + end +end diff --git a/spec/helpers/triggers_helper_spec.rb b/spec/presenters/ci/trigger_schedule_presenter_spec.rb similarity index 68% rename from spec/helpers/triggers_helper_spec.rb rename to spec/presenters/ci/trigger_schedule_presenter_spec.rb index ee3fd3fea0f..92e38441a8a 100644 --- a/spec/helpers/triggers_helper_spec.rb +++ b/spec/presenters/ci/trigger_schedule_presenter_spec.rb @@ -1,10 +1,34 @@ -require 'rails_helper' +require 'spec_helper' + +describe Ci::TriggerSchedulePresenter do + let(:trigger_schedule) { create(:ci_trigger_schedule) } + + subject(:presenter) do + described_class.new(trigger_schedule) + end + + it 'inherits from Gitlab::View::Presenter::Delegated' do + expect(described_class.superclass).to eq(Gitlab::View::Presenter::Delegated) + end + + describe '#initialize' do + it 'takes a trigger_schedule and optional params' do + expect { presenter }.not_to raise_error + end + + it 'exposes trigger_schedule' do + expect(presenter.trigger_schedule).to eq(trigger_schedule) + end + + it 'forwards missing methods to trigger_schedule' do + expect(presenter.ref).to eq('master') + end + end -describe TriggersHelper do describe '#real_next_run' do let(:trigger_schedule) { create(:ci_trigger_schedule, cron: user_cron, cron_time_zone: 'UTC') } - subject { helper.real_next_run(trigger_schedule, arguments) } + subject { described_class.new(trigger_schedule).real_next_run(arguments) } context 'when next_run_at > worker_next_time' do let(:arguments) { { worker_cron: '0 0 1 1 *', worker_time_zone: 'UTC' } } # every 00:00, January 1st