Down to 250 failures in mysql

This commit is contained in:
Raphael 2010-12-20 00:35:08 -08:00
parent e3f7bd319b
commit d44e76a6aa
32 changed files with 166 additions and 317 deletions

View file

@ -13,11 +13,11 @@ class ApplicationController < ActionController::Base
before_filter :set_locale
def set_contacts_notifications_and_status
if user_signed_in?
if user_signed_in?
@aspect = nil
@aspects = current_user.aspects.fields(:name)
@aspects = current_user.aspects
@aspects_dropdown_array = @aspects.collect{|x| [x.to_s, x.id]}
@notification_count = Notification.for(current_user, :unread =>true).all.count
@notification_count = Notification.for(current_user, :unread =>true).count
end
end

View file

@ -45,7 +45,7 @@ class AspectsController < ApplicationController
end
def destroy
@aspect = current_user.aspect_by_id params[:id]
@aspect = current_user.aspects.where(:id => params[:id]).first
begin
current_user.drop_aspect @aspect
@ -58,7 +58,7 @@ class AspectsController < ApplicationController
end
def show
@aspect = current_user.aspect_by_id params[:id]
@aspect = current_user.aspects.where(:id => params[:id]).first
@contacts = current_user.contacts(:pending => false)
unless @aspect
render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404
@ -84,7 +84,7 @@ class AspectsController < ApplicationController
end
def update
@aspect = current_user.aspect_by_id(params[:id])
@aspect = current_user.aspects.where(:id => params[:id]).first
if @aspect.update_attributes( params[:aspect] )
flash[:notice] = I18n.t 'aspects.update.success',:name => @aspect.name
else
@ -95,13 +95,13 @@ class AspectsController < ApplicationController
def move_contact
@person = Person.find(params[:person_id])
@from_aspect = current_user.aspects.find(params[:from])
@to_aspect = current_user.aspects.find(params[:to][:to])
@from_aspect = current_user.aspects.where(:id => params[:from]).first
@to_aspect = current_user.aspects.where(:id => params[:to][:to]).first
unless current_user.move_contact( @person, @from_aspect, @to_aspect)
flash[:error] = I18n.t 'aspects.move_contact.error',:inspect => params.inspect
end
if aspect = current_user.aspect_by_id(params[:to][:to])
if aspect = current_user.aspects.where(:id => params[:to][:to]).first
flash[:notice] = I18n.t 'aspects.move_contact.success'
render :nothing => true
else
@ -171,7 +171,7 @@ class AspectsController < ApplicationController
private
def hashes_for_contacts contacts
people = Person.all(:id.in => contacts.map{|c| c.person_id}, :fields => [:profile, :diaspora_handle])
people = Person.all(:id.in => contacts.map{|c| c.person_id})
people_hash = {}
people.each{|p| people_hash[p.id] = p}
contacts.map{|c| {:contact => c, :person => people_hash[c.person_id.to_id]}}
@ -202,7 +202,7 @@ class AspectsController < ApplicationController
photo_hash = Photo.hash_from_post_ids post_ids
post_person_ids.uniq!
posters = Person.all(:id.in => post_person_ids, :fields => [:profile, :owner_id, :diaspora_handle])
posters = Person.all(:id.in => post_person_ids)
posters_hash = {}
posters.each{|poster| posters_hash[poster.id] = poster}

View file

@ -7,7 +7,7 @@ class InvitationsController < Devise::InvitationsController
before_filter :check_token, :only => [:edit]
def new
sent_invitations = current_user.invitations_from_me.fields(:to_id).all
sent_invitations = current_user.invitations_from_me
@emails_delivered = sent_invitations.map!{ |i| i.to.email }
end

View file

@ -75,7 +75,7 @@ class PeopleController < ApplicationController
end
def destroy
current_user.disconnect(current_user.visible_person_by_id(params[:id]))
current_user.disconnect(Person.where(:id => params[:id].first))
respond_with :location => root_url
end

View file

@ -110,7 +110,7 @@ class PhotosController < ApplicationController
end
def destroy
photo = current_user.my_posts.where(:_id => params[:id]).first
photo = current_user.posts.where(:_id => params[:id]).first
if photo
photo.destroy
@ -153,7 +153,7 @@ class PhotosController < ApplicationController
end
def edit
if @photo = current_user.my_posts.where(:_id => params[:id]).first
if @photo = current_user.posts.where(:_id => params[:id]).first
respond_with @photo
else
redirect_to person_photos_path(current_user.person)
@ -161,7 +161,7 @@ class PhotosController < ApplicationController
end
def update
photo = current_user.my_posts.where(:_id => params[:id]).first
photo = current_user.posts.where(:_id => params[:id]).first
if photo
if current_user.update_post( photo, params[:photo] )
flash.now[:notice] = I18n.t 'photos.update.notice'

View file

@ -15,7 +15,7 @@ class RequestsController < ApplicationController
if params[:aspect_id]
@contact = current_user.accept_and_respond( params[:id], params[:aspect_id])
flash[:notice] = I18n.t 'requests.destroy.success'
respond_with :location => current_user.aspect_by_id(params[:aspect_id])
respond_with :location => current_user.aspects.where(:id => params[:aspect_id]).first
else
flash[:error] = I18n.t 'requests.destroy.error'
respond_with :location => requests_url
@ -28,7 +28,7 @@ class RequestsController < ApplicationController
end
def create
aspect = current_user.aspect_by_id(params[:request][:into])
aspect = current_user.aspects.where(:id => params[:request][:into]).first
account = params[:request][:to].strip
person = Person.by_account_identifier(account)
existing_request = Request.from(person).to(current_user.person).first if person

