From: Rick DeNatale Date: 2009-03-03T03:04:58+09:00 Subject: Re: passing a method as a paramter --0016e64f683a756c88046426ac31 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On Mon, Mar 2, 2009 at 10:16 AM, Sarah Allen wrote: > Michael Fellinger wrote: > > On Mon, Mar 2, 2009 at 7:44 PM, Sarah Allen > > wrote: > >>>> assert_not_nil record.errors.on(field) > >>>> end > >>>> end > >> > >> Any thoughts on how that could be called? > > > > It's the second example, you cannot obtain an instance of Method like > > you would do in Python or JavaScript by simply omitting the > > parenthesis, you have to use the Object#method method. > > > > All of these are equivalent: > > > > User.create > > User.create() > > User.method(:create).call > > User.send(:create) > > > > ^ manveru > > I get the error: (ActiveRecord::Base).create> is not a symbol > calling: > assert_required_fields User.method(:create), :create, :email, > :lastname, :password > > the code in my library uses send, not call > > Of course, I could just change the definition of assert_required_fields, > but since it is part of a plugin > ( > http://topfunky.net/svn/plugins/topfunky_power_tools/lib/topfunky/test_helper.rb > ), I figure there must be some standard way to call it Yes, you need to pass a symbol, just as the error is trying to tell you: def test_should_not_create_user_unless_default_fields assert_required_fields :create, :email, :lastname, :password end I'm assuming that this is in the unit test for the User model. -- 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 --0016e64f683a756c88046426ac31--