Stub user creation in registrations_controller

This commit is contained in:
Raphael 2010-10-29 18:46:57 -07:00
parent bc5dc934d6
commit 49e1bde150
2 changed files with 8 additions and 2 deletions

View file

@ -19,6 +19,10 @@ describe RegistrationsController do
describe "#create" do describe "#create" do
context "with valid parameters" do context "with valid parameters" do
before do
user = Factory.build(:user)
User.stub!(:build).and_return(user)
end
it "creates a user" do it "creates a user" do
lambda { get :create, @valid_params }.should change(User, :count).by(1) lambda { get :create, @valid_params }.should change(User, :count).by(1)
end end
@ -39,6 +43,9 @@ describe RegistrationsController do
before do before do
@valid_params["user"]["password_confirmation"] = "baddword" @valid_params["user"]["password_confirmation"] = "baddword"
@invalid_params = @valid_params @invalid_params = @valid_params
user = Factory.build(:user)
user.stub!(:save){user.errors.add_to_base("hello"); false}
User.stub!(:build).and_return(user)
end end
it "does not create a user" do it "does not create a user" do
lambda { get :create, @invalid_params }.should_not change(User, :count) lambda { get :create, @invalid_params }.should_not change(User, :count)
@ -53,7 +60,7 @@ describe RegistrationsController do
end end
it "goes back to the form" do it "goes back to the form" do
get :create, @invalid_params get :create, @invalid_params
response.should be_redirect response.should redirect_to new_user_registration_path
end end
end end
end end

View file

@ -35,7 +35,6 @@ describe 'making sure the spec runner works' do
describe 'factories' do describe 'factories' do
describe 'build' do describe 'build' do
it 'does not save a built user' do it 'does not save a built user' do
pending 'Why does this happen?'
Factory.build(:user).persisted?.should be_false Factory.build(:user).persisted?.should be_false
end end
end end