Don't do expensive things on invalid users

This commit is contained in:
Michael Sofaer and Raphael Sofaer 2010-11-26 11:55:45 -05:00
parent a4f1614fb2
commit b54164cef8
2 changed files with 4 additions and 1 deletions

View file

@ -372,6 +372,10 @@ class User
def setup(opts) def setup(opts)
self.username = opts[:username] self.username = opts[:username]
self.valid?
errors = self.errors
errors.delete :person
return if errors.size > 0
opts[:person] ||= {} opts[:person] ||= {}
opts[:person][:profile] ||= Profile.new opts[:person][:profile] ||= Profile.new

View file

@ -216,7 +216,6 @@ describe User do
lambda { User.build(@invalid_params) }.should_not change(Person, :count) lambda { User.build(@invalid_params) }.should_not change(Person, :count)
end end
it 'does not generate a key' do it 'does not generate a key' do
pending 'Validate users before generating keys'
User.should_receive(:generate_key).exactly(0).times User.should_receive(:generate_key).exactly(0).times
User.build(@invalid_params) User.build(@invalid_params)
end end