From 9a44578c37e9c823dc5a8446f497f4d02e8990d4 Mon Sep 17 00:00:00 2001 From: Maxwell Salzberg <mbs348@gmail.com> Date: Tue, 22 Jun 2010 23:11:55 -0700 Subject: [PATCH] DG; Person is now the parent of Friend and User --- app/models/friend.rb | 10 ++-------- app/models/user.rb | 7 +------ app/views/friends/index.html.haml | 6 ++++-- app/views/friends/new.html.haml | 8 ++++++-- app/views/friends/show.html.haml | 7 +++++-- app/views/users/index.html.haml | 4 +++- spec/factories.rb | 2 +- spec/models/friend_spec.rb | 4 ++-- spec/models/post_spec.rb | 2 -- 9 files changed, 24 insertions(+), 26 deletions(-) diff --git a/app/models/friend.rb b/app/models/friend.rb index 7f3463dd2f..dba24e580c 100644 --- a/app/models/friend.rb +++ b/app/models/friend.rb @@ -1,16 +1,10 @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 45624f10ed..a1ac4217fc 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,13 +1,8 @@ -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 diff --git a/app/views/friends/index.html.haml b/app/views/friends/index.html.haml index 044ade323b..52abf14510 100644 --- a/app/views/friends/index.html.haml +++ b/app/views/friends/index.html.haml @@ -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 diff --git a/app/views/friends/new.html.haml b/app/views/friends/new.html.haml index e9b1451bef..161bd0250d 100644 --- a/app/views/friends/new.html.haml +++ b/app/views/friends/new.html.haml @@ -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 diff --git a/app/views/friends/show.html.haml b/app/views/friends/show.html.haml index 034eb23ce6..fedc3e2a3e 100644 --- a/app/views/friends/show.html.haml +++ b/app/views/friends/show.html.haml @@ -1,8 +1,11 @@ - title "Friend" %p - %strong Username: - = @friend.username + %strong Real Name: + = @friend.real_name +%p + %strong Email: + = @friend.email %p %strong Url: = @friend.url diff --git a/app/views/users/index.html.haml b/app/views/users/index.html.haml index f0c2e7f87f..6f210359ca 100644 --- a/app/views/users/index.html.haml +++ b/app/views/users/index.html.haml @@ -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 diff --git a/spec/factories.rb b/spec/factories.rb index 236e2984d3..d995e1e883 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -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 diff --git a/spec/models/friend_spec.rb b/spec/models/friend_spec.rb index 4ec6cf848a..668e8e1f54 100644 --- a/spec/models/friend_spec.rb +++ b/spec/models/friend_spec.rb @@ -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 diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index f8908e23e0..7bc28571f6 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -5,8 +5,6 @@ describe Post do Factory.create(:user, :email => "bob@aol.com") end - describe 'requirements' do - end describe 'defaults' do before do -- GitLab