Skip to content

Instantly share code, notes, and snippets.

@JunichiIto
Forked from naichilab/controller_spec.rb
Last active January 19, 2016 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JunichiIto/c8fce01b840a228c9637 to your computer and use it in GitHub Desktop.
Save JunichiIto/c8fce01b840a228c9637 to your computer and use it in GitHub Desktop.
describe 'Post #create' do
context '有効なパラメータの場合' do
let(:create_user) { -> { post :create, user: attributes_for(:user) } }
it 'リクエストは302 リダイレクトとなること' do
create_user.call
expect(response.status).to eq 302
end
it 'データベースに新しいユーザーが登録されること' do
expect{
create_user.call
}.to change(User, :count).by(1)
end
it 'rootにリダイレクトすること' do
create_user.call
expect(response).to redirect_to root_path
end
end
end
describe 'Post #create' do
context '有効なパラメータの場合' do
def create_user
post :create, user: attributes_for(:user)
end
it 'リクエストは302 リダイレクトとなること' do
create_user
expect(response.status).to eq 302
end
it 'データベースに新しいユーザーが登録されること' do
expect{
create_user
}.to change(User, :count).by(1)
end
it 'rootにリダイレクトすること' do
create_user
expect(response).to redirect_to root_path
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment