start fixing other controller specs

This commit is contained in:
Devin Howard 2016-02-08 11:56:46 +08:00
parent 80a6bcbca2
commit 17ee69b147
4 changed files with 80 additions and 229 deletions

View file

@ -1,60 +1,30 @@
require 'rails_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
RSpec.describe MapsController, type: :controller do
# This should return the minimal set of attributes required to create a valid
# Map. As you add validations to Map, be sure to
# adjust the attributes here as well.
let(:valid_attributes) do
skip('Add a hash of attributes valid for your model')
let(:map) { create(:map) }
let(:valid_attributes) { map.attributes.except(:id) }
let(:invalid_attributes) { { permission: :commons } }
before :each do
sign_in
end
let(:invalid_attributes) do
skip('Add a hash of attributes invalid for your model')
end
# This should return the minimal set of values that should be in the session
# in order to pass any filters (e.g. authentication) defined in
# MapsController. Be sure to keep this updated too.
let(:valid_session) { {} }
describe 'GET #index' do
it 'assigns all maps as @maps' do
map = Map.create! valid_attributes
get :index, {}, valid_session
get :index, {}
expect(assigns(:maps)).to eq([map])
end
end
describe 'GET #show' do
it 'assigns the requested map as @map' do
map = Map.create! valid_attributes
get :show, { id: map.to_param }, valid_session
get :show, { id: map.to_param }
expect(assigns(:map)).to eq(map)
end
end
describe 'GET #edit' do
it 'assigns the requested map as @map' do
map = Map.create! valid_attributes
get :edit, { id: map.to_param }, valid_session
get :edit, { id: map.to_param }
expect(assigns(:map)).to eq(map)
end
end
@ -63,30 +33,30 @@ RSpec.describe MapsController, type: :controller do
context 'with valid params' do
it 'creates a new Map' do
expect do
post :create, { map: valid_attributes }, valid_session
post :create, { map: valid_attributes }
end.to change(Map, :count).by(1)
end
it 'assigns a newly created map as @map' do
post :create, { map: valid_attributes }, valid_session
post :create, { map: valid_attributes }
expect(assigns(:map)).to be_a(Map)
expect(assigns(:map)).to be_persisted
end
it 'redirects to the created map' do
post :create, { map: valid_attributes }, valid_session
post :create, { map: valid_attributes }
expect(response).to redirect_to(Map.last)
end
end
context 'with invalid params' do
it 'assigns a newly created but unsaved map as @map' do
post :create, { map: invalid_attributes }, valid_session
post :create, { map: invalid_attributes }
expect(assigns(:map)).to be_a_new(Map)
end
it "re-renders the 'new' template" do
post :create, { map: invalid_attributes }, valid_session
post :create, { map: invalid_attributes }
expect(response).to render_template('new')
end
end
@ -99,45 +69,35 @@ RSpec.describe MapsController, type: :controller do
end
it 'updates the requested map' do
map = Map.create! valid_attributes
put :update,
{ id: map.to_param, map: new_attributes },
valid_session
{ id: map.to_param, map: new_attributes }
map.reload
skip('Add assertions for updated state')
end
it 'assigns the requested map as @map' do
map = Map.create! valid_attributes
put :update,
{ id: map.to_param, map: valid_attributes },
valid_session
{ id: map.to_param, map: valid_attributes }
expect(assigns(:map)).to eq(map)
end
it 'redirects to the map' do
map = Map.create! valid_attributes
put :update,
{ id: map.to_param, map: valid_attributes },
valid_session
{ id: map.to_param, map: valid_attributes }
expect(response).to redirect_to(map)
end
end
context 'with invalid params' do
it 'assigns the map as @map' do
map = Map.create! valid_attributes
put :update,
{ id: map.to_param, map: invalid_attributes },
valid_session
{ id: map.to_param, map: invalid_attributes }
expect(assigns(:map)).to eq(map)
end
it "re-renders the 'edit' template" do
map = Map.create! valid_attributes
put :update,
{ id: map.to_param, map: invalid_attributes },
valid_session
{ id: map.to_param, map: invalid_attributes }
expect(response).to render_template('edit')
end
end
@ -145,15 +105,13 @@ RSpec.describe MapsController, type: :controller do
describe 'DELETE #destroy' do
it 'destroys the requested map' do
map = Map.create! valid_attributes
expect do
delete :destroy, { id: map.to_param }, valid_session
delete :destroy, { id: map.to_param }
end.to change(Map, :count).by(-1)
end
it 'redirects to the maps list' do
map = Map.create! valid_attributes
delete :destroy, { id: map.to_param }, valid_session
delete :destroy, { id: map.to_param }
expect(response).to redirect_to(maps_url)
end
end