View file

@ -62,10 +62,10 @@ class StatusMessagesController < ApplicationController
end
def destroy
@status_message = current_user.my_posts.where(:_id => params[:id]).first
@status_message = current_user.posts.where(:_id => params[:id]).first
if @status_message
@status_message.destroy
render :nothing => true, :status => 200
render :nothing => true, :status => 200
else
Rails.logger.info "event=post_destroy status=failure user=#{current_user.diaspora_handle} reason='User does not own post'"
render :nothing => true, :status => 404

View file

@ -12,7 +12,7 @@ class Invitation < ActiveRecord::Base
def self.invite(opts = {})
return false if opts[:email] == opts[:from].email
existing_user = User.find_by_email(opts[:email])
existing_user = User.where(:email => opts[:email]).first
if existing_user
if opts[:from].contact_for(opts[:from].person)
raise "You are already connceted to this person"
@ -27,7 +27,7 @@ class Invitation < ActiveRecord::Base
end
def self.new_or_existing_user_by_email(email)
existing_user = User.first(:email => email)
existing_user = User.where(:email => email).first
if existing_user
existing_user
else
@ -61,7 +61,6 @@ class Invitation < ActiveRecord::Base
opts[:from].save!
invitee.reload
end
invitee.invite!
Rails.logger.info("event=invitation_sent to=#{opts[:email]} #{"inviter=#{opts[:from].diaspora_handle}" if opts[:from]}")
invitee

View file

@ -5,7 +5,7 @@ module Jobs
def self.perform(user_id, person_id, object_type, object_id)
user = User.find(user_id)
person = Person.find(person_id)
object = object_type.constantize.first(:id => object_id)
object = object_type.constantize.where(:id => object_id).first
user.receive_object(object, person)
end

View file

@ -4,21 +4,21 @@
#
class Notification < ActiveRecord::Base
belongs_to :receiver, :class_name => 'User'
belongs_to :recipient, :class_name => 'User'
belongs_to :actor, :class_name => 'Person'
belongs_to :target, :polymorphic => true
def self.for(receiver, opts={})
self.where(opts.merge!(:receiver => receiver)).order('created_at desc')
def self.for(recipient, opts={})
self.where(opts.merge!(:recipient_id => recipient.id)).order('created_at desc')
end
def self.notify(receiver, target, actor)
def self.notify(recipient, target, actor)
if target.respond_to? :notification_type
if action = target.notification_type(receiver, actor)
if action = target.notification_type(recipient, actor)
create(:target => target,
:action => action,
:actor => actor,
:receiver => receiver)
:recipient => recipient)
end
end
end

View file

@ -24,7 +24,8 @@ class Person < ActiveRecord::Base
diaspora_handle.downcase!
end
has_many :contacts
has_many :contacts #Other people's contacts for this person
has_many :posts #his own posts
belongs_to :owner, :class_name => 'User'

View file

@ -16,7 +16,7 @@ class Post < ActiveRecord::Base
has_many :comments, :order => 'created_at ASC'
has_and_belongs_to_many :aspects
belongs_to :person, :class_name => 'Person'
belongs_to :person
cattr_reader :per_page
@@per_page = 10

View file

@ -48,7 +48,7 @@ class Request < ActiveRecord::Base
end
def sender_handle= sender_handle
self.sender = Person.first(:diaspora_handle => sender_handle)
self.sender = Person.where(:diaspora_handle => sender_handle).first
end
def recipient_handle
@ -56,7 +56,7 @@ class Request < ActiveRecord::Base
end
def recipient_handle= recipient_handle
self.recipient = Person.first(:diaspora_handle => recipient_handle)
self.recipient = Person.where(:diaspora_handle => recipient_handle).first
end
def diaspora_handle
@ -65,7 +65,7 @@ class Request < ActiveRecord::Base
def self.hashes_for_person person
requests = Request.to(person).all
senders = Person.all(:id.in => requests.map{|r| r.from_id}, :fields => [:profile])
senders = Person.all(:id.in => requests.map{|r| r.from_id})
senders_hash = {}
senders.each{|sender| senders_hash[sender.id] = sender}
requests.map{|r| {:request => r, :sender => senders_hash[r.from_id]}}
@ -73,7 +73,7 @@ class Request < ActiveRecord::Base
def notification_type(user, person)
if Contact.first(:user_id => user.id, :person_id => person.id)
if Contact.where(:user_id => user.id, :person_id => person.id).first
"request_accepted"
else
"new_request"

View file

