Skip to content

Commit

Permalink
set json as request default format
Browse files Browse the repository at this point in the history
  • Loading branch information
codez committed Oct 21, 2019
1 parent 0a6f7a2 commit f918424
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 62 deletions.

This file was deleted.

8 changes: 0 additions & 8 deletions config/initializers/application_controller_renderer.rb

This file was deleted.

72 changes: 38 additions & 34 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,59 @@

root to: 'apidocs#index'

resources :shows, only: [:index, :show]
defaults format: :json do

resources :broadcasts, only: [:show, :update] do
resources :audio_files, only: :index
resources :tracks, only: :index
end
resources :shows, only: [:index, :show]

resources :tracks, except: :index
resources :broadcasts, only: [:show, :update] do
resources :audio_files, only: :index
resources :tracks, only: :index
end

constraints(year: /\d{4}/, month: /\d{2}/, day: /\d{2}/,
hour: /\d{2}/, min: /\d{2}/, sec: /\d{2}/) do
get '(/shows/:show_id)/broadcasts(/:year(/:month(/:day(/:hour(:min(:sec))))))',
to: 'broadcasts#index',
as: :broadcasts
resources :tracks, except: :index

get 'audio_files/:year/:month/:day/:hour:min(:sec)_:playback_format.:format',
to: 'audio_files#show',
as: :audio_file
constraints(year: /\d{4}/, month: /\d{2}/, day: /\d{2}/,
hour: /\d{2}/, min: /\d{2}/, sec: /\d{2}/) do
get '(/shows/:show_id)/broadcasts(/:year(/:month(/:day(/:hour(:min(:sec))))))',
to: 'broadcasts#index',
as: :broadcasts

get '(/shows/:show_id)/tracks(/:year(/:month(/:day(/:hour(:min(:sec))))))',
to: 'tracks#index'
end
get 'audio_files/:year/:month/:day/:hour:min(:sec)_:playback_format.:format',
to: 'audio_files#show',
as: :audio_file

get '(/shows/:show_id)/tracks(/:year(/:month(/:day(/:hour(:min(:sec))))))',
to: 'tracks#index'
end

get 'login', to: 'login#show'
post 'login', to: 'login#create'
patch 'login', to: 'login#update'
get 'login', to: 'login#show'
post 'login', to: 'login#create'
patch 'login', to: 'login#update'

get 'status', to: 'status#show'
get 'status', to: 'status#show'

namespace :admin do
resources :access_codes
namespace :admin do
resources :access_codes

resources :audio_encodings, only: :index
resources :audio_encodings, only: :index

resources :playback_formats
resources :playback_formats

resources :profiles do
resources :archive_formats do
resources :downgrade_actions
resources :profiles do
resources :archive_formats do
resources :downgrade_actions
end
end
end

resources :shows do
post 'merge/:target_id', to: 'shows/merge#create', on: :member
end
resources :shows do
post 'merge/:target_id', to: 'shows/merge#create', on: :member
end

get 'stats/:year(/:month)', to: 'stats#index'
get 'stats/:year(/:month)', to: 'stats#index'

resources :users
end

resources :users
end

end
16 changes: 8 additions & 8 deletions test/controllers/broadcasts_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,47 +68,47 @@ class BroadcastsControllerTest < ActionController::TestCase
test 'GET index with show_id and time parts resolves params correctly' do
assert_routing({ path: 'shows/42/broadcasts/2013/05/20', method: :get },
{ controller: 'broadcasts', action: 'index', show_id: '42',
year: '2013', month: '05', day: '20' })
year: '2013', month: '05', day: '20', format: :json })
end

test 'GET index only with show_id resolves params correctly' do
assert_routing({ path: 'shows/42/broadcasts', method: :get },
{ controller: 'broadcasts', action: 'index', show_id: '42' })
{ controller: 'broadcasts', action: 'index', show_id: '42', format: :json })
end

test 'GET index with show_id and year resolves params correctly' do
assert_routing({ path: 'shows/42/broadcasts/2013', method: :get },
{ controller: 'broadcasts', action: 'index',
{ controller: 'broadcasts', action: 'index', format: :json,
show_id: '42', year: '2013' })
end

test 'GET index with time parts up to month resolves params correctly' do
assert_routing({ path: 'broadcasts/2013/05', method: :get },
{ controller: 'broadcasts', action: 'index',
{ controller: 'broadcasts', action: 'index', format: :json,
year: '2013', month: '05' })
end

test 'GET index with time parts up to day resolves params correctly' do
assert_routing({ path: 'broadcasts/2013/05/20', method: :get },
{ controller: 'broadcasts', action: 'index',
{ controller: 'broadcasts', action: 'index', format: :json,
year: '2013', month: '05', day: '20' })
end

test 'GET index with time parts up to hour resolves params correctly' do
assert_routing({ path: 'broadcasts/2013/05/20/20', method: :get },
{ controller: 'broadcasts', action: 'index',
{ controller: 'broadcasts', action: 'index', format: :json,
year: '2013', month: '05', day: '20', hour: '20' })
end

test 'GET index with time parts up to minute resolves params correctly' do
assert_routing({ path: 'broadcasts/2013/05/20/2015', method: :get },
{ controller: 'broadcasts', action: 'index',
{ controller: 'broadcasts', action: 'index', format: :json,
year: '2013', month: '05', day: '20', hour: '20', min: '15' })
end

test 'GET index with time parts up to seconds resolves params correctly' do
assert_routing({ path: 'broadcasts/2013/05/20/201534', method: :get },
{ controller: 'broadcasts', action: 'index',
{ controller: 'broadcasts', action: 'index', format: :json,
year: '2013', month: '05', day: '20', hour: '20', min: '15', sec: '34' })
end

Expand Down
16 changes: 8 additions & 8 deletions test/controllers/tracks_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,47 +63,47 @@ class TracksControllerTest < ActionController::TestCase
test 'GET index with show_id and time parts resolves params correctly' do
assert_routing({ path: 'shows/42/tracks/2013/05/20', method: :get },
{ controller: 'tracks', action: 'index', show_id: '42',
year: '2013', month: '05', day: '20' })
year: '2013', month: '05', day: '20', format: :json })
end

test 'GET index only with show_id resolves params correctly' do
assert_routing({ path: 'shows/42/tracks', method: :get },
{ controller: 'tracks', action: 'index', show_id: '42' })
{ controller: 'tracks', action: 'index', show_id: '42', format: :json })
end

test 'GET index with show_id and year resolves params correctly' do
assert_routing({ path: 'shows/42/tracks/2013', method: :get },
{ controller: 'tracks', action: 'index',
{ controller: 'tracks', action: 'index', format: :json,
show_id: '42', year: '2013' })
end

test 'GET index with time parts up to month resolves params correctly' do
assert_routing({ path: 'tracks/2013/05', method: :get },
{ controller: 'tracks', action: 'index',
{ controller: 'tracks', action: 'index', format: :json,
year: '2013', month: '05' })
end

test 'GET index with time parts up to day resolves params correctly' do
assert_routing({ path: 'tracks/2013/05/20', method: :get },
{ controller: 'tracks', action: 'index',
{ controller: 'tracks', action: 'index', format: :json,
year: '2013', month: '05', day: '20' })
end

test 'GET index with time parts up to hour resolves params correctly' do
assert_routing({ path: 'tracks/2013/05/20/20', method: :get },
{ controller: 'tracks', action: 'index',
{ controller: 'tracks', action: 'index', format: :json,
year: '2013', month: '05', day: '20', hour: '20' })
end

test 'GET index with time parts up to minute resolves params correctly' do
assert_routing({ path: 'tracks/2013/05/20/2015', method: :get },
{ controller: 'tracks', action: 'index',
{ controller: 'tracks', action: 'index', format: :json,
year: '2013', month: '05', day: '20', hour: '20', min: '15' })
end

test 'GET index with time parts up to seconds resolves params correctly' do
assert_routing({ path: 'tracks/2013/05/20/201534', method: :get },
{ controller: 'tracks', action: 'index',
{ controller: 'tracks', action: 'index', format: :json,
year: '2013', month: '05', day: '20', hour: '20', min: '15', sec: '34' })
end

Expand Down

0 comments on commit f918424

Please sign in to comment.