Merge branch 'master' of github.com:diaspora/diaspora_rails
This commit is contained in:
commit
3dce5f1b34
7 changed files with 82 additions and 41 deletions
|
|
@ -8,13 +8,9 @@ class Person
|
|||
key :email, String
|
||||
key :real_name, String
|
||||
|
||||
#key :post_ids, Array#, :typecast => ObjectId
|
||||
|
||||
one :profile, :class_name => 'Profile', :foreign_key => :person_id
|
||||
many :posts, :class_name => 'Post', :foreign_key => :person_id
|
||||
|
||||
validates_presence_of :email, :real_name
|
||||
validates_presence_of :email, :real_name, :profile
|
||||
|
||||
# def newest(type = nil)
|
||||
# type.constantize.where(:person_id => id).last
|
||||
# end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -8,19 +8,13 @@ class Post
|
|||
xml_accessor :_id
|
||||
|
||||
key :person_id, ObjectId
|
||||
belongs_to :person, :class_name => 'Person'
|
||||
|
||||
|
||||
many :comments, :class_name => 'Comment', :foreign_key => :post_id
|
||||
belongs_to :person, :class_name => 'Person'
|
||||
|
||||
timestamps!
|
||||
|
||||
|
||||
|
||||
after_save :send_to_view
|
||||
#validates_presence_of :person
|
||||
|
||||
|
||||
|
||||
def self.stream
|
||||
Post.sort(:created_at.desc).all
|
||||
|
|
|
|||
11
app/models/profile.rb
Normal file
11
app/models/profile.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
class Profile
|
||||
include MongoMapper::Document
|
||||
|
||||
key :first_name, String
|
||||
key :last_name, String
|
||||
|
||||
belongs_to :person, :class_name => "Person"
|
||||
|
||||
validates_presence_of :first_name, :last_name, :person
|
||||
|
||||
end
|
||||
|
|
@ -1,11 +1,33 @@
|
|||
#For Guidance
|
||||
#http://github.com/thoughtbot/factory_girl
|
||||
#http://railscasts.com/episodes/158-factories-not-fixtures
|
||||
# http://railscasts.com/episodes/158-factories-not-fixtures
|
||||
|
||||
|
||||
Factory.define :profile do |p|
|
||||
p.first_name "Robert"
|
||||
p.last_name "Grimm"
|
||||
p.person Person.new( :email => "bob@aol.com", :real_name => "Bob" )
|
||||
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"
|
||||
u.profile Profile.new( :first_name => "Bob", :last_name => "Smith" )
|
||||
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" )
|
||||
end
|
||||
|
||||
Factory.define :status_message do |m|
|
||||
|
|
@ -17,12 +39,6 @@ Factory.define :blog do |b|
|
|||
b.sequence(:body) {|n| "jimmy's huge #{n} whales"}
|
||||
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"
|
||||
end
|
||||
|
||||
Factory.define :bookmark do |b|
|
||||
b.link "http://www.yahooligans.com/"
|
||||
|
|
@ -31,4 +47,4 @@ end
|
|||
Factory.define :post do |p|
|
||||
end
|
||||
|
||||
Factory.define(:comment) {}
|
||||
Factory.define(:comment) {}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ describe Friend do
|
|||
n.valid?.should be true
|
||||
end
|
||||
|
||||
|
||||
it 'should validate its url' do
|
||||
friend = Factory.build(:friend)
|
||||
|
||||
|
|
@ -65,23 +64,4 @@ describe Friend do
|
|||
friend.url = "http:///www.asodij.com/"
|
||||
friend.valid?.should == false
|
||||
end
|
||||
|
||||
describe "XML" do
|
||||
before do
|
||||
@f = Factory.build(: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
|
||||
@f.to_xml.to_s.should == @xml
|
||||
end
|
||||
|
||||
it 'should marshal serialized XML to object' do
|
||||
parsed = Friend.from_xml(@xml)
|
||||
parsed.email.should == @f.email
|
||||
parsed.url.should == @f.url
|
||||
parsed.valid?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
12
spec/models/person_spec.rb
Normal file
12
spec/models/person_spec.rb
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
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
|
||||
32
spec/models/profile_spec.rb
Normal file
32
spec/models/profile_spec.rb
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Profile do
|
||||
before do
|
||||
@person = Factory.build(:person)
|
||||
end
|
||||
|
||||
describe 'requirements' do
|
||||
it "should include a first name" do
|
||||
@person.profile = Factory.build(:profile, :person => @person, :first_name => nil)
|
||||
@person.profile.valid?.should be false
|
||||
@person.profile.first_name = "Bob"
|
||||
@person.profile.valid?.should be true
|
||||
end
|
||||
|
||||
it "should include a last name" do
|
||||
@person.profile = Factory.build(:profile, :person => @person, :last_name => nil)
|
||||
@person.profile.valid?.should be false
|
||||
@person.profile.last_name = "Smith"
|
||||
@person.profile.valid?.should be true
|
||||
end
|
||||
|
||||
it "should include a person" do
|
||||
profile = Factory.build(:profile, :person => nil)
|
||||
profile.valid?.should be false
|
||||
profile.person = @person
|
||||
profile.valid?.should be true
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Loading…
Reference in a new issue