filling out map controller spec
This commit is contained in:
parent
005250f330
commit
374ac701c9
1 changed files with 30 additions and 19 deletions
|
@ -9,7 +9,7 @@ RSpec.describe MapsController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'GET #index' do
|
describe 'GET #index' do
|
||||||
it 'assigns all maps as @maps' do
|
it 'viewable maps as @maps' do
|
||||||
get :index, {}
|
get :index, {}
|
||||||
expect(assigns(:maps)).to eq([map])
|
expect(assigns(:maps)).to eq([map])
|
||||||
end
|
end
|
||||||
|
@ -18,7 +18,6 @@ RSpec.describe MapsController, type: :controller do
|
||||||
describe 'GET #contains' do
|
describe 'GET #contains' do
|
||||||
it 'returns json matching schema' do
|
it 'returns json matching schema' do
|
||||||
get :contains, { id: map.to_param, format: :json }
|
get :contains, { id: map.to_param, format: :json }
|
||||||
# get "maps/#{map.id}/contains"
|
|
||||||
expect(response.body).to match_json_schema(:map_contains)
|
expect(response.body).to match_json_schema(:map_contains)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -66,43 +65,55 @@ RSpec.describe MapsController, type: :controller do
|
||||||
|
|
||||||
it 'updates the requested map' do
|
it 'updates the requested map' do
|
||||||
put :update,
|
put :update,
|
||||||
{ id: map.to_param, map: new_attributes }
|
{ id: map.to_param, map: new_attributes, format: :json }
|
||||||
map.reload
|
map.reload
|
||||||
skip('Add assertions for updated state')
|
skip('Add assertions for updated state')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'assigns the requested map as @map' do
|
it 'assigns the requested map as @map' do
|
||||||
put :update,
|
put :update,
|
||||||
{ id: map.to_param, map: valid_attributes }
|
{ id: map.to_param, map: valid_attributes, format: :json }
|
||||||
expect(assigns(:map)).to eq(map)
|
expect(assigns(:map)).to eq(map)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'redirects to the map' do
|
|
||||||
put :update,
|
|
||||||
{ id: map.to_param, map: valid_attributes }
|
|
||||||
expect(response).to redirect_to(map)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with invalid params' do
|
context 'with invalid params' do
|
||||||
it 'assigns the map as @map' do
|
it 'assigns the map as @map' do
|
||||||
put :update,
|
put :update,
|
||||||
{ id: map.to_param, map: invalid_attributes }
|
{ id: map.to_param, map: invalid_attributes, format: :json }
|
||||||
expect(assigns(:map)).to eq(map)
|
expect(assigns(:map)).to eq(map)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'DELETE #destroy' do
|
describe 'update the map screenshot' do
|
||||||
it 'destroys the requested map' do
|
it 'successfully if authorized' do
|
||||||
expect do
|
skip
|
||||||
delete :destroy, { id: map.to_param }
|
|
||||||
end.to change(Map, :count).by(-1)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'redirects to the maps list' do
|
it 'unsucessfully if not authorized' do
|
||||||
delete :destroy, { id: map.to_param }
|
skip
|
||||||
expect(response).to redirect_to(maps_url)
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'DELETE #destroy' do
|
||||||
|
let(:unowned_map) { create(:map) }
|
||||||
|
let(:owned_map) { create(:map, user: controller.current_user) }
|
||||||
|
|
||||||
|
it 'prevents deletion by non-owners' do
|
||||||
|
unowned_map.reload
|
||||||
|
expect do
|
||||||
|
delete :destroy, { id: unowned_map.to_param, format: :json }
|
||||||
|
end.to change(Map, :count).by(0)
|
||||||
|
expect(response.body).to eq("unauthorized")
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'deletes owned map' do
|
||||||
|
owned_map.reload # ensure it's in the database
|
||||||
|
expect do
|
||||||
|
delete :destroy, { id: owned_map.to_param, format: :json }
|
||||||
|
end.to change(Map, :count).by(-1)
|
||||||
|
expect(response.body).to eq("success")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue