Skip to content

Commit

Permalink
Merge pull request #589 from transitland/operators-filter-name
Browse files Browse the repository at this point in the history
Operators filter name
  • Loading branch information
irees committed May 10, 2016
2 parents 6c58e28 + 6fb0507 commit 81fc865
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/controllers/api/v1/operators_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def index
@operators = AllowFiltering.by_attribute_array(@operators, params, :state)
@operators = AllowFiltering.by_attribute_array(@operators, params, :metro)
@operators = AllowFiltering.by_attribute_array(@operators, params, :timezone)
@operators = AllowFiltering.by_attribute_array(@operators, params, :name)
@operators = AllowFiltering.by_attribute_array(@operators, params, :short_name)

if [params[:lat], params[:lon]].map(&:present?).all?
point = Operator::GEOFACTORY.point(params[:lon], params[:lat])
Expand Down Expand Up @@ -71,7 +73,9 @@ def index
:onestop_id,
:tag_key,
:tag_value,
:import_level
:import_level,
:name,
:short_name
)
)
end
Expand Down
20 changes: 20 additions & 0 deletions spec/controllers/api/v1/operators_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@
}})
end

it 'filters by name' do
operators = create_list(:operator, 3)
operator = create(:operator, name: 'Test 123')
get :index, name: operator.name
expect_json({ operators: -> (operators) {
expect(operators.first[:onestop_id]).to eq operator.onestop_id
expect(operators.count).to eq 1
}})
end

it 'filters by short_name' do
operators = create_list(:operator, 3)
operator = create(:operator, short_name: 'Test 123')
get :index, short_name: operator.short_name
expect_json({ operators: -> (operators) {
expect(operators.first[:onestop_id]).to eq operator.onestop_id
expect(operators.count).to eq 1
}})
end

it 'returns the appropriate operator when identifier provided' do
get :index, identifier: 'VTA'
expect_json({ operators: -> (operators) {
Expand Down

0 comments on commit 81fc865

Please sign in to comment.