Commit 0816ea96 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Fix old emails on push integrations

We added a new branches_to_be_notified property and old integrations
were not working because these defaulted to nil
parent 749bc8b2
......@@ -25,10 +25,9 @@ class EmailsOnPushService < Service
end
def initialize_properties
if properties.nil?
self.properties = {}
self.branches_to_be_notified ||= "all"
end
super
self.branches_to_be_notified = 'all' if branches_to_be_notified.nil?
end
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
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
let(:push_data) { { object_kind: 'push' } }
let(:project) { create(:project, :repository) }
......
......@@ -127,21 +127,6 @@ describe API::Services do
expect(json_response['properties'].keys).to match_array(service_instance.api_field_names)
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
project.add_developer(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