public
Description: A Rails plugin that allows validation on partially completed Active Record models (useful in wizards that incrementally build a model).
Clone URL: git://github.com/jimweirich/partially_valid.git
Search Repo:
name age message
folder CHANGES Thu Jul 03 12:17:58 -0700 2008 added CHANGES file [jimweirich]
folder README Thu Jul 03 11:22:08 -0700 2008 Updated README [jimweirich]
folder Rakefile Wed Jul 02 14:06:05 -0700 2008 initial version [jimweirich]
folder init.rb Wed Jul 02 14:06:05 -0700 2008 initial version [jimweirich]
folder lib/ Thu Jul 03 10:04:51 -0700 2008 added a should_be_valid_except method, with tes... [DrMark]
folder test/ Thu Jul 03 10:04:51 -0700 2008 added a should_be_valid_except method, with tes... [DrMark]
README
h1. Partially Valid Rails Plugin

PartiallyValid allows you to valid an ActiveRecord model when only a subset of the models attributes are valid. This is 
particularly useful when using a wizard-like UI to build up a model in stages. 

h1. Example

Assume, for the purposes of this example that the name, age and phone number fields of a person model are required.

  bill = Person.new
  bill.partially_valid?  #=> true (no fields are checked at this point)

  bill.should_be_partially_valid_on :name, :address
  bill.partially_valid?  #=> false (name and address are invalid)

  bill.name = "Bill"
  bill.address = "Home Address"
  bill.partially_valid?  #=> true  (now name and address are valid)

  bill.should_be_partially_valid_on :phone_number
  bill.partially_valid?  #=> false  (fails now because phone number is checked)

  bill.should_be_partially_valid_except :phone_number
  bill.partially_valid?  #=> true  (passes now because phone number is not checked)

h2. Notes

After invoking :partially_valid?, the errors object will contain
only errors referencing attributes declared to be considered for
partial validation.

The list of partially valid attributes are stored on the object itself.  The object may be marshalled into session data 
and restored and will remember the attributes that have been declared to be checked for validity.  However, the list of 
valid attributes are not persisted to the database.  Generally, this is not a problem, because a model that is only 
partially valid cannot be saved to the database anyways.

The :valid? method continues to work as before.

h3. Requirements

The flexmock gem.
  > gem install flexmock