Skip to content

Commit

Permalink
Merge pull request #1063 from CruGlobal/GT-1672-add-abbreviation-filt…
Browse files Browse the repository at this point in the history
…er-to-resources

GT-1672, add abbreviation filter to resources
  • Loading branch information
frett authored Sep 8, 2022
2 parents 5abca82 + 3854fd0 commit c858701
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/controllers/resources_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,17 @@ def index_json
end

def all_resources
if params["filter"]
Resource.system_name(params["filter"]["system"])
resources = if params.dig(:filter, :system)
Resource.system_name(params[:filter][:system])
else
Resource.all
end

if params.dig(:filter, :abbreviation)
resources = resources.where(abbreviation: params[:filter][:abbreviation])
end

resources
end

def load_resource
Expand Down
7 changes: 7 additions & 0 deletions spec/acceptance/resources_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@
expect(data["attributes"].keys).to eq ["name"]
expect(data["relationships"].keys).to eq ["system"]
end

it "gets all resources with abbreviation" do
do_request "filter[abbreviation]": "es"

expect(status).to be(200)
expect(JSON.parse(response_body)["data"].count).to be(1)
end
end

get "resources/:id" do
Expand Down

0 comments on commit c858701

Please sign in to comment.