Commit 934e9497 authored by Shinya Maeda's avatar Shinya Maeda

Fix rubocop issues. Use add_concurrent_foreign_key.

parent 62480461
......@@ -5,7 +5,6 @@ class CronValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
cron_parser = Ci::CronParser.new(record.cron, record.cron_time_zone)
is_valid_cron, is_valid_cron_time_zone = cron_parser.validation
next_time = cron_parser.next_time_from(Time.now)
if !is_valid_cron
record.errors.add(:cron, " is invalid syntax")
......
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class AddRefToTriggers < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
# Set this constant to true if this migration requires downtime.
DOWNTIME = false
def change
......
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class CreateCiTriggerSchedules < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
# Set this constant to true if this migration requires downtime.
DOWNTIME = false
def change
disable_ddl_transaction!
def up
create_table :ci_trigger_schedules do |t|
t.integer "project_id"
t.integer "trigger_id", null: false
......@@ -21,6 +19,11 @@ class CreateCiTriggerSchedules < ActiveRecord::Migration
add_index :ci_trigger_schedules, ["next_run_at"], name: "index_ci_trigger_schedules_on_next_run_at", using: :btree
add_index :ci_trigger_schedules, ["project_id"], name: "index_ci_trigger_schedules_on_project_id", using: :btree
add_foreign_key :ci_trigger_schedules, :ci_triggers, column: :trigger_id, on_delete: :cascade
add_concurrent_foreign_key :ci_trigger_schedules, :ci_triggers, column: :trigger_id, on_delete: :cascade
end
def down
remove_foreign_key :ci_trigger_schedules, column: :trigger_id
drop_table :ci_trigger_schedules
end
end
......@@ -1313,7 +1313,7 @@ ActiveRecord::Schema.define(version: 20170405080720) do
add_foreign_key "boards", "projects"
add_foreign_key "chat_teams", "namespaces", on_delete: :cascade
add_foreign_key "ci_trigger_schedules", "ci_triggers", column: "trigger_id", on_delete: :cascade
add_foreign_key "ci_trigger_schedules", "ci_triggers", column: "trigger_id", name: "fk_90a406cc94", on_delete: :cascade
add_foreign_key "ci_triggers", "users", column: "owner_id", name: "fk_e8e10d1964", on_delete: :cascade
add_foreign_key "issue_metrics", "issues", on_delete: :cascade
add_foreign_key "label_priorities", "labels", on_delete: :cascade
......
module Ci
class CronParser
VALID_SYNTAX_SAMPLE_TIME_ZONE = 'UTC'
VALID_SYNTAX_SAMPLE_CRON = '* * * * *'
VALID_SYNTAX_SAMPLE_TIME_ZONE = 'UTC'.freeze
VALID_SYNTAX_SAMPLE_CRON = '* * * * *'.freeze
def initialize(cron, cron_time_zone = 'UTC')
@cron = cron
......@@ -9,9 +9,9 @@ module Ci
end
def next_time_from(time)
cronLine = try_parse_cron(@cron, @cron_time_zone)
if cronLine.present?
cronLine.next_time(time).in_time_zone(Time.zone)
cron_line = try_parse_cron(@cron, @cron_time_zone)
if cron_line.present?
cron_line.next_time(time).in_time_zone(Time.zone)
else
nil
end
......
require 'spec_helper'
describe Ci::TriggerSchedule, models: true do
it { is_expected.to belong_to(:project) }
it { is_expected.to belong_to(:trigger) }
it { is_expected.to respond_to :ref }
......
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