Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destroys Change Management Record when destroying Software Record. #373

Merged
merged 2 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading