Remove controllers spec already tested elsewhere
This commit is contained in:
@@ -1,45 +0,0 @@
|
||||
describe API::ApplicationController do
|
||||
include UserControllerHelpers
|
||||
|
||||
before { sign_in }
|
||||
|
||||
context 'CORS: Cross-Origin Ressource Sharing' do
|
||||
before { request.headers['Origin'] = 'http://origin.example/' }
|
||||
|
||||
context 'preflight' do
|
||||
controller(API::ApplicationController) do
|
||||
alias_method :index, :cor_preflight
|
||||
end
|
||||
|
||||
def options(action)
|
||||
process action, 'OPTIONS'
|
||||
end
|
||||
|
||||
it 'sets Access-Control-Allow-Methods header' do
|
||||
options :index
|
||||
expect(response.headers['Access-Control-Allow-Methods'])
|
||||
.to eq 'GET, POST, PUT, DELETE'
|
||||
end
|
||||
|
||||
it 'sets Access-Control-Allow-Methods header' do
|
||||
options :index
|
||||
expect(response.headers['Access-Control-Allow-Headers'])
|
||||
.to eq 'Content-Type, Content-Length, X-Requested-With'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'before filter' do
|
||||
controller(API::ApplicationController) do
|
||||
def index
|
||||
head :ok
|
||||
end
|
||||
end
|
||||
|
||||
it 'sets Access-Control-Allow-Origin header' do
|
||||
get :index
|
||||
expect(response.headers['Access-Control-Allow-Origin'])
|
||||
.to eq request.headers['Origin']
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -1,50 +0,0 @@
|
||||
describe API::PlaylistsController do
|
||||
include UserControllerHelpers
|
||||
|
||||
before { sign_in }
|
||||
|
||||
describe 'GET index' do
|
||||
render_views
|
||||
|
||||
before do
|
||||
FactoryGirl.create(:playlist, name: 'Playlist 1')
|
||||
FactoryGirl.create(:playlist, name: 'Playlist 2')
|
||||
end
|
||||
|
||||
def do_get
|
||||
get :index, format: :json
|
||||
JSON response.body
|
||||
end
|
||||
|
||||
it 'lists all playlists' do
|
||||
expect(do_get.size).to eq 2
|
||||
end
|
||||
|
||||
it 'lists playlists with their id' do
|
||||
do_get.each { |t| expect(t.keys).to include 'id' }
|
||||
end
|
||||
|
||||
it 'lists playlists with their name' do
|
||||
do_get.each { |t| expect(t.keys).to include 'name' }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST create' do
|
||||
def do_create
|
||||
post :create,
|
||||
format: :json,
|
||||
playlist: FactoryGirl.attributes_for(:playlist)
|
||||
end
|
||||
|
||||
it 'creates a new playlist for the current user' do
|
||||
expect {
|
||||
do_create
|
||||
}.to change(controller.current_user.playlists, :count).by(1)
|
||||
end
|
||||
|
||||
it 'assigns the playlist' do
|
||||
do_create
|
||||
expect(assigns[:playlist]).to be_a Playlist
|
||||
end
|
||||
end
|
||||
end
|
@@ -1,45 +0,0 @@
|
||||
describe API::SessionsController do
|
||||
describe 'POST create' do
|
||||
let(:user) { FactoryGirl.create(:user) }
|
||||
|
||||
def do_create
|
||||
post :create, format: :json, session: {
|
||||
email: user.email,
|
||||
password: user.password
|
||||
}
|
||||
end
|
||||
|
||||
context 'with valid credentials' do
|
||||
before { do_create }
|
||||
|
||||
it 'signs the user in' do
|
||||
expect(controller.current_user).to eq user
|
||||
end
|
||||
|
||||
it 'assigns the user' do
|
||||
expect(assigns[:user]).to eq user
|
||||
end
|
||||
end
|
||||
|
||||
[:email, :password].each do |attr|
|
||||
context "with invalid credentials (#{attr})" do
|
||||
before do
|
||||
allow(user).to receive(attr).and_return(user.send(attr) + '_INVALID')
|
||||
do_create
|
||||
end
|
||||
|
||||
it 'returns a not found response' do
|
||||
expect(response).to be_not_found
|
||||
end
|
||||
|
||||
it 'returns an empty body' do
|
||||
expect(response.body).to be_empty
|
||||
end
|
||||
|
||||
it 'assigns no user' do
|
||||
expect(assigns[:user]).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -1,35 +0,0 @@
|
||||
describe API::TracksController do
|
||||
include UserControllerHelpers
|
||||
|
||||
before { sign_in }
|
||||
|
||||
describe 'GET index' do
|
||||
render_views
|
||||
|
||||
before do
|
||||
FactoryGirl.create(:track_with_sound)
|
||||
FactoryGirl.create(:track_with_sound)
|
||||
end
|
||||
|
||||
def do_get
|
||||
get :index, format: :json
|
||||
JSON response.body
|
||||
end
|
||||
|
||||
it 'lists all tracks' do
|
||||
expect(do_get.size).to eq 2
|
||||
end
|
||||
|
||||
it 'lists tracks with their id' do
|
||||
do_get.each { |p| expect(p).to include 'id' }
|
||||
end
|
||||
|
||||
it 'lists tracks with their name' do
|
||||
do_get.each { |p| expect(p).to include 'name' }
|
||||
end
|
||||
|
||||
it 'lists tracks with sound URL' do
|
||||
do_get.each { |p| expect(p).to include 'sound_url' }
|
||||
end
|
||||
end
|
||||
end
|
@@ -1,96 +0,0 @@
|
||||
describe PlaylistsController do
|
||||
include UserControllerHelpers
|
||||
|
||||
before { sign_in }
|
||||
|
||||
describe 'GET index' do
|
||||
it 'assigns all playlists as @playlists' do
|
||||
playlist = FactoryGirl.create(:playlist)
|
||||
get :index
|
||||
expect(assigns[:playlists]).to eq [playlist]
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET new' do
|
||||
it 'assigns a new playlist as @playlist' do
|
||||
get :new
|
||||
expect(assigns[:playlist]).to be_a_new Playlist
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET edit' do
|
||||
it 'assigns the requested playlist as @playlist' do
|
||||
playlist = FactoryGirl.create(:playlist)
|
||||
get :edit, id: playlist.id.to_s
|
||||
expect(assigns[:playlist]).to eq playlist
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST create' do
|
||||
def do_create
|
||||
post :create, playlist: FactoryGirl.attributes_for(:playlist)
|
||||
end
|
||||
|
||||
context 'whith valid params' do
|
||||
it 'creates a new playlist for the current user' do
|
||||
expect {
|
||||
do_create
|
||||
}.to change(controller.current_user.playlists, :count).by(1)
|
||||
end
|
||||
|
||||
it 'redirects to the playlists index' do
|
||||
do_create
|
||||
expect(response).to redirect_to action: 'index'
|
||||
end
|
||||
end
|
||||
|
||||
context 'whith invalid params' do
|
||||
before { allow_any_instance_of(Playlist).to receive(:save) { false } }
|
||||
|
||||
it 'assigns the playlist as @playlist' do
|
||||
do_create
|
||||
expect(assigns[:playlist]).to be_a_new Playlist
|
||||
end
|
||||
|
||||
it 'renders the new template' do
|
||||
do_create
|
||||
expect(response).to render_template 'new'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PUT update' do
|
||||
let(:playlist) { FactoryGirl.create(:playlist) }
|
||||
|
||||
def do_update
|
||||
put :update, id: playlist.id.to_s, playlist: { name: 'Rock' }
|
||||
end
|
||||
|
||||
context 'whith valid params' do
|
||||
it 'updates the playlist' do
|
||||
expect_any_instance_of(Playlist)
|
||||
.to receive(:update_attributes).with('name' => 'Rock')
|
||||
do_update
|
||||
end
|
||||
|
||||
it 'redirects to the playlists index' do
|
||||
do_update
|
||||
expect(response).to redirect_to(action: 'index')
|
||||
end
|
||||
end
|
||||
|
||||
context 'with invalid params' do
|
||||
before { allow_any_instance_of(Playlist).to receive(:save) { false } }
|
||||
|
||||
it 'assigns the requested playlist as @playlist' do
|
||||
do_update
|
||||
expect(assigns[:playlist]).to eq playlist
|
||||
end
|
||||
|
||||
it 'renders the edit template' do
|
||||
do_update
|
||||
expect(response).to render_template 'edit'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -1,46 +0,0 @@
|
||||
describe SessionsController do
|
||||
describe 'GET new' do
|
||||
it 'responds successfully' do
|
||||
expect(response).to be_success
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST create' do
|
||||
let(:user) { FactoryGirl.create(:user) }
|
||||
|
||||
def do_create
|
||||
post :create, session: {
|
||||
email: user.email,
|
||||
password: user.password
|
||||
}
|
||||
end
|
||||
|
||||
context 'with valid credentials' do
|
||||
it 'signs the user in' do
|
||||
do_create
|
||||
expect(controller.current_user).to eq user
|
||||
end
|
||||
|
||||
it 'redirects to the home page' do
|
||||
do_create
|
||||
expect(response).to redirect_to :root
|
||||
end
|
||||
end
|
||||
|
||||
[:email, :password].each do |attr|
|
||||
context "with invalid credentials (#{attr})" do
|
||||
before do
|
||||
allow(user).to receive(attr).and_return(user.send(attr) + '_INVALID')
|
||||
end
|
||||
|
||||
it 'renders the new template' do
|
||||
do_create
|
||||
expect(response).to render_template 'new'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE destroy' do
|
||||
end
|
||||
end
|
@@ -1,23 +0,0 @@
|
||||
describe SoundsController do
|
||||
include UserControllerHelpers
|
||||
|
||||
before { sign_in }
|
||||
|
||||
describe 'GET show' do
|
||||
let(:sound) { FactoryGirl.create(:sound) }
|
||||
|
||||
def do_show
|
||||
get :show, id: sound.id
|
||||
end
|
||||
|
||||
it 'sets the sound file content as the response body' do
|
||||
do_show
|
||||
expect(response.body).to eq File.read(sound.path, encoding: 'BINARY')
|
||||
end
|
||||
|
||||
it 'sets the sound mime-type as the response content-type' do
|
||||
do_show
|
||||
expect(response.content_type).to eq sound.mime_type
|
||||
end
|
||||
end
|
||||
end
|
@@ -1,58 +0,0 @@
|
||||
describe TracksController do
|
||||
include UserControllerHelpers
|
||||
|
||||
before { sign_in }
|
||||
|
||||
describe 'GET show' do
|
||||
it 'assigns the requested track as @track' do
|
||||
track = FactoryGirl.create(:track)
|
||||
get :show, id: track.id.to_s
|
||||
expect(assigns[:track]).to eq track
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET new' do
|
||||
it 'assigns a new track as @track' do
|
||||
get :new
|
||||
expect(assigns[:track]).to be_a_new Track
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST create new' do
|
||||
def do_create
|
||||
post :create, track: FactoryGirl.attributes_for(:track).merge(
|
||||
file: fixture_file_upload(
|
||||
"#{Rails.root}/spec/fixtures/test.mp3",
|
||||
'audio/mpeg'
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
context 'whith valid params' do
|
||||
it 'creates a new track' do
|
||||
expect {
|
||||
do_create
|
||||
}.to change(Track, :count).by(1)
|
||||
end
|
||||
|
||||
it 'redirects to the track page' do
|
||||
do_create
|
||||
expect(response).to redirect_to Track.last
|
||||
end
|
||||
end
|
||||
|
||||
context 'whith invalid params' do
|
||||
before { allow_any_instance_of(Track).to receive(:save) { false } }
|
||||
|
||||
it 'assigns the track as @track' do
|
||||
do_create
|
||||
expect(assigns[:track]).to be_a_new Track
|
||||
end
|
||||
|
||||
it 'renders the new template' do
|
||||
do_create
|
||||
expect(response).to render_template 'new'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -1,48 +0,0 @@
|
||||
describe UsersController do
|
||||
let(:attributes) { FactoryGirl.attributes_for(:user) }
|
||||
|
||||
describe 'GET new' do
|
||||
it 'assigns a new user as @user' do
|
||||
get :new
|
||||
expect(assigns[:user]).to be_a_new User
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST create' do
|
||||
def do_post(params = {})
|
||||
post :create, user: attributes.merge(params)
|
||||
end
|
||||
|
||||
context 'whith valid params' do
|
||||
it 'creates a new user' do
|
||||
expect {
|
||||
do_post
|
||||
}.to change(User, :count).by(1)
|
||||
end
|
||||
|
||||
it 'signs the user in' do
|
||||
do_post
|
||||
expect(controller.current_user).not_to be_nil
|
||||
end
|
||||
|
||||
it 'redirects to the home page' do
|
||||
do_post
|
||||
expect(response).to redirect_to :root
|
||||
end
|
||||
end
|
||||
|
||||
context 'whith invalid params' do
|
||||
before { allow_any_instance_of(User).to receive(:save) { false } }
|
||||
|
||||
it 'assigns the user as @user' do
|
||||
do_post
|
||||
expect(assigns[:user]).to be_a_new User
|
||||
end
|
||||
|
||||
it 'renders the new template' do
|
||||
do_post
|
||||
expect(response).to render_template 'new'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user