Skip to content

Commit

Permalink
Remove uncoverable code in status::report model
Browse files Browse the repository at this point in the history
A checkable can only be of a certain type - and we shouldn't
have a default
  • Loading branch information
coolo committed Nov 14, 2018
1 parent 97c1636 commit 513a6b6
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/api/app/models/status/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class Status::Report < ApplicationRecord
validates :checkable, presence: true
validates :uuid, presence: true

validates_each :checkable do |record, attr, value|
record.errors.add(attr, "invalid class #{value.class}") unless %w[BsRequest Repository RepositoryArchitecture].include?(value.class.to_s)
end

#### Class methods using self. (public and then private)

#### To define class methods as private use private_class_method
Expand All @@ -41,11 +45,10 @@ def projects
[checkable.project]
when RepositoryArchitecture
[checkable.repository.project]
else
[]
end
end

# TODO: prefer duck typing - also for above
def notify_params
case checkable
when BsRequest
Expand All @@ -54,8 +57,6 @@ def notify_params
{ project: checkable.project.name, repo: checkable.name, buildid: uuid }
when RepositoryArchitecture
{ project: checkable.repository.project.name, repo: checkable.repository.name, arch: checkable.architecture.name, buildid: uuid }
else
{}
end
end

Expand Down

0 comments on commit 513a6b6

Please sign in to comment.