Skip to content

Commit

Permalink
Add actionable by filter
Browse files Browse the repository at this point in the history
This adds a new filter class for the actionable by field.
  • Loading branch information
thomasleese committed Sep 11, 2023
1 parent 3b26a1f commit a6719ff
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/lib/filters/actionable_by.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

class Filters::ActionableBy < Filters::Base
def apply
return scope if actionable_by.empty?

scope.where(actionable_by:)
end

def actionable_by
Array(params[:actionable_by]).compact_blank
end
end
34 changes: 34 additions & 0 deletions spec/lib/filters/actionable_by_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe Filters::ActionableBy do
subject(:filtered_scope) { described_class.apply(scope:, params:) }

context "the params include a actionable_by" do
let(:params) { { actionable_by: "assessor" } }
let(:scope) { ApplicationForm.all }

let!(:included) { create(:application_form, :actionable_by_assessor) }
let!(:excluded) { create(:application_form, :actionable_by_admin) }

it { is_expected.to contain_exactly(included) }
end

context "the params include multiple actionable_by" do
let(:params) { { actionable_by: %w[assessor nobody] } }
let(:scope) { ApplicationForm.all }

let!(:included) { create(:application_form, :actionable_by_assessor) }
let!(:excluded) { create(:application_form, :actionable_by_admin) }

it { is_expected.to contain_exactly(included) }
end

context "the params don't include reference" do
let(:params) { {} }
let(:scope) { double }

it { is_expected.to eq(scope) }
end
end

0 comments on commit a6719ff

Please sign in to comment.