posts now have authors instead of people

This commit is contained in:
danielvincent 2011-03-01 18:05:05 -08:00
parent 11309574cf
commit 21fd546cd0
50 changed files with 139 additions and 147 deletions

View file

@ -30,7 +30,7 @@ class PhotosController < ApplicationController
end
@posts = current_user.visible_photos.where(
:person_id => @person.id
:author_id => @person.id
).paginate(:page => params[:page])
render 'people/show'
@ -94,8 +94,8 @@ class PhotosController < ApplicationController
end
def make_profile_photo
person_id = current_user.person.id
@photo = Photo.where(:id => params[:photo_id], :person_id => person_id).first
author_id = current_user.person.id
@photo = Photo.where(:id => params[:photo_id], :author_id => author_id).first
if @photo
profile_hash = {:image_url => @photo.url(:thumb_large),
@ -108,7 +108,7 @@ class PhotosController < ApplicationController
:image_url => @photo.url(:thumb_large),
:image_url_medium => @photo.url(:thumb_medium),
:image_url_small => @photo.url(:thumb_small),
:person_id => person_id},
:author_id => author_id},
:status => 201}
end
else
@ -139,8 +139,8 @@ class PhotosController < ApplicationController
end
def show
@photo = current_user.visible_photos.where(:id => params[:id]).includes(:person, :status_message => :photos).first
@photo ||= Photo.where(:public => true, :id => params[:id]).includes(:person, :status_message => :photos).first
@photo = current_user.visible_photos.where(:id => params[:id]).includes(:author, :status_message => :photos).first
@photo ||= Photo.where(:public => true, :id => params[:id]).includes(:author, :status_message => :photos).first
if @photo
@parent = @photo.status_message

View file

@ -11,11 +11,11 @@ class PostsController < ApplicationController
skip_before_filter :set_grammatical_gender
def show
@post = Post.where(:id => params[:id], :public => true).includes(:person, :comments => :person).first
@post = Post.where(:id => params[:id], :public => true).includes(:author, :comments => :author).first
if @post
@landing_page = true
@person = @post.person
@person = @post.author
if @person.owner_id
I18n.locale = @person.owner.language
render "posts/#{@post.class.to_s.underscore}", :layout => true

View file

