tag:blogger.com,1999:blog-12467669.post26881901960757968..comments2023-04-29T07:23:25.825-04:00Comments on Jay Fields' Thoughts: Validatable 1.6.6 releasedJayhttp://www.blogger.com/profile/14491442812573747680noreply@blogger.comBlogger9125tag:blogger.com,1999:blog-12467669.post-24615885195754265242007-11-23T19:06:00.000-05:002007-11-23T19:06:00.000-05:00Validatable is here for anyone looking for it:http...Validatable is here for anyone looking for it:<BR/>http://validatable.rubyforge.org/Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-12467669.post-5217630097719145082007-11-09T12:50:00.000-05:002007-11-09T12:50:00.000-05:00I did wrote an extension so that I can say:email.s...I did wrote an extension so that I can say:<BR/>email.should <BR/> have(1).error_on_presence_of(:body)<BR/><BR/>it looks pretty neat.<BR/><BR/>The only thing is that I still cannot say:<BR/>email.should <BR/> have(:no).errors_on_presence_of(:attachment)<BR/><BR/>because validate_only('presence_of/attachment')<BR/>will raise an ArgumentError if I don't declare<BR/>validates_presence_of :attachment.Yi Wenhttps://www.blogger.com/profile/14117774604695585173noreply@blogger.comtag:blogger.com,1999:blog-12467669.post-15294124071323373392007-11-08T19:39:00.000-05:002007-11-08T19:39:00.000-05:00Actually, thinking twice, maybe it's not a good id...Actually, thinking twice, maybe it's not a good idea indeed. Because I can say<BR/><BR/>active_record_model.should <BR/>have(3).errors_on(:attribute)<BR/><BR/>This statement will do <I>valid?</I> and check the error for you.<BR/><BR/>So maybe a better way is to make a plugin connecting Rspec to Valitable so the same syntax can be applied on a validatable object as well. I will make this happen in my project. thanksYi Wenhttps://www.blogger.com/profile/14117774604695585173noreply@blogger.comtag:blogger.com,1999:blog-12467669.post-37566825781633844892007-11-08T18:51:00.000-05:002007-11-08T18:51:00.000-05:00Hey Jay,Thanks for the reply. If you have method h...Hey Jay,<BR/><BR/>Thanks for the reply. If you have method has_something on obj, you can say obj.should have_something in Rspec. It's a built-in feature of Rspec. so if you put has_error_on, in Rspec I can say email.should have_error_on, which is perfect.Yi Wenhttps://www.blogger.com/profile/14117774604695585173noreply@blogger.comtag:blogger.com,1999:blog-12467669.post-69466146977201247782007-11-08T18:11:00.000-05:002007-11-08T18:11:00.000-05:00Hey Yi,I'm not sure.@email.should have_error_on(:b...Hey Yi,<BR/><BR/>I'm not sure.<BR/><BR/>@email.should have_error_on(:body)<BR/><BR/>reads nicely; however, it only makes sense in the context of RSpec<BR/><BR/>@email.has_error_on?(:body)<BR/><BR/>reads nicely in general; however it causes the RSpec version to become<BR/><BR/>@email.should has_error_on?(:body)<BR/><BR/>which is not so nice.<BR/><BR/>I'm leaning towards has_error_on?<BR/><BR/>Thoughts?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-12467669.post-6275173385824975562007-11-08T17:56:00.000-05:002007-11-08T17:56:00.000-05:00Hey,Now if I need to verify validates_presence_of ...Hey,<BR/><BR/>Now if I need to verify validates_presence_of on an attribute using rspec, I need to say something like:<BR/><BR/>@email.validate_only(<BR/> "presence_of/body") @email.errors.on(:body).<BR/> should_not be_nil<BR/><BR/>Do you think it's valueable to add some methods like has_error_on into Validatable so that I can say something like<BR/><BR/>@email.should have_error_on(:body)<BR/><BR/>ThanksYi Wenhttps://www.blogger.com/profile/14117774604695585173noreply@blogger.comtag:blogger.com,1999:blog-12467669.post-72256906609989719502007-11-07T17:37:00.000-05:002007-11-07T17:37:00.000-05:00Jay, that's pretty cool. Any way I can convince yo...Jay, that's pretty cool. Any way I can convince you to drop by #datamapper on IRC sometime and we can discuss this a little more? I'd love to rip out my own validations and insert a dependency on your gem instead.<BR/><BR/>One last concern: I'm using a String#t no-op to allow for translated versions if you implement String#translate. Would you consider adding support for the same? It's such a small coding challenge, I really want to make it easy for international users to take advantage of DM without having to hack away at the internals.<BR/><BR/>Feel free to shoot me an email or IM if you're open to any of this. :)Unknownhttps://www.blogger.com/profile/16299009875913815146noreply@blogger.comtag:blogger.com,1999:blog-12467669.post-49274137201487940062007-11-05T07:20:00.000-05:002007-11-05T07:20:00.000-05:00Sam,Validatable already has support for contextual...Sam,<BR/><BR/>Validatable already has support for contextual-validations.<BR/><BR/>What you want to do can be accomplished using groups.<BR/><BR/><A HREF="http://blog.jayfields.com/2007/04/ruby-validatable-122-released.html" REL="nofollow">This entry</A> contains an example of how to use groups.<BR/><BR/>Using your example, you could write:<BR/><BR/>class User<BR/> validates_presence_of :login<BR/> validates_presence_of :account_number, :groups => :save<BR/>end<BR/><BR/>u = User.new(:login => 'bob')<BR/>u.valid? # => true<BR/>u.valid_for_saving? # => false<BR/><BR/>I'm definitely open to improving the contextual validations if you find them inadequate.<BR/><BR/>Cheers, JayAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-12467669.post-86866775508995900492007-11-04T23:14:00.000-05:002007-11-04T23:14:00.000-05:00Jay, have you thought about adding support for con...Jay, have you thought about adding support for contextual-validations?<BR/><BR/>I do something like:<BR/><BR/>validates_prescense_of :account_number, :on => :save<BR/>validates_presence_of :login<BR/><BR/>That way I can do something like:<BR/>u =User.new(:login => 'bob')<BR/>u.valid? => true<BR/>u.valid?(:save) => false<BR/><BR/>The point is that I often use models in multiple roles, not just within the web-app, so it makes sense that the business rules for an import script to pull legacy users from a CSV would have different business rules than the user edit form on an admin page.<BR/><BR/>So... my whole point is, if you're open to it, I'd love to ditch my own validation code in DataMapper and go with yours if you were open to the idea of adding context for validations (beyond Rails' limited :create and :update contexts).Unknownhttps://www.blogger.com/profile/16299009875913815146noreply@blogger.com