From 1acf44cdb12ea995e90a83adac30f0f7224f0e2b Mon Sep 17 00:00:00 2001 From: Ian Rees Date: Mon, 9 May 2016 17:21:43 -0700 Subject: [PATCH 1/3] Operators: filter by name, short_name --- app/controllers/api/v1/operators_controller.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/operators_controller.rb b/app/controllers/api/v1/operators_controller.rb index 133e6d3ca..3a08fcc46 100644 --- a/app/controllers/api/v1/operators_controller.rb +++ b/app/controllers/api/v1/operators_controller.rb @@ -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]) @@ -71,7 +73,9 @@ def index :onestop_id, :tag_key, :tag_value, - :import_level + :import_level, + :name, + :short_name ) ) end From ffc05ac0ba4edc08389987bf502f78510041e975 Mon Sep 17 00:00:00 2001 From: Ian Rees Date: Mon, 9 May 2016 17:21:47 -0700 Subject: [PATCH 2/3] Spec update --- .../api/v1/operators_controller_spec.rb | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/spec/controllers/api/v1/operators_controller_spec.rb b/spec/controllers/api/v1/operators_controller_spec.rb index caff784cd..85c82060c 100644 --- a/spec/controllers/api/v1/operators_controller_spec.rb +++ b/spec/controllers/api/v1/operators_controller_spec.rb @@ -30,6 +30,26 @@ }}) end + it 'filters by name' do + operators = create_list(:operator, 3) + operator = operators.first + 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 = operators.first + get :index, short_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 'returns the appropriate operator when identifier provided' do get :index, identifier: 'VTA' expect_json({ operators: -> (operators) { From 6fb05073e56c394b96e2beb947d596edbb9271fb Mon Sep 17 00:00:00 2001 From: Ian Rees Date: Mon, 9 May 2016 17:24:23 -0700 Subject: [PATCH 3/3] Spec update --- spec/controllers/api/v1/operators_controller_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/controllers/api/v1/operators_controller_spec.rb b/spec/controllers/api/v1/operators_controller_spec.rb index 85c82060c..04d12e4c9 100644 --- a/spec/controllers/api/v1/operators_controller_spec.rb +++ b/spec/controllers/api/v1/operators_controller_spec.rb @@ -32,7 +32,7 @@ it 'filters by name' do operators = create_list(:operator, 3) - operator = operators.first + 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 @@ -42,8 +42,8 @@ it 'filters by short_name' do operators = create_list(:operator, 3) - operator = operators.first - get :index, short_name: operator.name + 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