@ -47,7 +47,7 @@ class StatusMessagesController < ApplicationController
:partial => 'shared/stream_element',
:locals => {
:post => @status_message,
:person => @status_message.person,
:author => @status_message.author,
:photos => @status_message.photos,
:comments => [],
:all_aspects => current_user.aspects,
@ -61,7 +61,7 @@ class StatusMessagesController < ApplicationController
end
else
respond_to do |format|
format.js { render :json =>{:errors => @status_message.errors.full_messages}, :status => 406 }
format.js { render :json =>{:errors => @status_message.errors.full_messages}, :status => 406 }
format.html {redirect_to :back}
end
end

View file

@ -22,7 +22,7 @@ module NotificationsHelper
elsif note.instance_of?(Notifications::AlsoCommented)
post = Post.where(:id => note.target_id).first
if post
"#{translation(target_type, post.person.name)} #{link_to t('notifications.post'), object_path(post)}".html_safe
"#{translation(target_type, post.author.name)} #{link_to t('notifications.post'), object_path(post)}".html_safe
else
t('notifications.also_commented_deleted')
end

View file

@ -26,11 +26,11 @@ module SocketsHelper
if object.is_a? StatusMessage
post_hash = {:post => object,
:person => object.person,
:author => object.author,
:photos => object.photos,
:comments => object.comments.map{|c|
{:comment => c,
:person => c.person
:author => c.author
}
},
:current_user => user,
@ -70,12 +70,12 @@ module SocketsHelper
if object.is_a? Comment
post = object.post
action_hash[:comment_id] = object.id
action_hash[:my_post?] = (post.person.owner_id == uid)
action_hash[:my_post?] = (post.author.owner_id == uid)
action_hash[:post_guid] = post.guid
end
action_hash[:mine?] = object.person && (object.person.owner_id == uid) if object.respond_to?(:person)
action_hash[:mine?] = object.author && (object.author.owner_id == uid) if object.respond_to?(:author)
I18n.locale = old_locale unless user.nil?

View file

@ -84,7 +84,7 @@ class Notifier < ActionMailer::Base
@receiver = User.find_by_id(recipient_id)
@sender = Person.find_by_id(sender_id)
@comment = Comment.find_by_id(comment_id)
@post_author_name = @comment.post.person.name
@post_author_name = @comment.post.author.name
log_mail(recipient_id, sender_id, 'comment_on_post')

View file

@ -3,7 +3,7 @@ class DataPoint < ActiveRecord::Base
def self.users_with_posts_on_day(time, number)
sql = ActiveRecord::Base.connection()
value = sql.execute("SELECT COUNT(*) FROM (SELECT COUNT(*) AS post_sum, person_id FROM posts WHERE created_at >= '#{(time - 1.days).utc.to_datetime}' AND created_at <= '#{time.utc.to_datetime}' GROUP BY person_id) AS t1 WHERE t1.post_sum = #{number};").first[0]
value = sql.execute("SELECT COUNT(*) FROM (SELECT COUNT(*) AS post_sum, author_id FROM posts WHERE created_at >= '#{(time - 1.days).utc.to_datetime}' AND created_at <= '#{time.utc.to_datetime}' GROUP BY author_id) AS t1 WHERE t1.post_sum = #{number};").first[0]
self.new(:key => number.to_s, :value => value)
end
end

View file

@ -13,8 +13,8 @@ class Mention < ActiveRecord::Base
after_destroy :delete_notification
def notify_recipient
Rails.logger.info "event=mention_sent id=#{self.id} to=#{person.diaspora_handle} from=#{post.person.diaspora_handle}"
Notification.notify(person.owner, self, post.person) unless person.remote?
Rails.logger.info "event=mention_sent id=#{self.id} to=#{person.diaspora_handle} from=#{post.author.diaspora_handle}"
Notification.notify(person.owner, self, post.author) unless person.remote?
end

View file

@ -26,7 +26,7 @@ class Person < ActiveRecord::Base
end
has_many :contacts #Other people's contacts for this person
has_many :posts #his own posts
has_many :posts, :foreign_key => :author_id #his own posts
belongs_to :owner, :class_name => 'User'

View file

@ -17,35 +17,28 @@ class Post < ActiveRecord::Base
has_many :post_visibilities
has_many :aspects, :through => :post_visibilities
has_many :mentions, :dependent => :destroy
belongs_to :person
belongs_to :author, :class_name => 'Person'
cattr_reader :per_page
@@per_page = 10
after_destroy :propogate_retraction
def author
self.person
end
def author= author
self.person = author
end
def user_refs
self.post_visibilities.count
end
def diaspora_handle= nd
self.person = Person.where(:diaspora_handle => nd).first
self.author = Person.where(:diaspora_handle => nd).first
write_attribute(:diaspora_handle, nd)
end
def self.diaspora_initialize params
new_post = self.new params.to_hash
new_post.person = params[:person]
new_post.author = params[:author]
new_post.public = params[:public] if params[:public]
new_post.pending = params[:pending] if params[:pending]
new_post.diaspora_handle = new_post.person.diaspora_handle
new_post.diaspora_handle = new_post.author.diaspora_handle
new_post
end
@ -53,7 +46,7 @@ class Post < ActiveRecord::Base
{
:post => {
:id => self.id,
:person => self.person.as_json,
:author => self.author.as_json,
}
}
end
@ -74,7 +67,7 @@ class Post < ActiveRecord::Base
#you know about it, and it is not mutable
local_post = Post.where(:guid => self.guid).first
if local_post && local_post.person_id == self.person_id
if local_post && local_post.author_id == self.author_id
known_post = user.visible_posts(:guid => self.guid).first
if known_post
if known_post.mutable?
@ -99,7 +92,7 @@ class Post < ActiveRecord::Base
protected
def propogate_retraction
self.person.owner.retract(self) if self.person.owner
self.author.owner.retract(self) if self.author.owner
end
end

View file

@ -10,6 +10,6 @@ class PostVisibility < ActiveRecord::Base
belongs_to :post
validates_presence_of :post
has_one :user, :through => :aspect
has_one :person, :through => :post
has_one :person, :through => :post, :foreign_key => :author_id
end

View file

@ -54,7 +54,7 @@ class Retraction
return
end
user.disconnected_by(self.target)
elsif self.target.nil? || self.target.person != self.person
elsif self.target.nil? || self.target.author != self.person
Rails.logger.info("event=retraction status=abort reason='no post found authored by retractor' sender=#{person.diaspora_handle} post_guid=#{post_guid}")
else
self.perform(user)

View file

@ -80,8 +80,8 @@ class StatusMessage < Post
<<-XML
<entry>
<title>#{x(self.message)}</title>
<link rel="alternate" type="text/html" href="#{person.url}status_messages/#{self.id}"/>
<id>#{person.url}posts/#{self.id}</id>
<link rel="alternate" type="text/html" href="#{self.author.url}status_messages/#{self.id}"/>
<id>#{self.author.url}posts/#{self.id}</id>
<published>#{self.created_at.xmlschema}</published>
<updated>#{self.updated_at.xmlschema}</updated>
<activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>

View file

@ -87,8 +87,8 @@ class User < ActiveRecord::Base
######## Posting ########
def build_post(class_name, opts = {})
opts[:person] = self.person
opts[:diaspora_handle] = opts[:person].diaspora_handle
opts[:author] = self.person
opts[:diaspora_handle] = opts[:author].diaspora_handle
model_class = class_name.to_s.camelize.constantize
model_class.diaspora_initialize(opts)
@ -108,7 +108,7 @@ class User < ActiveRecord::Base
def add_post_to_aspects(post)
Rails.logger.debug("event=add_post_to_aspects user_id=#{self.id} post_id=#{post.id}")
add_to_streams(post, self.aspects_with_person(post.person))
add_to_streams(post, self.aspects_with_person(post.author))
post
end

View file

@ -10,5 +10,5 @@
%p.photo_description
= post.caption
= link_to t('.view_all', :name => post.person.name), person_photos_path(post.person), :class => "small_text"
= link_to t('.view_all', :name => post.author.name), person_photos_path(post.author), :class => "small_text"

View file

@ -14,7 +14,7 @@
=link_to "#{t('next')} →", @next_photo, :rel => 'prefetch', :id => 'photo_show_right'
#original_post_info
= render 'shared/author_info', :person => @photo.person, :post => @photo
= render 'shared/author_info', :person => @photo.author, :post => @photo
#photo_container
#show_photo{:data=>{:guid=>@photo.id}}
@ -28,7 +28,7 @@
= @photo.caption
- if @ownership
.photo_options{:data=>{:actor=>"#{@photo.person.owner.id}",:actor_person=>"#{@photo.person.id}",:image_url=>"#{@photo.url(:thumb_large)}"}}
.photo_options{:data=>{:actor=>"#{@photo.author.owner.id}", :actor_person => "#{@photo.author.id}", :image_url => "#{@photo.url(:thumb_large)}"}}
= link_to t('.make_profile_photo'), {:controller => "photos", :action => "make_profile_photo", :photo_id => @photo.id}, :remote => true, :class => 'make_profile_photo'
|
= link_to t('.edit'), '#', :id => "edit_photo_toggle"

View file

@ -3,18 +3,18 @@
-# the COPYRIGHT file.
.stream_element{:data=>{:guid=>post.id}}
- if post.person.owner_id == current_user.id
- if post.author.owner_id == current_user.id
.right.hidden.controls
- reshare_aspects = aspects_without_post(all_aspects, post)
- unless reshare_aspects.empty?
= render 'shared/reshare', :aspects => reshare_aspects, :post => post
= link_to image_tag('deletelabel.png'), status_message_path(post), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete", :title => t('delete')
= person_image_link(post.person, :size => :thumb_small)
= person_image_link(post.author, :size => :thumb_small)
.content
%strong
= person_link(post.person)
= person_link(post.author)
= render 'status_messages/status_message', :post => post, :photos => post.photos
@ -23,7 +23,7 @@
%span.aspect_badges
%span.aspect_badge.public
= t('the_world')
- elsif post.person.owner_id == current_user.id
- elsif post.author.owner_id == current_user.id
%span.aspect_badges
= aspect_badges(aspects_with_post(all_aspects, post))

View file

@ -7,11 +7,11 @@
%span.time
= time_ago_in_words(post.created_at)
= person_image_link(post.person, :size => :thumb_small)
= person_image_link(post.author, :size => :thumb_small)
.content
.from
= person_link(post.person)
= person_link(post.author)
= render 'status_messages/status_message', :post => post, :photos => post.photos

View file

@ -5,7 +5,7 @@
.span-16.append-4.prepend-4.last
#original_post_info
= render 'shared/author_info', :person => @status_message.person, :post => @status_message
= render 'shared/author_info', :person => @status_message.author, :post => @status_message
#show_text
%p

View file

@ -3,7 +3,7 @@
-# the COPYRIGHT file.
#show_content{:data=>{:guid=>@status_message.id}}
= render 'shared/author_info', :person => @status_message.person, :post => @status_message
= render 'shared/author_info', :person => @status_message.author, :post => @status_message
%p
= markdownify(@status_message.message, :youtube_maps => @status_message[:youtube_titles])

View file

@ -1,13 +1,19 @@
class RenamePersonToAuthor < ActiveRecord::Migration
def self.up
remove_foreign_key(:comments, :people)
remove_foreign_key(:posts, :people)
rename_column :comments, :person_id, :author_id
rename_column :posts, :person_id, :author_id
add_foreign_key(:comments, :people, :column => :author_id, :dependent => :delete)
add_foreign_key(:posts, :people, :column => :author_id, :dependent => :delete)
end
def self.down
remove_foreign_key(:comments, :people, :column => :author_id)
remove_foreign_key(:posts, :people, :column => :author_id)
rename_column :comments, :author_id, :person_id
rename_column :posts, :author_id, :person_id
add_foreign_key(:comments, :people, :dependent => :delete)
add_foreign_key(:posts, :people, :dependent => :delete)
end
end

View file

@ -389,7 +389,7 @@ ActiveRecord::Schema.define(:version => 20110301014507) do
add_index "post_visibilities", ["post_id"], :name => "index_post_visibilities_on_post_id"
create_table "posts", :force => true do |t|
t.integer "person_id", :null => false
t.integer "author_id", :null => false
t.boolean "public", :default => false, :null => false
t.string "diaspora_handle"
t.string "guid", :null => false
@ -408,9 +408,9 @@ ActiveRecord::Schema.define(:version => 20110301014507) do
t.string "mongo_id"
end
add_index "posts", ["author_id"], :name => "index_posts_on_person_id"
add_index "posts", ["guid"], :name => "index_posts_on_guid"
add_index "posts", ["mongo_id"], :name => "index_posts_on_mongo_id"
add_index "posts", ["person_id"], :name => "index_posts_on_person_id"
add_index "posts", ["status_message_id", "pending"], :name => "index_posts_on_status_message_id_and_pending"
add_index "posts", ["status_message_id"], :name => "index_posts_on_status_message_id"
add_index "posts", ["type", "pending", "id"], :name => "index_posts_on_type_and_pending_and_id"
@ -522,7 +522,7 @@ ActiveRecord::Schema.define(:version => 20110301014507) do
add_foreign_key "notification_actors", "notifications", :name => "notification_actors_notification_id_fk", :dependent => :delete
add_foreign_key "posts", "people", :name => "posts_person_id_fk", :dependent => :delete
add_foreign_key "posts", "people", :name => "posts_author_id_fk", :column => "author_id", :dependent => :delete
add_foreign_key "profiles", "people", :name => "profiles_person_id_fk", :dependent => :delete

View file

@ -37,7 +37,7 @@ module Diaspora
#}
xml.post_ids {
aspect.posts.find_all_by_person_id(user_person_id).each do |post|
aspect.posts.find_all_by_author_id(user_person_id).each do |post|
xml.post_id post.id
end
}
@ -64,7 +64,7 @@ module Diaspora
}
xml.posts {
user.raw_visible_posts.find_all_by_person_id(user_person_id).each do |post|
user.raw_visible_posts.find_all_by_author_id(user_person_id).each do |post|
#post.comments.each do |comment|
# post_doc << comment.to_xml
#end

View file

@ -84,9 +84,9 @@ module Diaspora
def remove_contact(contact)
bad_person_id = contact.person_id
posts = raw_visible_posts.where(:person_id => bad_person_id).all
posts = raw_visible_posts.where(:author_id => bad_person_id).all
visibilities = PostVisibility.joins(:post, :aspect).where(
:posts => {:person_id => bad_person_id},
:posts => {:author_id => bad_person_id},
:aspects => {:user_id => self.id}
)
visibility_ids = visibilities.map{|v| v.id}

View file

@ -7,7 +7,7 @@ module Diaspora
module Querying
def find_visible_post_by_id( id )
self.raw_visible_posts.where(:id => id).includes({:person => :profile}, {:comments => {:author => :profile}}, :photos).first
self.raw_visible_posts.where(:id => id).includes({:author => :profile}, {:comments => {:author => :profile}}, :photos).first
end
def raw_visible_posts

View file

@ -8,7 +8,7 @@ class PostsFake
def initialize(posts)
author_ids = []
posts.each do |p|
author_ids << p.person_id
author_ids << p.author_id
p.comments.each do |c|
author_ids << c.author_id
end

View file

@ -51,7 +51,7 @@ module Postzord
def xml_author
if @object.is_a?(Comment)
#if A and B are friends, and A sends B a comment from C, we delegate the validation to the owner of the post being commented on
xml_author = @user.owns?(@object.post) ? @object.diaspora_handle : @object.post.person.diaspora_handle
xml_author = @user.owns?(@object.post) ? @object.diaspora_handle : @object.post.author.diaspora_handle
@author = Webfinger.new(@object.diaspora_handle).fetch
else
xml_author = @object.diaspora_handle
@ -82,6 +82,7 @@ module Postzord
end
if @author
@object.author = @author if @object.respond_to? :author=
@object.person = @author if @object.respond_to? :person=
end

View file

@ -18,7 +18,7 @@ describe PhotosController do
@photo2 = @user2.post(:photo, :user_file => uploaded_photo, :to => @aspect2.id, :public => true)
@controller.stub!(:current_user).and_return(@user1)
sign_in :user, @user1
sign_in :user, @user1
request.env["HTTP_REFERER"] = ''
end
@ -128,9 +128,9 @@ describe PhotosController do
it "doesn't overwrite random attributes" do
new_user = Factory.create(:user)
params = { :caption => "now with lasers!", :person_id => new_user.id }
params = { :caption => "now with lasers!", :author_id => new_user.id }
put :update, :id => @photo1.id, :photo => params
@photo1.reload.person_id.should == @user1.person.id
@photo1.reload.author_id.should == @user1.person.id
end
it 'redirects if you do not have access to the post' do

View file

@ -73,11 +73,11 @@ describe StatusMessagesController do
post :create, status_message_hash
end
it "doesn't overwrite person_id" do
status_message_hash[:status_message][:person_id] = @user2.person.id
it "doesn't overwrite author_id" do
status_message_hash[:status_message][:author_id] = @user2.person.id
post :create, status_message_hash
new_message = StatusMessage.find_by_message(status_message_hash[:status_message][:message])
new_message.person_id.should == @user1.person.id
new_message.author_id.should == @user1.person.id
end
it "doesn't overwrite id" do

View file

@ -62,11 +62,11 @@ Factory.define :aspect do |aspect|
aspect.association :user
end
Factory.define :status_message do |m|
Factory.define(:status_message) do |m|
m.sequence(:message) { |n| "jimmy's #{n} whales" }
m.association :person
m.association :author, :factory => :person
m.after_build do|m|
m.diaspora_handle = m.person.diaspora_handle
m.diaspora_handle = m.author.diaspora_handle
end
end

View file

@ -115,35 +115,29 @@ describe 'a user receives a post' do
@user1.raw_visible_posts.should_not include @status_message
end
it 'deletes a post if the noone links to it' do
person = Factory(:person)
@user1.activate_contact(person, @aspect)
post = Factory.create(:status_message, :person => person)
post.post_visibilities.should be_empty
receive_with_zord(@user1, person, post.to_diaspora_xml)
@aspect.post_visibilities.reset
@aspect.posts(true).should include(post)
post.post_visibilities.reset
post.post_visibilities.length.should == 1
context 'dependant delete' do
before do
@person = Factory(:person)
@user1.activate_contact(@person, @aspect)
@post = Factory.create(:status_message, :author => @person)
@post.post_visibilities.should be_empty
receive_with_zord(@user1, @person, @post.to_diaspora_xml)
@aspect.post_visibilities.reset
@aspect.posts(true).should include(@post)
@post.post_visibilities.reset
end
lambda {
@user1.disconnected_by(person)
}.should change(Post, :count).by(-1)
end
it 'deletes post_visibilities on disconnected by' do
person = Factory(:person)
@user1.activate_contact(person, @aspect)
post = Factory.create(:status_message, :person => person)
post.post_visibilities.should be_empty
receive_with_zord(@user1, person, post.to_diaspora_xml)
@aspect.post_visibilities.reset
@aspect.posts(true).should include(post)
post.post_visibilities.reset
post.post_visibilities.length.should == 1
it 'deletes a post if the noone links to it' do
lambda {
@user1.disconnected_by(@person)
}.should change(Post, :count).by(-1)
end
lambda {
@user1.disconnected_by(person)
}.should change{post.post_visibilities(true).count}.by(-1)
it 'deletes post_visibilities on disconnected by' do
lambda {
@user1.disconnected_by(@person)
}.should change{@post.post_visibilities(true).count}.by(-1)
end
end
it 'should keep track of user references for one person ' do
@status_message.reload
@ -254,11 +248,11 @@ describe 'a user receives a post' do
describe 'receiving mulitple versions of the same post from a remote pod' do
before do
@local_luke, @local_leia, @remote_raphael = set_up_friends
@post = Factory.build(:status_message, :message => 'hey', :guid => 12313123, :person => @remote_raphael, :created_at => 5.days.ago, :updated_at => 5.days.ago)
@post = Factory.build(:status_message, :message => 'hey', :guid => 12313123, :author=> @remote_raphael, :created_at => 5.days.ago, :updated_at => 5.days.ago)
end
it 'does not update created_at or updated_at when two people save the same post' do
@post = Factory.build(:status_message, :message => 'hey', :guid => 12313123, :person => @remote_raphael, :created_at => 5.days.ago, :updated_at => 5.days.ago)
@post = Factory.build(:status_message, :message => 'hey', :guid => 12313123, :author=> @remote_raphael, :created_at => 5.days.ago, :updated_at => 5.days.ago)
xml = @post.to_diaspora_xml
receive_with_zord(@local_luke, @remote_raphael, xml)
sleep(2)
@ -269,11 +263,11 @@ describe 'a user receives a post' do
end
it 'does not update the post if a new one is sent with a new created_at' do
@post = Factory.build(:status_message, :message => 'hey', :guid => 12313123, :person => @remote_raphael, :created_at => 5.days.ago)
@post = Factory.build(:status_message, :message => 'hey', :guid => 12313123, :author => @remote_raphael, :created_at => 5.days.ago)
old_time = @post.created_at
xml = @post.to_diaspora_xml
receive_with_zord(@local_luke, @remote_raphael, xml)
@post = Factory.build(:status_message, :message => 'hey', :guid => 12313123, :person => @remote_raphael, :created_at => 2.days.ago)
@post = Factory.build(:status_message, :message => 'hey', :guid => 12313123, :author => @remote_raphael, :created_at => 2.days.ago)
receive_with_zord(@local_luke, @remote_raphael, xml)
(Post.find_by_guid @post.guid).created_at.day.should == old_time.day
end

View file

@ -357,8 +357,8 @@ describe DataConversion::ImportToMysql do
post.image.should be_nil
post.mongo_id.should == "4d2b6ebecc8cb43cc2000027"
post.guid.should == post.mongo_id
post.person_id.should == Person.where(:mongo_id => mongo_post.person_mongo_id).first.id
post.diaspora_handle.should == post.person.diaspora_handle
post.author_id.should == Person.where(:mongo_id => mongo_post.person_mongo_id).first.id
post.diaspora_handle.should == post.author.diaspora_handle
post.message.should == "User2 can see this"
post.created_at.should == mongo_post.created_at
post.updated_at.should == mongo_post.updated_at
@ -379,8 +379,8 @@ describe DataConversion::ImportToMysql do
post.image.file.file.should =~ /mUKUIxkYlV4d2b6ebfcc8cb43cc200002d\.png/
post.mongo_id.should == "4d2b6ebfcc8cb43cc200002d"
post.guid.should == post.mongo_id
post.person_id.should == Person.where(:mongo_id => mongo_post.person_mongo_id).first.id
post.diaspora_handle.should == post.person.diaspora_handle
post.author_id.should == Person.where(:mongo_id => mongo_post.person_mongo_id).first.id
post.diaspora_handle.should == post.author.diaspora_handle
post.message.should be_nil
post.created_at.should == mongo_post.created_at
post.updated_at.should == mongo_post.updated_at

View file

@ -5,7 +5,7 @@ describe PostsFake do
@people = []
4.times do
post = Factory(:status_message)
@people << post.person
@people << post.author
4.times do
comment = Factory(:comment, :post => post)
@people << comment.author

View file

@ -181,7 +181,7 @@ describe Postzord::Dispatch do
end
context "remote raphael's post is commented on by local luke" do
before do
@post = Factory(:status_message, :person => @remote_raphael)
@post = Factory(:status_message, :author => @remote_raphael)
@comment = @local_luke.build_comment "yo", :on => @post
@comment.save
@mailman = Postzord::Dispatch.new(@local_luke, @comment)
@ -304,7 +304,7 @@ describe Postzord::Dispatch do
it 'queues Job::NotifyLocalUsers jobs' do
@zord.instance_variable_get(:@object).should_receive(:socket_to_user).and_return(false)
Resque.should_receive(:enqueue).with(Job::NotifyLocalUsers, @local_user.id, @sm.class.to_s, @sm.id, @sm.person.id)
Resque.should_receive(:enqueue).with(Job::NotifyLocalUsers, @local_user.id, @sm.class.to_s, @sm.id, @sm.author.id)
@zord.send(:socket_and_notify_users, [@local_user])
end
end

View file

@ -5,12 +5,10 @@
require 'spec_helper'
describe Diaspora::Webhooks do
before do
@user = Factory.build(:user)
@post = Factory.build(:status_message, :person => @user.person)
end
it "should add the following methods to Post on inclusion" do
@post.respond_to?(:to_diaspora_xml).should be true
user = Factory.build(:user)
post = Factory.build(:status_message, :author => user.person)
post.respond_to?(:to_diaspora_xml).should be true
end
end

View file

@ -87,7 +87,7 @@ describe Notifier do
@sm = Factory(:status_message)
@m = Mention.create(:person => @user.person, :post=> @sm)
@mail = Notifier.mentioned(@user.id, @sm.person.id, @m.id)
@mail = Notifier.mentioned(@user.id, @sm.author.id, @m.id)
end
it 'goes to the right person' do
@mail.to.should == [@user.email]
@ -98,7 +98,7 @@ describe Notifier do
end
it 'has the name of person mentioning in the body' do
@mail.body.encoded.include?(@sm.person.name).should be true
@mail.body.encoded.include?(@sm.author.name).should be true
end
it 'has the post text in the body' do

View file

@ -53,7 +53,7 @@ describe 'making sure the spec runner works' do
describe '#comment' do
it "should send a user's comment on a person's post to that person" do
person = Factory.create(:person)
person_status = Factory.create(:status_message, :person => person)
person_status = Factory.create(:status_message, :author => person)
m = mock()
m.stub!(:post)
Postzord::Dispatch.should_receive(:new).and_return(m)

View file

@ -114,7 +114,7 @@ describe Aspect do
aspect = user.aspects.create(:name => 'losers')
contact = aspect.contacts.create(:person => connected_person)
status_message = user.post( :status_message, :message => "hey", :to => aspect.id )
status_message = user.post(:status_message, :message => "hey", :to => aspect.id)
aspect.reload
aspect.posts.include?(status_message).should be true

View file

@ -112,7 +112,7 @@ describe Comment do
describe 'it is relayable' do
before do
@local_luke, @local_leia, @remote_raphael = set_up_friends
@remote_parent = Factory.create(:status_message, :person => @remote_raphael)
@remote_parent = Factory.create(:status_message, :author => @remote_raphael)
@local_parent = @local_luke.post :status_message, :message => "hi", :to => @local_luke.aspects.first
@object_by_parent_author = @local_luke.comment("yo", :on => @local_parent)

View file

@ -6,7 +6,7 @@ describe ConversationVisibility do
@aspect = @user.aspects.create(:name => 'Boozers')
@person = Factory(:person)
@post = Factory(:status_message, :person => @person)
@post = Factory(:status_message, :author => @person)
end
it 'has an aspect' do
pv = PostVisibility.new(:aspect => @aspect)

View file

@ -13,9 +13,9 @@ describe Job::MailMentioned do
mail_mock = mock()
mail_mock.should_receive(:deliver)
Notifier.should_receive(:mentioned).with(user.id, sm.person.id, m.id).and_return(mail_mock)
Notifier.should_receive(:mentioned).with(user.id, sm.author.id, m.id).and_return(mail_mock)
Job::MailMentioned.perform_delegate(user.id, sm.person.id, m.id)
Job::MailMentioned.perform_delegate(user.id, sm.author.id, m.id)
end
end
end

View file

@ -17,7 +17,7 @@ describe Mention do
end
it 'notifies the person being mention' do
Notification.should_receive(:notify).with(@user, @m, @sm.person)
Notification.should_receive(:notify).with(@user, @m, @sm.author)
@m.save
end

View file

@ -101,8 +101,8 @@ describe Person do
end
it '#owns? posts' do
person_message = Factory.create(:status_message, :person => @person)
person_two = Factory.create(:person)
person_message = Factory.create(:status_message, :author => @person)
person_two = Factory.create(:person)
@person.owns?(person_message).should be true
person_two.owns?(person_message).should be false
@ -111,8 +111,8 @@ describe Person do
describe '#remove_all_traces' do
before do
@deleter = Factory(:person)
@status = Factory.create(:status_message, :person => @deleter)
@other_status = Factory.create(:status_message, :person => @person)
@status = Factory.create(:status_message, :author => @deleter)
@other_status = Factory.create(:status_message, :author => @person)
end
it "deletes all notifications from a person's actions" do

View file

@ -20,13 +20,13 @@ describe Photo do
describe "protected attributes" do
it "doesn't allow mass assignment of person" do
@photo.save!
@photo.update_attributes(:person => Factory(:person))
@photo.reload.person.should == @user.person
@photo.update_attributes(:author => Factory(:person))
@photo.reload.author.should == @user.person
end
it "doesn't allow mass assignment of person_id" do
@photo.save!
@photo.update_attributes(:person_id => Factory(:person).id)
@photo.reload.person.should == @user.person
@photo.update_attributes(:author_id => Factory(:person).id)
@photo.reload.author.should == @user.person
end
it 'allows assignmant of caption' do
@photo.save!
@ -50,14 +50,14 @@ describe Photo do
it 'has a constructor' do
image = File.open(@fixture_name)
photo = Photo.diaspora_initialize(
:person => @user.person, :user_file => image)
:author => @user.person, :user_file => image)
photo.created_at.nil?.should be_true
photo.image.read.nil?.should be_false
end
it 'sets a remote url' do
image = File.open(@fixture_name)
photo = Photo.diaspora_initialize(
:person => @user.person, :user_file => image)
:author => @user.person, :user_file => image)
photo.remote_photo_path.should include("http")
photo.remote_photo_name.should include(".png")
end
@ -139,7 +139,7 @@ describe Photo do
xml = @photo.to_diaspora_xml
@photo.destroy
zord = Postzord::Receiver.new(user2, :person => @photo.person)
zord = Postzord::Receiver.new(user2, :person => @photo.author)
zord.parse_and_receive(xml)
new_photo = Photo.where(:guid => @photo.guid).first