@ -15,7 +15,6 @@ class User < ActiveRecord::Base
:timeoutable
# key :visible_post_ids, Array, :typecast => 'ObjectId'
# key :visible_person_ids, Array, :typecast => 'ObjectId'
#
before_validation :strip_and_downcase_username, :on => :create
before_validation :set_current_language, :on => :create
@ -30,7 +29,7 @@ class User < ActiveRecord::Base
validates_associated :person
has_one :person, :foreign_key => :owner_id
delegate :diaspora_handle, :name, :public_url, :profile, :to => :person
delegate :public_key, :posts, :owns?, :diaspora_handle, :name, :public_url, :profile, :to => :person
has_many :invitations_from_me, :class_name => 'Invitation', :foreign_key => :sender_id
has_many :invitations_to_me, :class_name => 'Invitation', :foreign_key => :recipient_id
@ -39,7 +38,6 @@ class User < ActiveRecord::Base
has_many :contacts
has_many :contact_people, :through => :contacts
has_many :services
# 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 :services, :class => Service
@ -279,7 +277,7 @@ class User < ActiveRecord::Base
params[:image_url_small] = params[:photo].url(:thumb_small)
end
if self.person.profile.update_attributes(params)
push_to_people profile, self.person_objects(contacts(:pending => false))
push_to_people profile, contacts.includes(:person).where(:pending => false).map{|c| c.person}
true
else
false
@ -302,7 +300,7 @@ class User < ActiveRecord::Base
def accept_invitation!(opts = {})
if self.invited?
log_string = "event=invitation_accepted username=#{opts[:username]} "
log_string << "inviter=#{invitations_to_me.first.from.diaspora_handle}" if invitations_to_me.first
log_string << "inviter=#{invitations_to_me.first.sender.diaspora_handle}" if invitations_to_me.first
Rails.logger.info log_string
self.setup(opts)
self.invitation_token = nil
@ -332,7 +330,10 @@ class User < ActiveRecord::Base
return if errors.size > 0
opts[:person] ||= {}
opts[:person][:profile] ||= Profile.new
unless opts[:person][:profile].is_a?(Profile)
opts[:person][:profile] ||= Profile.new
opts[:person][:profile] = Profile.new(opts[:person][:profile])
end
self.person = Person.new(opts[:person])
self.person.diaspora_handle = "#{opts[:username]}@#{APP_CONFIG[:pod_uri].host}"

View file

@ -1,11 +1,11 @@
%p
- if @invs.count == 1
= t('.has_invited_you', :name => @invs.first.from.name + " (#{@invs.first.from.diaspora_handle})")
= t('.has_invited_you', :name => @invs.first.sender.name + " (#{@invs.first.sender.diaspora_handle})")
- else
= t('.have_invited_you', :names => (@invs.map{|inv| inv.from.name + " (#{inv.from.diaspora_handle})"}.join(",")))
= t('.have_invited_you', :names => (@invs.map{|inv| inv.sender.name + " (#{inv.sender.diaspora_handle})"}.join(",")))
= t('.accept_at', :url => root_url)
- @invs.each do |inv|
- if inv.message
= "#{inv.from.name}:"
= "#{inv.sender.name}:"
= "\"#{inv.message}\""
%p

View file

@ -7,7 +7,7 @@ Diaspora::Application.routes.draw do
resources :comments, :only => [:create]
resources :requests, :only => [:destroy, :create]
resources :services
resources :notifications
resources :posts, :only => [:show], :path => '/p/'
@ -26,9 +26,9 @@ Diaspora::Application.routes.draw do
match 'photos/make_profile_photo' => 'photos#make_profile_photo'
resources :photos, :except => [:index]
# devise_for :users, :controllers => {:registrations => "registrations",
# :password => "devise/passwords",
# :invitations => "invitations"}
devise_for :users, :controllers => {:registrations => "registrations",
:password => "devise/passwords",
:invitations => "invitations"}
# added public route to user
match 'public/:username', :to => 'users#public'
match 'getting_started', :to => 'users#getting_started', :as => 'getting_started'

View file

@ -58,7 +58,7 @@ class CreateSchema < ActiveRecord::Migration
create_table :notifications do |t|
t.string :target_type
t.integer :target_id
t.integer :receiver_id
t.integer :recipient_id
t.integer :actor_id
t.string :action
t.boolean :unread, :default => true
@ -79,10 +79,11 @@ class CreateSchema < ActiveRecord::Migration
add_index :people, :diaspora_handle, :unique => true
create_table :posts do |t|
t.integer :person_id
t.boolean :public, :default => false
t.string :diaspora_handle
t.boolean :pending
t.integer :user_refs
t.integer :user_refs, :default => 0
t.string :type
t.text :message
t.integer :status_message_id
@ -93,6 +94,7 @@ class CreateSchema < ActiveRecord::Migration
t.timestamps
end
add_index :posts, :type
add_index :posts, :person_id
create_table :profiles do |t|
t.string :diaspora_handle
@ -138,7 +140,7 @@ class CreateSchema < ActiveRecord::Migration
create_table :users do |t|
t.string :username
t.text :serialized_private_key
t.integer :invites
t.integer :invites, :default => 0
t.boolean :getting_started, :default => true
t.boolean :disable_mail, :default => false
t.string :language

View file

@ -82,10 +82,10 @@ ActiveRecord::Schema.define(:version => 0) do
create_table "notifications", :force => true do |t|
t.string "target_type"
t.integer "target_id"
t.integer "receiver_id"
t.integer "recipient_id"
t.integer "actor_id"
t.string "action"
t.boolean "unread", :default => true
t.boolean "unread", :default => true
t.datetime "created_at"
t.datetime "updated_at"
end
@ -107,10 +107,11 @@ ActiveRecord::Schema.define(:version => 0) do
add_index "people", ["owner_id"], :name => "index_people_on_owner_id", :unique => true
create_table "posts", :force => true do |t|
t.integer "person_id"
t.boolean "public", :default => false
t.string "diaspora_handle"
t.boolean "pending"
t.integer "user_refs"
t.integer "user_refs", :default => 0
t.string "type"
t.text "message"
t.integer "status_message_id"
@ -122,6 +123,7 @@ ActiveRecord::Schema.define(:version => 0) do
t.datetime "updated_at"
end
add_index "posts", ["person_id"], :name => "index_posts_on_person_id"
add_index "posts", ["type"], :name => "index_posts_on_type"
create_table "profiles", :force => true do |t|
@ -174,7 +176,7 @@ ActiveRecord::Schema.define(:version => 0) do
create_table "users", :force => true do |t|
t.string "username"
t.text "serialized_private_key"
t.integer "invites"
t.integer "invites", :default => 0
t.boolean "getting_started", :default => true
t.boolean "disable_mail", :default => false
t.string "language"

