Displaying 3 results from an estimated 3 matches for "should_valid".
2007 Oct 04
7
Using Predicates to look at an array..
Hi all,
I have an array of shipping_type''s being returned, and I want to see
what is in there. In the past I have done:
shipping_type.include?(Cart::SHIPPING_TYPE_REGULAR).should be_true
This works, but looks really ugly.. It just doesn''t roll of the
tongue very well. I then looked up the use of Predicates, which I
had been using, but hadn''t realized:
2007 May 31
28
Another attempt for a succinct model validation DSL
On 5/28/07, David Chelimsky <dchelimsky at gmail.com> wrote:
> The behaviour you''re trying to describe is that the User should
> require that passwords bear certain qualities - in this case a length
> between 5 and 40. So you need to ask yourself how the User should
> behave when this requirement is violated, and then specify that it
> behaves that way.
>
>
2007 May 05
10
have_one and have_present
...)
numericality_of(:age).only_integer(true)
end
Because Spec::Rails behaviours inherit from Test::Unit::TestCase, you
can install the validations gem (gem install validatable) and use
these as/is with RSpec. Or, if you want it to feel more spec''ish, you
could monkey patch an alias:
Foo.should_validate do
presence_of :name
format_of(:name).with(/^[A-Z]/)
numericality_of(:age).only_integer(true)
end
Whether you choose to use his framework or write your own, I think
there is something to be learned from its expressiveness.
Cheers,
David