View file

@ -12,7 +12,7 @@ describe Post do
describe 'deletion' do
it 'should delete a posts comments on delete' do
post = Factory.create(:status_message, :person => @user.person)
post = Factory.create(:status_message, :author => @user.person)
@user.comment "hey", :on => post
post.destroy
Post.where(:id => post.id).empty?.should == true

View file

@ -6,7 +6,7 @@ describe PostVisibility do
@aspect = @user.aspects.create(:name => 'Boozers')
@person = Factory(:person)
@post = Factory(:status_message, :person => @person)
@post = Factory(:status_message, :author => @person)
end
it 'has an aspect' do
pv = PostVisibility.new(:aspect => @aspect)

View file

@ -21,11 +21,11 @@ describe StatusMessage do
end
describe '#diaspora_handle=' do
it 'sets #person' do
it 'sets #author' do
person = Factory.create(:person)
post = Factory.create(:status_message, :person => @user.person)
post = Factory.create(:status_message, :author => @user.person)
post.diaspora_handle = person.diaspora_handle
post.person.should == person
post.author.should == person
end
end
it "should have either a message or at least one photo" do
@ -150,7 +150,7 @@ STR
end
describe "XML" do
before do
@message = Factory.create(:status_message, :message => "I hate WALRUSES!", :person => @user.person)
@message = Factory.create(:status_message, :message => "I hate WALRUSES!", :author => @user.person)
@xml = @message.to_xml.to_s
end
it 'serializes the unescaped, unprocessed message' do
@ -176,7 +176,7 @@ STR
@marshalled.guid.should == @message.guid
end
it 'marshals the author' do
@marshalled.person.should == @message.person
@marshalled.author.should == @message.author
end
it 'marshals the diaspora_handle' do
@marshalled.diaspora_handle.should == @message.diaspora_handle