View file

@ -1,72 +1,37 @@
require 'rails_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
RSpec.describe MetacodesController, type: :controller do
let(:metacode) { create(:metacode) }
let(:valid_attributes) { metacode.attributes.except(:id) }
let(:invalid_attributes) { { permission: :commons } }
before :each do
@user = create(:user, admin: true)
sign_in @user
sign_in
end
# This should return the minimal set of attributes required to create a valid
# Metacode. As you add validations to Metacode, be sure to
# adjust the attributes here as well.
let(:valid_attributes) do
skip('Add a hash of attributes valid for your model')
end
let(:invalid_attributes) do
skip('Add a hash of attributes invalid for your model')
end
# This should return the minimal set of values that should be in the session
# in order to pass any filters (e.g. authentication) defined in
# MetacodesController. Be sure to keep this updated too.
let(:valid_session) { {} }
describe 'GET #index' do
it 'assigns all metacodes as @metacodes' do
metacode = Metacode.create! valid_attributes
get :index, {}, valid_session
get :index, {}
expect(assigns(:metacodes)).to eq([metacode])
end
end
describe 'GET #show' do
it 'assigns the requested metacode as @metacode' do
metacode = Metacode.create! valid_attributes
get :show, { id: metacode.to_param }, valid_session
get :show, { id: metacode.to_param }
expect(assigns(:metacode)).to eq(metacode)
end
end
describe 'GET #new' do
it 'assigns a new metacode as @metacode' do
get :new, {}, valid_session
get :new, {}
expect(assigns(:metacode)).to be_a_new(Metacode)
end
end
describe 'GET #edit' do
it 'assigns the requested metacode as @metacode' do
metacode = Metacode.create! valid_attributes
get :edit, { id: metacode.to_param }, valid_session
get :edit, { id: metacode.to_param }
expect(assigns(:metacode)).to eq(metacode)
end
end
@ -75,30 +40,30 @@ RSpec.describe MetacodesController, type: :controller do
context 'with valid params' do
it 'creates a new Metacode' do
expect do
post :create, { metacode: valid_attributes }, valid_session
post :create, { metacode: valid_attributes }
end.to change(Metacode, :count).by(1)
end
it 'assigns a newly created metacode as @metacode' do
post :create, { metacode: valid_attributes }, valid_session
post :create, { metacode: valid_attributes }
expect(assigns(:metacode)).to be_a(Metacode)
expect(assigns(:metacode)).to be_persisted
end
it 'redirects to the created metacode' do
post :create, { metacode: valid_attributes }, valid_session
post :create, { metacode: valid_attributes }
expect(response).to redirect_to(Metacode.last)
end
end
context 'with invalid params' do
it 'assigns a newly created but unsaved metacode as @metacode' do
post :create, { metacode: invalid_attributes }, valid_session
post :create, { metacode: invalid_attributes }
expect(assigns(:metacode)).to be_a_new(Metacode)
end
it "re-renders the 'new' template" do
post :create, { metacode: invalid_attributes }, valid_session
post :create, { metacode: invalid_attributes }
expect(response).to render_template('new')
end
end
@ -111,45 +76,35 @@ RSpec.describe MetacodesController, type: :controller do
end
it 'updates the requested metacode' do
metacode = Metacode.create! valid_attributes
put :update,
{ id: metacode.to_param, metacode: new_attributes },
valid_session
{ id: metacode.to_param, metacode: new_attributes }
metacode.reload
skip('Add assertions for updated state')
end
it 'assigns the requested metacode as @metacode' do
metacode = Metacode.create! valid_attributes
put :update,
{ id: metacode.to_param, metacode: valid_attributes },
valid_session
{ id: metacode.to_param, metacode: valid_attributes }
expect(assigns(:metacode)).to eq(metacode)
end
it 'redirects to the metacode' do
metacode = Metacode.create! valid_attributes
put :update,
{ id: metacode.to_param, metacode: valid_attributes },
valid_session
{ id: metacode.to_param, metacode: valid_attributes }
expect(response).to redirect_to(metacode)
end
end
context 'with invalid params' do
it 'assigns the metacode as @metacode' do
metacode = Metacode.create! valid_attributes
put :update,
{ id: metacode.to_param, metacode: invalid_attributes },
valid_session
{ id: metacode.to_param, metacode: invalid_attributes }
expect(assigns(:metacode)).to eq(metacode)
end
it "re-renders the 'edit' template" do
metacode = Metacode.create! valid_attributes
put :update,
{ id: metacode.to_param, metacode: invalid_attributes },
valid_session
{ id: metacode.to_param, metacode: invalid_attributes }
expect(response).to render_template('edit')
end
end
@ -157,15 +112,13 @@ RSpec.describe MetacodesController, type: :controller do
describe 'DELETE #destroy' do
it 'destroys the requested metacode' do
metacode = Metacode.create! valid_attributes
expect do
delete :destroy, { id: metacode.to_param }, valid_session
delete :destroy, { id: metacode.to_param }
end.to change(Metacode, :count).by(-1)
end
it 'redirects to the metacodes list' do
metacode = Metacode.create! valid_attributes
delete :destroy, { id: metacode.to_param }, valid_session
delete :destroy, { id: metacode.to_param }
expect(response).to redirect_to(metacodes_url)
end
end

View file

@ -1,60 +1,30 @@
require 'rails_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.
RSpec.describe SynapsesController, type: :controller do
# This should return the minimal set of attributes required to create a valid
# Synapse. As you add validations to Synapse, be sure to
# adjust the attributes here as well.
let(:valid_attributes) do
skip('Add a hash of attributes valid for your model')
let(:synapse) { create(:synapse) }
let(:valid_attributes) { synapse.attributes.except(:id) }
let(:invalid_attributes) { { permission: :commons } }
before :each do
sign_in
end
let(:invalid_attributes) do
skip('Add a hash of attributes invalid for your model')
end
# This should return the minimal set of values that should be in the session
# in order to pass any filters (e.g. authentication) defined in
# SynapsesController. Be sure to keep this updated too.
let(:valid_session) { {} }
describe 'GET #index' do
it 'assigns all synapses as @synapses' do
synapse = Synapse.create! valid_attributes
get :index, {}, valid_session
get :index, {}
expect(assigns(:synapses)).to eq([synapse])
end
end
describe 'GET #show' do
it 'assigns the requested synapse as @synapse' do
synapse = Synapse.create! valid_attributes
get :show, { id: synapse.to_param }, valid_session
get :show, { id: synapse.to_param }
expect(assigns(:synapse)).to eq(synapse)
end
end
describe 'GET #edit' do
it 'assigns the requested synapse as @synapse' do
synapse = Synapse.create! valid_attributes
get :edit, { id: synapse.to_param }, valid_session
get :edit, { id: synapse.to_param }
expect(assigns(:synapse)).to eq(synapse)
end
end
@ -63,30 +33,30 @@ RSpec.describe SynapsesController, type: :controller do
context 'with valid params' do
it 'creates a new Synapse' do
expect do
post :create, { synapse: valid_attributes }, valid_session
post :create, { synapse: valid_attributes }
end.to change(Synapse, :count).by(1)
end
it 'assigns a newly created synapse as @synapse' do
post :create, { synapse: valid_attributes }, valid_session
post :create, { synapse: valid_attributes }
expect(assigns(:synapse)).to be_a(Synapse)
expect(assigns(:synapse)).to be_persisted
end
it 'redirects to the created synapse' do
post :create, { synapse: valid_attributes }, valid_session
post :create, { synapse: valid_attributes }
expect(response).to redirect_to(Synapse.last)
end
end
context 'with invalid params' do
it 'assigns a newly created but unsaved synapse as @synapse' do
post :create, { synapse: invalid_attributes }, valid_session
post :create, { synapse: invalid_attributes }
expect(assigns(:synapse)).to be_a_new(Synapse)
end
it "re-renders the 'new' template" do
post :create, { synapse: invalid_attributes }, valid_session
post :create, { synapse: invalid_attributes }
expect(response).to render_template('new')
end
end
@ -99,45 +69,35 @@ RSpec.describe SynapsesController, type: :controller do
end
it 'updates the requested synapse' do
synapse = Synapse.create! valid_attributes
put :update,
{ id: synapse.to_param, synapse: new_attributes },
valid_session
{ id: synapse.to_param, synapse: new_attributes }
synapse.reload
skip('Add assertions for updated state')
end
it 'assigns the requested synapse as @synapse' do
synapse = Synapse.create! valid_attributes
put :update,
{ id: synapse.to_param, synapse: valid_attributes },
valid_session
{ id: synapse.to_param, synapse: valid_attributes }
expect(assigns(:synapse)).to eq(synapse)
end
it 'redirects to the synapse' do
synapse = Synapse.create! valid_attributes
put :update,
{ id: synapse.to_param, synapse: valid_attributes },
valid_session
{ id: synapse.to_param, synapse: valid_attributes }
expect(response).to redirect_to(synapse)
end
end
context 'with invalid params' do
it 'assigns the synapse as @synapse' do
synapse = Synapse.create! valid_attributes
put :update,
{ id: synapse.to_param, synapse: invalid_attributes },
valid_session
{ id: synapse.to_param, synapse: invalid_attributes }
expect(assigns(:synapse)).to eq(synapse)
end
it "re-renders the 'edit' template" do
synapse = Synapse.create! valid_attributes
put :update,
{ id: synapse.to_param, synapse: invalid_attributes },
valid_session
{ id: synapse.to_param, synapse: invalid_attributes }
expect(response).to render_template('edit')
end
end
@ -145,15 +105,13 @@ RSpec.describe SynapsesController, type: :controller do
describe 'DELETE #destroy' do
it 'destroys the requested synapse' do
synapse = Synapse.create! valid_attributes
expect do
delete :destroy, { id: synapse.to_param }, valid_session
delete :destroy, { id: synapse.to_param }
end.to change(Synapse, :count).by(-1)
end
it 'redirects to the synapses list' do
synapse = Synapse.create! valid_attributes
delete :destroy, { id: synapse.to_param }, valid_session
delete :destroy, { id: synapse.to_param }
expect(response).to redirect_to(synapses_url)
end
end

