[#4177] Added validations and accessors.

This commit is contained in:
Eric Davis
2010-06-17 12:25:31 -07:00
parent 1138616e77
commit 8c7d865a60
2 changed files with 44 additions and 1 deletions

View File

@@ -4,5 +4,28 @@ class Contract < ActiveRecord::Base
# Associations
belongs_to :project
belongs_to :account_executive, :class_name => 'User', :foreign_key => 'account_executive_id'
# Validations
validates_presence_of :name
validates_presence_of :account_executive
validates_presence_of :project
validates_presence_of :start_date
validates_presence_of :end_date
validates_presence_of :executed
validates_inclusion_of :discount_type, :in => %w($ %), :allow_blank => true, :allow_nil => true
# Accessors
attr_accessible :name
attr_accessible :account_executive_id
attr_accessible :start_date
attr_accessible :end_date
attr_accessible :executed
attr_accessible :billable_rate
attr_accessible :discount
attr_accessible :discount_note
attr_accessible :payment_terms
attr_accessible :client_ap_contact_information
attr_accessible :po_number
attr_accessible :details
end

View File

@@ -3,4 +3,24 @@ require File.dirname(__FILE__) + '/../test_helper'
class ContractTest < ActiveSupport::TestCase
should_belong_to :account_executive
should_belong_to :project
should_validate_presence_of :name
should_validate_presence_of :account_executive
should_validate_presence_of :project
should_validate_presence_of :start_date
should_validate_presence_of :end_date
should_validate_presence_of :executed
should_not_allow_mass_assignment_of :project_id, :project, :discount_type
should_allow_values_for :discount_type, "$", "%", nil, ''
should_not_allow_values_for :discount_type, ["amount", "percent", "bar"]
context "start_date" do
should "be before end_date"
end
should "QUESTION: name be unique"
should "default executed to false"
end