Commit 01a4117338fa88e17b95e59e5907ac53f1d51c02
1 parent
d1683958
Exists in
master
and in
1 other branch
Rubocop: use modern unified format for Rails validations
Showing
8 changed files
with
10 additions
and
25 deletions
Show diff stats
.rubocop_todo.yml
| @@ -41,18 +41,6 @@ Rails/Output: | @@ -41,18 +41,6 @@ Rails/Output: | ||
| 41 | - 'app/interactors/problem_recacher.rb' | 41 | - 'app/interactors/problem_recacher.rb' |
| 42 | - 'db/seeds.rb' | 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 | # Offense count: 105 | 44 | # Offense count: 105 |
| 57 | # Cop supports --auto-correct. | 45 | # Cop supports --auto-correct. |
| 58 | # Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods. | 46 | # Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods. |
app/models/app.rb
| @@ -35,9 +35,7 @@ class App | @@ -35,9 +35,7 @@ class App | ||
| 35 | before_save :normalize_github_repo | 35 | before_save :normalize_github_repo |
| 36 | after_update :store_cached_attributes_on_problems | 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 | validates_associated :watchers | 39 | validates_associated :watchers |
| 42 | validates_associated :notice_fingerprinter | 40 | validates_associated :notice_fingerprinter |
| 43 | validate :check_issue_tracker | 41 | validate :check_issue_tracker |
app/models/comment.rb
| @@ -14,7 +14,7 @@ class Comment | @@ -14,7 +14,7 @@ class Comment | ||
| 14 | belongs_to :user | 14 | belongs_to :user |
| 15 | delegate :app, to: :err | 15 | delegate :app, to: :err |
| 16 | 16 | ||
| 17 | - validates_presence_of :body | 17 | + validates :body, presence: true |
| 18 | 18 | ||
| 19 | def deliver_email | 19 | def deliver_email |
| 20 | Mailer.comment_notification(self).deliver_now | 20 | Mailer.comment_notification(self).deliver_now |
app/models/deploy.rb
| @@ -16,7 +16,7 @@ class Deploy | @@ -16,7 +16,7 @@ class Deploy | ||
| 16 | after_create :store_cached_attributes_on_problems | 16 | after_create :store_cached_attributes_on_problems |
| 17 | after_create :deliver_email | 17 | after_create :deliver_email |
| 18 | 18 | ||
| 19 | - validates_presence_of :username, :environment | 19 | + validates :username, :environment, presence: true |
| 20 | 20 | ||
| 21 | def resolve_app_errs | 21 | def resolve_app_errs |
| 22 | app.problems.unresolved.in_env(environment).each(&:resolve!) | 22 | app.problems.unresolved.in_env(environment).each(&:resolve!) |
app/models/err.rb
| @@ -14,7 +14,7 @@ class Err | @@ -14,7 +14,7 @@ class Err | ||
| 14 | belongs_to :problem | 14 | belongs_to :problem |
| 15 | has_many :notices, inverse_of: :err, dependent: :destroy | 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 | delegate :app, :resolved?, to: :problem | 19 | delegate :app, :resolved?, to: :problem |
| 20 | end | 20 | end |
app/models/notice.rb
| @@ -24,7 +24,7 @@ class Notice | @@ -24,7 +24,7 @@ class Notice | ||
| 24 | before_save :sanitize | 24 | before_save :sanitize |
| 25 | before_destroy :problem_recache | 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 | scope :ordered, -> { order_by(:created_at.asc) } | 29 | scope :ordered, -> { order_by(:created_at.asc) } |
| 30 | scope :reverse_ordered, -> { order_by(:created_at.desc) } | 30 | scope :reverse_ordered, -> { order_by(:created_at.desc) } |
app/models/problem.rb
| @@ -53,7 +53,8 @@ class Problem | @@ -53,7 +53,8 @@ class Problem | ||
| 53 | has_many :errs, inverse_of: :problem, dependent: :destroy | 53 | has_many :errs, inverse_of: :problem, dependent: :destroy |
| 54 | has_many :comments, inverse_of: :err, dependent: :destroy | 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 | before_create :cache_app_attributes | 59 | before_create :cache_app_attributes |
| 59 | before_save :truncate_message | 60 | before_save :truncate_message |
| @@ -63,8 +64,6 @@ class Problem | @@ -63,8 +64,6 @@ class Problem | ||
| 63 | scope :ordered, -> { order_by(:last_notice_at.desc) } | 64 | scope :ordered, -> { order_by(:last_notice_at.desc) } |
| 64 | scope :for_apps, ->(apps) { where(:app_id.in => apps.all.map(&:id)) } | 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 | def self.all_else_unresolved(fetch_all) | 67 | def self.all_else_unresolved(fetch_all) |
| 69 | if fetch_all | 68 | if fetch_all |
| 70 | all | 69 | all |
app/models/user.rb
| @@ -38,12 +38,12 @@ class User | @@ -38,12 +38,12 @@ class User | ||
| 38 | 38 | ||
| 39 | before_save :ensure_authentication_token | 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 | if Errbit::Config.user_has_username | 44 | if Errbit::Config.user_has_username |
| 45 | field :username | 45 | field :username |
| 46 | - validates_presence_of :username | 46 | + validates :username, presence: true |
| 47 | end | 47 | end |
| 48 | 48 | ||
| 49 | def per_page | 49 | def per_page |