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

Include geometry #944

Merged
merged 4 commits into from
Feb 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 8 additions & 3 deletions app/controllers/api/v1/routes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,19 @@ def index
]}

respond_to do |format|
format.json { render paginated_json_collection(@routes).merge({ scope: { exclude_geometry: AllowFiltering.to_boolean(params[:exclude_geometry]) } }) }
# consider removing exclude_geometry
format.json { render paginated_json_collection(@routes).merge({ scope: { exclude_geometry: AllowFiltering.to_boolean(params[:exclude_geometry]),
include_geometry: AllowFiltering.to_boolean(params[:include_geometry])} }) }
format.geojson { render paginated_geojson_collection(@routes) }
format.csv { return_downloadable_csv(@routes, 'routes') }
end
end

def show
respond_to do |format|
format.json { render json: @route, scope: { exclude_geometry: AllowFiltering.to_boolean(params[:exclude_geometry]) } }
# consider removing exclude_geometry
format.json { render json: @route, scope: { exclude_geometry: AllowFiltering.to_boolean(params[:exclude_geometry]),
include_geometry: AllowFiltering.to_boolean(params[:include_geometry])} }
format.geojson { render json: @route, serializer: GeoJSONSerializer }
end
end
Expand All @@ -111,7 +115,8 @@ def query_params
:import_level,
:imported_from_feed,
:imported_from_feed_version,
:exclude_geometry
:exclude_geometry,
:include_geometry
)
end

Expand Down
8 changes: 7 additions & 1 deletion app/serializers/route_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ class RouteSerializer < CurrentEntitySerializer
:route_stop_patterns_by_onestop_id

def include_geometry?
!(scope.present? && scope[:exclude_geometry].present? && scope[:exclude_geometry]) && !!object.try(:geometry)
# support exclude_geometry here, but include_geometry takes priority
if (scope.present? && scope.has_key?(:include_geometry) && !scope[:include_geometry].nil?)
return scope[:include_geometry] && !!object.try(:geometry)
elsif (scope.present? && scope.has_key?(:exclude_geometry) && !scope[:exclude_geometry].nil?)
return !scope[:exclude_geometry] && !!object.try(:geometry)
end
return true
end

def operated_by_onestop_id
Expand Down
20 changes: 17 additions & 3 deletions spec/controllers/api/v1/routes_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,20 +190,34 @@
end
end

context 'exclude_geometry' do
it 'include' do
context 'include and exclude geometry' do
it 'exclude_geometry=false' do
get :index, exclude_geometry: "false"
expect_json({ routes: -> (routes) {
expect(routes.first.has_key?(:geometry)).to be true
}})
end

it 'exclude' do
it 'exclude_geometry=true' do
get :index, exclude_geometry: "true"
expect_json({ routes: -> (routes) {
expect(routes.first.has_key?(:geometry)).to be false
}})
end

it 'include_geometry=false' do
get :index, include_geometry: "false"
expect_json({ routes: -> (routes) {
expect(routes.first.has_key?(:geometry)).to be false
}})
end

it 'include_geometry=true' do
get :index, include_geometry: "true"
expect_json({ routes: -> (routes) {
expect(routes.first.has_key?(:geometry)).to be true
}})
end
end
end

Expand Down