Commit 04d542bb authored by charlie ablett's avatar charlie ablett

Merge branch 'issue_233941' into 'master'

Properly return boolean attributes in integrations API

See merge request gitlab-org/gitlab!64185
parents 2d573a30 58459f84
......@@ -165,9 +165,13 @@ class Integration < ApplicationRecord
args.each do |arg|
class_eval <<~RUBY, __FILE__, __LINE__ + 1
def #{arg}
Gitlab::Utils.to_boolean(properties['#{arg}'])
end
def #{arg}?
# '!!' is used because nil or empty string is converted to nil
!!ActiveRecord::Type::Boolean.new.cast(#{arg})
!!#{arg}
end
RUBY
end
......
......@@ -6,10 +6,18 @@ module API
# Expose serialized properties
expose :properties do |service, options|
# TODO: Simplify as part of https://gitlab.com/gitlab-org/gitlab/issues/29404
if service.data_fields_present?
service.data_fields.as_json.slice(*service.api_field_names)
else
service.properties.slice(*service.api_field_names)
attributes =
if service.data_fields_present?
service.data_fields.as_json.keys
else
service.properties.keys
end
attributes &= service.api_field_names
attributes.each_with_object({}) do |attribute, hash|
hash[attribute] = service.public_send(attribute) # rubocop:disable GitlabSecurity/PublicSend
end
end
end
......
......@@ -338,4 +338,26 @@ RSpec.describe API::Services do
expect(response).to have_gitlab_http_status(:ok)
end
end
describe 'Pipelines Email Integration' do
let(:service_name) { 'pipelines-email' }
context 'notify_only_broken_pipelines property was saved as a string' do
before do
project.create_pipelines_email_integration(
active: false,
properties: {
"notify_only_broken_pipelines": "true",
"branches_to_be_notified": "default"
}
)
end
it 'returns boolean values for notify_only_broken_pipelines' do
get api("/projects/#{project.id}/services/#{service_name}", user)
expect(json_response['properties']['notify_only_broken_pipelines']).to eq(true)
end
end
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