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

Operators filter name #589

Merged
merged 3 commits into from
May 10, 2016
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
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