Commit 01a4117338fa88e17b95e59e5907ac53f1d51c02

Authored by Laust Rud Jacobsen
1 parent d1683958
Exists in master and in 1 other branch production

Rubocop: use modern unified format for Rails validations

.rubocop_todo.yml
... ... @@ -41,18 +41,6 @@ Rails/Output:
41 41 - 'app/interactors/problem_recacher.rb'
42 42 - 'db/seeds.rb'
43 43  
44   -# Offense count: 12
45   -# Configuration parameters: Include.
46   -Rails/Validation:
47   - Exclude:
48   - - 'app/models/app.rb'
49   - - 'app/models/comment.rb'
50   - - 'app/models/deploy.rb'
51   - - 'app/models/err.rb'
52   - - 'app/models/notice.rb'
53   - - 'app/models/problem.rb'
54   - - 'app/models/user.rb'
55   -
56 44 # Offense count: 105
57 45 # Cop supports --auto-correct.
58 46 # Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
... ...
app/models/app.rb
... ... @@ -35,9 +35,7 @@ class App
35 35 before_save :normalize_github_repo
36 36 after_update :store_cached_attributes_on_problems
37 37  
38   - validates_presence_of :name, :api_key
39   - validates_uniqueness_of :name, allow_blank: true
40   - validates_uniqueness_of :api_key, allow_blank: true
  38 + validates :name, :api_key, presence: true, uniqueness: { allow_blank: true }
41 39 validates_associated :watchers
42 40 validates_associated :notice_fingerprinter
43 41 validate :check_issue_tracker
... ...
app/models/comment.rb
... ... @@ -14,7 +14,7 @@ class Comment
14 14 belongs_to :user
15 15 delegate :app, to: :err
16 16  
17   - validates_presence_of :body
  17 + validates :body, presence: true
18 18  
19 19 def deliver_email
20 20 Mailer.comment_notification(self).deliver_now
... ...
app/models/deploy.rb
... ... @@ -16,7 +16,7 @@ class Deploy
16 16 after_create :store_cached_attributes_on_problems
17 17 after_create :deliver_email
18 18  
19   - validates_presence_of :username, :environment
  19 + validates :username, :environment, presence: true
20 20  
21 21 def resolve_app_errs
22 22 app.problems.unresolved.in_env(environment).each(&:resolve!)
... ...
app/models/err.rb
... ... @@ -14,7 +14,7 @@ class Err
14 14 belongs_to :problem
15 15 has_many :notices, inverse_of: :err, dependent: :destroy
16 16  
17   - validates_presence_of :problem_id, :fingerprint
  17 + validates :problem_id, :fingerprint, presence: true
18 18  
19 19 delegate :app, :resolved?, to: :problem
20 20 end
... ...
app/models/notice.rb
... ... @@ -24,7 +24,7 @@ class Notice
24 24 before_save :sanitize
25 25 before_destroy :problem_recache
26 26  
27   - validates_presence_of :backtrace_id, :server_environment, :notifier
  27 + validates :backtrace_id, :server_environment, :notifier, presence: true
28 28  
29 29 scope :ordered, -> { order_by(:created_at.asc) }
30 30 scope :reverse_ordered, -> { order_by(:created_at.desc) }
... ...
app/models/problem.rb
... ... @@ -53,7 +53,8 @@ class Problem
53 53 has_many :errs, inverse_of: :problem, dependent: :destroy
54 54 has_many :comments, inverse_of: :err, dependent: :destroy
55 55  
56   - validates_presence_of :environment
  56 + validates :environment, presence: true
  57 + validates :last_notice_at, :first_notice_at, presence: true
57 58  
58 59 before_create :cache_app_attributes
59 60 before_save :truncate_message
... ... @@ -63,8 +64,6 @@ class Problem
63 64 scope :ordered, -> { order_by(:last_notice_at.desc) }
64 65 scope :for_apps, ->(apps) { where(:app_id.in => apps.all.map(&:id)) }
65 66  
66   - validates_presence_of :last_notice_at, :first_notice_at
67   -
68 67 def self.all_else_unresolved(fetch_all)
69 68 if fetch_all
70 69 all
... ...
app/models/user.rb
... ... @@ -38,12 +38,12 @@ class User
38 38  
39 39 before_save :ensure_authentication_token
40 40  
41   - validates_presence_of :name
42   - validates_uniqueness_of :github_login, allow_nil: true
  41 + validates :name, presence: true
  42 + validates :github_login, uniqueness: { allow_nil: true }
43 43  
44 44 if Errbit::Config.user_has_username
45 45 field :username
46   - validates_presence_of :username
  46 + validates :username, presence: true
47 47 end
48 48  
49 49 def per_page
... ...