From 9b3224cc8b41474e7ac6c9cdc289898054081967 Mon Sep 17 00:00:00 2001 From: patrick brisbin Date: Mon, 24 Feb 2014 16:36:00 -0500 Subject: [PATCH] Handle invalid Flowdock project Documentation for other client libraries indicates alphanumeric and underscore only. Experimentation shows space and hyphen are also valid. --- lib/cc/services/flowdock.rb | 3 ++- service_test.rb | 6 +++++- test/flowdock_test.rb | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/cc/services/flowdock.rb b/lib/cc/services/flowdock.rb index 163d6ff..8a1a260 100644 --- a/lib/cc/services/flowdock.rb +++ b/lib/cc/services/flowdock.rb @@ -8,6 +8,7 @@ class Config < CC::Service::Config end BASE_URL = "https://api.flowdock.com/v1" + INVALID_PROJECT_CHARACTERS = /[^0-9a-z\-_ ]+/i self.description = "Send messages to a Flowdock inbox" @@ -45,7 +46,7 @@ def notify(subject, project, content) from_name: "Code Climate", format: "html", subject: subject, - project: project, + project: project.gsub(INVALID_PROJECT_CHARACTERS, ''), content: content, link: "https://codeclimate.com" } diff --git a/service_test.rb b/service_test.rb index 827c43d..5317ea2 100755 --- a/service_test.rb +++ b/service_test.rb @@ -7,7 +7,7 @@ CC::Service.load_services def test_service(klass, config) - service = klass.new(:test, config, { repo_name: "Example" }) + service = klass.new(:test, config, { repo_name: "Example.org" }) service.receive end @@ -15,3 +15,7 @@ def test_service(klass, config) webhook_url: "...", channel: "..." }) + +test_service(CC::Service::Flowdock, { + api_token: "..." +}) diff --git a/test/flowdock_test.rb b/test/flowdock_test.rb index 27ebcb5..44d385c 100644 --- a/test/flowdock_test.rb +++ b/test/flowdock_test.rb @@ -1,6 +1,21 @@ require File.expand_path('../helper', __FILE__) class TestFlowdock < CC::Service::TestCase + def test_valid_project_parameter + @stubs.post '/v1/messages/team_inbox/token' do |env| + body = Hash[URI.decode_www_form(env[:body])] + assert_equal "Exampleorg", body["project"] + [200, {}, ''] + end + + receive( + CC::Service::Flowdock, + :test, + { api_token: "token" }, + { repo_name: "Example.org" } + ) + end + def test_test_hook assert_flowdock_receives( :test,