Skip to content

Commit

Permalink
These specs now covered in EntityController
Browse files Browse the repository at this point in the history
  • Loading branch information
irees committed Jun 13, 2017
1 parent 77198f6 commit 3e3cccd
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 446 deletions.
80 changes: 6 additions & 74 deletions spec/controllers/api/v1/feeds_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,7 @@
describe Api::V1::FeedsController do
context 'GET index' do
context 'as JSON' do
it 'returns all Feeds when no parameters provided' do
create_list(:feed, 2)
get :index, total: true
expect_json_types({ feeds: :array })
expect_json({
feeds: -> (feeds) {
expect(feeds.length).to eq 2
},
meta: {
total: 2
}
})
end

it 'query: onestop_id' do
create_list(:feed, 3)
onestop_id = Feed.second.onestop_id
get :index, onestop_id: onestop_id
expect_json_types({ feeds: :array })
expect_json({
feeds: -> (feeds) {
expect(feeds.first[:onestop_id]).to eq onestop_id
}
})
end

it 'query: active_feed_version_import_level' do
it '?active_feed_version_import_level' do
fv = create(:feed_version, import_level: 4)
feed = fv.feed
feed.update!(active_feed_version: fv)
Expand All @@ -39,7 +13,7 @@
})
end

it 'query: last_imported_since' do
it '?last_imported_since' do
feeds = create_list(:feed, 3)
past = DateTime.parse('2015-01-01 01:02:03')
now = DateTime.parse('2016-01-01 00:00:00')
Expand All @@ -56,7 +30,7 @@
expect_json({feeds: -> (feeds) {expect(feeds.size).to eq(0)}})
end

it 'query: latest_fetch_exception' do
it '?latest_fetch_exception' do
feeds = create_list(:feed, 3)
feed = feeds.first
Issue.create!(issue_type: 'feed_fetch_invalid_source').entities_with_issues.create!(entity: feed, entity_attribute: 'url')
Expand All @@ -68,7 +42,7 @@
expect_json({feeds: -> (feeds) {expect(feeds.size).to eq(2)}})
end

it 'query: where_latest_feed_version_import_status' do
it '?where_latest_feed_version_import_status' do
fvs = create_list(:feed_version, 3)
fvs[0].feed_version_imports.create!(success: true)
fvs[1].feed_version_imports.create!(success: false)
Expand All @@ -90,23 +64,7 @@
}})
end

it 'query: embed_issues' do
feeds = create_list(:feed, 3)
feed = feeds.first
Issue.create!(issue_type: 'feed_fetch_invalid_source').entities_with_issues.create!(entity: feed, entity_attribute: 'url')

get :index, embed_issues: 'true'
expect_json({feeds: -> (feeds) {
expect(feeds.first[:issues].size).to eq 1
}})

get :index, embed_issues: 'false'
expect_json({feeds: -> (feeds) {
expect(feeds.first[:issues]).to be_nil
}})
end

it 'query: by one source URL' do
it '?url' do
feeds = create_list(:feed, 3)
feed_to_find = feeds.second
get :index, url: feed_to_find.url
Expand All @@ -116,7 +74,7 @@
}})
end

it 'query: by two source URLs' do
it '?url=list' do
feeds = create_list(:feed, 3)
feeds_to_find = [feeds.second, feeds.third]
get :index, url: [feeds_to_find.first.url, feeds_to_find.second.url]
Expand All @@ -125,31 +83,6 @@
}})
end
end

context 'as GeoJSON' do
it 'should return GeoJSON for all feeds' do
create_list(:feed, 2, geometry: {
type: 'Polygon',
coordinates: [
[
[-71.04819, 42.254056],
[-70.9016389,42.254056],
[-70.9016389,42.359837],
[-71.04819,42.359837],
[-71.04819,42.254056]
]
]
})

get :index, format: :geojson
expect_json({
type: 'FeatureCollection',
features: -> (features) {
expect(features.map {|f| f[:properties][:onestop_id] }).to match_array(Feed.pluck(:onestop_id))
}
})
end
end
end

context 'GET fetch_info' do
Expand Down Expand Up @@ -183,6 +116,5 @@
get :download_latest_feed_version, id: @feed_that_disallows_download.onestop_id
expect(response.status).to eq(404)
end

end
end
103 changes: 0 additions & 103 deletions spec/controllers/api/v1/operators_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,6 @@
end

context 'as JSON' do
it 'returns all current operators when no parameters provided' do
get :index
expect_json_types({ operators: :array })
expect_json({ operators: -> (operators) {
expect(operators.length).to eq 2
}})
end

it 'filters by imported_with_gtfs_id' do
operators = create_list(:operator, 3)
operator = create(:operator, name: 'Test 123')
feed_version = create(:feed_version_example)
feed_version.entities_imported_from_feed.create!(entity: operator, feed: feed_version.feed, gtfs_id: "test")
get :index, imported_with_gtfs_id: 'test'
expect_json({ operators: -> (operators) {
expect(operators.first[:onestop_id]).to eq operator.onestop_id
expect(operators.count).to eq 1
}})
get :index, imported_with_gtfs_id: 'true', gtfs_id: 'test'
expect_json({ operators: -> (operators) {
expect(operators.first[:onestop_id]).to eq operator.onestop_id
expect(operators.count).to eq 1
}})
get :index, imported_with_gtfs_id: 'unknown'
expect_json({ operators: -> (operators) {
expect(operators.size).to eq 0
}})
end

it 'filters by name' do
operators = create_list(:operator, 3)
operator = create(:operator, name: 'Test 123')
Expand Down Expand Up @@ -87,80 +58,6 @@
expect(operators.count).to eq 1
}})
end

it 'returns operators within a circular radius when lat/lon/r provided' do
get :index, lat: 37.732520, lon: -122.433415, r: 10_000
expect_json({ operators: -> (operators) {
expect(operators.first[:onestop_id]).to eq sfmta.onestop_id
}})
end

it 'returns operator within a bounding box' do
get :index, bbox: '-122.4131,37.7136,-122.3789,37.8065'
expect_json({ operators: -> (operators) {
expect(operators.first[:onestop_id]).to eq sfmta.onestop_id
}})
end

it 'returns the appropriate operator when Onestop ID provided' do
get :index, onestop_id: sfmta.onestop_id
expect_json({ operators: -> (operators) {
expect(operators.first[:onestop_id]).to eq sfmta.onestop_id
expect(operators.count).to eq 1
}})
end
end

context 'as GeoJSON' do
it 'returns operator within a bounding box' do
get :index, format: :geojson, bbox: '-122.0883,37.198,-121.8191,37.54804'
expect_json({
type: 'FeatureCollection',
features: -> (features) { expect(features.first[:id]).to eq vta.onestop_id }
})
end
end

context 'as CSV' do
it 'should return a CSV file for download' do
get :index, format: :csv
expect(response.headers['Content-Type']).to eq 'text/csv'
expect(response.headers['Content-Disposition']).to eq 'attachment; filename=operators.csv'
end

it 'should include column headers and row values' do
get :index, format: :csv, bbox: '-122.0883,37.198,-121.8191,37.54804'
expect(response.body.lines.count).to eq 2
expect(response.body).to start_with(Operator.csv_column_names.join(','))
expect(response.body).to include([vta.onestop_id, vta.name, vta.tags[:agency_url]].join(','))
end
end
end

describe 'GET show' do
context 'as JSON' do
it 'returns operators by Onestop ID' do
get :show, id: vta.onestop_id
expect_json_types({
onestop_id: :string,
geometry: :object,
name: :string,
created_at: :date,
updated_at: :date
})
expect_json({ onestop_id: -> (onestop_id) {
expect(onestop_id).to eq vta.onestop_id
}})
end

it 'returns a 404 when not found' do
get :show, id: 'ntd9015'
expect(response.status).to eq 404
end
end

context 'as GeoJSON' do
pending 'TODO: write this functionality'
end
end

Expand Down
34 changes: 0 additions & 34 deletions spec/controllers/api/v1/route_stop_patterns_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,7 @@
@rsp.entities_imported_from_feed.create!(gtfs_id: 'trip2', feed: feed_version.feed, feed_version: feed_version)
end


describe 'GET index' do
context 'as JSON' do
it 'returns all current route_stop_patterns when no parameters provided' do
get :index
expect_json_types({ route_stop_patterns: :array })
expect_json({ route_stop_patterns: -> (route_stop_patterns) {
expect(route_stop_patterns.length).to eq 1
}})
end
end

context 'returns route_stop_patterns by trips' do
it 'when not found' do
get :index, trips: 'trip3'
Expand Down Expand Up @@ -88,27 +77,4 @@
end
end
end

describe 'GET show' do
it 'returns route stop patterns by OnestopID' do
get :show, id: 'r-9q9j-bullet-fc9abc-c83be2'
expect_json_types({
onestop_id: :string,
route_onestop_id: :string,
geometry: :object,
stop_pattern: :array,
trips: :array,
created_at: :date,
updated_at: :date
})
expect_json({ onestop_id: -> (onestop_id) {
expect(onestop_id).to eq 'r-9q9j-bullet-fc9abc-c83be2'
}})
end

it 'returns a 404 when not found' do
get :show, id: 'r-9q9j-bullet-test12-test12'
expect(response.status).to eq 404
end
end
end
Loading

0 comments on commit 3e3cccd

Please sign in to comment.