Skip to content

Instantly share code, notes, and snippets.

@floehopper
Created February 3, 2010 15: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 floehopper/293677 to your computer and use it in GitHub Desktop.
Save floehopper/293677 to your computer and use it in GitHub Desktop.
def create
@user = User.new(params[:user])
if @user.save_without_session_maintenance
@user.company.update_attributes(:owner_user_id => @user.id)
flash[:notice] = "Company registered!"
redirect_to login_url
else
render :action => :new
end
end
# attempt by Tom
User.any_instance.stubs(:save_without_session_maintenance).returns(true) #This is correct
company = mock('company')
user = mock('user')
User.any_instance.expects(:company).once.returns(company).expects(:update_attributes).with(:owner_user_id).returns(true)
post :create
# attempt by James
User.any_instance.stubs(:save_without_session_maintenance).returns(true)
company = mock('company')
user = mock('user', :id => 1)
User.any_instance.expects(:company).once.returns(company)
company.expects(:update_attributes).with(:owner_user_id => user.id).returns(true)
post :create
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment