Skip to content

Commit

Permalink
Merge pull request #124 from uclibs/122-Increase_Test_Coverage
Browse files Browse the repository at this point in the history
Increase test coverage
  • Loading branch information
hortongn authored Feb 22, 2021
2 parents 348efcf + 9910f03 commit bd473b3
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/controllers/cost_return_reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def update

def destroy
@conservation_record = ConservationRecord.find(params[:conservation_record_id])
@cost_return_report = @conservation_record.cost_return_report.find(params[:id])
@cost_return_report = @conservation_record.cost_return_report
@cost_return_report.destroy
redirect_to conservation_record_path(@conservation_record)
end
Expand Down
4 changes: 0 additions & 4 deletions app/helpers/abbreviated_treatment_report_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,4 @@ def generate_abbreviated_treatment_report_performed_by(ihrr, _ind)
def generate_abbreviated_treatment_report_time(ihrr, _ind)
ihrr.minutes_spent.to_s
end

def conservators_note(ihrr, _ind)
ihrr.conservators_note
end
end
Binary file added config/.routes.rb.swp
Binary file not shown.
36 changes: 35 additions & 1 deletion spec/controllers/cost_return_reports_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
sign_in(user)
end

let(:conservation_record) { create(:conservation_record) }
let(:valid_attributes) do
{
shipping_cost: 100.10,
Expand All @@ -19,7 +20,8 @@
invoice_sent_to_business_office: Time.now.utc,
complete: true,
returned_to_origin: Time.now.utc,
note: 'This is the note.'
note: 'This is the note.',
conservation_record_id: conservation_record.id
}
end

Expand All @@ -32,4 +34,36 @@
end
end
end

describe 'DELETE #destroy' do
it 'removes Cost Return Report' do
cost_return_report = CostReturnReport.create! valid_attributes
expect do
delete :destroy, params: { conservation_record_id: conservation_record.id, id: cost_return_report.to_param }
end.to change(CostReturnReport, :count).by(-1)
end
end

describe 'PUT #update' do
context 'with valid params' do
let(:new_attributes) do
{
shipping_cost: 90.10,
repair_estimate: 110.10,
repair_cost: 130.10,
invoice_sent_to_business_office: Time.now.utc,
complete: true,
returned_to_origin: Time.now.utc,
note: 'This is the note.'
}
end
it 'updates Cost Return Report' do
cost_return_report = CostReturnReport.create! valid_attributes
put :update, params: { conservation_record_id: conservation_record.id, id: cost_return_report.to_param, cost_return_report: new_attributes }
cost_return_report.reload
expect(cost_return_report.repair_estimate).to eq(110.10)
expect(cost_return_report.repair_cost).to eq(130.10)
end
end
end
end
47 changes: 45 additions & 2 deletions spec/controllers/treatment_reports_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
user = create(:user, role: 'admin')
sign_in(user)
end

let(:conservation_record) { create(:conservation_record) }
let(:valid_attributes) do
housing_a = create(:controlled_vocabulary, vocabulary: 'housing', key: 'housing')
{
Expand Down Expand Up @@ -39,7 +39,8 @@
treatment_proposal_housing_narrative: 'Treatment Propsal Housing Narrative',
treatment_proposal_storage_and_handling_notes: 'Treatment Proposal Storage Handling and Notes',
treatment_proposal_total_treatment_time: 30,
conservators_report: "Conservator's Note"
conservators_note: "Conservator's Note",
conservation_record_id: conservation_record.id
}
end

Expand All @@ -52,4 +53,46 @@
end
end
end

