diff --git a/app/models/contract.rb b/app/models/contract.rb index 958bf07..6275192 100644 --- a/app/models/contract.rb +++ b/app/models/contract.rb @@ -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 diff --git a/test/unit/contract_test.rb b/test/unit/contract_test.rb index c128b6e..8532fe7 100644 --- a/test/unit/contract_test.rb +++ b/test/unit/contract_test.rb @@ -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