Skip to content

Instantly share code, notes, and snippets.

@turizoft
Created May 22, 2015 23:13
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 turizoft/732a637feada18e2da07 to your computer and use it in GitHub Desktop.
Save turizoft/732a637feada18e2da07 to your computer and use it in GitHub Desktop.
Controller test
require 'test_helper'
class StudentsControllerTest < ActionController::TestCase
test "#create should create a student with complete info" do
assert_difference('Student.count') do
post :create, :student => { username: 'guillo', password: '123', password_confirmation: '123'}
end
assert_redirected_to new_confirmation_path
end
test "#create should not create a student with missing info" do
assert_no_difference('Student.count') do
post :create, student: { username: 'guillo'}
end
assert_template "new"
end
test "#update should update student info" do
student = students(:alfonso)
career = careers(:computer_sciences)
login_user(student)
patch :update, id: student.username, student: {first_name: 'Alfonso', last_name: 'Mancilla Alvis', career_id: career.id, notification_email: 'almancill@gmail.com'}
student.reload
assert_equal 'Alfonso', student.first_name
assert_equal 'Mancilla Alvis', student.last_name
assert_equal 'alfonso mancilla alvis', student.escaped_name
assert_equal true, student.account_completed
assert_equal 'Ingenieria de Sistemas', student.career.name
assert_redirected_to root_path
end
test "#update should not update student with missing info" do
student = students(:alfonso)
career = careers(:computer_sciences)
login_user(student)
patch :update, id: student.id, student: {first_name: 'alfonso', last_name: 'mancilla alvis', career_id: career.id, notification_email: ''}
student.reload
assert_equal nil, student.first_name
assert_equal nil, student.last_name
assert_equal nil, student.escaped_name
assert_equal false, student.account_completed
assert_equal nil, student.career_id
assert_template :edit
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment