Permalink
Browse files

support multiple tokens in flowdock, change flowdock test to use mult…

…iple tokens
  • Loading branch information...
1 parent 9202f1c commit a14a8c483dd6bdd188cf9b4e481e2b7cc7a5696a @kcm kcm committed Dec 20, 2012
Showing with 20 additions and 14 deletions.
  1. +6 −4 services/flowdock.rb
  2. +14 −10 test/flowdock_test.rb
View
@@ -7,10 +7,12 @@ class Service::Flowdock < Service
def receive_event
raise_config_error "Missing token" if data['token'].to_s.empty?
- token = URI.escape(data['token'].to_s.gsub(/\s/, ''))
+ data['token'].to_s.split(",").each do |t|
+ token = URI.escape(t.to_s.gsub(/\s/, ''))
- http.headers['X-GitHub-Event'] = event.to_s
- http.headers['content-type'] = 'application/json'
- http_post "https://api.flowdock.com/v1/github/#{token}", JSON.generate(payload)
+ http.headers['X-GitHub-Event'] = event.to_s
+ http.headers['content-type'] = 'application/json'
+ http_post "https://api.flowdock.com/v1/github/#{token}", JSON.generate(payload)
+ end
end
end
View
@@ -3,29 +3,33 @@
class FlowdockTest < Service::TestCase
def setup
@stubs = Faraday::Adapter::Test::Stubs.new
- @token = "token"
+ @tokens = "token1,token2"
end
def test_push
- @stubs.post "/v1/github/#{@token}" do |env|
- assert_match /json/, env[:request_headers]['content-type']
- assert_equal push_payload, JSON.parse(env[:body])
- [200, {}, '']
+ @tokens.to_s.split(",").each do |t|
+ @stubs.post "/v1/github/#{t}" do |env|
+ assert_match /json/, env[:request_headers]['content-type']
+ assert_equal push_payload, JSON.parse(env[:body])
+ [200, {}, '']
+ end
end
svc = service(
- {'token' => @token}, push_payload)
+ {'token' => @tokens}, push_payload)
svc.receive_event
end
def test_token_sanitization
- @stubs.post "/v1/github/#{@token}" do |env|
- assert_equal payload, JSON.parse(env[:body])
- [200, {}, '']
+ @tokens.to_s.split(",").each do |t|
+ @stubs.post "/v1/github/#{t}" do |env|
+ assert_equal payload, JSON.parse(env[:body])
+ [200, {}, '']
+ end
end
svc = service(
- {'token' => " " + @token + " "}, payload)
+ {'token' => " " + @tokens + " "}, payload)
svc.receive_event
end

0 comments on commit a14a8c4

Please sign in to comment.