The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Validatable 1.6.6 released

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Jay Fields

Posts: 765
Nickname: jayfields
Registered: Sep, 2006

Jay Fields is a software developer for ThoughtWorks
Validatable 1.6.6 released Posted: Nov 4, 2007 8:02 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Jay Fields.
Original Post: Validatable 1.6.6 released
Feed Title: Jay Fields Thoughts
Feed URL: http://blog.jayfields.com/rss.xml
Feed Description: Thoughts on Software Development
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Jay Fields
Latest Posts From Jay Fields Thoughts

Advertisement
The 1.6.6 version of Validatable was released this morning.

This was a minor release that removed custom validation assertion syntax. (http://blog.jayfields.com/2007/09/ruby-creating-custom-assertions.html)

You can replace custom validation assertions with the newly introduced validate_only instance method. The validate_only method is my latest attempt to make it easy to test model validations one at a time.

The following code should provide a decent example.

require 'rubygems'
require 'test/unit'
require 'dust'
require 'validatable'

class SampleModel
include Validatable
validates_presence_of :name, :address
attr_accessor :name, :address
end

unit_tests do
test "individual validation for name is executed" do
instance = SampleModel.new
instance.validate_only("presence_of/name")
assert_equal "can't be empty", instance.errors.on(:name)
end

test "individual validation for address is not executed" do
instance = SampleModel.new
instance.validate_only("presence_of/name")
assert_equal nil, instance.errors.on(:address)
end
end


The validate_only method accepts an argument that is a DSL for running a single validation. The format of the DSL is "[validation type]/[key or attribute]". If the validation has a key set you should provide the key, otherwise the attribute will suffice. The documentation provides the following examples.
  • validates_presence_of :name can be run with obj.validate_only("presence_of/name")
  • validates_presence_of :birthday, :key => "a key" can be run with obj.validate_only("presence_of/a key")

Read: Validatable 1.6.6 released

Topic: RubyConf begins Previous Topic   Next Topic Topic: RubyConf 2007 Friday Morning - Marcel's Talk

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use