require 'spec_helper' describe Medivo::PdfGroup do it "can call read on the pdf after creating it" do path = medivo_pdf_fixture_path "hepc_result_faq.pdf" pdf_group = Medivo::PdfGroup.create do static_pdf(path) end pdf_group.read.should_not be_empty pdf_group.close end it "#variable_fields" do name = "Duderoni" path = medivo_pdf_fixture_path "hepc_negative_results.pdf" pdf_group = Medivo::PdfGroup.create do variable_fields(path, {:patient_name=>name}) end text = pdf_to_text(pdf_group.pdf) text.should match name pdf_group.close end it "#variable_fields_with_images" do name = "Duderoni" path = medivo_pdf_fixture_path "hepc_negative_results.pdf" image_path = medivo_img_fixture_path "southeast.jpg" image_data = [{:path=> image_path, :options=>{:at=> [40, 100], :width=>180, :height=>28}}] pdf_group = Medivo::PdfGroup.create do variable_fields_with_images(path, {:patient_name=>name}, image_data) end show_me_the_pdf(pdf_group.pdf, '/tmp/test.pdf') text = pdf_to_text(pdf_group.pdf) text.should match name pdf_group.close end it "#lab_requisition" do requisition_id = 170420 stub_order_requisition(requisition_id, medivo_xml_fixture_path("lc_order_with_requisition.xml")) pdf_group = Medivo::PdfGroup.create do lab_requisition(requisition_id) end text = pdf_to_text(pdf_group.pdf) text.should match "Account #:111111111" text.should match "This order expires 2012-02-12" pdf_group.close end it "#lab_result" do requisition_id = 170420 stub_order_result(requisition_id, medivo_xml_fixture_path("lc_order_with_positive_results.xml")) pdf_group = Medivo::PdfGroup.create do lab_result(requisition_id) end text = pdf_to_text(pdf_group.pdf) text.strip_space.should match "COLLECTED:2011-09-06 RECEIVED:2011-09-06 REPORTED:2011-09-06".strip_space pdf_group.close end it "#static_pdf" do path = medivo_pdf_fixture_path "hepc_result_faq.pdf" pdf_group = Medivo::PdfGroup.create do static_pdf(path) end text = pdf_to_text(pdf_group.pdf) text.strip_space.should match "Q: What does a positive result mean".strip_space pdf_group.close end it "handles a combination of pdfs" do name = "Duderoni" cover_letter_path = medivo_pdf_fixture_path "hepc_negative_results.pdf" requisition_id = 170420 stub_order_result(requisition_id, medivo_xml_fixture_path("lc_order_with_normal_results.xml")) faq_path = medivo_pdf_fixture_path "hepc_result_faq.pdf" pdf_group = Medivo::PdfGroup.create do variable_fields(cover_letter_path, {:patient_name=>name}) lab_result(requisition_id) static_pdf(faq_path) end text = pdf_to_text(pdf_group.pdf) text = text.strip_space text.should match name text.strip_space.should match "COLLECTED:2011-09-06 RECEIVED:2011-09-06 REPORTED:2011-09-06".strip_space text.should match "Q: What does a positive result mean".strip_space pdf_group.close end end