-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to filter locations by activity status
Now that the OpenReferral spec requires a `status` field for Services, it’s possible that all of the Services for a particular Location could become `inactive` and/or `defunct`. If that’s the case, I would assume that you would no longer want to include that Location in search results because you wouldn’t be calling that location or visiting it if it no longer provides any services. To enable this filter, I added a boolean `active` field to the Locations table that automatically gets updated if the Location’s overall Services status changes. To only show active locations, pass in the `status=active` parameter. For example: https://ohana-api-demo.herokuapp.com/api/search?status=active To only show inactive locations, pass in `status=inactive`. For clients that display information about a particular Location, it might make sense to display a warning or other message if the Location currently doesn’t have any active services. You can determine if that’s the case by checking if the Location’s JSON contains an `active` attribute set to `false`.
Moncef Belyamani
committed
Oct 23, 2014
1 parent
c50dbfa
commit 3f0357f
Showing
14 changed files
with
110 additions
and
18 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
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
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
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
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
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
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
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
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,6 @@ | ||
class AddActiveToLocations < ActiveRecord::Migration | ||
def change | ||
add_column :locations, :active, :boolean, default: true | ||
add_index :locations, :active | ||
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
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
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
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
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,26 @@ | ||
require 'rails_helper' | ||
|
||
describe "GET 'search'" do | ||
|
||
context 'with status parameter' do | ||
before(:each) do | ||
create(:nearby_loc) | ||
@location = create(:location) | ||
@attrs = attributes_for(:service) | ||
end | ||
|
||
it 'only returns active locations when status=active' do | ||
@location.services.create!(@attrs.merge(status: 'inactive')) | ||
get 'api/search?status=active' | ||
expect(json.length).to eq(1) | ||
expect(json.first['name']).to eq 'Library' | ||
end | ||
|
||
it 'only returns inactive locations when status != active' do | ||
@location.services.create!(@attrs.merge(status: 'inactive')) | ||
get 'api/search?status=inactive' | ||
expect(json.length).to eq(1) | ||
expect(json.first['name']).to eq 'VRS Services' | ||
end | ||
end | ||
end |