Permalink
Browse files

Basic relationships for Email Addresses

  • Loading branch information...
1 parent 1fdd0b1 commit e84805988dbb58ae4e8dd2680035022a3ff3cc31 @jcasimir committed Apr 19, 2011
Showing with 18 additions and 1 deletion.
  1. +2 −0 app/models/email_address.rb
  2. +16 −1 spec/models/email_address_spec.rb
@@ -2,4 +2,6 @@ class EmailAddress < ActiveRecord::Base
attr_accessible :address, :person_id
belongs_to :person
+
+ validates_presence_of :address, :person
end
@@ -1,7 +1,22 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe EmailAddress do
+ before(:each) do
+ @person = Person.create(:first_name => "John", :last_name => "Doe")
+ @email_address = @person.email_addresses.new(:address => "john@doe.com")
+ end
+
it "should be valid" do
- EmailAddress.new.should be_valid
+ @email_address.should be_valid
+ end
+
+ it "should not be valid without an address" do
+ @email_address.address = nil
+ @email_address.should_not be_valid
+ end
+
+ it "should not be valid without a person" do
+ @email_address.person_id = nil
+ @email_address.should_not be_valid
end
end

0 comments on commit e848059

Please sign in to comment.