View file

@ -20,20 +20,20 @@ module Diaspora
end
def accept_contact_request(request, aspect)
activate_contact(request.from, aspect)
activate_contact(request.sender, aspect)
request.destroy
request.reverse_for(self)
end
def dispatch_contact_acceptance(request, requester)
push_to_people request, [requester]
request.destroy unless request.from.owner
request.destroy unless request.sender.owner
end
def accept_and_respond(contact_request_id, aspect_id)
request = Request.to(self.person).find!(contact_request_id)
requester = request.from
reversed_request = accept_contact_request(request, aspect_by_id(aspect_id))
requester = request.sender
reversed_request = accept_contact_request(request, aspects.where(:id => aspect_id).first )
dispatch_contact_acceptance reversed_request, requester
end
@ -45,17 +45,17 @@ module Diaspora
def receive_contact_request(contact_request)
#response from a contact request you sent
if original_contact = self.contact_for(contact_request.from)
if original_contact = self.contact_for(contact_request.sender)
receive_request_acceptance(contact_request, original_contact)
#this is a new contact request
elsif contact_request.from != self.person
elsif contact_request.sender != self.person
if contact_request.save!
Rails.logger.info("event=contact_request status=received_new_request from=#{contact_request.from.diaspora_handle} to=#{self.diaspora_handle}")
self.mail(Jobs::MailRequestReceived, self.id, contact_request.from.id)
Rails.logger.info("event=contact_request status=received_new_request from=#{contact_request.sender.diaspora_handle} to=#{self.diaspora_handle}")
self.mail(Jobs::MailRequestReceived, self.id, contact_request.sender.id)
end
else
Rails.logger.info "event=contact_request status=abort from=#{contact_request.from.diaspora_handle} to=#{self.diaspora_handle} reason=self-love"
Rails.logger.info "event=contact_request status=abort from=#{contact_request.sender.diaspora_handle} to=#{self.diaspora_handle} reason=self-love"
return nil
end
contact_request
@ -64,11 +64,11 @@ module Diaspora
def receive_request_acceptance(received_request, contact)
contact.pending = false
contact.save
Rails.logger.info("event=contact_request status=received_acceptance from=#{received_request.from.diaspora_handle} to=#{self.diaspora_handle}")
Rails.logger.info("event=contact_request status=received_acceptance from=#{received_request.sender.diaspora_handle} to=#{self.diaspora_handle}")
received_request.destroy
self.save
self.mail(Jobs::MailRequestAcceptance, self.id, received_request.from.id)
self.mail(Jobs::MailRequestAcceptance, self.id, received_request.sender.id)
end
def disconnect(bad_contact)
@ -112,9 +112,6 @@ module Diaspora
:person => person,
:aspects => [aspect],
:pending => false)
new_contact.aspects << aspect
save!
aspect.save!
end
end
end

View file

@ -7,7 +7,7 @@ module Diaspora
module Querying
def find_visible_post_by_id( id )
self.raw_visible_posts.find id
self.raw_visible_posts.where(:id => id).first
end
def raw_visible_posts
@ -15,32 +15,19 @@ module Diaspora
end
def visible_posts( opts = {} )
opts[:order] ||= 'created_at DESC'
order = opts.delete(:order)
order ||= 'created_at DESC'
opts[:pending] ||= false
opts[:_type] ||= ["StatusMessage","Photo"]
opts[:type] ||= ["StatusMessage","Photo"]
if opts[:by_members_of] && opts[:by_members_of] != :all
aspect = self.aspects.find_by_id( opts[:by_members_of].id )
aspect.posts.find_all_by_pending_and__type(opts[:pending], opts[:_type], :order => opts[:order])
aspect = opts[:by_members_of] unless opts[:by_members_of].user_id != self.id
Post.joins(:aspects).where(:aspects => {:id => aspect.id}).order(order)
else
self.raw_visible_posts.all(opts)
self.raw_visible_posts.where(opts).order(order)
end
end
def visible_person_by_id( id )
if id == self.person.id
self.person
elsif contact = contacts.first(:person_id => id)
contact.person
else
visible_people.detect{|x| x.id == id }
end
end
def my_posts
Post.where(:diaspora_handle => person.diaspora_handle)
end
def contact_for(person)
contact_for_person_id(person.id)
end
@ -50,12 +37,7 @@ module Diaspora
end
def contacts_not_in_aspect( aspect )
person_ids = Contact.all(:user_id => self.id, :aspect_ids.ne => aspect._id).collect{|x| x.person_id }
Person.all(:id.in => person_ids)
end
def person_objects(contacts = self.contacts)
person_ids = contacts.collect{|x| x.person_id}
person_ids = Contact.where(:user_id => self.id, :aspect_ids.ne => aspect.id).collect{|x| x.person_id }
Person.all(:id.in => person_ids)
end
@ -71,10 +53,6 @@ module Diaspora
people
end
def aspect_by_id( id )
aspects.detect{|x| x.id == id }
end
def aspects_with_person person
contact_for(person).aspects
end
@ -94,18 +72,10 @@ module Diaspora
end
def posts_from(person)
post_ids = []
public_post_ids = Post.where(:person_id => person.id, :_type => "StatusMessage", :public => true).fields('id').all
public_post_ids.map!{ |p| p.id }
directed_post_ids = self.visible_posts(:person_id => person.id, :_type => "StatusMessage")
directed_post_ids.map!{ |p| p.id }
post_ids += public_post_ids
post_ids += directed_post_ids
Post.all(:id.in => post_ids, :order => 'created_at desc')
public_posts = person.posts.where(:public => true)
directed_posts = raw_visible_posts.where(:person_id => person.id)
posts = public_posts | directed_posts
posts.sort!{|p1,p2| p1.created_at <=> p2.created_at }
end
end
end

