Skip to content

Commit 8ca84dc

Browse files
authored
Adds specs to make sure that test coverage is 100% (#273)
* Remove unnecessary log from procedures_default seed spec * Removes function on EventProcedure's controller that is not been used * Adds spec for Patients requests when theres an error on destroy * Removes function on PdfReports's controller that is not been used * Removes function on Header's Pdf that is not been used * Increases number of medical shifts created on MedicalShiftsReportPdf specs to test if new page is created
1 parent a2ba8c0 commit 8ca84dc

File tree

6 files changed

+23
-30
lines changed

6 files changed

+23
-30
lines changed

app/controllers/api/v1/event_procedures_controller.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,6 @@ def serialized_event_procedures(event_procedures)
116116
each_serializer: EventProcedureSerializer
117117
)
118118
end
119-
120-
def total_amount_cents_params
121-
{
122-
user_id: current_user.id,
123-
month: params[:month],
124-
year: params[:year]
125-
}
126-
end
127119
end
128120
end
129121
end

app/controllers/api/v1/pdf_reports_controller.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,6 @@ def permitted_query_params
7575
health_insurance: [:name]
7676
).to_h
7777
end
78-
79-
def total_amount_cents_params
80-
{
81-
user_id: current_user.id,
82-
month: permitted_query_params[:month],
83-
year: permitted_query_params[:year]
84-
}
85-
end
8678
end
8779
end
8880
end

app/pdfs/header_pdf.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ def header_spacing
3939
pdf.move_down 50
4040
end
4141

42-
def title_font_size
43-
20
44-
end
45-
4642
def header_current_date
4743
pdf.text "Data: #{Time.zone.now.strftime('%d/%m/%Y')}", align: :right, size: @header_font_size
4844
end

db/seeds/02_procedures_default.rb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,13 @@
1010

1111
batch_files = Rails.root.glob("lib/data/procedures/batch_*.json")
1212

13-
if batch_files.empty?
14-
Rails.logger.debug "No JSON files found."
15-
else
16-
batch_files.each do |batch_file|
17-
next unless File.exist?(batch_file)
13+
batch_files.each do |batch_file|
14+
next unless File.exist?(batch_file)
1815

19-
Rails.logger.debug { "Importing #{batch_file}" }
16+
Rails.logger.debug { "Importing #{batch_file}" }
2017

21-
Rake::Task["procedures:persist_in_database"].invoke(batch_file)
22-
Rake::Task["procedures:persist_in_database"].reenable
23-
end
18+
Rake::Task["procedures:persist_in_database"].invoke(batch_file)
19+
Rake::Task["procedures:persist_in_database"].reenable
2420
end
2521

2622
Rails.logger.debug { "Created #{batch_files.count} default Procedures!" }

spec/pdfs/medical_shifts_report_pdf_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
it "generates a report with the correct content" do
77
user = create(:user)
88
pdf = Prawn::Document.new
9-
medical_shifts = create_list(:medical_shift, 3, user_id: user.id)
9+
medical_shifts = create_list(:medical_shift, 20, user_id: user.id)
1010
amount = MedicalShifts::TotalAmountCents.call(medical_shifts: medical_shifts)
1111

1212
described_class.new(pdf: pdf, amount: amount, items: medical_shifts, title: "Plantões", email: user.email).generate

spec/requests/api/v1/patients_request_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,23 @@
192192
)
193193
end
194194
end
195+
196+
context "when theres an error on destroy" do
197+
it "returns unprocessable_content" do
198+
patient = create(:patient, user: user)
199+
200+
result_object = Struct.new(:success?, :error).new(
201+
false,
202+
{ error: "Error message." }
203+
)
204+
205+
allow(Patients::Destroy).to receive(:result).with(id: patient.id.to_s).and_return(result_object)
206+
207+
delete "/api/v1/patients/#{patient.id}", headers: headers
208+
209+
expect(response).to have_http_status(:unprocessable_content)
210+
end
211+
end
195212
end
196213

197214
include_context "when user is not authenticated"

0 commit comments

Comments
 (0)