diff --git a/app/controllers/cost_return_reports_controller.rb b/app/controllers/cost_return_reports_controller.rb index 2492beb4..c410bfad 100644 --- a/app/controllers/cost_return_reports_controller.rb +++ b/app/controllers/cost_return_reports_controller.rb @@ -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 diff --git a/app/helpers/abbreviated_treatment_report_helper.rb b/app/helpers/abbreviated_treatment_report_helper.rb index cdfd6d12..0c13eb61 100644 --- a/app/helpers/abbreviated_treatment_report_helper.rb +++ b/app/helpers/abbreviated_treatment_report_helper.rb @@ -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 diff --git a/config/.routes.rb.swp b/config/.routes.rb.swp new file mode 100644 index 00000000..d9065891 Binary files /dev/null and b/config/.routes.rb.swp differ diff --git a/spec/controllers/cost_return_reports_controller_spec.rb b/spec/controllers/cost_return_reports_controller_spec.rb index a14e54ce..8e31f229 100644 --- a/spec/controllers/cost_return_reports_controller_spec.rb +++ b/spec/controllers/cost_return_reports_controller_spec.rb @@ -11,6 +11,7 @@ sign_in(user) end + let(:conservation_record) { create(:conservation_record) } let(:valid_attributes) do { shipping_cost: 100.10, @@ -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 @@ -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 diff --git a/spec/controllers/treatment_reports_controller_spec.rb b/spec/controllers/treatment_reports_controller_spec.rb index b6b77851..f02389a1 100644 --- a/spec/controllers/treatment_reports_controller_spec.rb +++ b/spec/controllers/treatment_reports_controller_spec.rb @@ -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') { @@ -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 @@ -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 diff --git a/spec/helpers/abbreviated_treatment_report_helper_spec.rb b/spec/helpers/abbreviated_treatment_report_helper_spec.rb index a41517de..50bc6404 100644 --- a/spec/helpers/abbreviated_treatment_report_helper_spec.rb +++ b/spec/helpers/abbreviated_treatment_report_helper_spec.rb @@ -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 diff --git a/spec/helpers/conservation_records_helper_spec.rb b/spec/helpers/conservation_records_helper_spec.rb index 1bbb92dd..40abe8c1 100644 --- a/spec/helpers/conservation_records_helper_spec.rb +++ b/spec/helpers/conservation_records_helper_spec.rb @@ -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