post_spec now passes with mysql
This commit is contained in:
parent
58f757b91d
commit
5c21e220ff
17 changed files with 482 additions and 455 deletions
1
Gemfile
1
Gemfile
|
|
@ -9,7 +9,6 @@ gem "nokogiri", "1.4.3.1"
|
||||||
|
|
||||||
#Security
|
#Security
|
||||||
gem 'devise', '1.1.3'
|
gem 'devise', '1.1.3'
|
||||||
gem 'devise-mongo_mapper', :git => 'git://github.com/collectiveidea/devise-mongo_mapper'
|
|
||||||
gem 'devise_invitable','0.3.5'
|
gem 'devise_invitable','0.3.5'
|
||||||
|
|
||||||
#Authentication
|
#Authentication
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,6 @@ GIT
|
||||||
activesupport (>= 2.3.0)
|
activesupport (>= 2.3.0)
|
||||||
nokogiri (>= 1.3.3)
|
nokogiri (>= 1.3.3)
|
||||||
|
|
||||||
GIT
|
|
||||||
remote: git://github.com/collectiveidea/devise-mongo_mapper
|
|
||||||
revision: fa2f20310e0988295adc192255d3b1cedee1b412
|
|
||||||
specs:
|
|
||||||
devise-mongo_mapper (0.0.1)
|
|
||||||
devise (~> 1.1.0)
|
|
||||||
|
|
||||||
GIT
|
GIT
|
||||||
remote: git://github.com/iain/http_accept_language.git
|
remote: git://github.com/iain/http_accept_language.git
|
||||||
revision: 0b78aa7849fc90cf9e12586af162fa4c408a795d
|
revision: 0b78aa7849fc90cf9e12586af162fa4c408a795d
|
||||||
|
|
@ -390,7 +383,6 @@ DEPENDENCIES
|
||||||
cucumber-rails (= 0.3.2)
|
cucumber-rails (= 0.3.2)
|
||||||
database_cleaner (= 0.5.2)
|
database_cleaner (= 0.5.2)
|
||||||
devise (= 1.1.3)
|
devise (= 1.1.3)
|
||||||
devise-mongo_mapper!
|
|
||||||
devise_invitable (= 0.3.5)
|
devise_invitable (= 0.3.5)
|
||||||
em-http-request!
|
em-http-request!
|
||||||
em-websocket!
|
em-websocket!
|
||||||
|
|
|
||||||
|
|
@ -20,14 +20,14 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def aspects_with_post aspects, post
|
def aspects_with_post aspects, post
|
||||||
aspects.select do |a|
|
aspects.select do |aspect|
|
||||||
post.aspect_ids.include?(a.id)
|
aspect.posts.include?(post)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def aspects_without_post aspects, post
|
def aspects_without_post aspects, post
|
||||||
aspects.reject do |a|
|
aspects.reject do |aspect|
|
||||||
post.aspect_ids.include?(a.id)
|
aspect.posts.include?(post)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,10 @@ class Comment < ActiveRecord::Base
|
||||||
include Encryptable
|
include Encryptable
|
||||||
include Diaspora::Socketable
|
include Diaspora::Socketable
|
||||||
|
|
||||||
xml_reader :text
|
xml_accessor :text
|
||||||
xml_reader :diaspora_handle
|
xml_accessor :diaspora_handle
|
||||||
xml_reader :post_guid
|
xml_accessor :post_guid
|
||||||
xml_reader :guid
|
xml_accessor :guid
|
||||||
|
|
||||||
belongs_to :post
|
belongs_to :post
|
||||||
belongs_to :person
|
belongs_to :person
|
||||||
|
|
|
||||||
|
|
@ -3,23 +3,13 @@
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
class Photo < Post
|
class Photo < Post
|
||||||
require 'carrierwave/orm/mongomapper'
|
require 'carrierwave/orm/activerecord'
|
||||||
include MongoMapper::Document
|
|
||||||
mount_uploader :image, ImageUploader
|
mount_uploader :image, ImageUploader
|
||||||
|
|
||||||
xml_accessor :remote_photo
|
xml_accessor :remote_photo
|
||||||
xml_accessor :caption
|
xml_accessor :caption
|
||||||
xml_reader :status_message_id
|
xml_reader :status_message_id
|
||||||
|
|
||||||
key :caption, String
|
|
||||||
key :remote_photo_path
|
|
||||||
key :remote_photo_name
|
|
||||||
key :random_string
|
|
||||||
|
|
||||||
key :status_message_id, ObjectId
|
|
||||||
|
|
||||||
timestamps!
|
|
||||||
|
|
||||||
belongs_to :status_message
|
belongs_to :status_message
|
||||||
|
|
||||||
attr_accessible :caption, :pending
|
attr_accessible :caption, :pending
|
||||||
|
|
|
||||||
|
|
@ -2,33 +2,22 @@
|
||||||
# licensed under the Affero General Public License version 3 or later. See
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
class Post
|
class Post < ActiveRecord::Base
|
||||||
require File.join(Rails.root, 'lib/encryptable')
|
require File.join(Rails.root, 'lib/encryptable')
|
||||||
require File.join(Rails.root, 'lib/diaspora/web_socket')
|
require File.join(Rails.root, 'lib/diaspora/web_socket')
|
||||||
include MongoMapper::Document
|
|
||||||
include ApplicationHelper
|
include ApplicationHelper
|
||||||
include ROXML
|
include ROXML
|
||||||
include Diaspora::Webhooks
|
include Diaspora::Webhooks
|
||||||
|
|
||||||
xml_reader :_id
|
xml_reader :guid
|
||||||
xml_reader :diaspora_handle
|
xml_reader :diaspora_handle
|
||||||
xml_reader :public
|
xml_reader :public
|
||||||
xml_reader :created_at
|
xml_reader :created_at
|
||||||
|
|
||||||
|
has_many :comments, :order => 'created_at ASC'
|
||||||
key :public, Boolean, :default => false
|
has_and_belongs_to_many :aspects
|
||||||
|
|
||||||
key :diaspora_handle, String
|
|
||||||
key :user_refs, Integer, :default => 0
|
|
||||||
key :pending, Boolean, :default => false
|
|
||||||
key :aspect_ids, Array, :typecast => 'ObjectId'
|
|
||||||
|
|
||||||
many :comments, :class_name => 'Comment', :foreign_key => :post_id, :order => 'created_at ASC'
|
|
||||||
many :aspects, :in => :aspect_ids, :class_name => 'Aspect'
|
|
||||||
belongs_to :person, :class_name => 'Person'
|
belongs_to :person, :class_name => 'Person'
|
||||||
|
|
||||||
timestamps!
|
|
||||||
|
|
||||||
cattr_reader :per_page
|
cattr_reader :per_page
|
||||||
@@per_page = 10
|
@@per_page = 10
|
||||||
|
|
||||||
|
|
@ -40,7 +29,9 @@ class Post
|
||||||
def self.instantiate params
|
def self.instantiate params
|
||||||
new_post = self.new params.to_hash
|
new_post = self.new params.to_hash
|
||||||
new_post.person = params[:person]
|
new_post.person = params[:person]
|
||||||
new_post.aspect_ids = params[:aspect_ids]
|
params[:aspect_ids].each do |aspect_id|
|
||||||
|
new_post.aspects << Aspect.find_by_id(aspect_id)
|
||||||
|
end if params[:aspect_ids]
|
||||||
new_post.public = params[:public]
|
new_post.public = params[:public]
|
||||||
new_post.pending = params[:pending]
|
new_post.pending = params[:pending]
|
||||||
new_post.diaspora_handle = new_post.person.diaspora_handle
|
new_post.diaspora_handle = new_post.person.diaspora_handle
|
||||||
|
|
@ -62,7 +53,7 @@ class Post
|
||||||
|
|
||||||
protected
|
protected
|
||||||
def destroy_comments
|
def destroy_comments
|
||||||
comments.each{|c| c.destroy}
|
comments.each { |c| c.destroy }
|
||||||
end
|
end
|
||||||
|
|
||||||
def propogate_retraction
|
def propogate_retraction
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,9 @@ class StatusMessage < Post
|
||||||
|
|
||||||
validates_length_of :message, :maximum => 1000, :message => "please make your status messages less than 1000 characters"
|
validates_length_of :message, :maximum => 1000, :message => "please make your status messages less than 1000 characters"
|
||||||
xml_name :status_message
|
xml_name :status_message
|
||||||
xml_reader :message
|
xml_accessor :message
|
||||||
|
|
||||||
key :message, String
|
has_many :photos, :dependent => :destroy
|
||||||
many :photos, :class => Photo, :foreign_key => :status_message_id, :dependent => :destroy
|
|
||||||
validate :message_or_photos_present?
|
validate :message_or_photos_present?
|
||||||
|
|
||||||
attr_accessible :message
|
attr_accessible :message
|
||||||
|
|
@ -21,6 +20,7 @@ class StatusMessage < Post
|
||||||
before_save do
|
before_save do
|
||||||
get_youtube_title message
|
get_youtube_title message
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_activity
|
def to_activity
|
||||||
<<-XML
|
<<-XML
|
||||||
<entry>
|
<entry>
|
||||||
|
|
@ -35,7 +35,6 @@ class StatusMessage < Post
|
||||||
XML
|
XML
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def public_message(length, url = "")
|
def public_message(length, url = "")
|
||||||
space_for_url = url.blank? ? 0 : (url.length + 1)
|
space_for_url = url.blank? ? 0 : (url.length + 1)
|
||||||
truncated = truncate(self.message, :length => (length - space_for_url))
|
truncated = truncate(self.message, :length => (length - space_for_url))
|
||||||
|
|
@ -50,6 +49,5 @@ class StatusMessage < Post
|
||||||
errors[:base] << 'Status message requires a message or at least one photo'
|
errors[:base] << 'Status message requires a message or at least one photo'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,391 +7,367 @@ require File.join(Rails.root, 'lib/salmon/salmon')
|
||||||
require 'rest-client'
|
require 'rest-client'
|
||||||
|
|
||||||
class User < ActiveRecord::Base
|
class User < ActiveRecord::Base
|
||||||
# include MongoMapper::Document
|
include Diaspora::UserModules
|
||||||
# include Diaspora::UserModules
|
include Encryptor::Private
|
||||||
# include Encryptor::Private
|
|
||||||
#
|
devise :invitable, :database_authenticatable, :registerable,
|
||||||
# plugin MongoMapper::Devise
|
:recoverable, :rememberable, :trackable, :validatable,
|
||||||
#
|
:timeoutable
|
||||||
# devise :invitable, :database_authenticatable, :registerable,
|
|
||||||
# :recoverable, :rememberable, :trackable, :validatable,
|
|
||||||
# :timeoutable
|
|
||||||
#
|
|
||||||
# key :username
|
|
||||||
# key :serialized_private_key, String
|
|
||||||
# key :invites, Integer, :default => 5
|
|
||||||
# key :invitation_token, String
|
|
||||||
# key :invitation_sent_at, DateTime
|
|
||||||
# key :visible_post_ids, Array, :typecast => 'ObjectId'
|
# key :visible_post_ids, Array, :typecast => 'ObjectId'
|
||||||
# key :visible_person_ids, Array, :typecast => 'ObjectId'
|
# key :visible_person_ids, Array, :typecast => 'ObjectId'
|
||||||
#
|
#
|
||||||
# key :getting_started, Boolean, :default => true
|
before_validation :strip_and_downcase_username, :on => :create
|
||||||
# key :disable_mail, Boolean, :default => false
|
before_validation :set_current_language, :on => :create
|
||||||
#
|
|
||||||
# key :language, String
|
validates_presence_of :username
|
||||||
#
|
validates_uniqueness_of :username, :case_sensitive => false
|
||||||
# before_validation :strip_and_downcase_username, :on => :create
|
validates_format_of :username, :with => /\A[A-Za-z0-9_]+\z/
|
||||||
# before_validation :set_current_language, :on => :create
|
validates_length_of :username, :maximum => 32
|
||||||
#
|
validates_inclusion_of :language, :in => AVAILABLE_LANGUAGE_CODES
|
||||||
# validates_presence_of :username
|
|
||||||
# validates_uniqueness_of :username, :case_sensitive => false
|
validates_presence_of :person, :unless => proc {|user| user.invitation_token.present?}
|
||||||
# validates_format_of :username, :with => /\A[A-Za-z0-9_]+\z/
|
validates_associated :person
|
||||||
# validates_length_of :username, :maximum => 32
|
|
||||||
# validates_inclusion_of :language, :in => AVAILABLE_LANGUAGE_CODES
|
has_one :person, :foreign_key => :owner_id
|
||||||
#
|
|
||||||
# validates_presence_of :person, :unless => proc {|user| user.invitation_token.present?}
|
has_many :invitations_from_me, :class_name => 'Invitation', :foreign_key => :sender_id
|
||||||
# validates_associated :person
|
has_many :invitations_to_me, :class_name => 'Invitation', :foreign_key => :recipient_id
|
||||||
#
|
has_many :aspects, :dependent => :destroy
|
||||||
# one :person, :class => Person, :foreign_key => :owner_id
|
has_many :aspect_memberships, :through => :aspects
|
||||||
#
|
|
||||||
# many :invitations_from_me, :class => Invitation, :foreign_key => :from_id
|
|
||||||
# many :invitations_to_me, :class => Invitation, :foreign_key => :to_id
|
|
||||||
# has_many :aspects, :dependent => :destroy
|
|
||||||
# has_many :aspect_memberships, :through => :aspects
|
|
||||||
# many :visible_people, :in => :visible_person_ids, :class => Person # One of these needs to go
|
# many :visible_people, :in => :visible_person_ids, :class => Person # One of these needs to go
|
||||||
# many :raw_visible_posts, :in => :visible_post_ids, :class => Post
|
# many :raw_visible_posts, :in => :visible_post_ids, :class => Post
|
||||||
#
|
|
||||||
# many :services, :class => Service
|
# many :services, :class => Service
|
||||||
# timestamps!
|
|
||||||
# #after_create :seed_aspects
|
before_destroy :disconnect_everyone, :remove_person
|
||||||
#
|
before_save do
|
||||||
# before_destroy :disconnect_everyone, :remove_person
|
person.save if person
|
||||||
# before_save do
|
end
|
||||||
# person.save if person
|
|
||||||
# end
|
attr_accessible :getting_started, :password, :password_confirmation, :language, :disable_mail
|
||||||
#
|
|
||||||
# attr_accessible :getting_started, :password, :password_confirmation, :language, :disable_mail
|
def strip_and_downcase_username
|
||||||
#
|
if username.present?
|
||||||
# def strip_and_downcase_username
|
username.strip!
|
||||||
# if username.present?
|
username.downcase!
|
||||||
# username.strip!
|
end
|
||||||
# username.downcase!
|
end
|
||||||
# end
|
|
||||||
# end
|
def set_current_language
|
||||||
#
|
self.language = I18n.locale.to_s if self.language.blank?
|
||||||
# def set_current_language
|
end
|
||||||
# self.language = I18n.locale.to_s if self.language.blank?
|
|
||||||
# end
|
def self.find_for_authentication(conditions={})
|
||||||
#
|
conditions[:username] = conditions[:username].downcase
|
||||||
# def self.find_for_authentication(conditions={})
|
if conditions[:username] =~ /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i # email regex
|
||||||
# conditions[:username] = conditions[:username].downcase
|
conditions[:email] = conditions.delete(:username)
|
||||||
# if conditions[:username] =~ /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i # email regex
|
end
|
||||||
# conditions[:email] = conditions.delete(:username)
|
super
|
||||||
# end
|
end
|
||||||
# super
|
|
||||||
# end
|
######### Aspects ######################
|
||||||
#
|
def drop_aspect(aspect)
|
||||||
# ######## Making things work ########
|
if aspect.contacts.count == 0
|
||||||
# key :email, String
|
aspect.destroy
|
||||||
#
|
else
|
||||||
# def method_missing(method, *args)
|
raise "Aspect not empty"
|
||||||
# self.person.send(method, *args) if self.person
|
end
|
||||||
# end
|
end
|
||||||
#
|
|
||||||
# ######### Aspects ######################
|
def move_contact(person, to_aspect, from_aspect)
|
||||||
# def drop_aspect(aspect)
|
contact = contact_for(person)
|
||||||
# if aspect.contacts.count == 0
|
if to_aspect == from_aspect
|
||||||
# aspect.destroy
|
true
|
||||||
# else
|
elsif add_contact_to_aspect(contact, to_aspect)
|
||||||
# raise "Aspect not empty"
|
delete_person_from_aspect(person.id, from_aspect.id)
|
||||||
# end
|
end
|
||||||
# end
|
end
|
||||||
#
|
|
||||||
# def move_contact(person, to_aspect, from_aspect)
|
def add_contact_to_aspect(contact, aspect)
|
||||||
# contact = contact_for(person)
|
return true if contact.aspect_ids.include?(aspect.id)
|
||||||
# if to_aspect == from_aspect
|
contact.aspects << aspect
|
||||||
# true
|
contact.save!
|
||||||
# elsif add_contact_to_aspect(contact, to_aspect)
|
end
|
||||||
# delete_person_from_aspect(person.id, from_aspect.id)
|
|
||||||
# end
|
def delete_person_from_aspect(person_id, aspect_id, opts = {})
|
||||||
# end
|
aspect = Aspect.find(aspect_id)
|
||||||
#
|
raise "Can not delete a person from an aspect you do not own" unless aspect.user == self
|
||||||
# def add_contact_to_aspect(contact, aspect)
|
contact = contact_for Person.find(person_id)
|
||||||
# return true if contact.aspect_ids.include?(aspect.id)
|
|
||||||
# contact.aspects << aspect
|
if opts[:force] || contact.aspect_ids.count > 1
|
||||||
# contact.save!
|
contact.aspect_ids.delete aspect.id
|
||||||
# end
|
contact.save!
|
||||||
#
|
aspect.save!
|
||||||
# def delete_person_from_aspect(person_id, aspect_id, opts = {})
|
else
|
||||||
# aspect = Aspect.find(aspect_id)
|
raise "Can not delete a person from last aspect"
|
||||||
# raise "Can not delete a person from an aspect you do not own" unless aspect.user == self
|
end
|
||||||
# contact = contact_for Person.find(person_id)
|
end
|
||||||
#
|
|
||||||
# if opts[:force] || contact.aspect_ids.count > 1
|
######## Posting ########
|
||||||
# contact.aspect_ids.delete aspect.id
|
def build_post(class_name, opts = {})
|
||||||
# contact.save!
|
opts[:person] = self.person
|
||||||
# aspect.save!
|
opts[:diaspora_handle] = opts[:person].diaspora_handle
|
||||||
# else
|
|
||||||
# raise "Can not delete a person from last aspect"
|
model_class = class_name.to_s.camelize.constantize
|
||||||
# end
|
model_class.instantiate(opts)
|
||||||
# end
|
end
|
||||||
#
|
|
||||||
# ######## Posting ########
|
def dispatch_post(post, opts = {})
|
||||||
# def build_post(class_name, opts = {})
|
aspect_ids = opts.delete(:to)
|
||||||
# opts[:person] = self.person
|
|
||||||
# opts[:diaspora_handle] = opts[:person].diaspora_handle
|
Rails.logger.info("event=dispatch user=#{diaspora_handle} post=#{post.id.to_s}")
|
||||||
#
|
push_to_aspects(post, aspects_from_ids(aspect_ids))
|
||||||
# model_class = class_name.to_s.camelize.constantize
|
Resque.enqueue(Jobs::PostToServices, self.id, post.id, opts[:url]) if post.public
|
||||||
# model_class.instantiate(opts)
|
end
|
||||||
# end
|
|
||||||
#
|
def post_to_services(post, url)
|
||||||
# def dispatch_post(post, opts = {})
|
if post.respond_to?(:message)
|
||||||
# aspect_ids = opts.delete(:to)
|
self.services.each do |service|
|
||||||
#
|
service.post(post, url)
|
||||||
# Rails.logger.info("event=dispatch user=#{diaspora_handle} post=#{post.id.to_s}")
|
end
|
||||||
# push_to_aspects(post, aspects_from_ids(aspect_ids))
|
end
|
||||||
# Resque.enqueue(Jobs::PostToServices, self.id, post.id, opts[:url]) if post.public
|
end
|
||||||
# end
|
|
||||||
#
|
def post_to_hub(post)
|
||||||
# def post_to_services(post, url)
|
Rails.logger.debug("event=post_to_service type=pubsub sender_handle=#{self.diaspora_handle}")
|
||||||
# if post.respond_to?(:message)
|
EventMachine::PubSubHubbub.new(APP_CONFIG[:pubsub_server]).publish self.public_url
|
||||||
# self.services.each do |service|
|
end
|
||||||
# service.post(post, url)
|
|
||||||
# end
|
def update_post(post, post_hash = {})
|
||||||
# end
|
if self.owns? post
|
||||||
# end
|
post.update_attributes(post_hash)
|
||||||
#
|
aspects = aspects_with_post(post.id)
|
||||||
# def post_to_hub(post)
|
self.push_to_aspects(post, aspects)
|
||||||
# Rails.logger.debug("event=post_to_service type=pubsub sender_handle=#{self.diaspora_handle}")
|
end
|
||||||
# EventMachine::PubSubHubbub.new(APP_CONFIG[:pubsub_server]).publish self.public_url
|
end
|
||||||
# end
|
|
||||||
#
|
def add_to_streams(post, aspect_ids)
|
||||||
# def update_post(post, post_hash = {})
|
self.raw_visible_posts << post
|
||||||
# if self.owns? post
|
self.save
|
||||||
# post.update_attributes(post_hash)
|
|
||||||
# aspects = aspects_with_post(post.id)
|
post.socket_to_uid(id, :aspect_ids => aspect_ids) if post.respond_to? :socket_to_uid
|
||||||
# self.push_to_aspects(post, aspects)
|
target_aspects = aspects_from_ids(aspect_ids)
|
||||||
# end
|
target_aspects.each do |aspect|
|
||||||
# end
|
aspect.posts << post
|
||||||
#
|
aspect.save
|
||||||
# def add_to_streams(post, aspect_ids)
|
end
|
||||||
# self.raw_visible_posts << post
|
end
|
||||||
# self.save
|
|
||||||
#
|
def aspects_from_ids(aspect_ids)
|
||||||
# post.socket_to_uid(id, :aspect_ids => aspect_ids) if post.respond_to? :socket_to_uid
|
if aspect_ids == "all" || aspect_ids == :all
|
||||||
# target_aspects = aspects_from_ids(aspect_ids)
|
self.aspects
|
||||||
# target_aspects.each do |aspect|
|
else
|
||||||
# aspect.posts << post
|
if aspect_ids.respond_to? :to_id
|
||||||
# aspect.save
|
aspect_ids = [aspect_ids]
|
||||||
# end
|
end
|
||||||
# end
|
aspect_ids.map!{ |x| x.to_id }
|
||||||
#
|
aspects.all(:id.in => aspect_ids)
|
||||||
# def aspects_from_ids(aspect_ids)
|
end
|
||||||
# if aspect_ids == "all" || aspect_ids == :all
|
end
|
||||||
# self.aspects
|
|
||||||
# else
|
def push_to_aspects(post, aspects)
|
||||||
# if aspect_ids.respond_to? :to_id
|
#send to the aspects
|
||||||
# aspect_ids = [aspect_ids]
|
target_aspect_ids = aspects.map {|a| a.id}
|
||||||
# end
|
|
||||||
# aspect_ids.map!{ |x| x.to_id }
|
target_contacts = Contact.all(:aspect_ids.in => target_aspect_ids, :pending => false)
|
||||||
# aspects.all(:id.in => aspect_ids)
|
|
||||||
# end
|
post_to_hub(post) if post.respond_to?(:public) && post.public
|
||||||
# end
|
push_to_people(post, self.person_objects(target_contacts))
|
||||||
#
|
end
|
||||||
# def push_to_aspects(post, aspects)
|
|
||||||
# #send to the aspects
|
def push_to_people(post, people)
|
||||||
# target_aspect_ids = aspects.map {|a| a.id}
|
salmon = salmon(post)
|
||||||
#
|
people.each do |person|
|
||||||
# target_contacts = Contact.all(:aspect_ids.in => target_aspect_ids, :pending => false)
|
push_to_person(salmon, post, person)
|
||||||
#
|
end
|
||||||
# post_to_hub(post) if post.respond_to?(:public) && post.public
|
end
|
||||||
# push_to_people(post, self.person_objects(target_contacts))
|
|
||||||
# end
|
def push_to_person(salmon, post, person)
|
||||||
#
|
person.reload # Sadly, we need this for Ruby 1.9.
|
||||||
# def push_to_people(post, people)
|
# person.owner will always return a ProxyObject.
|
||||||
# salmon = salmon(post)
|
# calling nil? performs a necessary evaluation.
|
||||||
# people.each do |person|
|
if person.owner_id
|
||||||
# push_to_person(salmon, post, person)
|
Rails.logger.info("event=push_to_person route=local sender=#{self.diaspora_handle} recipient=#{person.diaspora_handle} payload_type=#{post.class}")
|
||||||
# end
|
|
||||||
# end
|
if post.is_a?(Post) || post.is_a?(Comment)
|
||||||
#
|
Resque.enqueue(Jobs::ReceiveLocal, person.owner_id, self.person.id, post.class.to_s, post.id)
|
||||||
# def push_to_person(salmon, post, person)
|
else
|
||||||
# person.reload # Sadly, we need this for Ruby 1.9.
|
Resque.enqueue(Jobs::Receive, person.owner_id, post.to_diaspora_xml, self.person.id)
|
||||||
# # person.owner will always return a ProxyObject.
|
end
|
||||||
# # calling nil? performs a necessary evaluation.
|
else
|
||||||
# if person.owner_id
|
xml = salmon.xml_for person
|
||||||
# Rails.logger.info("event=push_to_person route=local sender=#{self.diaspora_handle} recipient=#{person.diaspora_handle} payload_type=#{post.class}")
|
Rails.logger.info("event=push_to_person route=remote sender=#{self.diaspora_handle} recipient=#{person.diaspora_handle} payload_type=#{post.class}")
|
||||||
#
|
MessageHandler.add_post_request(person.receive_url, xml)
|
||||||
# if post.is_a?(Post) || post.is_a?(Comment)
|
end
|
||||||
# Resque.enqueue(Jobs::ReceiveLocal, person.owner_id, self.person.id, post.class.to_s, post.id)
|
end
|
||||||
# else
|
|
||||||
# Resque.enqueue(Jobs::Receive, person.owner_id, post.to_diaspora_xml, self.person.id)
|
def salmon(post)
|
||||||
# end
|
created_salmon = Salmon::SalmonSlap.create(self, post.to_diaspora_xml)
|
||||||
# else
|
created_salmon
|
||||||
# xml = salmon.xml_for person
|
end
|
||||||
# Rails.logger.info("event=push_to_person route=remote sender=#{self.diaspora_handle} recipient=#{person.diaspora_handle} payload_type=#{post.class}")
|
|
||||||
# MessageHandler.add_post_request(person.receive_url, xml)
|
######## Commenting ########
|
||||||
# end
|
def build_comment(text, options = {})
|
||||||
# end
|
comment = Comment.new(:person_id => self.person.id,
|
||||||
#
|
:text => text,
|
||||||
# def salmon(post)
|
:post => options[:on])
|
||||||
# created_salmon = Salmon::SalmonSlap.create(self, post.to_diaspora_xml)
|
|
||||||
# created_salmon
|
#sign comment as commenter
|
||||||
# end
|
comment.creator_signature = comment.sign_with_key(self.encryption_key)
|
||||||
#
|
|
||||||
# ######## Commenting ########
|
if !comment.post_id.blank? && person.owns?(comment.post)
|
||||||
# def build_comment(text, options = {})
|
#sign comment as post owner
|
||||||
# comment = Comment.new(:person_id => self.person.id,
|
comment.post_creator_signature = comment.sign_with_key(self.encryption_key)
|
||||||
# :diaspora_handle => self.person.diaspora_handle,
|
end
|
||||||
# :text => text,
|
|
||||||
# :post => options[:on])
|
comment
|
||||||
#
|
end
|
||||||
# #sign comment as commenter
|
|
||||||
# comment.creator_signature = comment.sign_with_key(self.encryption_key)
|
def dispatch_comment(comment)
|
||||||
#
|
if person.owns? comment.post
|
||||||
# if !comment.post_id.blank? && owns?(comment.post)
|
#push DOWNSTREAM (to original audience)
|
||||||
# #sign comment as post owner
|
Rails.logger.info "event=dispatch_comment direction=downstream user=#{self.person.diaspora_handle} comment=#{comment.id}"
|
||||||
# comment.post_creator_signature = comment.sign_with_key(self.encryption_key)
|
aspects = comment.post.aspects
|
||||||
# end
|
|
||||||
#
|
#just socket to local users, as the comment has already
|
||||||
# comment
|
#been associated and saved by post owner
|
||||||
# end
|
# (we'll push to all of their aspects for now, the comment won't
|
||||||
#
|
# show up via js where corresponding posts are not present)
|
||||||
# def dispatch_comment(comment)
|
|
||||||
# if owns? comment.post
|
people_in_aspects(aspects, :type => 'local').each do |person|
|
||||||
# #push DOWNSTREAM (to original audience)
|
comment.socket_to_uid(person.owner_id, :aspect_ids => 'all')
|
||||||
# Rails.logger.info "event=dispatch_comment direction=downstream user=#{self.diaspora_handle} comment=#{comment.id}"
|
end
|
||||||
# aspects = aspects_with_post(comment.post_id)
|
|
||||||
#
|
#push to remote people
|
||||||
# #just socket to local users, as the comment has already
|
push_to_people(comment, people_in_aspects(aspects, :type => 'remote'))
|
||||||
# #been associated and saved by post owner
|
|
||||||
# # (we'll push to all of their aspects for now, the comment won't
|
elsif owns? comment
|
||||||
# # show up via js where corresponding posts are not present)
|
#push UPSTREAM (to poster)
|
||||||
#
|
Rails.logger.info "event=dispatch_comment direction=upstream user=#{self.diaspora_handle} comment=#{comment.id}"
|
||||||
# people_in_aspects(aspects, :type => 'local').each do |person|
|
push_to_people comment, [comment.post.person]
|
||||||
# comment.socket_to_uid(person.owner_id, :aspect_ids => 'all')
|
end
|
||||||
# end
|
end
|
||||||
#
|
|
||||||
# #push to remote people
|
######### Mailer #######################
|
||||||
# push_to_people(comment, people_in_aspects(aspects, :type => 'remote'))
|
def mail(job, *args)
|
||||||
#
|
unless self.disable_mail
|
||||||
# elsif owns? comment
|
Resque.enqueue(job, *args)
|
||||||
# #push UPSTREAM (to poster)
|
end
|
||||||
# Rails.logger.info "event=dispatch_comment direction=upstream user=#{self.diaspora_handle} comment=#{comment.id}"
|
end
|
||||||
# push_to_people comment, [comment.post.person]
|
|
||||||
# end
|
######### Posts and Such ###############
|
||||||
# end
|
def retract(post)
|
||||||
#
|
aspects = post.aspects
|
||||||
# ######### Mailer #######################
|
|
||||||
# def mail(job, *args)
|
post.unsocket_from_uid(self.id, :aspect_ids => aspects.map { |a| a.id.to_s }) if post.respond_to? :unsocket_from_uid
|
||||||
# unless self.disable_mail
|
retraction = Retraction.for(post)
|
||||||
# Resque.enqueue(job, *args)
|
push_to_people retraction, people_in_aspects(aspects)
|
||||||
# end
|
retraction
|
||||||
# end
|
end
|
||||||
#
|
|
||||||
# ######### Posts and Such ###############
|
########### Profile ######################
|
||||||
# def retract(post)
|
def update_profile(params)
|
||||||
# aspect_ids = aspects_with_post(post.id)
|
if params[:photo]
|
||||||
# aspect_ids.map! { |aspect| aspect.id.to_s }
|
params[:photo].update_attributes(:pending => false) if params[:photo].pending
|
||||||
#
|
params[:image_url] = params[:photo].url(:thumb_large)
|
||||||
# post.unsocket_from_uid(self.id, :aspect_ids => aspect_ids) if post.respond_to? :unsocket_from_uid
|
params[:image_url_medium] = params[:photo].url(:thumb_medium)
|
||||||
# retraction = Retraction.for(post)
|
params[:image_url_small] = params[:photo].url(:thumb_small)
|
||||||
# push_to_people retraction, people_in_aspects(aspects_with_post(post.id))
|
end
|
||||||
# retraction
|
if self.person.profile.update_attributes(params)
|
||||||
# end
|
push_to_people profile, self.person_objects(contacts(:pending => false))
|
||||||
#
|
true
|
||||||
# ########### Profile ######################
|
else
|
||||||
# def update_profile(params)
|
false
|
||||||
# if params[:photo]
|
end
|
||||||
# params[:photo].update_attributes(:pending => false) if params[:photo].pending
|
end
|
||||||
# params[:image_url] = params[:photo].url(:thumb_large)
|
|
||||||
# params[:image_url_medium] = params[:photo].url(:thumb_medium)
|
###Invitations############
|
||||||
# params[:image_url_small] = params[:photo].url(:thumb_small)
|
def invite_user(email, aspect_id, invite_message = "")
|
||||||
# end
|
aspect_object = Aspect.first(:user_id => self.id, :id => aspect_id)
|
||||||
# if self.person.profile.update_attributes(params)
|
if aspect_object
|
||||||
# push_to_people profile, self.person_objects(contacts(:pending => false))
|
Invitation.invite(:email => email,
|
||||||
# true
|
:from => self,
|
||||||
# else
|
:into => aspect_object,
|
||||||
# false
|
:message => invite_message)
|
||||||
# end
|
else
|
||||||
# end
|
false
|
||||||
#
|
end
|
||||||
# ###Invitations############
|
end
|
||||||
# def invite_user(email, aspect_id, invite_message = "")
|
|
||||||
# aspect_object = Aspect.first(:user_id => self.id, :id => aspect_id)
|
def accept_invitation!(opts = {})
|
||||||
# if aspect_object
|
if self.invited?
|
||||||
# Invitation.invite(:email => email,
|
log_string = "event=invitation_accepted username=#{opts[:username]} "
|
||||||
# :from => self,
|
log_string << "inviter=#{invitations_to_me.first.from.diaspora_handle}" if invitations_to_me.first
|
||||||
# :into => aspect_object,
|
Rails.logger.info log_string
|
||||||
# :message => invite_message)
|
self.setup(opts)
|
||||||
# else
|
self.invitation_token = nil
|
||||||
# false
|
self.password = opts[:password]
|
||||||
# end
|
self.password_confirmation = opts[:password_confirmation]
|
||||||
# end
|
self.save!
|
||||||
#
|
invitations_to_me.each{|invitation| invitation.to_request!}
|
||||||
# def accept_invitation!(opts = {})
|
|
||||||
# if self.invited?
|
self.reload # Because to_request adds a request and saves elsewhere
|
||||||
# log_string = "event=invitation_accepted username=#{opts[:username]} "
|
self
|
||||||
# log_string << "inviter=#{invitations_to_me.first.from.diaspora_handle}" if invitations_to_me.first
|
end
|
||||||
# Rails.logger.info log_string
|
end
|
||||||
# self.setup(opts)
|
|
||||||
# self.invitation_token = nil
|
###Helpers############
|
||||||
# self.password = opts[:password]
|
def self.build(opts = {})
|
||||||
# self.password_confirmation = opts[:password_confirmation]
|
u = User.new(opts)
|
||||||
# self.save!
|
u.email = opts[:email]
|
||||||
# invitations_to_me.each{|invitation| invitation.to_request!}
|
u.setup(opts)
|
||||||
#
|
u
|
||||||
# self.reload # Because to_request adds a request and saves elsewhere
|
end
|
||||||
# self
|
|
||||||
# end
|
def setup(opts)
|
||||||
# end
|
self.username = opts[:username]
|
||||||
#
|
self.valid?
|
||||||
# ###Helpers############
|
errors = self.errors
|
||||||
# def self.build(opts = {})
|
errors.delete :person
|
||||||
# u = User.new(opts)
|
return if errors.size > 0
|
||||||
# u.email = opts[:email]
|
|
||||||
# u.setup(opts)
|
opts[:person] ||= {}
|
||||||
# u
|
opts[:person][:profile] ||= Profile.new
|
||||||
# end
|
|
||||||
#
|
self.person = Person.new(opts[:person])
|
||||||
# def setup(opts)
|
self.person.diaspora_handle = "#{opts[:username]}@#{APP_CONFIG[:pod_uri].host}"
|
||||||
# self.username = opts[:username]
|
self.person.url = APP_CONFIG[:pod_url]
|
||||||
# self.valid?
|
|
||||||
# errors = self.errors
|
|
||||||
# errors.delete :person
|
self.serialized_private_key ||= User.generate_key
|
||||||
# return if errors.size > 0
|
self.person.serialized_public_key = OpenSSL::PKey::RSA.new(self.serialized_private_key).public_key
|
||||||
#
|
|
||||||
# opts[:person] ||= {}
|
self
|
||||||
# opts[:person][:profile] ||= Profile.new
|
end
|
||||||
#
|
|
||||||
# self.person = Person.new(opts[:person])
|
def seed_aspects
|
||||||
# self.person.diaspora_handle = "#{opts[:username]}@#{APP_CONFIG[:pod_uri].host}"
|
self.aspects.create(:name => I18n.t('aspects.seed.family'))
|
||||||
# self.person.url = APP_CONFIG[:pod_url]
|
self.aspects.create(:name => I18n.t('aspects.seed.work'))
|
||||||
#
|
end
|
||||||
#
|
|
||||||
# self.serialized_private_key ||= User.generate_key
|
def self.generate_key
|
||||||
# self.person.serialized_public_key = OpenSSL::PKey::RSA.new(self.serialized_private_key).public_key
|
key_size = (Rails.env == 'test' ? 512 : 4096)
|
||||||
#
|
OpenSSL::PKey::RSA::generate key_size
|
||||||
# self
|
end
|
||||||
# end
|
|
||||||
#
|
def encryption_key
|
||||||
# def seed_aspects
|
OpenSSL::PKey::RSA.new(serialized_private_key)
|
||||||
# self.aspects.create(:name => I18n.t('aspects.seed.family'))
|
end
|
||||||
# self.aspects.create(:name => I18n.t('aspects.seed.work'))
|
|
||||||
# end
|
protected
|
||||||
#
|
|
||||||
# def self.generate_key
|
def remove_person
|
||||||
# key_size = (Rails.env == 'test' ? 512 : 4096)
|
self.person.destroy
|
||||||
# OpenSSL::PKey::RSA::generate key_size
|
end
|
||||||
# end
|
|
||||||
#
|
def disconnect_everyone
|
||||||
# def encryption_key
|
contacts.each { |contact|
|
||||||
# OpenSSL::PKey::RSA.new(serialized_private_key)
|
if contact.person.owner?
|
||||||
# end
|
contact.person.owner.disconnected_by self.person
|
||||||
#
|
else
|
||||||
# protected
|
self.disconnect contact
|
||||||
#
|
end
|
||||||
# def remove_person
|
}
|
||||||
# self.person.destroy
|
end
|
||||||
# end
|
|
||||||
#
|
|
||||||
# def disconnect_everyone
|
|
||||||
# contacts.each { |contact|
|
|
||||||
# if contact.person.owner?
|
|
||||||
# contact.person.owner.disconnected_by self.person
|
|
||||||
# else
|
|
||||||
# self.disconnect contact
|
|
||||||
# end
|
|
||||||
# }
|
|
||||||
# end
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,6 @@ module Diaspora
|
||||||
|
|
||||||
# Configure generators values. Many other options are available, be sure to check the documentation.
|
# Configure generators values. Many other options are available, be sure to check the documentation.
|
||||||
config.generators do |g|
|
config.generators do |g|
|
||||||
g.orm :mongo_mapper
|
|
||||||
g.template_engine :haml
|
g.template_engine :haml
|
||||||
g.test_framework :rspec
|
g.test_framework :rspec
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ Devise.setup do |config|
|
||||||
# ==> ORM configuration
|
# ==> ORM configuration
|
||||||
# Load and configure the ORM. Supports :active_record (default), :mongoid
|
# Load and configure the ORM. Supports :active_record (default), :mongoid
|
||||||
# (bson_ext recommended) and :data_mapper (experimental).
|
# (bson_ext recommended) and :data_mapper (experimental).
|
||||||
require 'devise/orm/mongo_mapper'
|
require 'devise/orm/active_record'
|
||||||
|
|
||||||
# ==> Configuration for any authentication mechanism
|
# ==> Configuration for any authentication mechanism
|
||||||
# Configure which keys are used when authenticating an user. By default is
|
# Configure which keys are used when authenticating an user. By default is
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,44 @@ class CreateSchema < ActiveRecord::Migration
|
||||||
add_index :profiles, [:last_name, :searchable]
|
add_index :profiles, [:last_name, :searchable]
|
||||||
add_index :profiles, [:first_name, :last_name, :searchable]
|
add_index :profiles, [:first_name, :last_name, :searchable]
|
||||||
add_index :profiles, :person_id
|
add_index :profiles, :person_id
|
||||||
|
|
||||||
|
create_table :posts do |t|
|
||||||
|
t.boolean :public, :default => false
|
||||||
|
t.string :diaspora_handle
|
||||||
|
t.boolean :pending
|
||||||
|
t.integer :user_refs
|
||||||
|
t.string :type
|
||||||
|
t.text :message
|
||||||
|
t.integer :status_message_id
|
||||||
|
t.text :caption
|
||||||
|
t.text :remote_photo_path
|
||||||
|
t.string :remote_photo_name
|
||||||
|
t.string :random_string
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
add_index :posts, :type
|
||||||
|
|
||||||
|
create_table :users do |t|
|
||||||
|
t.string :username
|
||||||
|
t.text :serialized_private_key
|
||||||
|
t.integer :invites
|
||||||
|
t.boolean :getting_started, :default => true
|
||||||
|
t.boolean :disable_mail, :default => false
|
||||||
|
t.string :language
|
||||||
|
t.string :email
|
||||||
|
|
||||||
|
t.database_authenticatable
|
||||||
|
t.invitable
|
||||||
|
t.recoverable
|
||||||
|
t.rememberable
|
||||||
|
t.trackable
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
add_index :users, :username, :unique => true
|
||||||
|
add_index :users, :email, :unique => true
|
||||||
|
add_index :users, :invitation_token
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.down
|
def self.down
|
||||||
|
|
|
||||||
46
db/schema.rb
46
db/schema.rb
|
|
@ -94,6 +94,24 @@ ActiveRecord::Schema.define(:version => 0) do
|
||||||
add_index "people", ["guid"], :name => "index_people_on_guid", :unique => true
|
add_index "people", ["guid"], :name => "index_people_on_guid", :unique => true
|
||||||
add_index "people", ["owner_id"], :name => "index_people_on_owner_id", :unique => true
|
add_index "people", ["owner_id"], :name => "index_people_on_owner_id", :unique => true
|
||||||
|
|
||||||
|
create_table "posts", :force => true do |t|
|
||||||
|
t.boolean "public", :default => false
|
||||||
|
t.string "diaspora_handle"
|
||||||
|
t.boolean "pending"
|
||||||
|
t.integer "user_refs"
|
||||||
|
t.string "type"
|
||||||
|
t.text "message"
|
||||||
|
t.integer "status_message_id"
|
||||||
|
t.text "caption"
|
||||||
|
t.text "remote_photo_path"
|
||||||
|
t.string "remote_photo_name"
|
||||||
|
t.string "random_string"
|
||||||
|
t.datetime "created_at"
|
||||||
|
t.datetime "updated_at"
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index "posts", ["type"], :name => "index_posts_on_type"
|
||||||
|
|
||||||
create_table "profiles", :force => true do |t|
|
create_table "profiles", :force => true do |t|
|
||||||
t.string "diaspora_handle"
|
t.string "diaspora_handle"
|
||||||
t.string "first_name"
|
t.string "first_name"
|
||||||
|
|
@ -115,4 +133,32 @@ ActiveRecord::Schema.define(:version => 0) do
|
||||||
add_index "profiles", ["last_name", "searchable"], :name => "index_profiles_on_last_name_and_searchable"
|
add_index "profiles", ["last_name", "searchable"], :name => "index_profiles_on_last_name_and_searchable"
|
||||||
add_index "profiles", ["person_id"], :name => "index_profiles_on_person_id"
|
add_index "profiles", ["person_id"], :name => "index_profiles_on_person_id"
|
||||||
|
|
||||||
|
create_table "users", :force => true do |t|
|
||||||
|
t.string "username"
|
||||||
|
t.text "serialized_private_key"
|
||||||
|
t.integer "invites"
|
||||||
|
t.boolean "getting_started", :default => true
|
||||||
|
t.boolean "disable_mail", :default => false
|
||||||
|
t.string "language"
|
||||||
|
t.string "email", :default => "", :null => false
|
||||||
|
t.string "encrypted_password", :limit => 128, :default => "", :null => false
|
||||||
|
t.string "password_salt", :default => "", :null => false
|
||||||
|
t.string "invitation_token", :limit => 20
|
||||||
|
t.datetime "invitation_sent_at"
|
||||||
|
t.string "reset_password_token"
|
||||||
|
t.string "remember_token"
|
||||||
|
t.datetime "remember_created_at"
|
||||||
|
t.integer "sign_in_count", :default => 0
|
||||||
|
t.datetime "current_sign_in_at"
|
||||||
|
t.datetime "last_sign_in_at"
|
||||||
|
t.string "current_sign_in_ip"
|
||||||
|
t.string "last_sign_in_ip"
|
||||||
|
t.datetime "created_at"
|
||||||
|
t.datetime "updated_at"
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
|
||||||
|
add_index "users", ["invitation_token"], :name => "index_users_on_invitation_token"
|
||||||
|
add_index "users", ["username"], :name => "index_users_on_username", :unique => true
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ module Diaspora
|
||||||
|
|
||||||
def people_in_aspects(aspects, opts={})
|
def people_in_aspects(aspects, opts={})
|
||||||
person_ids = contacts_in_aspects(aspects).collect{|contact| contact.person_id}
|
person_ids = contacts_in_aspects(aspects).collect{|contact| contact.person_id}
|
||||||
people = Person.all(:id.in => person_ids)
|
people = Person.where(:id => person_ids)
|
||||||
|
|
||||||
if opts[:type] == 'remote'
|
if opts[:type] == 'remote'
|
||||||
people.delete_if{ |p| !p.owner.blank? }
|
people.delete_if{ |p| !p.owner.blank? }
|
||||||
|
|
@ -71,14 +71,9 @@ module Diaspora
|
||||||
end
|
end
|
||||||
|
|
||||||
def aspect_by_id( id )
|
def aspect_by_id( id )
|
||||||
id = id.to_id
|
|
||||||
aspects.detect{|x| x.id == id }
|
aspects.detect{|x| x.id == id }
|
||||||
end
|
end
|
||||||
|
|
||||||
def aspects_with_post( id )
|
|
||||||
self.aspects.find_all_by_post_ids( id.to_id )
|
|
||||||
end
|
|
||||||
|
|
||||||
def aspects_with_person person
|
def aspects_with_person person
|
||||||
contact_for(person).aspects
|
contact_for(person).aspects
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ Factory.define :user do |u|
|
||||||
u.serialized_private_key OpenSSL::PKey::RSA.generate(1024).export
|
u.serialized_private_key OpenSSL::PKey::RSA.generate(1024).export
|
||||||
u.after_build do |user|
|
u.after_build do |user|
|
||||||
user.person = Factory.build(:person, :profile => Factory.create(:profile),
|
user.person = Factory.build(:person, :profile => Factory.create(:profile),
|
||||||
:owner_id => user._id,
|
:owner_id => user.id,
|
||||||
:serialized_public_key => user.encryption_key.public_key.export,
|
:serialized_public_key => user.encryption_key.public_key.export,
|
||||||
:diaspora_handle => "#{user.username}@#{APP_CONFIG[:pod_url].gsub(/(https?:|www\.)\/\//, '').chop!}")
|
:diaspora_handle => "#{user.username}@#{APP_CONFIG[:pod_url].gsub(/(https?:|www\.)\/\//, '').chop!}")
|
||||||
end
|
end
|
||||||
|
|
@ -48,7 +48,7 @@ end
|
||||||
|
|
||||||
Factory.define :status_message do |m|
|
Factory.define :status_message do |m|
|
||||||
m.sequence(:message) { |n| "jimmy's #{n} whales" }
|
m.sequence(:message) { |n| "jimmy's #{n} whales" }
|
||||||
m.person
|
m.association :person
|
||||||
end
|
end
|
||||||
|
|
||||||
Factory.define :photo do |p|
|
Factory.define :photo do |p|
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,9 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Person do
|
describe Person do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
@user = Factory(:user)
|
|
||||||
@user2 = Factory(:user)
|
|
||||||
@person = Factory.create(:person)
|
@person = Factory.create(:person)
|
||||||
@aspect = @user.aspects.create(:name => "Dudes")
|
|
||||||
@aspect2 = @user2.aspects.create(:name => "Abscence of Babes")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "delegating" do
|
describe "delegating" do
|
||||||
|
|
@ -121,6 +118,12 @@ describe Person do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "disconnecting" do
|
describe "disconnecting" do
|
||||||
|
before do
|
||||||
|
@user = Factory(:user)
|
||||||
|
@user2 = Factory(:user)
|
||||||
|
@aspect = @user.aspects.create(:name => "Dudes")
|
||||||
|
@aspect2 = @user2.aspects.create(:name => "Abscence of Babes")
|
||||||
|
end
|
||||||
it 'should not delete an orphaned contact' do
|
it 'should not delete an orphaned contact' do
|
||||||
@user.activate_contact(@person, @aspect)
|
@user.activate_contact(@person, @aspect)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ require 'spec_helper'
|
||||||
|
|
||||||
describe Post do
|
describe Post do
|
||||||
before do
|
before do
|
||||||
@user = make_user
|
@user = Factory(:user)
|
||||||
@aspect = @user.aspects.create(:name => "winners")
|
@aspect = @user.aspects.create(:name => "winners")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -15,8 +15,8 @@ describe Post do
|
||||||
post = Factory.create(:status_message, :person => @user.person)
|
post = Factory.create(:status_message, :person => @user.person)
|
||||||
@user.comment "hey", :on => post
|
@user.comment "hey", :on => post
|
||||||
post.destroy
|
post.destroy
|
||||||
Post.all(:id => post.id).empty?.should == true
|
Post.where(:id => post.id).empty?.should == true
|
||||||
Comment.all(:text => "hey").empty?.should == true
|
Comment.where(:text => "hey").empty?.should == true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ require 'spec_helper'
|
||||||
describe StatusMessage do
|
describe StatusMessage do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
@user = make_user
|
@user = Factory(:user)
|
||||||
@aspect = @user.aspects.create(:name => "losers")
|
@aspect = @user.aspects.create(:name => "losers")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue