Commit bf3f39e4f90585e8db7095476ace900d7256e6e9

Authored by Manuel van Rijn
1 parent a9084c10
Exists in master and in 1 other branch production

use config.protocol instead of hardcoded http

app/models/notification_service.rb
@@ -54,6 +54,6 @@ class NotificationService @@ -54,6 +54,6 @@ class NotificationService
54 end 54 end
55 55
56 def problem_url(problem) 56 def problem_url(problem)
57 - "http://#{Errbit::Config.host}/apps/#{problem.app.id}/problems/#{problem.id}" 57 + "#{Errbit::Config.protocol}://#{Errbit::Config.host}/apps/#{problem.app.id}/problems/#{problem.id}"
58 end 58 end
59 end 59 end
app/models/notification_services/campfire_service.rb
@@ -30,7 +30,7 @@ if defined? Campy @@ -30,7 +30,7 @@ if defined? Campy
30 # build the campfire client 30 # build the campfire client
31 campy = Campy::Room.new(:account => subdomain, :token => api_token, :room_id => room_id) 31 campy = Campy::Room.new(:account => subdomain, :token => api_token, :room_id => room_id)
32 # post the issue to the campfire room 32 # post the issue to the campfire room
33 - campy.speak "[errbit] #{problem.app.name} #{notification_description problem} - http://#{Errbit::Config.host}/apps/#{problem.app.id.to_s}/problems/#{problem.id.to_s}" 33 + campy.speak "[errbit] #{problem.app.name} #{notification_description problem} - #{Errbit::Config.protocol}://#{Errbit::Config.host}/apps/#{problem.app.id.to_s}/problems/#{problem.id.to_s}"
34 end 34 end
35 end 35 end
36 end 36 end
app/models/notification_services/gtalk_service.rb
@@ -47,7 +47,7 @@ class NotificationServices::GtalkService < NotificationService @@ -47,7 +47,7 @@ class NotificationServices::GtalkService < NotificationService
47 47
48 #has to look like this to be formatted properly in the client 48 #has to look like this to be formatted properly in the client
49 message = """#{problem.app.name.to_s} 49 message = """#{problem.app.name.to_s}
50 -http://#{Errbit::Config.host}/apps/#{problem.app.id.to_s} 50 +#{Errbit::Config.protocol}://#{Errbit::Config.host}/apps/#{problem.app.id.to_s}
51 #{notification_description problem}""" 51 #{notification_description problem}"""
52 52
53 # post the issue to the xmpp room(s) 53 # post the issue to the xmpp room(s)
app/models/notification_services/hoiio_service.rb
@@ -35,7 +35,7 @@ class NotificationServices::HoiioService < NotificationService @@ -35,7 +35,7 @@ class NotificationServices::HoiioService < NotificationService
35 35
36 # send sms 36 # send sms
37 room_id.split(',').each do |number| 37 room_id.split(',').each do |number|
38 - sms.send :dest => number, :msg => "http://#{Errbit::Config.host}/apps/#{problem.app.id.to_s} #{notification_description problem}" 38 + sms.send :dest => number, :msg => "#{Errbit::Config.protocol}://#{Errbit::Config.host}/apps/#{problem.app.id.to_s} #{notification_description problem}"
39 end 39 end
40 40
41 end 41 end
app/models/notification_services/pushover_service.rb
@@ -26,7 +26,7 @@ class NotificationServices::PushoverService < NotificationService @@ -26,7 +26,7 @@ class NotificationServices::PushoverService < NotificationService
26 notification = Rushover::Client.new(subdomain) 26 notification = Rushover::Client.new(subdomain)
27 27
28 # send push notification to pushover 28 # send push notification to pushover
29 - notification.notify(api_token, "#{notification_description problem}", :priority => 1, :title => "Errbit Notification", :url => "http://#{Errbit::Config.host}/apps/#{problem.app.id.to_s}", :url_title => "Link to error") 29 + notification.notify(api_token, "#{notification_description problem}", :priority => 1, :title => "Errbit Notification", :url => "#{Errbit::Config.protocol}://#{Errbit::Config.host}/apps/#{problem.app.id.to_s}", :url_title => "Link to error")
30 30
31 end 31 end
32 end 32 end
config/initializers/_load_config.rb
@@ -6,9 +6,12 @@ unless defined?(Errbit::Config) @@ -6,9 +6,12 @@ unless defined?(Errbit::Config)
6 Errbit::Config = OpenStruct.new 6 Errbit::Config = OpenStruct.new
7 use_env = ENV['HEROKU'] || ENV['USE_ENV'] 7 use_env = ENV['HEROKU'] || ENV['USE_ENV']
8 8
  9 + Errbit::Config.protocol = 'http'
  10 +
9 # If Errbit is running on Heroku, config can be set from environment variables. 11 # If Errbit is running on Heroku, config can be set from environment variables.
10 if use_env 12 if use_env
11 Errbit::Config.host = ENV['ERRBIT_HOST'] 13 Errbit::Config.host = ENV['ERRBIT_HOST']
  14 + Errbit::Config.protocol = ENV['ERRBIT_PROTOCOL'] || 'http'
12 Errbit::Config.port = ENV['ERRBIT_PORT'] 15 Errbit::Config.port = ENV['ERRBIT_PORT']
13 Errbit::Config.email_from = ENV['ERRBIT_EMAIL_FROM'] 16 Errbit::Config.email_from = ENV['ERRBIT_EMAIL_FROM']
14 # Not really easy to use like an env because need an array and ENV return a string :( 17 # Not really easy to use like an env because need an array and ENV return a string :(
spec/models/notification_service/gtalk_service_spec.rb
@@ -17,7 +17,7 @@ describe NotificationService::GtalkService do @@ -17,7 +17,7 @@ describe NotificationService::GtalkService do
17 expect(gtalk).to receive(:connect).with(notification_service.service) 17 expect(gtalk).to receive(:connect).with(notification_service.service)
18 expect(gtalk).to receive(:auth).with(notification_service.api_token) 18 expect(gtalk).to receive(:auth).with(notification_service.api_token)
19 message_value = """#{problem.app.name.to_s} 19 message_value = """#{problem.app.name.to_s}
20 -http://#{Errbit::Config.host}/apps/#{problem.app.id.to_s} 20 +#{Errbit::Config.protocol}://#{Errbit::Config.host}/apps/#{problem.app.id.to_s}
21 #{notification_service.notification_description problem}""" 21 #{notification_service.notification_description problem}"""
22 22
23 expect(Jabber::Message).to receive(:new).with(notification_service.user_id, message_value).and_return(message) 23 expect(Jabber::Message).to receive(:new).with(notification_service.user_id, message_value).and_return(message)
@@ -39,7 +39,7 @@ http://#{Errbit::Config.host}/apps/#{problem.app.id.to_s} @@ -39,7 +39,7 @@ http://#{Errbit::Config.host}/apps/#{problem.app.id.to_s}
39 @notification_service = Fabricate :gtalk_notification_service, :app => @notice.app 39 @notification_service = Fabricate :gtalk_notification_service, :app => @notice.app
40 @problem = @notice.problem 40 @problem = @notice.problem
41 @error_msg = """#{@problem.app.name.to_s} 41 @error_msg = """#{@problem.app.name.to_s}
42 -http://#{Errbit::Config.host}/apps/#{@problem.app.id.to_s} 42 +#{Errbit::Config.protocol}://#{Errbit::Config.host}/apps/#{@problem.app.id.to_s}
43 #{@notification_service.notification_description @problem}""" 43 #{@notification_service.notification_description @problem}"""
44 44
45 # gtalk stubbing 45 # gtalk stubbing
@@ -105,7 +105,7 @@ http://#{Errbit::Config.host}/apps/#{@problem.app.id.to_s} @@ -105,7 +105,7 @@ http://#{Errbit::Config.host}/apps/#{@problem.app.id.to_s}
105 expect(gtalk).to receive(:connect) 105 expect(gtalk).to receive(:connect)
106 expect(gtalk).to receive(:auth).with(notification_service.api_token) 106 expect(gtalk).to receive(:auth).with(notification_service.api_token)
107 message_value = """#{problem.app.name.to_s} 107 message_value = """#{problem.app.name.to_s}
108 -http://#{Errbit::Config.host}/apps/#{problem.app.id.to_s} 108 +#{Errbit::Config.protocol}://#{Errbit::Config.host}/apps/#{problem.app.id.to_s}
109 #{notification_service.notification_description problem}""" 109 #{notification_service.notification_description problem}"""
110 110
111 expect(Jabber::Message).to receive(:new).with(notification_service.room_id, message_value).and_return(message) 111 expect(Jabber::Message).to receive(:new).with(notification_service.room_id, message_value).and_return(message)
spec/models/notification_service/notification_service_spec.rb 0 → 100644
@@ -0,0 +1,18 @@ @@ -0,0 +1,18 @@
  1 +require 'spec_helper'
  2 +
  3 +describe NotificationService do
  4 +
  5 + let(:notice) { Fabricate :notice }
  6 + let(:notification_service) { Fabricate :notification_service, :app => notice.app }
  7 + let(:problem) { notice.problem }
  8 +
  9 + it "it should use http by default in #problem_url" do
  10 + notification_service.problem_url(problem).should start_with 'http://'
  11 + end
  12 +
  13 + it "it should use the protocol value specified in the config in #problem_url" do
  14 + Errbit::Config.protocol = 'https'
  15 + notification_service.problem_url(problem).should start_with 'https://'
  16 + end
  17 +
  18 +end