Hello Folks,
This gist http://gist.github.com/261791 has an example user.rb, user_spec.rb
At runtime, this snippet fails
u = User.find(123)
u.update_with_profile({...})
The error occurred while evaluating nil.select):
app/models/user.rb:6:in `moderator_fields'
app/models/user.rb:118:in `update_with_profile'
The spec passes all-green.
Could you tell me how this might be ?
Thanks,
Peter Fitzgibbons
(847) 687-7646
Email: peter.fi...@gmail.com
IM GTalk: peter.fitzgibbons
IM AOL: peter.fi...@gmail.com
_______________________________________________
rspec-users mailing list
rspec...@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users
On Tue, Dec 22, 2009 at 9:14 AM, Peter Fitzgibbons <peter.fi...@gmail.com> wrote:
Hello Folks,
This gist http://gist.github.com/261791 has an example user.rb, user_spec.rb
At runtime, this snippet fails
u = User.find(123)
u.update_with_profile({...})
The error occurred while evaluating nil.select):
app/models/user.rb:6:in `moderator_fields'
app/models/user.rb:118:in `update_with_profile'
The spec passes all-green.
Could you tell me how this might be ?
The user in the spec comes from new_with_profile(), which sets instance variables on the User class.The user in the console comes from find(), and those ivars are not yet set.
Also counting on class variables to retain state in Rails is a recipe
for disaster.
--
Rick DeNatale
Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
Also counting on class variables to retain state in Rails is a recipefor disaster.
> Please explain why - thanks.
Because, classes and class variables aren't guaranteed to be persistent.
In development mode, classes can get reloaded, which wipes out class
(and class instance) variables.
In most deployment scenarios requests from a single user might be
handled by different processes, each with it's own state.
State that needs to be around between requests needs to be somewhere
persistent like the DB, or the session.