metamaps--metamaps/spec/controllers/synapses_controller_spec.rb

94 lines
2.6 KiB
Ruby
Raw Normal View History

require 'rails_helper'
2015-12-16 14:19:58 +00:00
RSpec.describe SynapsesController, type: :controller do
2016-02-08 03:56:46 +00:00
let(:synapse) { create(:synapse) }
let(:valid_attributes) { synapse.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 #show' do
it 'assigns the requested synapse as @synapse' do
2016-02-08 03:56:46 +00:00
get :show, { id: synapse.to_param }
expect(assigns(:synapse)).to eq(synapse)
end
end
2015-12-16 14:19:58 +00:00
describe 'POST #create' do
context 'with valid params' do
it 'creates a new Synapse' do
expect do
2016-02-08 03:56:46 +00:00
post :create, { synapse: valid_attributes }
2015-12-16 14:19:58 +00:00
end.to change(Synapse, :count).by(1)
end
2015-12-16 14:19:58 +00:00
it 'assigns a newly created synapse as @synapse' do
2016-02-08 03:56:46 +00:00
post :create, { synapse: valid_attributes }
expect(assigns(:synapse)).to be_a(Synapse)
expect(assigns(:synapse)).to be_persisted
end
2015-12-16 14:19:58 +00:00
it 'redirects to the created synapse' do
2016-02-08 03:56:46 +00:00
post :create, { synapse: valid_attributes }
expect(response).to redirect_to(Synapse.last)
end
end
2015-12-16 14:19:58 +00:00
context 'with invalid params' do
it 'assigns a newly created but unsaved synapse as @synapse' do
2016-02-08 03:56:46 +00:00
post :create, { synapse: invalid_attributes }
expect(assigns(:synapse)).to be_a_new(Synapse)
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 synapse' do
2015-12-16 14:33:29 +00:00
put :update,
2016-02-08 03:56:46 +00:00
{ id: synapse.to_param, synapse: new_attributes }
synapse.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 synapse as @synapse' do
2015-12-16 14:33:29 +00:00
put :update,
2016-02-08 03:56:46 +00:00
{ id: synapse.to_param, synapse: valid_attributes }
expect(assigns(:synapse)).to eq(synapse)
end
2015-12-16 14:19:58 +00:00
it 'redirects to the synapse' do
2015-12-16 14:33:29 +00:00
put :update,
2016-02-08 03:56:46 +00:00
{ id: synapse.to_param, synapse: valid_attributes }
expect(response).to redirect_to(synapse)
end
end
2015-12-16 14:19:58 +00:00
context 'with invalid params' do
it 'assigns the synapse as @synapse' do
2015-12-16 14:33:29 +00:00
put :update,
2016-02-08 03:56:46 +00:00
{ id: synapse.to_param, synapse: invalid_attributes }
expect(assigns(:synapse)).to eq(synapse)
end
end
end
2015-12-16 14:19:58 +00:00
describe 'DELETE #destroy' do
it 'destroys the requested synapse' do
expect do
2016-02-08 03:56:46 +00:00
delete :destroy, { id: synapse.to_param }
2015-12-16 14:19:58 +00:00
end.to change(Synapse, :count).by(-1)
end
2015-12-16 14:19:58 +00:00
it 'redirects to the synapses list' do
2016-02-08 03:56:46 +00:00
delete :destroy, { id: synapse.to_param }
expect(response).to redirect_to(synapses_url)
end
end
end