describe 'PUT #update' do
context 'with valid params' do
let(:new_attributes) do
housing_a = create(:controlled_vocabulary, vocabulary: 'housing', key: 'housing')
{
description_general_remarks: 'General Description Remarks',
description_binding: 'Description Binding',
description_textblock: 'Description Textblock',
description_primary_support: 'Description Support',
description_medium: 'Description Medium',
description_attachments_inserts: 'Description Attachments Inserts',
description_housing: 'Description Housing',
condition_summary: 'Condition Summary',
condition_binding: 'Condition Binding',
condition_textblock: 'Condition Textblock',
condition_primary_support: 'Condition Primary Support',
condition_medium: 'Condition Medium',
condition_housing_id: housing_a.id,
condition_housing_narrative: 'Condition Housing Narrative',
condition_attachments_inserts: 'Condition Attachments Inserts',
condition_previous_treatment: 'Condition Previous Treatment',
condition_materials_analysis: 'Condition Materials Analysis',
treatment_proposal_proposal: 'Treatment Proposal Proposal',
treatment_proposal_housing_need_id: housing_a.id,
treatment_proposal_factors_influencing_treatment: 'Treatment Propsal Factors Influencing Treatment',
treatment_proposal_performed_treatment: 'Treatment Propsal Performed Treatment',
treatment_proposal_housing_provided_id: housing_a.id,
treatment_proposal_housing_narrative: 'Treatment Propsal Housing Narrative',
treatment_proposal_storage_and_handling_notes: 'Treatment Proposal Storage Handling and Notes',
treatment_proposal_total_treatment_time: 30,
conservators_note: "Conservator's Note"
}
end
it 'updates the Treatment Report' do
treatment_report = TreatmentReport.create! valid_attributes
put :update, params: { conservation_record_id: conservation_record.id, id: treatment_report.to_param, treatment_report: new_attributes }
treatment_report.reload
expect(treatment_report.description_primary_support).to eq('Description Support')
end
end
end
end
31 changes: 31 additions & 0 deletions spec/helpers/abbreviated_treatment_report_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,35 @@
# end
# end
RSpec.describe AbbreviatedTreatmentReportHelper, type: :helper do
let(:conservation_record) { create(:conservation_record) }
let(:repair_type) { create(:controlled_vocabulary, vocabulary: 'repair_type', key: 'Repair/restore binding') }
let(:user) { create(:user, display_name: 'Haritha Vytla') }
let(:repair_record) do
create(:in_house_repair_record,
performed_by_user_id: user.id,
repair_type: repair_type.id,
conservation_record: conservation_record,
minutes_spent: 2)
end

describe 'generate_abbreviated_treatment_report_type' do
it 'returns "Repair Type"' do
return_value = helper.generate_abbreviated_treatment_report_type(repair_record, 1)
expect(return_value).to eq('Repair/restore binding')
end
end

describe 'generate_abbreviated_treatment_report_performed_by' do
it 'returns the "User ID"' do
return_value = helper.generate_abbreviated_treatment_report_performed_by(repair_record, 1)
expect(return_value).to eq('Haritha Vytla')
end
end

describe 'generate_abbreviated_treatment_report_time' do
it 'returns "minutes spent on In House Repair Record"' do
return_value = helper.generate_abbreviated_treatment_report_time(repair_record, 1)
expect(return_value).to eq('2')
end
end
end
23 changes: 23 additions & 0 deletions spec/helpers/conservation_records_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,27 @@
return_value = helper.date_returned(conservation_record)
expect(return_value).to eq('2020-04-22 17:34:48'.to_date)
end

describe 'friendly_housing' do
context 'defines id as nil' do
it 'returns "No Housing method Selected"' do
return_value = helper.friendly_housing(nil)
expect(return_value).to eq('No housing method selected.')
end
end

context 'defines id as not nil' do
let!(:controlled_vocabulary) do
ControlledVocabulary.create(vocabulary: 'repair_type',
key: 'Repair/restore binding',
active: true,
created_at: '2021-01-06 22:59:40',
updated_at: '2021-01-06 22:59:40')
end
it 'return Controlled Vocabulary object' do
return_value = helper.friendly_housing(controlled_vocabulary.id)
expect(return_value.key).to eq('Repair/restore binding')
end
end
end
end

0 comments on commit bd473b3

Please sign in to comment.