DG IZ; friend and owner now require a real name
This commit is contained in:
parent
7f795e05cb
commit
a1361da770
6 changed files with 31 additions and 7 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 = "<friend>\n <username>#{@f.username}</username>\n <url>#{@f.url}</url>\n</friend>"
|
||||
@xml = "<friend>\n <username>#{@f.username}</username>\n <url>#{@f.url}</url>\n <real_name>#{@f.real_name}</real_name>\n</friend>"
|
||||
end
|
||||
|
||||
it 'should serialize to XML' do
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue