Peter Fitzgibbons
2009-Dec-22 15:14 UTC
[rspec-users] class variables different between spec and runtime?
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.fitzgibbons at gmail.com IM GTalk: peter.fitzgibbons IM AOL: peter.fitzgibbons at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20091222/26233577/attachment.html>
David Chelimsky
2009-Dec-22 15:22 UTC
[rspec-users] class variables different between spec and runtime?
On Tue, Dec 22, 2009 at 9:14 AM, Peter Fitzgibbons < peter.fitzgibbons at 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.> > Thanks, > > Peter Fitzgibbons > (847) 687-7646 > Email: peter.fitzgibbons at gmail.com > IM GTalk: peter.fitzgibbons > IM AOL: peter.fitzgibbons at gmail.com > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20091222/71d2d69f/attachment-0001.html>
David Chelimsky
2009-Dec-22 15:24 UTC
[rspec-users] class variables different between spec and runtime?
On Tue, Dec 22, 2009 at 9:22 AM, David Chelimsky <dchelimsky at gmail.com>wrote:> > > On Tue, Dec 22, 2009 at 9:14 AM, Peter Fitzgibbons < > peter.fitzgibbons at 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 - @params in the User class (in the class methods) is not the same @params in the User instances (in update_with_profile). HTH, David> > >> >> Thanks, >> >> Peter Fitzgibbons >> (847) 687-7646 >> Email: peter.fitzgibbons at gmail.com >> IM GTalk: peter.fitzgibbons >> IM AOL: peter.fitzgibbons at gmail.com >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20091222/7cec0ee5/attachment.html>
Rick DeNatale
2009-Dec-22 15:30 UTC
[rspec-users] class variables different between spec and runtime?
On Tue, Dec 22, 2009 at 10:24 AM, David Chelimsky <dchelimsky at gmail.com> wrote:> > > On Tue, Dec 22, 2009 at 9:22 AM, David Chelimsky <dchelimsky at gmail.com> > wrote: >> >> >> On Tue, Dec 22, 2009 at 9:14 AM, Peter Fitzgibbons >> <peter.fitzgibbons at 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 - @params in the User class (in the class methods) is not the same > @params in the User instances (in update_with_profile). > HTH, > DavidAlso 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
David Chelimsky
2009-Dec-22 15:36 UTC
[rspec-users] class variables different between spec and runtime?
On Tue, Dec 22, 2009 at 9:30 AM, Rick DeNatale <rick.denatale at gmail.com>wrote:> Also counting on class variables to retain state in Rails is a recipe > for disaster. >Did you read that in rails recipes? :-/ -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20091222/66d2f636/attachment.html>
Peter Fitzgibbons
2009-Dec-22 18:51 UTC
[rspec-users] class variables different between spec and runtime?
DOH! Thanks David, Happy Holidays! Peter Fitzgibbons (847) 687-7646 Email: peter.fitzgibbons at gmail.com IM GTalk: peter.fitzgibbons IM AOL: peter.fitzgibbons at gmail.com On Tue, Dec 22, 2009 at 9:24 AM, David Chelimsky <dchelimsky at gmail.com>wrote:> > > On Tue, Dec 22, 2009 at 9:22 AM, David Chelimsky <dchelimsky at gmail.com>wrote: > >> >> >> On Tue, Dec 22, 2009 at 9:14 AM, Peter Fitzgibbons < >> peter.fitzgibbons at 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 - @params in the User class (in the class methods) is not the same > @params in the User instances (in update_with_profile). > > HTH, > David > > >> >> >>> >>> Thanks, >>> >>> Peter Fitzgibbons >>> (847) 687-7646 >>> Email: peter.fitzgibbons at gmail.com >>> IM GTalk: peter.fitzgibbons >>> IM AOL: peter.fitzgibbons at gmail.com >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> >> > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20091222/7e649b65/attachment.html>
Andrew Premdas
2009-Dec-28 05:18 UTC
[rspec-users] class variables different between spec and runtime?
2009/12/22 Rick DeNatale <rick.denatale at gmail.com>> On Tue, Dec 22, 2009 at 10:24 AM, David Chelimsky <dchelimsky at gmail.com> > wrote: > > > > > > On Tue, Dec 22, 2009 at 9:22 AM, David Chelimsky <dchelimsky at gmail.com> > > wrote: > >> > >> > >> On Tue, Dec 22, 2009 at 9:14 AM, Peter Fitzgibbons > >> <peter.fitzgibbons at 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 - @params in the User class (in the class methods) is not the same > > @params in the User instances (in update_with_profile). > > HTH, > > David > > > Also counting on class variables to retain state in Rails is a recipe > for disaster. > >Please explain why - thanks. Andrew> -- > 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 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20091228/365d539e/attachment.html>
Rick DeNatale
2009-Dec-28 13:24 UTC
[rspec-users] class variables different between spec and runtime?
On Mon, Dec 28, 2009 at 12:18 AM, Andrew Premdas <apremdas at gmail.com> wrote:> 2009/12/22 Rick DeNatale <rick.denatale at gmail.com>> 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. -- 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