-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a new filter class for the action_required_by field.
- Loading branch information
1 parent
88c18b3
commit e2f8412
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
class Filters::ActionRequiredBy < Filters::Base | ||
def apply | ||
return scope if action_required_by.empty? | ||
|
||
scope.where(action_required_by:) | ||
end | ||
|
||
def action_required_by | ||
Array(params[:action_required_by]).compact_blank | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe Filters::ActionRequiredBy do | ||
subject(:filtered_scope) { described_class.apply(scope:, params:) } | ||
|
||
context "the params includes a action_required_by" do | ||
let(:params) { { action_required_by: "assessor" } } | ||
let(:scope) { ApplicationForm.all } | ||
|
||
let!(:included) { create(:application_form, :action_required_by_assessor) } | ||
let!(:excluded) { create(:application_form, :action_required_by_admin) } | ||
|
||
it { is_expected.to contain_exactly(included) } | ||
end | ||
|
||
context "the params include multiple action_required_by" do | ||
let(:params) { { action_required_by: %w[assessor external] } } | ||
let(:scope) { ApplicationForm.all } | ||
|
||
let!(:included) { create(:application_form, :action_required_by_assessor) } | ||
let!(:excluded) { create(:application_form, :action_required_by_admin) } | ||
|
||
it { is_expected.to contain_exactly(included) } | ||
end | ||
|
||
context "the params don't include action_required_by" do | ||
let(:params) { {} } | ||
let(:scope) { double } | ||
|
||
it { is_expected.to eq(scope) } | ||
end | ||
end |