Commit 294d63adbe29eb3639b75a0afec932756af838e7
Exists in
master
and in
1 other branch
Merge pull request #964 from rud/chore/fix-low-hanging-rubocop-issues
Fix some low hanging rubocop issues
Showing
42 changed files
with
124 additions
and
277 deletions
Show diff stats
.rubocop.yml
.rubocop_todo.yml
1 | 1 | # This configuration was generated by |
2 | 2 | # `rubocop --auto-gen-config` |
3 | -# on 2015-10-12 09:35:47 +0200 using RuboCop version 0.34.2. | |
3 | +# on 2015-10-12 21:53:36 +0200 using RuboCop version 0.34.2. | |
4 | 4 | # The point is for the user to remove these configuration records |
5 | 5 | # one by one as the offenses are removed from the code base. |
6 | 6 | # Note that changes in the inspected code, or installation of new |
... | ... | @@ -13,7 +13,7 @@ Metrics/AbcSize: |
13 | 13 | # Offense count: 5 |
14 | 14 | # Configuration parameters: CountComments. |
15 | 15 | Metrics/ClassLength: |
16 | - Max: 203 | |
16 | + Max: 206 | |
17 | 17 | |
18 | 18 | # Offense count: 5 |
19 | 19 | Metrics/CyclomaticComplexity: |
... | ... | @@ -33,36 +33,6 @@ Metrics/MethodLength: |
33 | 33 | Metrics/PerceivedComplexity: |
34 | 34 | Max: 12 |
35 | 35 | |
36 | -# Offense count: 2 | |
37 | -# Cop supports --auto-correct. | |
38 | -Performance/Sample: | |
39 | - Exclude: | |
40 | - - 'lib/tasks/errbit/demo.rake' | |
41 | - - 'spec/fabricators/backtrace_fabricator.rb' | |
42 | - | |
43 | -# Offense count: 2 | |
44 | -# Cop supports --auto-correct. | |
45 | -Performance/StringReplacement: | |
46 | - Exclude: | |
47 | - - 'app/models/notification_services/gtalk_service.rb' | |
48 | - - 'lib/hoptoad/v2.rb' | |
49 | - | |
50 | -# Offense count: 1 | |
51 | -# Cop supports --auto-correct. | |
52 | -# Configuration parameters: EnforcedStyle, SupportedStyles, Include. | |
53 | -Rails/ActionFilter: | |
54 | - Exclude: | |
55 | - - 'app/controllers/notices_controller.rb' | |
56 | - | |
57 | -# Offense count: 4 | |
58 | -# Cop supports --auto-correct. | |
59 | -# Configuration parameters: Include. | |
60 | -Rails/FindBy: | |
61 | - Exclude: | |
62 | - - 'app/models/app.rb' | |
63 | - - 'app/models/error_report.rb' | |
64 | - - 'app/models/user.rb' | |
65 | - | |
66 | 36 | # Offense count: 16 |
67 | 37 | # Configuration parameters: Include. |
68 | 38 | Rails/Output: |
... | ... | @@ -71,19 +41,6 @@ Rails/Output: |
71 | 41 | - 'app/interactors/problem_recacher.rb' |
72 | 42 | - 'db/seeds.rb' |
73 | 43 | |
74 | -# Offense count: 14 | |
75 | -# Configuration parameters: EnforcedStyle, SupportedStyles. | |
76 | -Rails/TimeZone: | |
77 | - Exclude: | |
78 | - - 'app/models/problem.rb' | |
79 | - - 'lib/tasks/errbit/demo.rake' | |
80 | - - 'spec/controllers/api/v1/notices_controller_spec.rb' | |
81 | - - 'spec/controllers/problems_controller_spec.rb' | |
82 | - - 'spec/models/error_report_spec.rb' | |
83 | - - 'spec/models/problem_spec.rb' | |
84 | - - 'spec/views/apps/index.html.haml_spec.rb' | |
85 | - - 'spec/views/users/show.html.haml_spec.rb' | |
86 | - | |
87 | 44 | # Offense count: 12 |
88 | 45 | # Configuration parameters: Include. |
89 | 46 | Rails/Validation: |
... | ... | @@ -96,19 +53,6 @@ Rails/Validation: |
96 | 53 | - 'app/models/problem.rb' |
97 | 54 | - 'app/models/user.rb' |
98 | 55 | |
99 | -# Offense count: 2 | |
100 | -# Cop supports --auto-correct. | |
101 | -# Configuration parameters: EnforcedStyle, SupportedStyles. | |
102 | -Style/AccessModifierIndentation: | |
103 | - Enabled: false | |
104 | - | |
105 | -# Offense count: 3 | |
106 | -# Cop supports --auto-correct. | |
107 | -Style/Alias: | |
108 | - Exclude: | |
109 | - - 'app/decorators/issue_tracker_field_decorator.rb' | |
110 | - - 'app/models/app.rb' | |
111 | - | |
112 | 56 | # Offense count: 8 |
113 | 57 | # Cop supports --auto-correct. |
114 | 58 | # Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles. |
... | ... | @@ -120,7 +64,7 @@ Style/AlignHash: |
120 | 64 | - 'spec/controllers/problems_controller_spec.rb' |
121 | 65 | - 'spec/models/problem_spec.rb' |
122 | 66 | |
123 | -# Offense count: 7 | |
67 | +# Offense count: 6 | |
124 | 68 | # Cop supports --auto-correct. |
125 | 69 | # Configuration parameters: EnforcedStyle, SupportedStyles. |
126 | 70 | Style/AlignParameters: |
... | ... | @@ -128,17 +72,8 @@ Style/AlignParameters: |
128 | 72 | - 'app/helpers/apps_helper.rb' |
129 | 73 | - 'app/models/app.rb' |
130 | 74 | - 'app/models/notification_services/gtalk_service.rb' |
131 | - - 'app/models/problem.rb' | |
132 | 75 | - 'config/initializers/devise.rb' |
133 | 76 | |
134 | -# Offense count: 2 | |
135 | -# Cop supports --auto-correct. | |
136 | -# Configuration parameters: EnforcedStyle, SupportedStyles. | |
137 | -Style/AndOr: | |
138 | - Exclude: | |
139 | - - 'app/controllers/users_controller.rb' | |
140 | - - 'app/models/error_report.rb' | |
141 | - | |
142 | 77 | # Offense count: 105 |
143 | 78 | # Cop supports --auto-correct. |
144 | 79 | # Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods. |
... | ... | @@ -178,19 +113,6 @@ Style/ClassAndModuleChildren: |
178 | 113 | - 'app/models/notification_services/webhook_service.rb' |
179 | 114 | - 'config/initializers/overrides.rb' |
180 | 115 | |
181 | -# Offense count: 1 | |
182 | -# Cop supports --auto-correct. | |
183 | -# Configuration parameters: EnforcedStyle, SupportedStyles. | |
184 | -Style/ClassCheck: | |
185 | - Exclude: | |
186 | - - 'app/helpers/navigation_helper.rb' | |
187 | - | |
188 | -# Offense count: 1 | |
189 | -# Cop supports --auto-correct. | |
190 | -Style/ClosingParenthesisIndentation: | |
191 | - Exclude: | |
192 | - - 'app/models/problem.rb' | |
193 | - | |
194 | 116 | # Offense count: 23 |
195 | 117 | Style/ConstantName: |
196 | 118 | Exclude: |
... | ... | @@ -205,33 +127,17 @@ Style/ConstantName: |
205 | 127 | - 'app/models/notification_services/slack_service.rb' |
206 | 128 | - 'app/models/notification_services/webhook_service.rb' |
207 | 129 | |
208 | -# Offense count: 11 | |
209 | -# Cop supports --auto-correct. | |
210 | -Style/DeprecatedHashMethods: | |
211 | - Exclude: | |
212 | - - 'lib/airbrake_api/v3/notice_parser.rb' | |
213 | - - 'lib/hoptoad/v2.rb' | |
214 | - - 'spec/lib/airbrake_api/v3/notice_parser_spec.rb' | |
215 | - | |
216 | 130 | # Offense count: 70 |
217 | 131 | # Configuration parameters: Exclude. |
218 | 132 | Style/Documentation: |
219 | 133 | Enabled: false |
220 | 134 | |
221 | -# Offense count: 7 | |
135 | +# Offense count: 9 | |
222 | 136 | # Cop supports --auto-correct. |
223 | 137 | # Configuration parameters: EnforcedStyle, SupportedStyles. |
224 | 138 | Style/DotPosition: |
225 | 139 | Enabled: false |
226 | 140 | |
227 | -# Offense count: 6 | |
228 | -Style/DoubleNegation: | |
229 | - Exclude: | |
230 | - - 'Gemfile' | |
231 | - - 'app/controllers/apps_controller.rb' | |
232 | - - 'app/helpers/apps_helper.rb' | |
233 | - - 'app/models/app.rb' | |
234 | - | |
235 | 141 | # Offense count: 5 |
236 | 142 | Style/EachWithObject: |
237 | 143 | Exclude: |
... | ... | @@ -253,12 +159,11 @@ Style/EmptyLineBetweenDefs: |
253 | 159 | - 'spec/decorators/issue_tracker_type_decorator_spec.rb' |
254 | 160 | - 'spec/views/problems/show.html.haml_spec.rb' |
255 | 161 | |
256 | -# Offense count: 13 | |
162 | +# Offense count: 12 | |
257 | 163 | # Cop supports --auto-correct. |
258 | 164 | Style/EmptyLines: |
259 | 165 | Exclude: |
260 | 166 | - 'app/controllers/api/v1/stats_controller.rb' |
261 | - - 'app/controllers/application_controller.rb' | |
262 | 167 | - 'app/decorators/issue_tracker_field_decorator.rb' |
263 | 168 | - 'app/models/app.rb' |
264 | 169 | - 'app/models/problem.rb' |
... | ... | @@ -267,20 +172,6 @@ Style/EmptyLines: |
267 | 172 | - 'script/rspec-queue-mongoid.rb' |
268 | 173 | - 'spec/acceptance/app_regenerate_api_key_spec.rb' |
269 | 174 | |
270 | -# Offense count: 9 | |
271 | -# Cop supports --auto-correct. | |
272 | -Style/EmptyLinesAroundAccessModifier: | |
273 | - Exclude: | |
274 | - - 'app/controllers/apps_controller.rb' | |
275 | - - 'app/controllers/comments_controller.rb' | |
276 | - - 'app/decorators/backtrace_line_decorator.rb' | |
277 | - - 'app/helpers/application_helper.rb' | |
278 | - - 'app/models/backtrace.rb' | |
279 | - - 'app/models/comment.rb' | |
280 | - - 'lib/hoptoad.rb' | |
281 | - - 'lib/hoptoad/v2.rb' | |
282 | - - 'lib/overrides/hoptoad_notifier/hoptoad_notifier.rb' | |
283 | - | |
284 | 175 | # Offense count: 28 |
285 | 176 | # Cop supports --auto-correct. |
286 | 177 | # Configuration parameters: EnforcedStyle, SupportedStyles. |
... | ... | @@ -398,13 +289,6 @@ Style/IndentationConsistency: |
398 | 289 | - 'app/models/watcher.rb' |
399 | 290 | - 'lib/hoptoad.rb' |
400 | 291 | |
401 | -# Offense count: 1 | |
402 | -# Cop supports --auto-correct. | |
403 | -# Configuration parameters: Width. | |
404 | -Style/IndentationWidth: | |
405 | - Exclude: | |
406 | - - 'app/controllers/notices_controller.rb' | |
407 | - | |
408 | 292 | # Offense count: 6 |
409 | 293 | # Cop supports --auto-correct. |
410 | 294 | Style/Lambda: |
... | ... | @@ -427,19 +311,6 @@ Style/LeadingCommentSpace: |
427 | 311 | - 'spec/models/notification_service/hoiio_service_spec.rb' |
428 | 312 | - 'spec/models/notification_service/pushover_service_spec.rb' |
429 | 313 | |
430 | -# Offense count: 6 | |
431 | -# Cop supports --auto-correct. | |
432 | -Style/MethodCallParentheses: | |
433 | - Exclude: | |
434 | - - 'spec/controllers/api/v1/notices_controller_spec.rb' | |
435 | - - 'spec/controllers/api/v1/problems_controller_spec.rb' | |
436 | - | |
437 | -# Offense count: 3 | |
438 | -# Cop supports --auto-correct. | |
439 | -# Configuration parameters: EnforcedStyle, SupportedStyles. | |
440 | -Style/MethodDefParentheses: | |
441 | - Enabled: false | |
442 | - | |
443 | 314 | # Offense count: 7 |
444 | 315 | # Cop supports --auto-correct. |
445 | 316 | Style/MultilineBlockLayout: |
... | ... | @@ -457,19 +328,6 @@ Style/MultilineBlockLayout: |
457 | 328 | Style/MultilineOperationIndentation: |
458 | 329 | Enabled: false |
459 | 330 | |
460 | -# Offense count: 1 | |
461 | -# Cop supports --auto-correct. | |
462 | -Style/NegatedIf: | |
463 | - Exclude: | |
464 | - - 'app/controllers/apps_controller.rb' | |
465 | - | |
466 | -# Offense count: 2 | |
467 | -# Cop supports --auto-correct. | |
468 | -Style/ParallelAssignment: | |
469 | - Exclude: | |
470 | - - 'app/models/problem.rb' | |
471 | - - 'spec/models/app_spec.rb' | |
472 | - | |
473 | 331 | # Offense count: 5 |
474 | 332 | # Cop supports --auto-correct. |
475 | 333 | # Configuration parameters: PreferredDelimiters. |
... | ... | @@ -494,19 +352,9 @@ Style/Proc: |
494 | 352 | - 'app/models/problem.rb' |
495 | 353 | |
496 | 354 | # Offense count: 2 |
497 | -# Configuration parameters: SupportedStyles. | |
355 | +# Configuration parameters: EnforcedStyle, SupportedStyles. | |
498 | 356 | Style/RaiseArgs: |
499 | - EnforcedStyle: compact | |
500 | - | |
501 | -# Offense count: 13 | |
502 | -# Cop supports --auto-correct. | |
503 | -Style/RedundantSelf: | |
504 | - Exclude: | |
505 | - - 'app/models/app.rb' | |
506 | - - 'app/models/issue_tracker.rb' | |
507 | - - 'app/models/notification_service.rb' | |
508 | - - 'app/models/problem.rb' | |
509 | - - 'lib/configurator.rb' | |
357 | + Enabled: false | |
510 | 358 | |
511 | 359 | # Offense count: 3 |
512 | 360 | # Cop supports --auto-correct. |
... | ... | @@ -715,22 +563,3 @@ Style/TrailingWhitespace: |
715 | 563 | Style/UnlessElse: |
716 | 564 | Exclude: |
717 | 565 | - 'app/controllers/problems_searcher.rb' |
718 | - | |
719 | -# Offense count: 1 | |
720 | -# Cop supports --auto-correct. | |
721 | -Style/UnneededPercentQ: | |
722 | - Exclude: | |
723 | - - 'spec/models/notice_spec.rb' | |
724 | - | |
725 | -# Offense count: 6 | |
726 | -# Cop supports --auto-correct. | |
727 | -Style/WhenThen: | |
728 | - Exclude: | |
729 | - - 'app/models/problem.rb' | |
730 | - - 'lib/hoptoad.rb' | |
731 | - | |
732 | -# Offense count: 10 | |
733 | -# Cop supports --auto-correct. | |
734 | -# Configuration parameters: WordRegex. | |
735 | -Style/WordArray: | |
736 | - MinSize: 11 | ... | ... |
Gemfile
... | ... | @@ -8,8 +8,8 @@ detected_ruby_version = Gem::Version.new(RUBY_VERSION.dup) |
8 | 8 | required_ruby_version = Gem::Version.new('2.1.0') # minimum supported version |
9 | 9 | |
10 | 10 | if detected_ruby_version < required_ruby_version |
11 | - fail RuntimeError, "RUBY_VERSION must be at least #{required_ruby_version}" \ | |
12 | - ", detected RUBY_VERSION #{RUBY_VERSION}" | |
11 | + fail "RUBY_VERSION must be at least #{required_ruby_version}, " \ | |
12 | + "detected RUBY_VERSION #{RUBY_VERSION}" | |
13 | 13 | end |
14 | 14 | |
15 | 15 | gem 'actionmailer', RAILS_VERSION |
... | ... | @@ -100,7 +100,7 @@ group :test do |
100 | 100 | end |
101 | 101 | |
102 | 102 | group :heroku, :production do |
103 | - gem 'rails_12factor', require: !!ENV["HEROKU"] | |
103 | + gem 'rails_12factor', require: ENV.key?("HEROKU") | |
104 | 104 | gem 'unicorn', require: false, platform: 'ruby' |
105 | 105 | end |
106 | 106 | ... | ... |
app/controllers/application_controller.rb
app/controllers/apps_controller.rb
... | ... | @@ -20,7 +20,7 @@ class AppsController < ApplicationController |
20 | 20 | end |
21 | 21 | |
22 | 22 | expose(:all_errs) { |
23 | - !!params[:all_errs] | |
23 | + params[:all_errs].present? | |
24 | 24 | } |
25 | 25 | |
26 | 26 | expose(:problems) { |
... | ... | @@ -97,13 +97,13 @@ class AppsController < ApplicationController |
97 | 97 | if params[:app][:notification_service_attributes] && (notification_type = params[:app][:notification_service_attributes][:type]) |
98 | 98 | available_notification_classes = [NotificationService] + NotificationService.subclasses |
99 | 99 | notification_class = available_notification_classes.detect{|c| c.name == notification_type} |
100 | - if !notification_class.nil? | |
100 | + if notification_class.present? | |
101 | 101 | app.notification_service = notification_class.new(params[:app][:notification_service_attributes]) |
102 | 102 | end |
103 | 103 | end |
104 | 104 | end |
105 | 105 | |
106 | - def plug_params app | |
106 | + def plug_params(app) | |
107 | 107 | app.watchers.build if app.watchers.none? |
108 | 108 | app.issue_tracker ||= IssueTracker.new |
109 | 109 | app.notification_service = NotificationService.new unless app.notification_service_configured? |
... | ... | @@ -142,6 +142,7 @@ class AppsController < ApplicationController |
142 | 142 | end |
143 | 143 | |
144 | 144 | private |
145 | + | |
145 | 146 | def app_params |
146 | 147 | params.require(:app).permit! |
147 | 148 | end | ... | ... |
app/controllers/comments_controller.rb
app/controllers/notices_controller.rb
... | ... | @@ -3,7 +3,7 @@ class NoticesController < ApplicationController |
3 | 3 | class ParamsError < StandardError; end |
4 | 4 | |
5 | 5 | skip_before_action :authenticate_user!, only: :create |
6 | - skip_before_filter :verify_authenticity_token, only: :create | |
6 | + skip_before_action :verify_authenticity_token, only: :create | |
7 | 7 | |
8 | 8 | rescue_from ParamsError, :with => :bad_params |
9 | 9 | |
... | ... | @@ -15,7 +15,7 @@ class NoticesController < ApplicationController |
15 | 15 | if report.should_keep? |
16 | 16 | report.generate_notice! |
17 | 17 | api_xml = report.notice.to_xml(:only => false, :methods => [:id]) do |xml| |
18 | - xml.url locate_url(report.notice.id, :host => Errbit::Config.host) | |
18 | + xml.url locate_url(report.notice.id, :host => Errbit::Config.host) | |
19 | 19 | end |
20 | 20 | render :xml => api_xml |
21 | 21 | else | ... | ... |
app/controllers/users_controller.rb
... | ... | @@ -55,7 +55,7 @@ class UsersController < ApplicationController |
55 | 55 | |
56 | 56 | def require_user_edit_priviledges |
57 | 57 | can_edit = current_user == user || current_user.admin? |
58 | - redirect_to(root_path) and return(false) unless can_edit | |
58 | + redirect_to(root_path) unless can_edit | |
59 | 59 | end |
60 | 60 | |
61 | 61 | def user_params | ... | ... |
app/decorators/backtrace_line_decorator.rb
app/decorators/issue_tracker_field_decorator.rb
app/helpers/application_helper.rb
app/helpers/apps_helper.rb
... | ... | @@ -45,7 +45,7 @@ module AppsHelper |
45 | 45 | @any_github_repos ||= app.github_repo? |
46 | 46 | @any_bitbucket_repos ||= app.bitbucket_repo? |
47 | 47 | @any_issue_trackers ||= app.issue_tracker_configured? |
48 | - @any_deploys ||= !!app.last_deploy_at | |
48 | + @any_deploys ||= app.last_deploy_at.present? | |
49 | 49 | @any_notification_services ||= app.notification_service_configured? |
50 | 50 | end |
51 | 51 | end | ... | ... |
app/helpers/navigation_helper.rb
... | ... | @@ -28,7 +28,7 @@ module NavigationHelper |
28 | 28 | |
29 | 29 | active = nil |
30 | 30 | sections.each do |controller, actions| |
31 | - actions = ([] << actions) unless actions.kind_of?(Array) | |
31 | + actions = Array(actions) | |
32 | 32 | active = ' active' if current_controller == controller && (actions.include?(:all) || actions.include?(current_action)) |
33 | 33 | end |
34 | 34 | active | ... | ... |
app/models/app.rb
... | ... | @@ -94,7 +94,7 @@ class App |
94 | 94 | def notify_on_errs |
95 | 95 | !(super == false) |
96 | 96 | end |
97 | - alias :notify_on_errs? :notify_on_errs | |
97 | + alias_method :notify_on_errs?, :notify_on_errs | |
98 | 98 | |
99 | 99 | def emailable? |
100 | 100 | notify_on_errs? && notification_recipients.any? |
... | ... | @@ -103,14 +103,14 @@ class App |
103 | 103 | def notify_on_deploys |
104 | 104 | !(super == false) |
105 | 105 | end |
106 | - alias :notify_on_deploys? :notify_on_deploys | |
106 | + alias_method :notify_on_deploys?, :notify_on_deploys | |
107 | 107 | |
108 | 108 | def repo_branch |
109 | - self.repository_branch.present? ? self.repository_branch : 'master' | |
109 | + repository_branch.present? ? repository_branch : 'master' | |
110 | 110 | end |
111 | 111 | |
112 | 112 | def github_repo? |
113 | - self.github_repo.present? | |
113 | + github_repo.present? | |
114 | 114 | end |
115 | 115 | |
116 | 116 | def github_url |
... | ... | @@ -122,7 +122,7 @@ class App |
122 | 122 | end |
123 | 123 | |
124 | 124 | def bitbucket_repo? |
125 | - self.bitbucket_repo.present? | |
125 | + bitbucket_repo.present? | |
126 | 126 | end |
127 | 127 | |
128 | 128 | def bitbucket_url |
... | ... | @@ -135,11 +135,12 @@ class App |
135 | 135 | |
136 | 136 | |
137 | 137 | def issue_tracker_configured? |
138 | - !!issue_tracker && !!(issue_tracker.configured?) | |
138 | + issue_tracker.present? && issue_tracker.configured? | |
139 | 139 | end |
140 | 140 | |
141 | 141 | def notification_service_configured? |
142 | - !!(notification_service.class < NotificationService && notification_service.configured?) | |
142 | + (notification_service.class < NotificationService) && | |
143 | + notification_service.configured? | |
143 | 144 | end |
144 | 145 | |
145 | 146 | |
... | ... | @@ -156,12 +157,12 @@ class App |
156 | 157 | if (copy_app = App.where(:_id => app_id).first) |
157 | 158 | # Copy fields |
158 | 159 | (copy_app.fields.keys - %w(_id name created_at updated_at)).each do |k| |
159 | - self.send("#{k}=", copy_app.send(k)) | |
160 | + send("#{k}=", copy_app.send(k)) | |
160 | 161 | end |
161 | 162 | # Clone the embedded objects that can be changed via apps/edit (ignore errs & deploys, etc.) |
162 | 163 | %w(watchers issue_tracker notification_service).each do |relation| |
163 | 164 | if (obj = copy_app.send(relation)) |
164 | - self.send("#{relation}=", obj.is_a?(Array) ? obj.map(&:clone) : obj.clone) | |
165 | + send("#{relation}=", obj.is_a?(Array) ? obj.map(&:clone) : obj.clone) | |
165 | 166 | end |
166 | 167 | end |
167 | 168 | end | ... | ... |
app/models/backtrace.rb
app/models/comment.rb
app/models/error_report.rb
... | ... | @@ -94,7 +94,7 @@ class ErrorReport |
94 | 94 | |
95 | 95 | # Launch all notification define on the app associate to this notice |
96 | 96 | def services_notification |
97 | - return true unless app.notification_service_configured? and should_notify? | |
97 | + return true unless app.notification_service_configured? && should_notify? | |
98 | 98 | app.notification_service.create_notification(problem) |
99 | 99 | rescue => e |
100 | 100 | HoptoadNotifier.notify(e) | ... | ... |
app/models/issue_tracker.rb
... | ... | @@ -12,7 +12,7 @@ class IssueTracker |
12 | 12 | def tracker |
13 | 13 | @tracker ||= |
14 | 14 | begin |
15 | - klass = ErrbitPlugin::Registry.issue_trackers[self.type_tracker] || ErrbitPlugin::NoneIssueTracker | |
15 | + klass = ErrbitPlugin::Registry.issue_trackers[type_tracker] || ErrbitPlugin::NoneIssueTracker | |
16 | 16 | # TODO: we need to find out a better way to pass those config to the issue tracker |
17 | 17 | klass.new(options.merge( |
18 | 18 | github_repo: app.try(:github_repo), |
... | ... | @@ -22,7 +22,7 @@ class IssueTracker |
22 | 22 | end |
23 | 23 | |
24 | 24 | def type_tracker |
25 | - self.attributes['type_tracker'] ? self.attributes['type_tracker'] : 'none' | |
25 | + attributes['type_tracker'] ? attributes['type_tracker'] : 'none' | |
26 | 26 | end |
27 | 27 | |
28 | 28 | # Allow the tracker to validate its own params | ... | ... |
app/models/notification_service.rb
app/models/notification_services/gtalk_service.rb
... | ... | @@ -59,13 +59,13 @@ class NotificationServices::GtalkService < NotificationService |
59 | 59 | |
60 | 60 | private |
61 | 61 | |
62 | - def send_to_users client, message | |
63 | - user_id.gsub(/ /i, ",").gsub(/;/i, ",").split(",").map(&:strip).reject(&:empty?).each do |user| | |
62 | + def send_to_users(client, message) | |
63 | + user_id.tr(' ', ",").tr(';', ",").split(",").map(&:strip).reject(&:empty?).each do |user| | |
64 | 64 | client.send(Jabber::Message.new(user, message)) |
65 | 65 | end |
66 | 66 | end |
67 | 67 | |
68 | - def send_to_muc client, message | |
68 | + def send_to_muc(client, message) | |
69 | 69 | #TODO: set this so that it can send to multiple rooms like users, nb multiple room joins in one send fail randomly so leave as one room for the moment |
70 | 70 | muc = Jabber::MUC::SimpleMUCClient.new(client) |
71 | 71 | muc.join(room_id + "/errbit") | ... | ... |
app/models/notification_services/hipchat_service.rb
app/models/problem.rb
... | ... | @@ -13,8 +13,8 @@ class Problem |
13 | 13 | }.freeze |
14 | 14 | |
15 | 15 | |
16 | - field :last_notice_at, :type => ActiveSupport::TimeWithZone, :default => Proc.new { Time.now } | |
17 | - field :first_notice_at, :type => ActiveSupport::TimeWithZone, :default => Proc.new { Time.now } | |
16 | + field :last_notice_at, :type => ActiveSupport::TimeWithZone, :default => Proc.new { Time.zone.now } | |
17 | + field :first_notice_at, :type => ActiveSupport::TimeWithZone, :default => Proc.new { Time.zone.now } | |
18 | 18 | field :last_deploy_at, :type => Time |
19 | 19 | field :resolved, :type => Boolean, :default => false |
20 | 20 | field :resolved_at, :type => Time |
... | ... | @@ -162,7 +162,9 @@ class Problem |
162 | 162 | end |
163 | 163 | |
164 | 164 | def url |
165 | - Rails.application.routes.url_helpers.app_problem_url(app, self, | |
165 | + Rails.application.routes.url_helpers.app_problem_url( | |
166 | + app, | |
167 | + self, | |
166 | 168 | :host => Errbit::Config.host, |
167 | 169 | :port => Errbit::Config.port |
168 | 170 | ) |
... | ... | @@ -173,7 +175,7 @@ class Problem |
173 | 175 | end |
174 | 176 | |
175 | 177 | def resolve! |
176 | - self.update_attributes!(:resolved => true, :resolved_at => Time.now) | |
178 | + self.update_attributes!(:resolved => true, :resolved_at => Time.zone.now) | |
177 | 179 | end |
178 | 180 | |
179 | 181 | def unresolve! |
... | ... | @@ -214,11 +216,11 @@ class Problem |
214 | 216 | |
215 | 217 | def self.ordered_by(sort, order) |
216 | 218 | case sort |
217 | - when "app"; order_by(["app_name", order]) | |
218 | - when "message"; order_by(["message", order]) | |
219 | - when "last_notice_at"; order_by(["last_notice_at", order]) | |
220 | - when "last_deploy_at"; order_by(["last_deploy_at", order]) | |
221 | - when "count"; order_by(["notices_count", order]) | |
219 | + when "app" then order_by(["app_name", order]) | |
220 | + when "message" then order_by(["message", order]) | |
221 | + when "last_notice_at" then order_by(["last_notice_at", order]) | |
222 | + when "last_deploy_at" then order_by(["last_deploy_at", order]) | |
223 | + when "count" then order_by(["notices_count", order]) | |
222 | 224 | else raise("\"#{sort}\" is not a recognized sort") |
223 | 225 | end |
224 | 226 | end |
... | ... | @@ -231,7 +233,7 @@ class Problem |
231 | 233 | end |
232 | 234 | |
233 | 235 | def truncate_message |
234 | - self.message = self.message[0, 1000] if self.message | |
236 | + self.message = message[0, 1000] if message | |
235 | 237 | end |
236 | 238 | |
237 | 239 | def issue_type |
... | ... | @@ -247,7 +249,8 @@ class Problem |
247 | 249 | private |
248 | 250 | |
249 | 251 | def attribute_count_descrease(name, value) |
250 | - counter, index = send(name), attribute_index(value) | |
252 | + counter = send(name) | |
253 | + index = attribute_index(value) | |
251 | 254 | if counter[index] && counter[index]['count'] > 1 |
252 | 255 | counter[index]['count'] -= 1 |
253 | 256 | else | ... | ... |
config/load.rb
... | ... | @@ -26,7 +26,7 @@ Errbit::Config = Configurator.run({ |
26 | 26 | |
27 | 27 | serve_static_assets: ['SERVE_STATIC_ASSETS'], |
28 | 28 | secret_key_base: ['SECRET_KEY_BASE'], |
29 | - mongo_url: ['MONGOLAB_URI', 'MONGOHQ_URL', 'MONGODB_URL', 'MONGO_URL'], | |
29 | + mongo_url: %w(MONGOLAB_URI MONGOHQ_URL MONGODB_URL MONGO_URL), | |
30 | 30 | |
31 | 31 | # github |
32 | 32 | github_url: ['GITHUB_URL', ->(values) { |
... | ... | @@ -48,8 +48,8 @@ Errbit::Config = Configurator.run({ |
48 | 48 | smtp_address: ['SMTP_SERVER'], |
49 | 49 | smtp_port: ['SMTP_PORT'], |
50 | 50 | smtp_authentication: ['SMTP_AUTHENTICATION'], |
51 | - smtp_user_name: ['SMTP_USERNAME', 'SENDGRID_USERNAME'], | |
52 | - smtp_password: ['SMTP_PASSWORD', 'SENDGRID_PASSWORD'], | |
51 | + smtp_user_name: %w(SMTP_USERNAME SENDGRID_USERNAME), | |
52 | + smtp_password: %w(SMTP_PASSWORD SENDGRID_PASSWORD), | |
53 | 53 | smtp_domain: ['SMTP_DOMAIN', 'SENDGRID_DOMAIN', ->(values) { |
54 | 54 | values[:smtp_domain] || |
55 | 55 | (values[:email_from] && values[:email_from].split('@').last)|| | ... | ... |
lib/airbrake_api/v3/notice_parser.rb
... | ... | @@ -27,7 +27,7 @@ module AirbrakeApi |
27 | 27 | private |
28 | 28 | |
29 | 29 | def error |
30 | - raise AirbrakeApi::ParamsError unless params.has_key?('errors') && params['errors'].any? | |
30 | + raise AirbrakeApi::ParamsError unless params.key?('errors') && params['errors'].any? | |
31 | 31 | @error ||= params['errors'].first |
32 | 32 | end |
33 | 33 | ... | ... |
lib/configurator.rb
lib/hoptoad.rb
lib/hoptoad/v2.rb
... | ... | @@ -6,25 +6,26 @@ module Hoptoad |
6 | 6 | rekey(parsed))) |
7 | 7 | end |
8 | 8 | |
9 | - private | |
9 | + private | |
10 | + | |
10 | 11 | def self.rekey(node) |
11 | 12 | case node |
12 | 13 | when Hash |
13 | - if node.has_key?('var') && node.has_key?('key') | |
14 | + if node.key?('var') && node.key?('key') | |
14 | 15 | {normalize_key(node['key']) => rekey(node['var'])} |
15 | - elsif node.has_key?('var') | |
16 | + elsif node.key?('var') | |
16 | 17 | rekey(node['var']) |
17 | - elsif node.has_key?('__content__') && node.has_key?('key') | |
18 | + elsif node.key?('__content__') && node.key?('key') | |
18 | 19 | {normalize_key(node['key']) => rekey(node['__content__'])} |
19 | - elsif node.has_key?('__content__') | |
20 | + elsif node.key?('__content__') | |
20 | 21 | rekey(node['__content__']) |
21 | - elsif node.has_key?('key') | |
22 | + elsif node.key?('key') | |
22 | 23 | {normalize_key(node['key']) => nil} |
23 | 24 | else |
24 | 25 | node.inject({}) {|rekeyed, (key, val)| rekeyed.merge(normalize_key(key) => rekey(val))} |
25 | 26 | end |
26 | 27 | when Array |
27 | - if node.first.has_key?('key') | |
28 | + if node.first.key?('key') | |
28 | 29 | node.inject({}) {|rekeyed, keypair| rekeyed.merge(rekey(keypair))} |
29 | 30 | else |
30 | 31 | node.map {|n| rekey(n)} |
... | ... | @@ -35,7 +36,7 @@ module Hoptoad |
35 | 36 | end |
36 | 37 | |
37 | 38 | def self.normalize_key(key) |
38 | - key.gsub('.', '_') | |
39 | + key.tr('.', '_') | |
39 | 40 | end |
40 | 41 | |
41 | 42 | def self.normalize(notice) | ... | ... |
lib/overrides/hoptoad_notifier/hoptoad_notifier.rb
lib/tasks/errbit/demo.rake
... | ... | @@ -3,7 +3,7 @@ namespace :errbit do |
3 | 3 | task :demo => :environment do |
4 | 4 | require 'fabrication' |
5 | 5 | |
6 | - app = Fabricate(:app, :name => "Demo App #{Time.now.strftime("%N")}") | |
6 | + app = Fabricate(:app, :name => "Demo App #{Time.zone.now.strftime("%N")}") | |
7 | 7 | |
8 | 8 | # Report a number of errors for the application |
9 | 9 | app.problems.delete_all |
... | ... | @@ -35,7 +35,7 @@ namespace :errbit do |
35 | 35 | 99.times {|t| backtrace << { |
36 | 36 | 'number' => t.hash % 1000, |
37 | 37 | 'file' => "/path/to/file.rb", |
38 | - 'method' => RANDOM_METHODS.shuffle.first.to_s | |
38 | + 'method' => RANDOM_METHODS.sample.to_s | |
39 | 39 | }} |
40 | 40 | backtrace |
41 | 41 | end | ... | ... |
spec/controllers/api/v1/notices_controller_spec.rb
... | ... | @@ -6,15 +6,15 @@ describe Api::V1::NoticesController, type: 'controller' do |
6 | 6 | |
7 | 7 | describe "GET /api/v1/notices" do |
8 | 8 | before do |
9 | - Fabricate(:notice, :created_at => Time.new(2012, 8, 01)) | |
10 | - Fabricate(:notice, :created_at => Time.new(2012, 8, 01)) | |
11 | - Fabricate(:notice, :created_at => Time.new(2012, 8, 21)) | |
12 | - Fabricate(:notice, :created_at => Time.new(2012, 8, 30)) | |
9 | + Fabricate(:notice, :created_at => Time.zone.parse('2012-08-01')) | |
10 | + Fabricate(:notice, :created_at => Time.zone.parse('2012-08-01')) | |
11 | + Fabricate(:notice, :created_at => Time.zone.parse('2012-08-21')) | |
12 | + Fabricate(:notice, :created_at => Time.zone.parse('2012-08-30')) | |
13 | 13 | end |
14 | 14 | |
15 | 15 | it "should return JSON if JSON is requested" do |
16 | 16 | get :index, :auth_token => @user.authentication_token, :format => "json" |
17 | - expect { JSON.load(response.body) }.not_to raise_error() #JSON::ParserError) | |
17 | + expect { JSON.load(response.body) }.not_to raise_error #JSON::ParserError) | |
18 | 18 | end |
19 | 19 | |
20 | 20 | it "should return XML if XML is requested" do |
... | ... | @@ -24,7 +24,7 @@ describe Api::V1::NoticesController, type: 'controller' do |
24 | 24 | |
25 | 25 | it "should return JSON by default" do |
26 | 26 | get :index, :auth_token => @user.authentication_token |
27 | - expect { JSON.load(response.body) }.not_to raise_error() #JSON::ParserError) | |
27 | + expect { JSON.load(response.body) }.not_to raise_error #JSON::ParserError) | |
28 | 28 | end |
29 | 29 | |
30 | 30 | describe "given a date range" do | ... | ... |
spec/controllers/api/v1/problems_controller_spec.rb
... | ... | @@ -13,7 +13,7 @@ describe Api::V1::ProblemsController, type: 'controller' do |
13 | 13 | |
14 | 14 | it "should return JSON if JSON is requested" do |
15 | 15 | get :show, :auth_token => @user.authentication_token, :format => "json", :id => Problem.first.id |
16 | - expect { JSON.load(response.body) }.not_to raise_error() #JSON::ParserError | |
16 | + expect { JSON.load(response.body) }.not_to raise_error #JSON::ParserError | |
17 | 17 | end |
18 | 18 | |
19 | 19 | it "should return XML if XML is requested" do |
... | ... | @@ -23,7 +23,7 @@ describe Api::V1::ProblemsController, type: 'controller' do |
23 | 23 | |
24 | 24 | it "should return JSON by default" do |
25 | 25 | get :show, :auth_token => @user.authentication_token, :id => @problem.id |
26 | - expect { JSON.load(response.body) }.not_to raise_error()#JSON::ParserError) | |
26 | + expect { JSON.load(response.body) }.not_to raise_error#JSON::ParserError) | |
27 | 27 | end |
28 | 28 | |
29 | 29 | it "should return the correct problem" do |
... | ... | @@ -37,19 +37,18 @@ describe Api::V1::ProblemsController, type: 'controller' do |
37 | 37 | get :show, :auth_token => @user.authentication_token, :format => "json", :id => @problem.id |
38 | 38 | returned_problem = JSON.parse(response.body) |
39 | 39 | |
40 | - expect( returned_problem.keys ).to match_array([ | |
41 | - "app_name", | |
42 | - "first_notice_at", | |
43 | - "message", | |
44 | - "app_id", | |
45 | - "last_notice_at", | |
46 | - "_id", | |
47 | - "resolved", | |
48 | - "resolved_at", | |
49 | - "where", | |
50 | - "notices_count", | |
51 | - "environment" | |
52 | - ]) | |
40 | + expect( returned_problem.keys ).to match_array(%w( | |
41 | + app_name | |
42 | + first_notice_at | |
43 | + message | |
44 | + app_id | |
45 | + last_notice_at | |
46 | + _id | |
47 | + resolved | |
48 | + resolved_at | |
49 | + where | |
50 | + notices_count | |
51 | + environment)) | |
53 | 52 | end |
54 | 53 | |
55 | 54 | it "returns a 404 if the problem cannot be found" do |
... | ... | @@ -68,7 +67,7 @@ describe Api::V1::ProblemsController, type: 'controller' do |
68 | 67 | |
69 | 68 | it "should return JSON if JSON is requested" do |
70 | 69 | get :index, :auth_token => @user.authentication_token, :format => "json" |
71 | - expect { JSON.load(response.body) }.not_to raise_error()#JSON::ParserError) | |
70 | + expect { JSON.load(response.body) }.not_to raise_error#JSON::ParserError) | |
72 | 71 | end |
73 | 72 | |
74 | 73 | it "should return XML if XML is requested" do |
... | ... | @@ -78,7 +77,7 @@ describe Api::V1::ProblemsController, type: 'controller' do |
78 | 77 | |
79 | 78 | it "should return JSON by default" do |
80 | 79 | get :index, :auth_token => @user.authentication_token |
81 | - expect { JSON.load(response.body) }.not_to raise_error()#JSON::ParserError) | |
80 | + expect { JSON.load(response.body) }.not_to raise_error#JSON::ParserError) | |
82 | 81 | end |
83 | 82 | |
84 | 83 | describe "given a date range" do | ... | ... |
spec/controllers/apps_controller_spec.rb
... | ... | @@ -118,7 +118,7 @@ describe AppsController, type: 'controller' do |
118 | 118 | |
119 | 119 | context 'with environment filters' do |
120 | 120 | before(:each) do |
121 | - environments = ['production', 'test', 'development', 'staging'] | |
121 | + environments = %w(production test development staging) | |
122 | 122 | 20.times do |i| |
123 | 123 | Fabricate(:problem, :app => app, :environment => environments[i % environments.length]) |
124 | 124 | end | ... | ... |
spec/controllers/problems_controller_spec.rb
... | ... | @@ -34,7 +34,7 @@ describe ProblemsController, type: 'controller' do |
34 | 34 | |
35 | 35 | context 'with environment filters' do |
36 | 36 | before(:each) do |
37 | - environments = ['production', 'test', 'development', 'staging'] | |
37 | + environments = %w(production test development staging) | |
38 | 38 | 20.times do |i| |
39 | 39 | Fabricate(:problem, :environment => environments[i % environments.length]) |
40 | 40 | end |
... | ... | @@ -139,7 +139,7 @@ describe ProblemsController, type: 'controller' do |
139 | 139 | context 'pagination' do |
140 | 140 | let!(:notices) do |
141 | 141 | 3.times.reduce([]) do |coll, i| |
142 | - coll << Fabricate(:notice, :err => err, :created_at => (Time.now + i)) | |
142 | + coll << Fabricate(:notice, :err => err, :created_at => (i.seconds.from_now)) | |
143 | 143 | end |
144 | 144 | end |
145 | 145 | ... | ... |
spec/fabricators/backtrace_fabricator.rb
spec/lib/airbrake_api/v3/notice_parser_spec.rb
... | ... | @@ -53,8 +53,8 @@ describe AirbrakeApi::V3::NoticeParser do |
53 | 53 | json = Rails.root.join('spec', 'fixtures', 'api_v3_request.json').read |
54 | 54 | data = JSON.parse(json) |
55 | 55 | |
56 | - data['key'] = options[:key] if options.has_key?(:key) | |
57 | - data['project_id'] = options[:project_id] if options.has_key?(:project_id) | |
56 | + data['key'] = options[:key] if options.key?(:key) | |
57 | + data['project_id'] = options[:project_id] if options.key?(:project_id) | |
58 | 58 | |
59 | 59 | data |
60 | 60 | end | ... | ... |
spec/lib/configurator_spec.rb
... | ... | @@ -6,12 +6,12 @@ describe Configurator do |
6 | 6 | end |
7 | 7 | |
8 | 8 | it 'takes the first existing env, second item' do |
9 | - result = Configurator.run({ two: ['VARTWO', 'VARTHREE'] }) | |
9 | + result = Configurator.run({ two: %w(VARTWO VARTHREE) }) | |
10 | 10 | expect(result.two).to eq('zipp') |
11 | 11 | end |
12 | 12 | |
13 | 13 | it 'takes the first existing env, first item' do |
14 | - result = Configurator.run({ three: ['VARTHREE', 'VARONE'] }) | |
14 | + result = Configurator.run({ three: %w(VARTHREE VARONE) }) | |
15 | 15 | expect(result.three).to eq('zipp') |
16 | 16 | end |
17 | 17 | |
... | ... | @@ -44,7 +44,7 @@ describe Configurator do |
44 | 44 | it 'extracts array values' do |
45 | 45 | allow(ENV).to receive(:[]).with('MYARRAY').and_return('[one,two,three]') |
46 | 46 | result = Configurator.run({ myarray: ['MYARRAY'] }) |
47 | - expect(result.myarray).to eq(['one', 'two', 'three']) | |
47 | + expect(result.myarray).to eq(%w(one two three)) | |
48 | 48 | end |
49 | 49 | |
50 | 50 | it 'extracts booleans' do | ... | ... |
spec/models/app_spec.rb
... | ... | @@ -152,8 +152,8 @@ describe App, type: 'model' do |
152 | 152 | |
153 | 153 | context "copying attributes from existing app" do |
154 | 154 | it "should only copy the necessary fields" do |
155 | - @app, @copy_app = Fabricate(:app, :name => "app", :github_repo => "url"), | |
156 | - Fabricate(:app, :name => "copy_app", :github_repo => "copy url") | |
155 | + @app = Fabricate(:app, :name => "app", :github_repo => "url") | |
156 | + @copy_app = Fabricate(:app, :name => "copy_app", :github_repo => "copy url") | |
157 | 157 | @copy_watcher = Fabricate(:watcher, :email => "copywatcher@example.com", :app => @copy_app) |
158 | 158 | @app.copy_attributes_from(@copy_app.id) |
159 | 159 | expect(@app.name).to eq "app" | ... | ... |
spec/models/error_report_spec.rb
spec/models/notice_spec.rb
... | ... | @@ -41,7 +41,7 @@ describe Notice, type: 'model' do |
41 | 41 | |
42 | 42 | it 'has a curl representation' do |
43 | 43 | cmd = notice.to_curl |
44 | - expect(cmd).to eq(%q[curl -X GET -H 'User-Agent: Mozilla/5.0' http://example.com/resource/12]) | |
44 | + expect(cmd).to eq("curl -X GET -H 'User-Agent: Mozilla/5.0' http://example.com/resource/12") | |
45 | 45 | end |
46 | 46 | end |
47 | 47 | ... | ... |
spec/models/problem_spec.rb
... | ... | @@ -236,7 +236,7 @@ describe Problem, type: 'model' do |
236 | 236 | context "#last_deploy_at" do |
237 | 237 | before do |
238 | 238 | @app = Fabricate(:app) |
239 | - @last_deploy = Time.at(10.days.ago.localtime.to_i) | |
239 | + @last_deploy = 10.days.ago | |
240 | 240 | Fabricate(:deploy, :app => @app, :created_at => @last_deploy, :environment => "production") |
241 | 241 | end |
242 | 242 | |
... | ... | @@ -247,11 +247,13 @@ describe Problem, type: 'model' do |
247 | 247 | |
248 | 248 | it "is updated when a deploy is created" do |
249 | 249 | problem = Fabricate(:problem, :app => @app, :environment => "production") |
250 | - next_deploy = Time.at(5.minutes.ago.localtime.to_i) | |
250 | + next_deploy = 5.minutes.ago | |
251 | 251 | expect { |
252 | 252 | @deploy = Fabricate(:deploy, :app => @app, :created_at => next_deploy) |
253 | 253 | problem.reload |
254 | - }.to change(problem, :last_deploy_at).from(@last_deploy).to(next_deploy) | |
254 | + }.to change { problem.last_deploy_at.iso8601 }. | |
255 | + from(@last_deploy.iso8601). | |
256 | + to(next_deploy.iso8601) | |
255 | 257 | end |
256 | 258 | end |
257 | 259 | ... | ... |
spec/views/apps/index.html.haml_spec.rb
1 | 1 | describe "apps/index.html.haml", type: 'view' do |
2 | 2 | before do |
3 | - app = stub_model(App, :deploys => [stub_model(Deploy, :created_at => Time.now, :revision => "123456789abcdef")]) | |
3 | + app = stub_model(App, :deploys => [stub_model(Deploy, :created_at => Time.zone.now, :revision => "123456789abcdef")]) | |
4 | 4 | allow(view).to receive(:apps).and_return([app]) |
5 | 5 | allow(controller).to receive(:current_user).and_return(stub_model(User)) |
6 | 6 | end | ... | ... |
spec/views/users/show.html.haml_spec.rb