metamaps--metamaps/spec/controllers/maps_controller_spec.rb

101 lines
2.6 KiB
Ruby
Raw Normal View History

require 'rails_helper'
2015-12-16 14:19:58 +00:00
RSpec.describe MapsController, type: :controller do
2016-02-08 03:56:46 +00:00
let(:map) { create(:map) }
let(:valid_attributes) { map.attributes.except(:id) }
let(:invalid_attributes) { { permission: :commons } }
before :each do
sign_in
2015-12-16 14:19:58 +00:00
end
2015-12-16 14:19:58 +00:00
describe 'GET #index' do
it 'assigns all maps as @maps' do
2016-02-08 03:56:46 +00:00
get :index, {}
expect(assigns(:maps)).to eq([map])
end
end
2015-12-16 14:19:58 +00:00
describe 'GET #show' do
it 'assigns the requested map as @map' do
2016-02-08 03:56:46 +00:00
get :show, { id: map.to_param }
expect(assigns(:map)).to eq(map)
end
end
2015-12-16 14:19:58 +00:00
describe 'POST #create' do
context 'with valid params' do
it 'creates a new Map' do
expect do
2016-02-08 03:56:46 +00:00
post :create, { map: valid_attributes }
2015-12-16 14:19:58 +00:00
end.to change(Map, :count).by(1)
end
2015-12-16 14:19:58 +00:00
it 'assigns a newly created map as @map' do
2016-02-08 03:56:46 +00:00
post :create, { map: valid_attributes }
expect(assigns(:map)).to be_a(Map)
expect(assigns(:map)).to be_persisted
end
2015-12-16 14:19:58 +00:00
it 'redirects to the created map' do
2016-02-08 03:56:46 +00:00
post :create, { map: valid_attributes }
expect(response).to redirect_to(Map.last)
end
end
2015-12-16 14:19:58 +00:00
context 'with invalid params' do
it 'assigns a newly created but unsaved map as @map' do
2016-02-08 03:56:46 +00:00
post :create, { map: invalid_attributes }
expect(assigns(:map)).to be_a_new(Map)
end
end
end
2015-12-16 14:19:58 +00:00
describe 'PUT #update' do
context 'with valid params' do
let(:new_attributes) do
skip('Add a hash of attributes valid for your model')
end
2015-12-16 14:19:58 +00:00
it 'updates the requested map' do
2015-12-16 14:33:29 +00:00
put :update,
2016-02-08 03:56:46 +00:00
{ id: map.to_param, map: new_attributes }
map.reload
2015-12-16 14:19:58 +00:00
skip('Add assertions for updated state')
end
2015-12-16 14:19:58 +00:00
it 'assigns the requested map as @map' do
2015-12-16 14:33:29 +00:00
put :update,
2016-02-08 03:56:46 +00:00
{ id: map.to_param, map: valid_attributes }
expect(assigns(:map)).to eq(map)
end
2015-12-16 14:19:58 +00:00
it 'redirects to the map' do
2015-12-16 14:33:29 +00:00
put :update,
2016-02-08 03:56:46 +00:00
{ id: map.to_param, map: valid_attributes }
expect(response).to redirect_to(map)
end
end
2015-12-16 14:19:58 +00:00
context 'with invalid params' do
it 'assigns the map as @map' do
2015-12-16 14:33:29 +00:00
put :update,
2016-02-08 03:56:46 +00:00
{ id: map.to_param, map: invalid_attributes }
expect(assigns(:map)).to eq(map)
end
end
end
2015-12-16 14:19:58 +00:00
describe 'DELETE #destroy' do
it 'destroys the requested map' do
expect do
2016-02-08 03:56:46 +00:00
delete :destroy, { id: map.to_param }
2015-12-16 14:19:58 +00:00
end.to change(Map, :count).by(-1)
end
2015-12-16 14:19:58 +00:00
it 'redirects to the maps list' do
2016-02-08 03:56:46 +00:00
delete :destroy, { id: map.to_param }
expect(response).to redirect_to(maps_url)
end
end
end