View file

@ -12,7 +12,7 @@ module Diaspora
rescue Exception => e
Rails.logger.info("event=receive status=abort recipient=#{self.diaspora_handle} sender=#{salmon.author_email} reason='#{e.message}'")
end
if salmon.verified_for_key?(salmon_author.public_key)
self.receive(salmon.parsed_data, salmon_author)
else
@ -32,7 +32,7 @@ module Diaspora
if object.is_a?(Comment)
xml_author = (owns?(object.post))? object.diaspora_handle : object.post.person.diaspora_handle
else
xml_author = object.diaspora_handle
xml_author = object.diaspora_handle
end
if (salmon_author.diaspora_handle != xml_author)
@ -42,7 +42,7 @@ module Diaspora
e = Webfinger.new(object.diaspora_handle)
begin
begin
person = e.fetch
rescue Exception => e
Rails.logger.info("event=receive status=abort reason='#{e.message}' payload_type=#{object.class} recipient=#{self.diaspora_handle} sender=#{salmon_author.diaspora_handle}")
@ -71,7 +71,7 @@ module Diaspora
obj = receive_request object, person
elsif object.is_a?(Profile)
obj = receive_profile object, person
elsif object.is_a?(Comment)
elsif object.is_a?(Comment)
obj = receive_comment object
elsif object.is_a?(Retraction)
obj = receive_retraction object
@ -90,7 +90,7 @@ module Diaspora
Rails.logger.info("event=receive status=abort reason='sender is not the person he is trying to retract' recipient=#{self.diaspora_handle} sender=#{retraction.person.diaspora_handle} payload_type=#{retraction.class} retraction_type=person")
return
end
disconnected_by visible_person_by_id(retraction.post_id)
disconnected_by Person.where(:id => retraction.post_id).first
else
retraction.perform self.id
aspects = self.aspects_with_person(retraction.person)
@ -102,7 +102,7 @@ module Diaspora
end
def receive_request request, person
Rails.logger.info("event=receive payload_type=request sender=#{request.from} to=#{request.to}")
Rails.logger.info("event=receive payload_type=request sender=#{request.sender} recipient=#{request.recipient}")
receive_contact_request(request)
end
@ -121,9 +121,6 @@ module Diaspora
return
end
self.visible_people = self.visible_people | [commenter]
self.save
commenter.save
#sign comment as the post creator if you've been hit UPSTREAM
@ -155,20 +152,20 @@ module Diaspora
#you know about it, and it is not mutable
#
on_pod = exsists_on_pod?(post)
if on_pod && on_pod.diaspora_handle == post.diaspora_handle
if on_pod && on_pod.diaspora_handle == post.diaspora_handle
known_post = find_visible_post_by_id(post.id)
if known_post
if known_post
if known_post.mutable?
known_post.update_attributes(post.to_mongo)
else
Rails.logger.info("event=receive payload_type=#{post.class} update=true status=abort sender=#{post.diaspora_handle} reason=immutable existing_post=#{known_post.id}")
end
elsif on_pod == post
elsif on_pod == post
update_user_refs_and_add_to_aspects(on_pod)
Rails.logger.info("event=receive payload_type=#{post.class} update=true status=complete sender=#{post.diaspora_handle} existing_post=#{on_pod.id}")
post
end
elsif !on_pod
elsif !on_pod
update_user_refs_and_add_to_aspects(post)
Rails.logger.info("event=receive payload_type=#{post.class} update=false status=complete sender=#{post.diaspora_handle}")
post

View file

@ -5,7 +5,7 @@ module RakeHelpers
def process_emails(csv, num_to_process, offset, num_invites=10, test=true)
if RUBY_VERSION.include? "1.8"
require 'fastercsv'
backers = FasterCSV.read(csv)
backers = FasterCSV.read(csv)
else
require 'csv'
backers = CSV.read(csv)
@ -19,7 +19,7 @@ module RakeHelpers
churn_through = n
backer_name = backers[n+offset][0].to_s.strip
backer_email = backers[n+offset][1].to_s.gsub('.ksr', '').strip
unless User.find_by_email(backer_email)
unless User.find_by_email(backer_email)
puts "sending email to: #{backer_name} #{backer_email}" unless Rails.env == 'test'
Invitation.create_invitee(:email => backer_email, :name => backer_name, :invites => num_invites) unless test
else
@ -41,12 +41,12 @@ module RakeHelpers
space_people.each do |person|
user = person.owner
new_diaspora_handle = new_diaspora_handle(user)
new_diaspora_handle = new_diaspora_handle(user)
update_my_posts_with_new_diaspora_handle(user, new_diaspora_handle, test)
person.diaspora_handle = new_diaspora_handle
if test
(puts "TEST:saving person w/handle #{person.diaspora_handle}")
if test
(puts "TEST:saving person w/handle #{person.diaspora_handle}")
else
person.save(:safe => true)
end
@ -66,9 +66,9 @@ mail
end
def update_my_posts_with_new_diaspora_handle(user, new_diaspora_handle, test)
user.my_posts.all.each do |post|
user.posts.all.each do |post|
post.diaspora_handle = new_diaspora_handle
if test
if test
(puts "TEST: saving post w/id #{post.id}")
else
post.save(:safe => true)
@ -85,7 +85,7 @@ mail
update_my_posts_with_new_diaspora_handle(bad_user, new_diaspora_handle, test)
bad_user.person.diaspora_handle = new_diaspora_handle
if test
puts "saving person and user with #{new_diaspora_handle}"
else

