-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
59 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,14 @@ | ||
class UsersController < ApplicationController | ||
def create | ||
@user = User.new(params[:user]) | ||
@user.password = params[:password] | ||
@user.password_confirmation = params[:password_confirmation] | ||
|
||
@user.save! | ||
session[:user_id] = @user.id | ||
|
||
redirect_to root_path | ||
rescue ActiveRecord::RecordInvalid | ||
render 'authentication/sign_up' | ||
end | ||
end |
This file contains 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
This file contains 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
25 changes: 25 additions & 0 deletions
25
examples/auction/spec/controllers/users_controller_spec.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,30 @@ | ||
require 'spec_helper' | ||
|
||
describe UsersController do | ||
describe 'POST create' do | ||
subject { post :create, params } | ||
|
||
context 'when valid params' do | ||
let(:password) { Forgery(:basic).password } | ||
let(:params) do | ||
{ | ||
user: { | ||
name: Forgery(:name).full_name, | ||
email: Forgery(:internet).email_address | ||
}, | ||
password: password, | ||
password_confirmation: password | ||
} | ||
end | ||
|
||
it { should redirect_to(root_path) } | ||
it { expect { subject }.to change { User.count }.from(0).to(1) } | ||
end | ||
|
||
context 'when invalid params' do | ||
let(:params) { {} } | ||
|
||
it { should render_template('authentication/sign_up') } | ||
end | ||
end | ||
end |
This file contains 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