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 54 end
55 55  
56 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 58 end
59 59 end
... ...
app/models/notification_services/campfire_service.rb
... ... @@ -30,7 +30,7 @@ if defined? Campy
30 30 # build the campfire client
31 31 campy = Campy::Room.new(:account => subdomain, :token => api_token, :room_id => room_id)
32 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 34 end
35 35 end
36 36 end
... ...
app/models/notification_services/gtalk_service.rb
... ... @@ -47,7 +47,7 @@ class NotificationServices::GtalkService < NotificationService
47 47  
48 48 #has to look like this to be formatted properly in the client
49 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 51 #{notification_description problem}"""
52 52  
53 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 35  
36 36 # send sms
37 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 39 end
40 40  
41 41 end
... ...
app/models/notification_services/pushover_service.rb
... ... @@ -26,7 +26,7 @@ class NotificationServices::PushoverService < NotificationService
26 26 notification = Rushover::Client.new(subdomain)
27 27  
28 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 31 end
32 32 end
... ...
config/initializers/_load_config.rb
... ... @@ -6,9 +6,12 @@ unless defined?(Errbit::Config)
6 6 Errbit::Config = OpenStruct.new
7 7 use_env = ENV['HEROKU'] || ENV['USE_ENV']
8 8  
  9 + Errbit::Config.protocol = 'http'
  10 +
9 11 # If Errbit is running on Heroku, config can be set from environment variables.
10 12 if use_env
11 13 Errbit::Config.host = ENV['ERRBIT_HOST']
  14 + Errbit::Config.protocol = ENV['ERRBIT_PROTOCOL'] || 'http'
12 15 Errbit::Config.port = ENV['ERRBIT_PORT']
13 16 Errbit::Config.email_from = ENV['ERRBIT_EMAIL_FROM']
14 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 17 expect(gtalk).to receive(:connect).with(notification_service.service)
18 18 expect(gtalk).to receive(:auth).with(notification_service.api_token)
19 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 21 #{notification_service.notification_description problem}"""
22 22  
23 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 39 @notification_service = Fabricate :gtalk_notification_service, :app => @notice.app
40 40 @problem = @notice.problem
41 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 43 #{@notification_service.notification_description @problem}"""
44 44  
45 45 # gtalk stubbing
... ... @@ -105,7 +105,7 @@ http://#{Errbit::Config.host}/apps/#{@problem.app.id.to_s}
105 105 expect(gtalk).to receive(:connect)
106 106 expect(gtalk).to receive(:auth).with(notification_service.api_token)
107 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 109 #{notification_service.notification_description problem}"""
110 110  
111 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 @@
  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
... ...