Skip to content

Commit

Permalink
Merge pull request #5888 from hennevogel/bugfix/status
Browse files Browse the repository at this point in the history
Bugfix/status
  • Loading branch information
Ana06 committed Sep 21, 2018
2 parents 5f2f211 + 3c99cb9 commit 9575685
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 30 deletions.
7 changes: 6 additions & 1 deletion src/api/app/models/status/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,23 @@ class Status::Report < ApplicationRecord
has_many :checks, class_name: 'Status::Check', dependent: :destroy, foreign_key: 'status_reports_id'

#### Callbacks macros: before_save, after_save, etc.
after_initialize :set_request_uuid, if: proc { |record| record.checkable.is_a?(BsRequest) }

#### Scopes (first the default_scope macro if is used)

#### Validations macros
validates :checkable, presence: true
validates :uuid, presence: true, if: proc { |record| record.checkable.is_a?(Repository) }
validates :uuid, presence: true

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

#### To define class methods as private use private_class_method
#### private

def set_request_uuid
self.uuid = checkable.number
end

def missing_checks
checkable.required_checks - checks.pluck(:name)
end
Expand Down
3 changes: 1 addition & 2 deletions src/api/app/views/status/checks/_check.xml.builder
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
builder.check(id: object.id, required: object.required?) do |check|
check.name object.name
builder.check(name: object.name, required: object.required?) do |check|
check.state object.state
check.short_description object.short_description
check.url object.url
Expand Down
5 changes: 0 additions & 5 deletions src/api/app/views/status/reports/_check.xml.builder

This file was deleted.

2 changes: 1 addition & 1 deletion src/api/app/views/status/reports/show.xml.builder
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
xml.status_report(uuid: @status_report.uuid) do |xml|
@checks.each do |check|
render(partial: 'check', locals: { builder: xml, object: check })
render(partial: 'status/checks/check', locals: { builder: xml, object: check })
end

@missing_checks.each do |name|
Expand Down
22 changes: 1 addition & 21 deletions src/api/spec/models/status/report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,6 @@
RSpec.describe Status::Report, type: :model do
describe 'validations' do
it { is_expected.to validate_presence_of(:checkable) }

context 'for bs requests' do
let(:source_project) { create(:project_with_package) }
let(:target_project) { create(:project_with_package) }
let(:bs_request) do
create(:bs_request_with_submit_action,
source_project: source_project,
source_package: source_project.packages.first,
target_project: target_project,
target_package: target_project.packages.first)
end
let(:status_report) { create(:status_report, checkable: bs_request) }

it { expect(status_report).not_to validate_presence_of(:uuid) }
end

context 'for repositories' do
let(:status_report) { create(:status_report, checkable: create(:repository)) }

it { expect(status_report).to validate_presence_of(:uuid) }
end
it { is_expected.to validate_presence_of(:uuid) }
end
end

0 comments on commit 9575685

Please sign in to comment.