diff --git a/app/controllers/api/tracks_controller.rb b/app/controllers/api/tracks_controller.rb index 427d4fa..a8cbd0e 100644 --- a/app/controllers/api/tracks_controller.rb +++ b/app/controllers/api/tracks_controller.rb @@ -3,5 +3,9 @@ module API def index @tracks = Track.all end + + def show + @track = Track.find(params[:id]) + end end end diff --git a/app/views/api/tracks/show.rabl b/app/views/api/tracks/show.rabl new file mode 100644 index 0000000..beb065c --- /dev/null +++ b/app/views/api/tracks/show.rabl @@ -0,0 +1,4 @@ +object @track + +attribute :id +attribute :name diff --git a/config/routes.rb b/config/routes.rb index 70f0e84..5dc225b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,7 +7,7 @@ Rails.application.routes.draw do resources :playlists, only: %i[index show create] resources :sessions, only: :create resources :sounds, only: :show - resources :tracks, only: :index + resources :tracks, only: %i[index show] match '*all', to: 'application#not_found', via: :all end diff --git a/spec/integration/api/tracks_spec.rb b/spec/integration/api/tracks_spec.rb index 226d342..9f00375 100644 --- a/spec/integration/api/tracks_spec.rb +++ b/spec/integration/api/tracks_spec.rb @@ -20,4 +20,14 @@ describe 'API tracks' do } ] end + + it 'shows a track' do + track = create :track + get api_track_path track, format: :json + + expect(json).to match( + id: track.id, + name: track.name + ) + end end