Commit 2966fa82 authored by Thong Kuah's avatar Thong Kuah

Merge branch '198577-fix-emails-on-push' into 'master'

Fix emails on push integrations created before 12.7

See merge request gitlab-org/gitlab!23699
parents 254a7ef3 0816ea96
...@@ -25,10 +25,9 @@ class EmailsOnPushService < Service ...@@ -25,10 +25,9 @@ class EmailsOnPushService < Service
end end
def initialize_properties def initialize_properties
if properties.nil? super
self.properties = {}
self.branches_to_be_notified ||= "all" self.branches_to_be_notified = 'all' if branches_to_be_notified.nil?
end
end end
def execute(push_data) def execute(push_data)
......
---
title: Fix emails on push integrations created before 12.7
merge_request: 23699
author:
type: fixed
...@@ -21,6 +21,22 @@ describe EmailsOnPushService do ...@@ -21,6 +21,22 @@ describe EmailsOnPushService do
end end
end end
context 'when properties is missing branches_to_be_notified' do
subject { described_class.new(properties: {}) }
it 'sets the default value to all' do
expect(subject.branches_to_be_notified).to eq('all')
end
end
context 'when branches_to_be_notified is already set' do
subject { described_class.new(properties: { branches_to_be_notified: 'protected' }) }
it 'does not overwrite it with the default value' do
expect(subject.branches_to_be_notified).to eq('protected')
end
end
context 'project emails' do context 'project emails' do
let(:push_data) { { object_kind: 'push' } } let(:push_data) { { object_kind: 'push' } }
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
......
...@@ -127,21 +127,6 @@ describe API::Services do ...@@ -127,21 +127,6 @@ describe API::Services do
expect(json_response['properties'].keys).to match_array(service_instance.api_field_names) expect(json_response['properties'].keys).to match_array(service_instance.api_field_names)
end end
it "returns empty hash or nil values if properties and data fields are empty" do
# deprecated services are not valid for update
initialized_service.update_attribute(:properties, {})
if initialized_service.data_fields_present?
initialized_service.data_fields.destroy
initialized_service.reload
end
get api("/projects/#{project.id}/services/#{dashed_service}", user)
expect(response).to have_gitlab_http_status(200)
expect(json_response['properties'].values.compact).to be_empty
end
it "returns error when authenticated but not a project owner" do it "returns error when authenticated but not a project owner" do
project.add_developer(user2) project.add_developer(user2)
get api("/projects/#{project.id}/services/#{dashed_service}", user2) get api("/projects/#{project.id}/services/#{dashed_service}", user2)
......
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