diff --git a/app/models/friend.rb b/app/models/friend.rb index 319762eef..7f3463dd2 100644 --- a/app/models/friend.rb +++ b/app/models/friend.rb @@ -4,11 +4,13 @@ class Friend xml_accessor :username xml_accessor :url + xml_accessor :real_name field :username field :url + field :real_name - validates_presence_of :username, :url + validates_presence_of :username, :url, :real_name 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 2c5c134b5..45624f10e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,9 +1,13 @@ class User include Mongoid::Document - + # 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/layouts/application.html.haml b/app/views/layouts/application.html.haml index deab8559a..441a285bc 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -44,7 +44,7 @@ #header_below - if user_signed_in? %h1#user_name - = link_to User.first.email, root_url + = link_to User.first.real_name, root_url %span.description - if StatusMessage.my_newest = StatusMessage.my_newest.message @@ -71,4 +71,4 @@ = yield #debug - .msg \ No newline at end of file + .msg diff --git a/spec/controllers/blogs_controller_spec.rb b/spec/controllers/blogs_controller_spec.rb index 71c503ccb..545dc414f 100644 --- a/spec/controllers/blogs_controller_spec.rb +++ b/spec/controllers/blogs_controller_spec.rb @@ -4,8 +4,10 @@ describe BlogsController do before do #TODO(dan) Mocking Warden; this is a temp fix request.env['warden'] = mock_model(Warden, :authenticate? => @user, :authenticate! => @user) - User.create(:email => "bob@aol.com", :password => "secret") - Blog.create(:title => "hello", :body => "sir") + u = Factory.build(:user, :email => "bob@aol.com", :password => "secret") + b = Factory.build(:blog, :title => "hello", :body => "sir") + u.save + b.save end render_views diff --git a/spec/factories.rb b/spec/factories.rb index 5997c11e5..236e2984d 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -3,6 +3,7 @@ #http://railscasts.com/episodes/158-factories-not-fixtures Factory.define :friend do |f| + f.real_name 'John Doe' f.username 'max' f.url 'http://max.com/' end @@ -17,6 +18,7 @@ Factory.define :blog do |b| end Factory.define :user do |u| + u.real_name 'Bob Smith' u.sequence(:email) {|n| "bob#{n}@aol.com"} u.password "bluepin7" end diff --git a/spec/models/friend_spec.rb b/spec/models/friend_spec.rb index 4ccf0ee7c..4ec6cf848 100644 --- a/spec/models/friend_spec.rb +++ b/spec/models/friend_spec.rb @@ -2,13 +2,20 @@ require File.dirname(__FILE__) + '/../spec_helper' describe Friend do - it 'should have a diaspora username and diaspora url' do - n = Factory.build(:friend, :url => "") + 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 + end + it 'should validate its url' do friend = Factory.build(:friend) @@ -57,7 +64,7 @@ describe Friend do describe "XML" do before do @f = Factory.build(:friend) - @xml = "\n #{@f.username}\n #{@f.url}\n" + @xml = "\n #{@f.username}\n #{@f.url}\n #{@f.real_name}\n" end it 'should serialize to XML' do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 0f545327b..07b2c57b3 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,4 +1,11 @@ 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 + end