From 9a3e179563ec631760a3dc93055a6fe8d1e7fa5a Mon Sep 17 00:00:00 2001 From: Thomas Scherz Date: Tue, 18 Jun 2024 10:52:06 -0400 Subject: [PATCH] Applys decommision filter to exports. --- exports/software_records.rb | 4 ++-- .../software_records_controller_spec.rb | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/exports/software_records.rb b/exports/software_records.rb index e0f3210..fad5f33 100644 --- a/exports/software_records.rb +++ b/exports/software_records.rb @@ -8,9 +8,9 @@ class SoftwareRecords < ApplicationRecord def software_records file = "#{Dir.pwd}/public/software_records.csv" -# software_records = SoftwareRecords.all + # software_records = SoftwareRecords.all software_records = SoftwareRecord.joins(:status).where.not(statuses: { status_type: 'Decommissioned' }) - + headers = [ 'Software Record', 'Description', 'Status', 'Created on', 'Software Type', 'Authentication Type', 'Vendor Record', 'Departments', 'Date Implemented', diff --git a/spec/controllers/software_records_controller_spec.rb b/spec/controllers/software_records_controller_spec.rb index 10adcc3..daa716f 100644 --- a/spec/controllers/software_records_controller_spec.rb +++ b/spec/controllers/software_records_controller_spec.rb @@ -125,10 +125,21 @@ def sign_in_user(admin) end end + # context 'when filter_by is software_types and software_type_filter is provided' do + # it 'assigns filtered software records to @software_records' do + # software_record = SoftwareRecord.create! valid_attributes + # get :list_road_map, params: { filter_by: 'software_types', software_type_filter: SoftwareType.first.id }, session: valid_session + # expect(assigns(:software_records)).to include(software_record) + # end + # end + context 'when filter_by is software_types and software_type_filter is provided' do + let!(:software_type) { SoftwareType.create!(title: 'Test Type', status_type: 'Decommissioned') } + + let!(:software_record) { SoftwareRecord.create!(valid_attributes.merge(software_type:)) } + it 'assigns filtered software records to @software_records' do - software_record = SoftwareRecord.create! valid_attributes - get :list_road_map, params: { filter_by: 'software_types', software_type_filter: SoftwareType.first.id } + get :list_road_map, params: { filter_by: 'software_types', software_type_filter: software_type.id } expect(assigns(:software_records)).to include(software_record) end end @@ -136,7 +147,7 @@ def sign_in_user(admin) context 'when filter_by is not software_types' do it 'assigns all software records to @software_records' do software_record = SoftwareRecord.create! valid_attributes - get :list_road_map, params: { filter_by: 'other_filter' } + get :list_road_map, params: { filter_by: 'other_filter' }, session: valid_session expect(assigns(:software_records)).to include(software_record) end end