From 464a16e9645c679efb29a6fe9a865cf38aa6cd96 Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Tue, 5 May 2015 00:49:23 +0000 Subject: [PATCH] Fix API sounds/show action --- app/controllers/api/sounds_controller.rb | 4 +++- spec/integration/api/sounds_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 spec/integration/api/sounds_spec.rb diff --git a/app/controllers/api/sounds_controller.rb b/app/controllers/api/sounds_controller.rb index 67efd3a..980cf12 100644 --- a/app/controllers/api/sounds_controller.rb +++ b/app/controllers/api/sounds_controller.rb @@ -1,9 +1,11 @@ module API class SoundsController < ApplicationController + skip_before_filter :json_filter!, only: :show + before_action :set_sound, only: :show def show - send_file sound.path, type: sound.mime_type + send_file @sound.path, type: @sound.mime_type end diff --git a/spec/integration/api/sounds_spec.rb b/spec/integration/api/sounds_spec.rb new file mode 100644 index 0000000..4bc3ce8 --- /dev/null +++ b/spec/integration/api/sounds_spec.rb @@ -0,0 +1,21 @@ +describe 'API sounds' do + before { api_sign_in } + + describe 'sound show' do + let(:sound) { create :sound } + let(:request_show) { get api_sound_path sound } + subject { response } + + before { request_show } + + it { is_expected.to have_http_status 200 } + + it 'has the sound mime type as content type' do + expect(response.content_type).to eq sound.mime_type + end + + it 'returns the sound file as the body' do + expect(response.body).to eq File.read(sound.path, mode: 'rb') + end + end +end