Skip to content
Extraits de code Groupes Projets
Valider 9a44578c rédigé par Maxwell Salzberg's avatar Maxwell Salzberg
Parcourir les fichiers

DG; Person is now the parent of Friend and User

parent afbefcaf
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
class Friend
include Mongoid::Document
include ROXML
class Friend < Person
xml_accessor :username
xml_accessor :url
xml_accessor :real_name
field :username
field :url
field :real_name
validates_presence_of :username, :url, :real_name
validates_presence_of :url
validates_format_of :url, :with =>
/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix
......
class User
include Mongoid::Document
class User < Person
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable, :lockable and :timeoutable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
field :real_name
validates_presence_of :real_name
end
......@@ -2,11 +2,13 @@
%table
%tr
%th username
%th real name
%th email
%th url
- for friend in @friends
%tr
%td= friend.username
%td= friend.real_name
%td= friend.email
%td= friend.url
%td= link_to 'Show', friend
%td= link_to 'Destroy', friend, :confirm => 'Are you sure?', :method => :delete
......
......@@ -3,9 +3,13 @@
= form_for @friend do |f|
= f.error_messages
%p
= f.label :username
= f.label :real_name
%br
= f.text_field :username
= f.text_field :real_name
%p
= f.label :email
%br
= f.text_field :email
%p
= f.label :url
%br
......
- title "Friend"
%p
%strong Username:
= @friend.username
%strong Real Name:
= @friend.real_name
%p
%strong Email:
= @friend.email
%p
%strong Url:
= @friend.url
......
......@@ -2,9 +2,11 @@
%table
%tr
%th User
%th Real Name
%th email
%th Password
- for user in @users
%tr
%td= user.real_name
%td= user.email
%td= user.encrypted_password
......@@ -4,7 +4,7 @@
Factory.define :friend do |f|
f.real_name 'John Doe'
f.username 'max'
f.email 'max@max.com'
f.url 'http://max.com/'
end
......
......@@ -64,7 +64,7 @@ describe Friend do
describe "XML" do
before do
@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
it 'should serialize to XML' do
......@@ -73,7 +73,7 @@ describe Friend do
it 'should marshal serialized XML to object' do
parsed = Friend.from_xml(@xml)
parsed.username.should == @f.username
parsed.email.should == @f.email
parsed.url.should == @f.url
parsed.valid?.should be_true
end
......
......@@ -5,8 +5,6 @@ describe Post do
Factory.create(:user, :email => "bob@aol.com")
end
describe 'requirements' do
end
describe 'defaults' do
before do
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter