From b5b9c647d76e542e6fc2b2f4937e386d6aa65582 Mon Sep 17 00:00:00 2001 From: ilya <ilya@laptop.(none)> Date: Mon, 28 Jun 2010 21:32:09 -0400 Subject: [PATCH] DG IZ Created the profile model & friend view now shows the information --- app/controllers/friends_controller.rb | 1 + app/models/person.rb | 7 ++++--- app/models/profile.rb | 6 ++++-- app/models/user.rb | 1 + app/views/bookmarks/_form.html.haml | 12 ++++++++++++ app/views/friends/new.html.haml | 4 ---- app/views/friends/show.html.haml | 19 ++++++++++++++++++- spec/factories.rb | 5 +---- spec/models/friend_spec.rb | 19 +++++++------------ spec/models/person_spec.rb | 8 -------- spec/models/user_spec.rb | 11 ----------- 11 files changed, 48 insertions(+), 45 deletions(-) create mode 100644 app/views/bookmarks/_form.html.haml diff --git a/app/controllers/friends_controller.rb b/app/controllers/friends_controller.rb index ebf2c1df84..a13c3f2e49 100644 --- a/app/controllers/friends_controller.rb +++ b/app/controllers/friends_controller.rb @@ -7,6 +7,7 @@ class FriendsController < ApplicationController def show @friend = Friend.where(:id => params[:id]).first + @friend_profile = @friend.profile @friend_posts = Post.where(:person_id => @friend.id).sort(:created_at.desc) end diff --git a/app/models/person.rb b/app/models/person.rb index a7ccdbf0e5..7428e9b5f2 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -3,14 +3,15 @@ class Person include ROXML xml_accessor :email - xml_accessor :real_name key :email, String - key :real_name, String one :profile, :class_name => 'Profile', :foreign_key => :person_id many :posts, :class_name => 'Post', :foreign_key => :person_id - validates_presence_of :email, :real_name, :profile + validates_presence_of :email + def real_name + self.profile.first_name + " " + self.profile.last_name + end end diff --git a/app/models/profile.rb b/app/models/profile.rb index 16a3d22b35..0e4e6c9138 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -4,8 +4,10 @@ class Profile key :first_name, String key :last_name, String - belongs_to :person, :class_name => "Person" + key :person_id, ObjectId - validates_presence_of :first_name, :last_name, :person + belongs_to :person + + validates_presence_of :first_name, :last_name, :person_id end diff --git a/app/models/user.rb b/app/models/user.rb index c2b03629ee..1751f15a10 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -14,6 +14,7 @@ class User < Person Comment.new(:person_id => self.id, :text => text, :post => options[:on]).save end + validates_presence_of :profile before_validation :do_bad_things def do_bad_things diff --git a/app/views/bookmarks/_form.html.haml b/app/views/bookmarks/_form.html.haml new file mode 100644 index 0000000000..0e02f4082f --- /dev/null +++ b/app/views/bookmarks/_form.html.haml @@ -0,0 +1,12 @@ += form_for @bookmark do |f| + = f.error_messages + %p + = f.label :title + %br + = f.text_field :title + %p + = f.label :link + %br + = f.text_field :link + %p + = f.submit diff --git a/app/views/friends/new.html.haml b/app/views/friends/new.html.haml index 161bd0250d..d8f89f2f6b 100644 --- a/app/views/friends/new.html.haml +++ b/app/views/friends/new.html.haml @@ -2,10 +2,6 @@ = form_for @friend do |f| = f.error_messages - %p - = f.label :real_name - %br - = f.text_field :real_name %p = f.label :email %br diff --git a/app/views/friends/show.html.haml b/app/views/friends/show.html.haml index f4218409b1..5e91a295dc 100644 --- a/app/views/friends/show.html.haml +++ b/app/views/friends/show.html.haml @@ -1,5 +1,22 @@ -%h1= "#{@friend.real_name}'s network stream" +%h1= "#{@friend.real_name}" + +- if @friend_profile + %p + %b First Name + %p + = @friend_profile.first_name + %p + %b Last Name + %p + = @friend_profile.last_name + +%br +%br +%br +%br + - if @friend.posts + %h3 stream %ul#stream - for post in @friend_posts = render type_partial(post), :post => post diff --git a/spec/factories.rb b/spec/factories.rb index 306471d97a..b75cdbc920 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -6,17 +6,15 @@ Factory.define :profile do |p| p.first_name "Robert" p.last_name "Grimm" - p.person Person.new( :email => "bob@aol.com", :real_name => "Bob" ) + p.person Person.new( :email => "bob@aol.com" ) end Factory.define :person do |p| p.email "bob@aol.com" - p.real_name "Bob" p.profile Profile.new( :first_name => "Robert", :last_name => "Grimm" ) end Factory.define :user do |u| - u.real_name 'Bob Smith' u.sequence(:email) {|n| "bob#{n}@aol.com"} u.password "bluepin7" u.password_confirmation "bluepin7" @@ -24,7 +22,6 @@ Factory.define :user do |u| end Factory.define :friend do |f| - f.real_name 'John Doe' f.email 'max@max.com' f.url 'http://max.com/' f.profile Profile.new( :first_name => "Robert", :last_name => "Grimm" ) diff --git a/spec/models/friend_spec.rb b/spec/models/friend_spec.rb index 5ef06a6256..5861742a13 100644 --- a/spec/models/friend_spec.rb +++ b/spec/models/friend_spec.rb @@ -2,18 +2,13 @@ require File.dirname(__FILE__) + '/../spec_helper' describe Friend do - it 'should require a diaspora username and diaspora url' do - n = Factory.build(:friend, :url => nil) - n.valid?.should be false - n.url = "http://max.com/" - n.valid?.should be true - end - - it 'should require a real name' do - n = Factory.build(:friend, :real_name => nil) - n.valid?.should be false - n.real_name = "John Smith" - n.valid?.should be true + describe 'requirements' do + it 'should include a url' do + n = Factory.build(:friend, :url => nil) + n.valid?.should be false + n.url = "http://max.com/" + n.valid?.should be true + end end it 'should validate its url' do diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index 0701b8c693..ddd91e38db 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -1,12 +1,4 @@ require 'spec_helper' describe Person do - - it 'should require a profile' do - person = Factory.build(:person, :profile => nil) - person.valid?.should be false - person.profile = Factory.build(:profile) - person.valid?.should be true - end - end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index b52406211a..abdbdf22ae 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,20 +1,9 @@ require 'spec_helper' describe User do - it "should require a real name" do - u = Factory.build(:user, :real_name => nil) - u.valid?.should be false - u.real_name = "John Smith" - u.valid?.should be true - end - it "should create a valid user with the factory" do - u = Factory.build(:user) - u.valid?.should be true - end it "should be a person" do n = Person.count Factory.create(:user) Person.count.should == n+1 end - end -- GitLab