Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4653: Permit :date_range filter param in DistributionsController#index #4776

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/controllers/distributions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def index
.distributions
.includes(:partner, :storage_location, line_items: [:item])
.order('issued_at DESC')
.apply_filters(filter_params, helpers.selected_range)
.apply_filters(filter_params.except(:date_range), helpers.selected_range)
@paginated_distributions = @distributions.page(params[:page])
@items = current_organization.items.alphabetized
@item_categories = current_organization.item_categories
Expand Down Expand Up @@ -310,7 +310,7 @@ def daily_items(pick_ups)
def filter_params
return {} unless params.key?(:filters)

params.require(:filters).permit(:by_item_id, :by_item_category_id, :by_partner, :by_state, :by_location)
params.require(:filters).permit(:by_item_id, :by_item_category_id, :by_partner, :by_state, :by_location, :date_range)
end

def perform_inventory_check
Expand Down
23 changes: 23 additions & 0 deletions spec/controllers/distributions_controller_spec.rb
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be handled by a request test? Controller tests are kind of missing some of the extra validations and coverage that request tests give us.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can change it to a request spec. I had figured that this permit shoulda-matcher on the controller was enough, but I guess with a request spec I could also ensure no "unpermitted params" messages are being logged.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the controller spec to a request spec. Let me know if this is the kind of implementation you had in mind.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,29 @@
sign_in(user)
end

describe "GET #index" do
let(:params) do
{
filters: {
by_item_id: 1,
by_item_category_id: 1,
by_partner: 1,
by_state: "NY",
by_location: 1,
date_range: "July 1, 1919 - July 31, 2020"
}
}
end

before { get :index, params: params }

it do
should permit(:by_item_id, :by_item_category_id, :by_partner, :by_state, :by_location, :date_range)
.for(:index, verb: :get, params: params)
.on(:filters)
end
end

describe "POST #create" do
context "when distribution causes inventory quantity to be below minimum quantity" do
let(:item) { create(:item, name: "Item 1", organization: organization, on_hand_minimum_quantity: 5) }
Expand Down