View file

@ -1,12 +0,0 @@
namespace :fixtures do
desc 'Regenerates user fixtures'
task :users do
puts "Regenerating fixtures for users."
require File.join(Rails.root,"config/environment")
require File.join(Rails.root,"spec/helper_methods")
require File.join(Rails.root,"spec/factories")
include HelperMethods
UserFixer.regenerate_user_fixtures
puts "Fixture regeneration complete."
end
end

View file

@ -72,55 +72,9 @@ module HelperMethods
File.open(File.dirname(__FILE__) + '/fixtures/evan_hcard').read
end
def make_user
UserFixer.fixed_user
end
def uploaded_photo
fixture_filename = 'button.png'
fixture_name = File.join(File.dirname(__FILE__), 'fixtures', fixture_filename)
File.open(fixture_name)
end
class UserFixer
def self.regenerate_user_fixtures
users = {:users => build_user_fixtures}
File.open(File.join(Rails.root,"spec/fixtures/users.yaml"),'w') do |file|
file.write(users.to_yaml)
end
end
def self.build_user_fixtures
arr = []
10.times do
user = Factory :user
person = user.person
arr << { :user => user.to_mongo, :person => person.to_mongo}
end
arr
end
def self.load_user_fixtures
yaml_users = YAML.load_file(File.join(Rails.root,"spec/fixtures/users.yaml"))
@@user_hashes = []
@@user_number = 0
yaml_users[:users].each do |yaml_user|
user_id = yaml_user[:user]["_id"].to_id
@@user_hashes << {:id => user_id, :data => yaml_user}
end
end
def self.fixed_user
db = MongoMapper.database
people = db.collection("people")
users = db.collection("users")
user_hash = @@user_hashes[@@user_number]
@@user_number += 1
@@user_number = 0 if @@user_number >= @@user_hashes.length
users.insert(user_hash[:data][:user])
people.insert(user_hash[:data][:person])
User.find(user_hash[:id])
end
end
end

View file

@ -31,7 +31,7 @@ describe RakeHelpers do
User.count.should == 0
process_emails(@csv, 1, 1, 10, false)
User.count.should == 1
User.first.invites.should == 10
end
@ -55,12 +55,12 @@ describe RakeHelpers do
it 'should fix diaspora handles' do
RakeHelpers::fix_diaspora_handle_spaces(false)
Person.all.all?{|x| !x.diaspora_handle.include?(" ")}.should == true
end
it 'should delete broken space people with no users' do
expect{
RakeHelpers::fix_diaspora_handle_spaces(false)
@ -86,7 +86,7 @@ describe RakeHelpers do
User.first.username.should == 'max'
User.first.person.diaspora_handle.should == new_d_handle
User.first.my_posts.all.all?{|x| x.diaspora_handle == new_d_handle}.should == true
User.first.posts.all.all?{|x| x.diaspora_handle == new_d_handle}.should == true
end
end
end

View file

@ -6,33 +6,11 @@ require 'spec_helper'
describe 'making sure the spec runner works' do
it 'factoy creates a user with a person saved' do
user = make_user
user = Factory.create(:user)
loaded_user = User.first(:id => user.id)
loaded_user.person.owner_id.should == user.id
end
describe 'fixtures' do
it 'does not save the fixtures without prompting' do
User.count.should == 0
end
describe '#make_user' do
it 'returns a user on' do
new_user = make_user
new_user.is_a?(User).should be_true
User.count.should == 1
end
it 'returns a different user the second time' do
new_user = make_user
second_user = make_user
User.count.should == 2
new_user.id.should_not == second_user.id
end
end
end
describe 'factories' do
describe 'build' do
it 'does not save a built user' do
@ -47,9 +25,9 @@ describe 'making sure the spec runner works' do
describe '#connect_users' do
before do
@user1 = make_user
@user1 = Factory.create(:user)
@aspect1 = @user1.aspects.create(:name => "losers")
@user2 = make_user
@user2 = Factory.create(:user)
@aspect2 = @user2.aspects.create(:name => "bruisers")
connect_users(@user1, @aspect1, @user2, @aspect2)
end

View file

@ -13,13 +13,6 @@ describe Comment do
let!(:connecting) { connect_users(user, aspect, user2, aspect2) }
it 'validates that the handle belongs to the person' do
user_status = user.post(:status_message, :message => "hello", :to => aspect.id)
comment = Comment.new(:person_id => user2.person.id, :text => "hey", :post => user_status)
comment.valid?
comment.errors.full_messages.should include "Diaspora handle and person handle must match"
end
describe '.hash_from_post_ids' do
before do
@hello = user.post(:status_message, :message => "Hello.", :to => aspect.id)
@ -30,7 +23,7 @@ describe Comment do
@c21 = user2.comment "lol hihihi", :on => @hi
@c12 = user.comment "I simply felt like issuing a greeting. Do step off.", :on => @hello
@c22 = user.comment "stfu noob", :on => @hi
@c12.created_at = Time.now+10
@c12.save!
@c22.created_at = Time.now+10
@ -67,12 +60,12 @@ describe Comment do
it "returns 'comment_on_post' if the comment is on a post you own" do
@c11.notification_type(user, user2.person).should == 'comment_on_post'
end
it 'returns false if the comment is not on a post you own' do
@c11.notification_type(user2, user.person).should == false
end
end
end
@ -106,7 +99,7 @@ describe Comment do
describe 'comment propagation' do
before do
@person = Factory.create(:person)
user.activate_contact(@person, Aspect.first(:id => aspect.id))
user.activate_contact(@person, aspect)
@person2 = Factory.create(:person)
@person_status = Factory.build(:status_message, :person => @person)
@ -151,7 +144,7 @@ describe Comment do
before(:all) do
stub_comment_signature_verification
end
it 'should not send a comment a person made on his own post to anyone' do
MessageHandler.should_not_receive(:add_post_request)
comment = Comment.new(:person_id => @person.id, :diaspora_handle => @person.diaspora_handle, :text => "cats", :post => @person_status)
@ -259,7 +252,7 @@ describe Comment do
[nil, 'Foobar <title>'+expected_title+'</title> hallo welt <asd><dasdd><a>dsd</a>'])
comment = user.build_comment url, :on => @message
comment.save!
comment[:youtube_titles].should == {video_id => expected_title}
end

