Created
September 11, 2016 00:27
-
-
Save AleksandrKudashkin/3bcfa5e40c990d0af7dcced2aa7d472a to your computer and use it in GitHub Desktop.
Proc refactoring for controller test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe 'POST #create' do | |
let(:create_request) { Proc.new { |q| post :create, question: attributes_for(q) } } | |
context 'with valid object' do | |
it 'saves the new question in the database' do | |
expect { create_request.call(:question) }.to change(Question, :count).by(1) | |
end | |
it 'redirects to show this question view' do | |
create_request.call(:question) | |
expect(response).to redirect_to question_path(assigns(:question)) | |
end | |
end | |
context 'with invalid object' do | |
it 'does not save the question' do | |
expect { create_request.call(:invalid_question) }.to_not change(Question, :count) | |
end | |
it 're-renders template with form for new question' do | |
create_request.call(:invalid_question) | |
expect(response).to render_template :new | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment