DG; Person is now the parent of Friend and User

This commit is contained in:
Maxwell Salzberg 2010-06-22 23:11:55 -07:00
parent afbefcafb5
commit 9a44578c37
9 changed files with 24 additions and 26 deletions

View file

@ -1,16 +1,10 @@
class Friend class Friend < Person
include Mongoid::Document
include ROXML
xml_accessor :username
xml_accessor :url xml_accessor :url
xml_accessor :real_name
field :username
field :url field :url
field :real_name
validates_presence_of :username, :url, :real_name validates_presence_of :url
validates_format_of :url, :with => validates_format_of :url, :with =>
/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix

View file

@ -1,13 +1,8 @@
class User class User < Person
include Mongoid::Document
# Include default devise modules. Others available are: # Include default devise modules. Others available are:
# :token_authenticatable, :confirmable, :lockable and :timeoutable # :token_authenticatable, :confirmable, :lockable and :timeoutable
devise :database_authenticatable, :registerable, devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable :recoverable, :rememberable, :trackable, :validatable
field :real_name
validates_presence_of :real_name
end end

View file

@ -2,11 +2,13 @@
%table %table
%tr %tr
%th username %th real name
%th email
%th url %th url
- for friend in @friends - for friend in @friends
%tr %tr
%td= friend.username %td= friend.real_name
%td= friend.email
%td= friend.url %td= friend.url
%td= link_to 'Show', friend %td= link_to 'Show', friend
%td= link_to 'Destroy', friend, :confirm => 'Are you sure?', :method => :delete %td= link_to 'Destroy', friend, :confirm => 'Are you sure?', :method => :delete

View file

@ -3,9 +3,13 @@
= form_for @friend do |f| = form_for @friend do |f|
= f.error_messages = f.error_messages
%p %p
= f.label :username = f.label :real_name
%br %br
= f.text_field :username = f.text_field :real_name
%p
= f.label :email
%br
= f.text_field :email
%p %p
= f.label :url = f.label :url
%br %br

View file

@ -1,8 +1,11 @@
- title "Friend" - title "Friend"
%p %p
%strong Username: %strong Real Name:
= @friend.username = @friend.real_name
%p
%strong Email:
= @friend.email
%p %p
%strong Url: %strong Url:
= @friend.url = @friend.url

View file

@ -2,9 +2,11 @@
%table %table
%tr %tr
%th User %th Real Name
%th email
%th Password %th Password
- for user in @users - for user in @users
%tr %tr
%td= user.real_name
%td= user.email %td= user.email
%td= user.encrypted_password %td= user.encrypted_password

View file

@ -4,7 +4,7 @@
Factory.define :friend do |f| Factory.define :friend do |f|
f.real_name 'John Doe' f.real_name 'John Doe'
f.username 'max' f.email 'max@max.com'
f.url 'http://max.com/' f.url 'http://max.com/'
end end

View file

@ -64,7 +64,7 @@ describe Friend do
describe "XML" do describe "XML" do
before do before do
@f = Factory.build(:friend) @f = Factory.build(:friend)
@xml = "<friend>\n <username>#{@f.username}</username>\n <url>#{@f.url}</url>\n <real_name>#{@f.real_name}</real_name>\n</friend>" @xml = "<friend>\n <url>#{@f.url}</url>\n <email>#{@f.email}</email>\n <real_name>#{@f.real_name}</real_name>\n</friend>"
end end
it 'should serialize to XML' do it 'should serialize to XML' do
@ -73,7 +73,7 @@ describe Friend do
it 'should marshal serialized XML to object' do it 'should marshal serialized XML to object' do
parsed = Friend.from_xml(@xml) parsed = Friend.from_xml(@xml)
parsed.username.should == @f.username parsed.email.should == @f.email
parsed.url.should == @f.url parsed.url.should == @f.url
parsed.valid?.should be_true parsed.valid?.should be_true
end end

View file

@ -5,8 +5,6 @@ describe Post do
Factory.create(:user, :email => "bob@aol.com") Factory.create(:user, :email => "bob@aol.com")
end end
describe 'requirements' do
end
describe 'defaults' do describe 'defaults' do
before do before do