Skip to content

Instantly share code, notes, and snippets.

@tarolandia
Created October 31, 2012 12:22
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 tarolandia/3986754 to your computer and use it in GitHub Desktop.
Save tarolandia/3986754 to your computer and use it in GitHub Desktop.
Testing create action
require 'spec_helper'
describe UsersController do
describe "User creation" do
it "should create a new user" do
@user = mock_model(User,
:email => 'test@gmail.com',
:password => 'test',
:name => 'tester',
:username => 'Tester',
:birthdate => '1/10/1986',
:sex => true
)
@user.should_receive(:email=)
@user.should_receive(:password=)
@user.should_receive(:name=)
@user.should_receive(:sex=)
@user.should_receive(:birthDate=)
@user.stub!(:save).and_return(true)
User.stub!(:new).and_return(@user)
post 'create', :email => @user.email, :password => @user.password, :name => @user.name, :birthdate => @user.birthdate, :sex => @user.sex
expect(session[:user]).to_not eq(nil)
expect(session[:user].email).to eq(@user.email)
end
end
end
@kandalf
Copy link

kandalf commented Oct 31, 2012

it "should create a new user" do
@user.stub!(:save).and_return(true)
User.stub!(:new).and_return(@user)
post 'create', :email => @user.email, :password => @user.password, :name => @user.name, :birthdate => @user.birthdate, :sex => @user.sex
expect(session[:user]).to_not eq(nil)
expect(session[:user].email).to eq(@user.email)
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment