Commit a9401aed authored by Stan Hu's avatar Stan Hu Committed by Mayra Cabrera

Set Web hook schema defaults to intended default values

parent a4a77904
---
title: Set Web hook defaults to intended default values
merge_request: 59814
author:
type: fixed
# frozen_string_literal: true
class ChangeWebHookEventsDefault < ActiveRecord::Migration[6.0]
def up
change_column_default :web_hooks, :push_events, true
change_column_default :web_hooks, :issues_events, false
change_column_default :web_hooks, :merge_requests_events, false
change_column_default :web_hooks, :tag_push_events, false
end
# This is a NOP because this migration is supposed to restore the
# intended schema, not revert it.
def down
end
end
f0bf8c79c1981ecd95c933f37ec5b0187ee6321792d96db26d863b192843c5ab
\ No newline at end of file
# frozen_string_literal: true
require 'spec_helper'
require Rails.root.join('db', 'migrate', '20210420012444_change_web_hook_events_default.rb')
RSpec.describe ChangeWebHookEventsDefault do
let(:web_hooks) { table(:web_hooks) }
let(:projects) { table(:projects) }
let(:groups) { table(:namespaces) }
let(:group) { groups.create!(name: 'gitlab', path: 'gitlab-org') }
let(:project) { projects.create!(name: 'gitlab', path: 'gitlab', namespace_id: group.id) }
let(:hook) { web_hooks.create!(project_id: project.id, type: 'ProjectHook') }
let(:group_hook) { web_hooks.create!(group_id: group.id, type: 'GroupHook') }
before do
# Simulate the wrong schema
%w(push_events issues_events merge_requests_events tag_push_events).each do |column|
ActiveRecord::Base.connection.execute "ALTER TABLE web_hooks ALTER COLUMN #{column} DROP DEFAULT"
end
end
it 'sets default values' do
migrate!
expect(hook.push_events).to be true
expect(hook.issues_events).to be false
expect(hook.merge_requests_events).to be false
expect(hook.tag_push_events).to be false
expect(group_hook.push_events).to be true
expect(group_hook.issues_events).to be false
expect(group_hook.merge_requests_events).to be false
expect(group_hook.tag_push_events).to be false
end
end
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