|
506 | 506 | end |
507 | 507 | end |
508 | 508 | end |
| 509 | + |
| 510 | + describe "extra_languages filter" do |
| 511 | + let(:org) { build :casa_org } |
| 512 | + let(:supervisor) { create :supervisor, casa_org: org } |
| 513 | + let(:volunteer_with_language) { create :volunteer, casa_org: org, supervisor: supervisor } |
| 514 | + let(:volunteer_without_language) { create :volunteer, casa_org: org, supervisor: supervisor } |
| 515 | + let(:language) { create :language, casa_org: org } |
| 516 | + |
| 517 | + before do |
| 518 | + create :user_language, user: volunteer_with_language, language: language |
| 519 | + end |
| 520 | + |
| 521 | + context "when filtering for volunteers with extra languages with default ordering" do |
| 522 | + # Use an invalid order_by to trigger the default COALESCE ordering |
| 523 | + # which causes PG::InvalidColumnReference when combined with DISTINCT |
| 524 | + let(:order_by) { "invalid_column" } |
| 525 | + let(:additional_filters) do |
| 526 | + { |
| 527 | + active: %w[false true], |
| 528 | + supervisor: [supervisor.id], |
| 529 | + transition_aged_youth: %w[false true], |
| 530 | + extra_languages: %w[true] |
| 531 | + } |
| 532 | + end |
| 533 | + |
| 534 | + it "does not raise PG::InvalidColumnReference error" do |
| 535 | + # Bug: PG::InvalidColumnReference: ERROR: for SELECT DISTINCT, ORDER BY |
| 536 | + # expressions must appear in select list |
| 537 | + # This occurs because extra_languages filter adds .distinct but the default |
| 538 | + # ORDER BY COALESCE(users.display_name, users.email) is not in the SELECT list |
| 539 | + expect { subject }.not_to raise_error |
| 540 | + end |
| 541 | + |
| 542 | + it "returns only volunteers with languages" do |
| 543 | + expect(subject[:data].map { |d| d[:id].to_i }).to contain_exactly(volunteer_with_language.id) |
| 544 | + end |
| 545 | + end |
| 546 | + |
| 547 | + context "when filtering for volunteers without extra languages with default ordering" do |
| 548 | + let(:order_by) { "invalid_column" } |
| 549 | + let(:additional_filters) do |
| 550 | + { |
| 551 | + active: %w[false true], |
| 552 | + supervisor: [supervisor.id], |
| 553 | + transition_aged_youth: %w[false true], |
| 554 | + extra_languages: %w[false] |
| 555 | + } |
| 556 | + end |
| 557 | + |
| 558 | + it "does not raise PG::InvalidColumnReference error" do |
| 559 | + expect { subject }.not_to raise_error |
| 560 | + end |
| 561 | + end |
| 562 | + |
| 563 | + context "when filtering with multiple extra_languages options with default ordering" do |
| 564 | + let(:order_by) { "invalid_column" } |
| 565 | + let(:additional_filters) do |
| 566 | + { |
| 567 | + active: %w[false true], |
| 568 | + supervisor: [supervisor.id], |
| 569 | + transition_aged_youth: %w[false true], |
| 570 | + extra_languages: %w[true false] |
| 571 | + } |
| 572 | + end |
| 573 | + |
| 574 | + it "does not raise PG::InvalidColumnReference error" do |
| 575 | + expect { subject }.not_to raise_error |
| 576 | + end |
| 577 | + end |
| 578 | + end |
509 | 579 | end |
0 commit comments