2015-10-12 03:37:44 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2015-12-16 14:19:58 +00:00
|
|
|
RSpec.describe MetacodesController, type: :controller do
|
2016-02-08 03:56:46 +00:00
|
|
|
let(:metacode) { create(:metacode) }
|
|
|
|
let(:valid_attributes) { metacode.attributes.except(:id) }
|
|
|
|
let(:invalid_attributes) { { permission: :commons } }
|
2015-12-16 13:32:50 +00:00
|
|
|
before :each do
|
2016-02-08 03:56:46 +00:00
|
|
|
sign_in
|
2015-12-16 14:19:58 +00:00
|
|
|
end
|
2015-10-12 03:37:44 +00:00
|
|
|
|
2015-12-16 14:19:58 +00:00
|
|
|
describe 'GET #index' do
|
|
|
|
it 'assigns all metacodes as @metacodes' do
|
2016-02-08 03:56:46 +00:00
|
|
|
get :index, {}
|
2016-02-09 04:43:34 +00:00
|
|
|
expect(assigns(:metacodes).to_a).to eq([metacode])
|
2015-10-12 03:37:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-16 14:19:58 +00:00
|
|
|
describe 'GET #new' do
|
|
|
|
it 'assigns a new metacode as @metacode' do
|
2016-02-08 03:56:46 +00:00
|
|
|
get :new, {}
|
2015-10-12 03:37:44 +00:00
|
|
|
expect(assigns(:metacode)).to be_a_new(Metacode)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-16 14:19:58 +00:00
|
|
|
describe 'GET #edit' do
|
|
|
|
it 'assigns the requested metacode as @metacode' do
|
2016-02-08 03:56:46 +00:00
|
|
|
get :edit, { id: metacode.to_param }
|
2015-10-12 03:37:44 +00:00
|
|
|
expect(assigns(:metacode)).to eq(metacode)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-16 14:19:58 +00:00
|
|
|
describe 'POST #create' do
|
|
|
|
context 'with valid params' do
|
|
|
|
it 'creates a new Metacode' do
|
|
|
|
expect do
|
2016-02-08 03:56:46 +00:00
|
|
|
post :create, { metacode: valid_attributes }
|
2015-12-16 14:19:58 +00:00
|
|
|
end.to change(Metacode, :count).by(1)
|
2015-10-12 03:37:44 +00:00
|
|
|
end
|
|
|
|
|
2015-12-16 14:19:58 +00:00
|
|
|
it 'assigns a newly created metacode as @metacode' do
|
2016-02-08 03:56:46 +00:00
|
|
|
post :create, { metacode: valid_attributes }
|
2015-10-12 03:37:44 +00:00
|
|
|
expect(assigns(:metacode)).to be_a(Metacode)
|
|
|
|
expect(assigns(:metacode)).to be_persisted
|
|
|
|
end
|
|
|
|
|
2015-12-16 14:19:58 +00:00
|
|
|
it 'redirects to the created metacode' do
|
2016-02-08 03:56:46 +00:00
|
|
|
post :create, { metacode: valid_attributes }
|
2015-10-12 03:37:44 +00:00
|
|
|
expect(response).to redirect_to(Metacode.last)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-16 14:19:58 +00:00
|
|
|
context 'with invalid params' do
|
|
|
|
it 'assigns a newly created but unsaved metacode as @metacode' do
|
2016-02-08 03:56:46 +00:00
|
|
|
post :create, { metacode: invalid_attributes }
|
2015-10-12 03:37:44 +00:00
|
|
|
expect(assigns(:metacode)).to be_a_new(Metacode)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "re-renders the 'new' template" do
|
2016-02-08 03:56:46 +00:00
|
|
|
post :create, { metacode: invalid_attributes }
|
2015-12-16 14:19:58 +00:00
|
|
|
expect(response).to render_template('new')
|
2015-10-12 03:37:44 +00:00
|
|
|
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-10-12 03:37:44 +00:00
|
|
|
|
2015-12-16 14:19:58 +00:00
|
|
|
it 'updates the requested metacode' do
|
2015-12-16 14:33:29 +00:00
|
|
|
put :update,
|
2016-02-08 03:56:46 +00:00
|
|
|
{ id: metacode.to_param, metacode: new_attributes }
|
2015-10-12 03:37:44 +00:00
|
|
|
metacode.reload
|
2015-12-16 14:19:58 +00:00
|
|
|
skip('Add assertions for updated state')
|
2015-10-12 03:37:44 +00:00
|
|
|
end
|
|
|
|
|
2015-12-16 14:19:58 +00:00
|
|
|
it 'assigns the requested metacode as @metacode' do
|
2015-12-16 14:33:29 +00:00
|
|
|
put :update,
|
2016-02-08 03:56:46 +00:00
|
|
|
{ id: metacode.to_param, metacode: valid_attributes }
|
2015-10-12 03:37:44 +00:00
|
|
|
expect(assigns(:metacode)).to eq(metacode)
|
|
|
|
end
|
|
|
|
|
2015-12-16 14:19:58 +00:00
|
|
|
it 'redirects to the metacode' do
|
2015-12-16 14:33:29 +00:00
|
|
|
put :update,
|
2016-02-08 03:56:46 +00:00
|
|
|
{ id: metacode.to_param, metacode: valid_attributes }
|
2015-10-12 03:37:44 +00:00
|
|
|
expect(response).to redirect_to(metacode)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-16 14:19:58 +00:00
|
|
|
context 'with invalid params' do
|
2016-02-09 04:43:34 +00:00
|
|
|
it 'redirects to edit template' do
|
2015-12-16 14:33:29 +00:00
|
|
|
put :update,
|
2016-02-08 03:56:46 +00:00
|
|
|
{ id: metacode.to_param, metacode: invalid_attributes }
|
2016-02-09 04:43:34 +00:00
|
|
|
expect(response.status).to eq 302
|
2015-10-12 03:37:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|