public
Description: A Rails plugin to DRY up testing of required model attributes.
Homepage: http://corrupt.save-state.net/
Clone URL: git://github.com/Oshuma/test_required_attributes.git
Click here to lend your support to: test_required_attributes and make a donation at www.pledgie.com !

TestRequiredAttributes

A Rails plugin to DRY up testing of required model attributes.

Author:Dale Campbell <dale@save-state.net>
Code:github.com/Oshuma/test_required_attributes/

Install

Manual labor:

  cd $RAILS_ROOT
  git submodule add git://github.com/Oshuma/test_required_attributes.git vendor/plugins/test_required_attributes
  git submodule init

Then to update:

  git submodule update

No includes or anything else required. Just follow the example below to use in your test cases.

Example

  # standard migration
  class CreateGangsters < ActiveRecord::Migration
    def self.up
      create_table :gangsters do |t|
        t.string :name
        t.string :nickname
        t.integer :gun_id
        t.boolean :boss
        t.integer :loot
      end
    end
    def self.down; drop_table :gangsters; end
  end

  # standard model
  class Gangster < ActiveRecord::Base
    validates_presence_of :name, :boss, :loot
  end

  # ultra DRY unit test
  class GangsterTest < ActiveSupport::TestCase
    # Only pass attributes listed in the validates_presence_of call in the model.
    test_required_attributes(Gangster, :name => 'Al', :boss => true, :loot => 1e10)
  end

Copyright © 2008 Dale Campbell <dale@save-state.net>, released under the WTFPL license