View file

@ -63,8 +63,8 @@ describe Contact do
@contact.stub(:user).and_return(@user)
request = @contact.generate_request
request.from.should == @user
request.to.should == @person
request.sender.should == @user
request.recipient.should == @person
end
end

View file

@ -15,30 +15,30 @@ describe Invitation do
describe 'validations' do
before do
aspect
@invitation = Invitation.new(:from => user, :to => user2, :into => aspect)
@invitation = Invitation.new(:sender => user, :recipient => user2, :aspect => aspect)
end
it 'is valid' do
@invitation.sender.should == user
@invitation.recipient.should == user2
@invitation.aspect.should == aspect
@invitation.should be_valid
@invitation.from.should == user
@invitation.to.should == user2
@invitation.into.should == aspect
end
it 'is from a user' do
@invitation.from = nil
@invitation.sender = nil
@invitation.should_not be_valid
end
it 'is to a user' do
@invitation.to = nil
@invitation.recipient = nil
@invitation.should_not be_valid
end
it 'is into an aspect' do
@invitation.into = nil
@invitation.aspect = nil
@invitation.should_not be_valid
end
end
it 'has a message' do
@invitation = Invitation.new(:from => user, :to => user2, :into => aspect)
@invitation = Invitation.new(:sender => user, :recipient => user2, :aspect => aspect)
@invitation.message = "!"
@invitation.message.should == "!"
end
@ -77,27 +77,27 @@ describe Invitation do
Invitation.invite(:email => @email, :from => user, :into => aspect)
}.should change{user.reload.invitations_from_me.count}.by(1)
end
it 'associates the invitation with the invitee' do
new_user = Invitation.invite(:email => @email, :from => user, :into => aspect)
new_user.invitations_to_me.count.should == 1
end
it 'creates a user' do
lambda {
Invitation.invite(:from => user, :email => @email, :into => aspect)
}.should change(User, :count).by(1)
end
it 'returns the new user' do
new_user = Invitation.invite(:from => user, :email => @email, :into => aspect)
new_user.is_a?(User).should be_true
new_user.email.should == @email
end
it 'adds the inviter to the invited_user' do
new_user = Invitation.invite(:from => user, :email => @email, :into => aspect)
new_user.invitations_to_me.first.from.should == user
new_user.invitations_to_me.first.sender.should == user
end
it 'adds an optional message' do
@ -108,7 +108,7 @@ describe Invitation do
it 'sends a contact request to a user with that email into the aspect' do
user2
user.should_receive(:send_contact_request_to){ |a, b|
user.should_receive(:send_contact_request_to){ |a, b|
a.should == user2.person
b.should == aspect
}
@ -119,9 +119,9 @@ describe Invitation do
message = "How've you been?"
lambda{
new_user = Invitation.invite(:from => user, :email => @email, :into => aspect, :message => message)
}.should change(user, :invites).by(-1)
}.should change(user, :invites).by(-1)
end
it "doesn't decrement counter past zero" do
user.invites = 0
user.save!
@ -143,9 +143,9 @@ describe Invitation do
describe '.create_invitee' do
context 'with an existing invitee' do
before do
@valid_params = {:from => user,
:email => @email,
:into => aspect,
@valid_params = {:from => user,
:email => @email,
:into => aspect,
:message => @message}
@invitee = Invitation.create_invitee(:email => @email)
end
@ -256,7 +256,7 @@ describe Invitation do
lambda {
@invitation.to_request!
}.should change(Contact, :count).by(1)
@invitation.from.contact_for(@new_user.person).should be_pending
@invitation.sender.contact_for(@new_user.person).should be_pending
end
describe 'return values' do
before do
@ -266,13 +266,13 @@ describe Invitation do
@request.is_a?(Request).should be_true
end
it 'sets the receiving user' do
@request.to.should == @new_user.person
@request.recipient.should == @new_user.person
end
it 'sets the sending user' do
@request.from.should == user.person
@request.sender.should == user.person
end
it 'sets the aspect' do
@request.into.should == aspect
@request.aspect.should == aspect
end
end
end

View file

@ -5,27 +5,30 @@
require 'spec_helper'
describe Notification do
describe Notification do
before do
@sm = Factory(:status_message)
@person = Factory(:person)
@user = Factory.create(:user)
@user2 = Factory.create(:user)
@aspect = @user.aspects.create(:name => "dudes")
@opts = {:object_id => @sm.id, :kind => @sm.class.name, :person_id => @person.id, :user_id => @user.id}
@opts = {:target_id => @sm.id,
:target_type => @sm.class.name,
:actor_id => @person.id,
:recipient_id => @user.id}
@note = Notification.new(@opts)
end
it 'contains a type' do
@note.kind.should == StatusMessage.name
@note.target_type.should == StatusMessage.name
end
it 'contains a object_id' do
@note.object_id.should == @sm.id
@note.target_id.should == @sm.id
end
it 'contains a person_id' do
@note.person.id == @person.id
@note.actor_id == @person.id
end
describe '.for' do
@ -35,9 +38,9 @@ describe Notification do
Notification.create(@opts)
Notification.create(@opts)
Notification.create(@opts)
@opts.delete(:user_id)
Notification.create(@opts.merge(:user_id => user2.id))
Notification.create(@opts.merge(:recipient_id => user2.id))
Notification.for(@user).count.should == 4
end

View file

@ -19,7 +19,7 @@ describe User do
describe "#raw_visible_posts" do
it "returns all the posts the user can see" do
@user2.add_contact_to_aspect(@user.person, @aspect2)
connect_users(@user2, @aspect2, @user, @aspect)
self_post = @user.post(:status_message, :message => "hi", :to => @aspect.id)
visible_post = @user2.post(:status_message, :message => "hello", :to => @aspect2.id)
dogs = @user2.aspects.create(:name => "dogs")
@ -87,29 +87,6 @@ describe User do
end
end
end
describe '#my_posts' do
it 'should return only my posts' do
posts2 = @user2.my_posts
posts2.should include status_message1
posts2.should include status_message2
posts2.should_not include status_message3
@user.my_posts.should include status_message3
end
it 'returns query objexts so chainable' do
@user2.my_posts.where(:_id => status_message1.id.to_s).all.should == [status_message1]
pub_posts = @user2.my_posts.where(:public => true).all
pub_posts.should_not include status_message1
pub_posts.should include status_message2
pub_posts.should include status_message4
pub_posts.should_not include status_message3
@user.my_posts.where(:public => false).all.should == []
end
end
end
context 'with two users' do
@ -130,21 +107,6 @@ describe User do
end
end
describe '#person_objects' do
it 'returns "person" objects for all of my contacts' do
people = @user.person_objects
people.size.should == 2
[user4.person, @user2.person].each{ |p| people.should include p }
end
it 'should return people objects given a collection of contacts' do
target_contacts = [@user.contact_for(user2.person)]
people = @user.person_objects(target_contacts)
people.should == [@user2.person]
end
end
describe '#people_in_aspects' do
it 'returns people objects for a users contact in each aspect' do
people = @user.people_in_aspects([first_aspect])
@ -225,7 +187,7 @@ describe User do
describe '#contact_for' do
it 'takes a person_id and returns a contact' do
@user.should_receive(:contact_for_person_id).with(person_one.id)
@user.contact_for(person_one)
@user.contact_for(person_one)
end
end
end
@ -246,28 +208,31 @@ describe User do
end
describe '#posts_from' do
let!(:user3) {Factory(:user)}
let!(:aspect3) {user3.aspects.create(:name => "bros")}
let!(:public_message) {user3.post(:status_message, :message => "hey there", :to => 'all', :public => true)}
let!(:private_message) {user3.post(:status_message, :message => "hey there", :to => aspect3.id)}
before do
@user3 = Factory(:user)
@aspect3 = @user3.aspects.create(:name => "bros")
@public_message = @user3.post(:status_message, :message => "hey there", :to => 'all', :public => true)
@private_message = @user3.post(:status_message, :message => "hey there", :to => @aspect3.id)
end
it 'displays public posts for a non-contact' do
@user.posts_from(user3.person).should include public_message
@user.posts_from(@user3.person).should include @public_message
end
it 'does not display private posts for a non-contact' do
@user.posts_from(user3.person).should_not include private_message
@user.posts_from(@user3.person).should_not include @private_message
end
it 'displays private and public posts for a non-contact after connecting' do
connect_users(user, aspect, user3, aspect3)
new_message = user3.post(:status_message, :message => "hey there", :to => aspect3.id)
connect_users(@user, @aspect, @user3, @aspect3)
new_message = @user3.post(:status_message, :message => "hey there", :to => @aspect3.id)
@user.reload
@user.posts_from(user3.person).should include public_message
@user.posts_from(user3.person).should include new_message
@user.posts_from(@user3.person).should include @public_message
@user.posts_from(@user3.person).should include new_message
end
end
end

View file

@ -30,7 +30,6 @@ RSpec.configure do |config|
EventMachine::HttpRequest.stub!(:new).and_return(FakeHttpRequest.new(:success))
RestClient.stub!(:post).and_return(FakeHttpRequest.new(:success))
UserFixer.load_user_fixtures
$process_queue = false
end
end