View file

@ -1,36 +1,30 @@
require 'rails_helper'
RSpec.describe TopicsController, type: :controller do
let(:valid_attributes) do
skip('Add a hash of attributes valid for your model')
let(:topic) { create(:topic) }
let(:valid_attributes) { topic.attributes.except(:id) }
let(:invalid_attributes) { { permission: :commons } }
before :each do
sign_in
end
let(:invalid_attributes) do
skip('Add a hash of attributes invalid for your model')
end
let(:valid_session) { {} }
describe 'GET #index' do
it 'assigns all topics as @topics' do
topic = Topic.create! valid_attributes
get :index, {}, valid_session
get :index, {}
expect(assigns(:topics)).to eq([topic])
end
end
describe 'GET #show' do
it 'assigns the requested topic as @topic' do
topic = Topic.create! valid_attributes
get :show, { id: topic.to_param }, valid_session
get :show, { id: topic.to_param }
expect(assigns(:topic)).to eq(topic)
end
end
describe 'GET #edit' do
it 'assigns the requested topic as @topic' do
topic = Topic.create! valid_attributes
get :edit, { id: topic.to_param }, valid_session
get :edit, { id: topic.to_param }
expect(assigns(:topic)).to eq(topic)
end
end
@ -39,30 +33,30 @@ RSpec.describe TopicsController, type: :controller do
context 'with valid params' do
it 'creates a new Topic' do
expect do
post :create, { topic: valid_attributes }, valid_session
post :create, { topic: valid_attributes }
end.to change(Topic, :count).by(1)
end
it 'assigns a newly created topic as @topic' do
post :create, { topic: valid_attributes }, valid_session
post :create, { topic: valid_attributes }
expect(assigns(:topic)).to be_a(Topic)
expect(assigns(:topic)).to be_persisted
end
it 'redirects to the created topic' do
post :create, { topic: valid_attributes }, valid_session
post :create, { topic: valid_attributes }
expect(response).to redirect_to(Topic.last)
end
end
context 'with invalid params' do
it 'assigns a newly created but unsaved topic as @topic' do
post :create, { topic: invalid_attributes }, valid_session
post :create, { topic: invalid_attributes }
expect(assigns(:topic)).to be_a_new(Topic)
end
it "re-renders the 'new' template" do
post :create, { topic: invalid_attributes }, valid_session
post :create, { topic: invalid_attributes }
expect(response).to render_template('new')
end
end
@ -75,45 +69,35 @@ RSpec.describe TopicsController, type: :controller do
end
it 'updates the requested topic' do
topic = Topic.create! valid_attributes
put :update,
{ id: topic.to_param, topic: new_attributes },
valid_session
{ id: topic.to_param, topic: new_attributes }
topic.reload
skip('Add assertions for updated state')
end
it 'assigns the requested topic as @topic' do
topic = Topic.create! valid_attributes
put :update,
{ id: topic.to_param, topic: valid_attributes },
valid_session
{ id: topic.to_param, topic: valid_attributes }
expect(assigns(:topic)).to eq(topic)
end
it 'redirects to the topic' do
topic = Topic.create! valid_attributes
put :update,
{ id: topic.to_param, topic: valid_attributes },
valid_session
{ id: topic.to_param, topic: valid_attributes }
expect(response).to redirect_to(topic)
end
end
context 'with invalid params' do
it 'assigns the topic as @topic' do
topic = Topic.create! valid_attributes
put :update,
{ id: topic.to_param, topic: invalid_attributes },
valid_session
{ id: topic.to_param, topic: invalid_attributes }
expect(assigns(:topic)).to eq(topic)
end
it "re-renders the 'edit' template" do
topic = Topic.create! valid_attributes
put :update,
{ id: topic.to_param, topic: invalid_attributes },
valid_session
{ id: topic.to_param, topic: invalid_attributes }
expect(response).to render_template('edit')
end
end
@ -121,15 +105,13 @@ RSpec.describe TopicsController, type: :controller do
describe 'DELETE #destroy' do
it 'destroys the requested topic' do
topic = Topic.create! valid_attributes
expect do
delete :destroy, { id: topic.to_param }, valid_session
delete :destroy, { id: topic.to_param }
end.to change(Topic, :count).by(-1)
end
it 'redirects to the topics list' do
topic = Topic.create! valid_attributes
delete :destroy, { id: topic.to_param }, valid_session
delete :destroy, { id: topic.to_param }
expect(response).to redirect_to(topics_url)
end
end