|
479 | 479 | expect(response.body).to eq("fake pdf content") |
480 | 480 | end |
481 | 481 | end |
| 482 | + |
| 483 | + describe "GET #print_picklist" do |
| 484 | + let(:organization) { create(:organization) } |
| 485 | + let(:partner) { create(:partner, organization: organization) } |
| 486 | + let(:partner_user) { partner.primary_user } |
| 487 | + let(:org_admin) { create(:organization_admin, organization: organization) } |
| 488 | + let(:request) { create(:request, :with_item_requests, organization: organization, partner: partner, partner_user: org_admin) } |
| 489 | + |
| 490 | + before do |
| 491 | + sign_in(org_admin) |
| 492 | + end |
| 493 | + |
| 494 | + it "generates a PDF for a single request" do |
| 495 | + # Create a double for the PDF instance |
| 496 | + pdf_double = double("PicklistsPdf") |
| 497 | + |
| 498 | + # Expect PicklistsPdf.new to be called with correct args and return our double |
| 499 | + expect(PicklistsPdf).to receive(:new) |
| 500 | + .with(organization, [request]) |
| 501 | + .and_return(pdf_double) |
| 502 | + |
| 503 | + # Expect compute_and_render to be called on our double and return some PDF data |
| 504 | + expect(pdf_double).to receive(:compute_and_render) |
| 505 | + .and_return("fake pdf content") |
| 506 | + |
| 507 | + # Make the request |
| 508 | + get print_picklist_request_path(request, format: :pdf) |
| 509 | + |
| 510 | + # Verify the response |
| 511 | + expect(response).to be_successful |
| 512 | + expect(response.content_type).to eq("application/pdf") |
| 513 | + expect(response.headers["Content-Disposition"]).to include("inline") |
| 514 | + expect(response.headers["Content-Disposition"]).to include("Picklists_") |
| 515 | + expect(response.body).to eq("fake pdf content") |
| 516 | + end |
| 517 | + |
| 518 | + it "includes correct associations in the query" do |
| 519 | + pdf_double = double("PicklistsPdf", compute_and_render: "pdf content") |
| 520 | + |
| 521 | + expect(PicklistsPdf).to receive(:new) do |org, requests| |
| 522 | + # Verify the request includes the necessary associations |
| 523 | + expect(requests.first.association(:item_requests)).to be_loaded |
| 524 | + expect(requests.first.association(:partner)).to be_loaded |
| 525 | + expect(requests.first.partner.association(:profile)).to be_loaded |
| 526 | + pdf_double |
| 527 | + end |
| 528 | + |
| 529 | + get print_picklist_request_path(request, format: :pdf) |
| 530 | + end |
| 531 | + end |
482 | 532 | end |
0 commit comments