Skip to content

Commit

Permalink
Merge pull request #1162 from transitland/feed-add-name
Browse files Browse the repository at this point in the history
Feed: add name
  • Loading branch information
irees committed Aug 11, 2017
2 parents b78066c + e6b2f4a commit a856068
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 3 deletions.
6 changes: 6 additions & 0 deletions app/controllers/api/v1/feeds_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def download_latest_feed_version

def index_query
super
@collection = AllowFiltering.by_attribute_array(@collection, params, :name)
@collection = AllowFiltering.by_attribute_array(@collection, params, :url, case_sensitive: true)
@collection = AllowFiltering.by_attribute_since(@collection, params, :last_imported_since, :last_imported_at)
if params[:latest_fetch_exception].present?
Expand Down Expand Up @@ -69,6 +70,11 @@ def index_includes

def query_params
super.merge({
name: {
desc: "Feed name",
type: "string",
array: true
},
last_imported_since: {
desc: "Last imported since",
type: "datetime"
Expand Down
1 change: 1 addition & 0 deletions app/models/feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# license_attribution_text :text
# active_feed_version_id :integer
# edited_attributes :string default([]), is an Array
# name :string
#
# Indexes
#
Expand Down
4 changes: 3 additions & 1 deletion app/serializers/feed_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# license_attribution_text :text
# active_feed_version_id :integer
# edited_attributes :string default([]), is an Array
# name :string
#
# Indexes
#
Expand All @@ -32,7 +33,8 @@
#

class FeedSerializer < CurrentEntitySerializer
attributes :url,
attributes :name,
:url,
:feed_format,
:license_name,
:license_url,
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20170811211047_add_name_to_feeds.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddNameToFeeds < ActiveRecord::Migration
def change
[:current, :old].each do |version|
change_table "#{version}_feeds" do |t|
t.string :name, index: true
end
end
end
end
5 changes: 3 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20170725011839) do
ActiveRecord::Schema.define(version: 20170811211047) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -62,6 +62,7 @@
t.text "license_attribution_text"
t.integer "active_feed_version_id"
t.string "edited_attributes", default: [], array: true
t.string "name"
end

add_index "current_feeds", ["active_feed_version_id"], name: "index_current_feeds_on_active_feed_version_id", using: :btree
Expand Down Expand Up @@ -242,7 +243,6 @@
add_index "current_schedule_stop_pairs", ["trip"], name: "current_schedule_stop_pairs64_trip_idx", using: :btree
add_index "current_schedule_stop_pairs", ["updated_at"], name: "current_schedule_stop_pairs64_updated_at_idx", using: :btree


create_table "current_stop_transfers", force: :cascade do |t|
t.string "transfer_type"
t.integer "min_transfer_time"
Expand Down Expand Up @@ -408,6 +408,7 @@
t.integer "active_feed_version_id"
t.string "edited_attributes", default: [], array: true
t.string "action"
t.string "name"
end

add_index "old_feeds", ["active_feed_version_id"], name: "index_old_feeds_on_active_feed_version_id", using: :btree
Expand Down
13 changes: 13 additions & 0 deletions spec/controllers/api/v1/feeds_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@
})
end

it '?name' do
feed1 = create(:feed, name: "test")
feed2 = create(:feed, name: "bar")
get :index, name: "bar"
expect_json_types({ feeds: :array })
expect_json({
feeds: -> (feeds) {
expect(feeds.size).to eq(1)
expect(feeds.first[:onestop_id]).to eq feed2.onestop_id
}
})
end

it 'query: onestop_id' do
create_list(:feed, 3)
onestop_id = Feed.second.onestop_id
Expand Down
1 change: 1 addition & 0 deletions spec/factories/feed_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# license_attribution_text :text
# active_feed_version_id :integer
# edited_attributes :string default([]), is an Array
# name :string
#
# Indexes
#
Expand Down
1 change: 1 addition & 0 deletions spec/models/feed_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# license_attribution_text :text
# active_feed_version_id :integer
# edited_attributes :string default([]), is an Array
# name :string
#
# Indexes
#
Expand Down

0 comments on commit a856068

Please sign in to comment.