View file

@ -67,7 +67,7 @@ describe "attack vectors" do
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml)
zord.perform
malicious_message = Factory.build( :status_message, :id => original_message.id, :message => 'BAD!!!', :person => user3.person)
malicious_message = Factory.build(:status_message, :id => original_message.id, :message => 'BAD!!!', :author => user3.person)
salmon_xml = user3.salmon(malicious_message).xml_for(user.person)
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml)
zord.perform
@ -83,7 +83,7 @@ describe "attack vectors" do
zord.perform
lambda {
malicious_message = Factory.build( :status_message, :id => original_message.id, :message => 'BAD!!!', :person => user2.person)
malicious_message = Factory.build( :status_message, :id => original_message.id, :message => 'BAD!!!', :author => user2.person)
salmon_xml2 = user3.salmon(malicious_message).xml_for(user.person)
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml)

View file

@ -47,7 +47,7 @@ describe User do
describe "#visible_posts" do
it "queries by person id" do
query = @user2.visible_posts(:person_id => @user2.person.id)
query = @user2.visible_posts(:author_id => @user2.person.id)
query.include?(@status_message1).should == true
query.include?(@status_message2).should == true
query.include?(@status_message3).should == false
@ -195,7 +195,7 @@ describe User do
end
it 'returns nil if the input is nil' do
@user.contact_for(nil).should be_nil
@user.contact_for(nil).should be_nil
end
end
end

View file

@ -271,7 +271,7 @@ describe User do
fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', fixture_filename)
image = File.open(fixture_name)
@photo = Photo.diaspora_initialize(
:person => alice.person, :user_file => image)
:author => alice.person, :user_file => image)
@photo.save!
@params = {:photo => @photo}
end