Skip to content

Commit

Permalink
Destroys Change Management Record when destroying Software Record. (#373
Browse files Browse the repository at this point in the history
)

* Destroys Change Management Record when destroying Software Record.

* Adds test for deleting software record with change management.

---------

Co-authored-by: Thomas Scherz <[email protected]>
  • Loading branch information
scherztc and Thomas Scherz authored Jul 15, 2024
1 parent 51f7fef commit a423a62
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/software_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class SoftwareRecord < ApplicationRecord
belongs_to :vendor_record
belongs_to :status
belongs_to :hosting_environment
has_many :change_request
has_many :change_request, dependent: :destroy
validates :title, :description, :status, :created_by, presence: true
serialize :tech_leads, Array
serialize :developers, Array
Expand Down
23 changes: 23 additions & 0 deletions spec/controllers/software_records_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@
)
end

let(:change_attributes) do
{
change_title: 'A Good Software',
change_description: 'A Good description about the software',
software_record_id: 1,
application_pages: 10,
number_roles: 3,
authentication_needed: true,
custom_error_pages: true
}
end

let(:valid_attributes) do
{
title: 'A Good Software',
Expand Down Expand Up @@ -505,11 +517,22 @@ def sign_in_user(admin)
describe 'DELETE #destroy' do
it 'destroys the requested software_record' do
software_record = SoftwareRecord.create! valid_attributes
ChangeRequest.create! change_attributes

expect do
delete :destroy, params: { id: software_record.to_param }, session: valid_session
end.to change(SoftwareRecord, :count).by(-1)
end

it 'also destroys the change request associated with the software_record' do
software_record = SoftwareRecord.create! valid_attributes
ChangeRequest.create! change_attributes
expect do
delete :destroy, params: { id: software_record.to_param }, session: valid_session
end.to change(ChangeRequest, :count).by(-1)
expect(response).to redirect_to(session[:previous])
end

it 'redirects to the software_records list' do
session[:previous] = software_records_url
software_record = SoftwareRecord.create! valid_attributes
Expand Down

0 comments on commit a423a62

Please sign in to comment.