Skip to content

Commit

Permalink
Fix for Org selection dropdowns (#2747)
Browse files Browse the repository at this point in the history
* fix for issue with Org selection. Strong params were always resulting in local DB search

* updated tests to catch future issues with org selection

* fixed Rubocop
  • Loading branch information
briri authored Dec 1, 2020
1 parent 8806a58 commit 0762c4e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions app/controllers/orgs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ def shibboleth_ds_passthru
# rubocop:enable Metrics/AbcSize

# POST /orgs (via AJAX from Org Typeaheads ... see below for specific pages)
# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
def search
args = search_params
# If the search term is greater than 2 characters
if args.present? && args.fetch(:name, "").length > 2
type = args.fetch(:type, "local")
type = params.fetch(:type, "local")

# If we are including external API results
orgs = case type
Expand Down Expand Up @@ -192,7 +192,7 @@ def search

# If we need to restrict the results to funding orgs then
# only return the ones with a valid fundref
if orgs.present? && args.fetch(:funder_only, "false") == true
if orgs.present? && params.fetch(:funder_only, "false") == true
orgs = orgs.select do |org|
org[:fundref].present? && !org[:fundref].blank?
end
Expand All @@ -204,8 +204,7 @@ def search
render json: []
end
end
# rubocop:enable Metrics/MethodLength
# rubocop:enable
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize

private

Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/orgs_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@

it "calls search_externally when query string contains type=external" do
OrgSelection::SearchService.expects(:search_externally).at_least(1)
post :search, params: { org: { name: Faker::Lorem.sentence, type: "external" } },
post :search, params: { org: { name: Faker::Lorem.sentence }, type: "external" },
format: :js
end

it "calls search_combined when query string contains type=combined" do
OrgSelection::SearchService.expects(:search_combined).at_least(1)
post :search, params: { org: { name: Faker::Lorem.sentence, type: "combined" } },
post :search, params: { org: { name: Faker::Lorem.sentence }, type: "combined" },
format: :js
end
end
Expand Down

0 comments on commit 0762c4e

Please sign in to comment.