Permalink
Browse files

The User Create and Update Integration Tests, Users Controller and ne…

…w Edit View Template
  • Loading branch information...
xajler committed Nov 7, 2012
1 parent b62efc2 commit ebbd2b0e48b3b6d94571f8d593d8d194bd6aec46
@@ -2,4 +2,32 @@ class UsersController < ApplicationController
def new
@user = User.new
end
def create
@user = User.new params[:user]
if @user.save
flash[:notice] = 'The User is successfully saved!'
redirect_to signup_path
else
flash[:error] = @user.errors.full_messages[0]
redirect_to signup_path
end
end
def edit
@user = User.find params[:id]
end
def update
@user = User.find params[:id]
if @user.update_attributes params[:user]
flash[:notice] = 'The User is successfully updated!'
redirect_to edit_user_path
else
flash[:error] = @user.errors.full_messages[0]
redirect_to edit_user_path
end
end
end
@@ -1,14 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>JustToDoIt</title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
@@ -7,4 +7,7 @@
= csrf_meta_tags
%body
- flash.each do |name, message|
= content_tag :div, message, id: "flash_#{name}"
= yield
@@ -11,15 +11,15 @@
%br
= f.label :password, 'Password:'
= f.text_field :password
= f.password_field :password
%br
= f.label :password_confirmation, 'Confirm Password:'
= f.text_field :password_confirmation
= f.password_field :password_confirmation
%br
= f.label :full_name, 'Full Name:'
= f.text_field :full_name
%br
= f.submit 'Sign Up'
= f.submit @user.id ? 'Update User' : 'Sign Up'
@@ -0,0 +1,3 @@
%h1 Update User
= render partial: 'form', locals: { user: @user }
View
@@ -32,4 +32,151 @@
page.has_button? 'Sign Up'
end
end
context 'POST /users' do
it 'creates and saves the valid user' do
visit new_user_path
fill_in 'Email', with: 'xajler@gmail.com'
fill_in 'Password', with: 'x1234567'
fill_in 'Confirm Password', with: 'x1234567'
fill_in 'Full Name', with: 'Kornelije Sajler'
click_button 'Sign Up'
current_path.should == signup_path
page.should have_content 'The User is successfully saved!'
end
context 'not saving invalid user' do
it 'when passwords mismatch' do
visit new_user_path
fill_in 'Email', with: 'xajler@gmail.com'
fill_in 'Password', with: 'x1234567'
fill_in 'Confirm Password', with: 'x123'
fill_in 'Full Name', with: 'Kornelije Sajler'
click_button 'Sign Up'
current_path.should == signup_path
page.should have_content "Password doesn't match confirmation"
end
it 'when email is blank' do
visit new_user_path
fill_in 'Email', with: ''
fill_in 'Password', with: 'x1234567'
fill_in 'Confirm Password', with: 'x1234567'
fill_in 'Full Name', with: 'Kornelije Sajler'
click_button 'Sign Up'
current_path.should == signup_path
page.should have_content "Email can't be blank"
end
it 'when password is blank' do
visit new_user_path
fill_in 'Email', with: 'xajler@gmail.com'
fill_in 'Password', with: ''
fill_in 'Confirm Password', with: ''
fill_in 'Full Name', with: 'Kornelije Sajler'
click_button 'Sign Up'
current_path.should == signup_path
page.should have_content "Password digest can't be blank"
end
it 'when full name is blank' do
visit new_user_path
fill_in 'Email', with: 'xajler@gmail.com'
fill_in 'Password', with: 'x1234567'
fill_in 'Confirm Password', with: 'x1234567'
fill_in 'Full Name', with: ''
click_button 'Sign Up'
current_path.should == signup_path
page.should have_content "Full name can't be blank"
end
it 'when email is not unique' do
create :user
visit new_user_path
fill_in 'Email', with: 'xajler@gmail.com'
fill_in 'Password', with: 'x1234567'
fill_in 'Confirm Password', with: 'x1234567'
fill_in 'Full Name', with: 'Kornelije Sajler'
click_button 'Sign Up'
current_path.should == signup_path
page.should have_content 'Email has already been taken'
end
it 'when password is less than 8 characters' do
visit new_user_path
fill_in 'Email', with: 'xajler@gmail.com'
fill_in 'Password', with: '123'
fill_in 'Confirm Password', with: '123'
fill_in 'Full Name', with: 'Kornelije Sajler'
click_button 'Sign Up'
current_path.should == signup_path
page.should have_content "Password is too short (minimum is 8 characters)"
end
end
context '_PUT users/:id_' do
it 'valid user update' do
user = create :user
visit edit_user_path user
find_field('Email').value.should == 'xajler@gmail.com'
find_field('Full Name').value.should == 'Kornelije Sajler'
fill_in 'Email', with: 'xajler@gmail.com'
fill_in 'Password', with: 'aoeuidht'
fill_in 'Confirm Password', with: 'aoeuidht'
fill_in 'Full Name', with: 'Kornelije Sajler - xajler'
click_button 'Update User'
current_path.should == edit_user_path(user)
page.should have_content 'The User is successfully updated!'
end
it 'invalid when passwords mismatch' do
user = create :user
visit edit_user_path user
fill_in 'Email', with: 'xajler@gmail.com'
fill_in 'Password', with: 'aoeuidht'
fill_in 'Confirm Password', with: 'aoeu'
fill_in 'Full Name', with: 'Kornelije Sajler'
click_button 'Update User'
current_path.should == edit_user_path(user)
page.should have_content "Password doesn't match confirmation"
end
it 'keeps the User Email intact while other fields do change' do
user = create :user
visit edit_user_path user
find_field('Email').value.should == 'xajler@gmail.com'
find_field('Full Name').value.should == 'Kornelije Sajler'
fill_in 'Email', with: 'xxx@example.com'
fill_in 'Password', with: 'aoeuidht'
fill_in 'Confirm Password', with: 'aoeuidht'
fill_in 'Full Name', with: 'Kornelije Sajler - xajler'
click_button 'Update User'
current_path.should == edit_user_path(user)
find_field('Email').value.should == 'xajler@gmail.com'
find_field('Full Name').value.should == 'Kornelije Sajler - xajler'
end
end
end
end

0 comments on commit ebbd2b0

Please sign in to comment.