I'm working through a book on Sinatra/padrino and they're walking through
user registration confirmation with confirmation codes.
The tutorial uses active_record, but I'm using the sequel orm so I need to
adapt the snippet to sequel syntax to work. I'm pretty comfortable with the
syntax, so that's not the problem. I just can't figure out how the
authenticate method works.
So the Model Code is
class User < ActiveRecord::Base
...
def authenticate(confirmation_code)
return false unless @user = User.find_by_id(self.id)
if @user.confirmation_code == self.confirmation_code
self.confirmation = true
self.save
true
else
false
end
end
...
end
And this is how they call it in the rspec test
it 'confirmation should be set true after a user is authenticated' do
user_confirmation.save
confirmation_of_saved_user = User.find_by_id(user_confirmation.id)
user_confirmation.confirmation_code =
confirmation_of_saved_user.confirmation_code
user_confirmation.authenticate(user_confirmation.confirmation_code).should
be_true
user_confirmation.confirmation.should be_true
end
What's really confusing me is this line:
return false unless @user = User.find_by_id(self.id)
How does the model/method know "self.id" since it's not being passed in?
Thanks.
--
--
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
---
You received this message because you are subscribed to the Google Groups "SD
Ruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.