Changing message to text, partway done, deleted data conversion
This commit is contained in:
parent
adbd23ec50
commit
4b4654a408
61 changed files with 220 additions and 2246 deletions
|
|
@ -25,7 +25,7 @@ class StatusMessagesController < ApplicationController
|
|||
@status_message.photos << photos
|
||||
end
|
||||
if @status_message.save
|
||||
Rails.logger.info("event=create type=status_message chars=#{params[:status_message][:message].length}")
|
||||
Rails.logger.info("event=create type=status_message chars=#{params[:status_message][:text].length}")
|
||||
|
||||
current_user.add_to_streams(@status_message, aspects)
|
||||
receiving_services = params[:services].map{|s| current_user.services.where(
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
module Mongo
|
||||
def self.table_name_prefix
|
||||
"mongo_"
|
||||
end
|
||||
|
||||
class Aspect < ActiveRecord::Base; end
|
||||
class AspectMembership < ActiveRecord::Base; end
|
||||
class Comment < ActiveRecord::Base; end
|
||||
class Contact < ActiveRecord::Base; end
|
||||
class Invitation < ActiveRecord::Base; end
|
||||
class Notification < ActiveRecord::Base; end
|
||||
class Person < ActiveRecord::Base; end
|
||||
#Photo?
|
||||
class Post < ActiveRecord::Base; end
|
||||
class PostVisibility < ActiveRecord::Base; end
|
||||
class Profile < ActiveRecord::Base; end
|
||||
class Request < ActiveRecord::Base; end
|
||||
class Service < ActiveRecord::Base; end
|
||||
#StatusMessage?
|
||||
class User < ActiveRecord::Base; end
|
||||
end
|
||||
|
|
@ -9,12 +9,12 @@ class Photo < Post
|
|||
xml_attr :remote_photo_path
|
||||
xml_attr :remote_photo_name
|
||||
|
||||
xml_attr :caption
|
||||
xml_attr :text
|
||||
xml_attr :status_message_guid
|
||||
|
||||
belongs_to :status_message
|
||||
|
||||
attr_accessible :caption, :pending
|
||||
attr_accessible :text, :pending
|
||||
validate :ownership_of_status_message
|
||||
|
||||
before_destroy :ensure_user_picture
|
||||
|
|
@ -101,7 +101,7 @@ class Photo < Post
|
|||
:id => self.id,
|
||||
:url => self.url(:thumb_medium),
|
||||
:thumb_small => self.url(:thumb_small),
|
||||
:caption => self.caption
|
||||
:text => self.text
|
||||
}
|
||||
}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,18 +10,18 @@ class StatusMessage < Post
|
|||
|
||||
acts_as_taggable_on :tags
|
||||
|
||||
validates_length_of :message, :maximum => 1000, :message => "please make your status messages less than 1000 characters"
|
||||
validates_length_of :message, :maximum => 1000, :text => "please make your status messages less than 1000 characters"
|
||||
xml_name :status_message
|
||||
xml_attr :raw_message
|
||||
|
||||
has_many :photos, :dependent => :destroy
|
||||
validate :message_or_photos_present?
|
||||
|
||||
attr_accessible :message
|
||||
attr_accessible :text
|
||||
|
||||
serialize :youtube_titles, Hash
|
||||
before_save do
|
||||
get_youtube_title message
|
||||
get_youtube_title text
|
||||
end
|
||||
|
||||
before_create :build_tags
|
||||
|
|
@ -31,10 +31,10 @@ class StatusMessage < Post
|
|||
end
|
||||
|
||||
def raw_message
|
||||
read_attribute(:message)
|
||||
read_attribute(:text)
|
||||
end
|
||||
def raw_message=(text)
|
||||
write_attribute(:message, text)
|
||||
write_attribute(:text, text)
|
||||
end
|
||||
|
||||
def formatted_message(opts={})
|
||||
|
|
@ -136,7 +136,7 @@ class StatusMessage < Post
|
|||
protected
|
||||
|
||||
def message_or_photos_present?
|
||||
if self.message.blank? && self.photos == []
|
||||
if self.text.blank? && self.photos == []
|
||||
errors[:base] << 'Status message requires a message or at least one photo'
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
= post.pending
|
||||
|
||||
%p.photo_description
|
||||
= post.caption
|
||||
= post.text
|
||||
|
||||
= link_to t('.view_all', :name => post.author.name), person_photos_path(post.author), :class => "small_text"
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
= image_tag @photo.url(:scaled_full)
|
||||
|
||||
= form_for @photo do |photo|
|
||||
= photo.label :caption
|
||||
= photo.text_field :caption, :value => @photo.caption
|
||||
= photo.label :text
|
||||
= photo.text_field :text, :value => @photo.text
|
||||
= photo.submit
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
= image_tag @photo.url(:scaled_full)
|
||||
|
||||
#caption
|
||||
= @photo.caption
|
||||
= @photo.text
|
||||
|
||||
- if @ownership
|
||||
.photo_options{:data=>{:actor=>"#{@photo.author.owner.id}", :actor_person => "#{@photo.author.id}", :image_url => "#{@photo.url(:thumb_large)}"}}
|
||||
|
|
@ -56,7 +56,7 @@
|
|||
%h4= t('.edit_delete_photo')
|
||||
%p
|
||||
= form_for @photo, :remote => true do |p|
|
||||
= p.text_field :caption, :value => @photo.caption
|
||||
= p.text_field :text, :value => @photo.text
|
||||
= p.submit t('.update_photo')
|
||||
%p
|
||||
= button_to t('.delete_photo'), @photo, :confirm => t('are_you_sure'), :method => :delete
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
= image_tag @post.url(:scaled_full)
|
||||
|
||||
#caption
|
||||
= @post.caption
|
||||
= @post.text
|
||||
|
||||
%br
|
||||
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@
|
|||
%params
|
||||
#publisher_textarea_wrapper
|
||||
%ul#photodropzone
|
||||
= status.text_area :fake_message, :rows => 2, :value => h(params[:prefill])
|
||||
= status.hidden_field :message, :value => '', :class => 'clear_on_submit'
|
||||
= status.text_area :fake_text, :rows => 2, :value => h(params[:prefill])
|
||||
= status.hidden_field :text, :value => '', :class => 'clear_on_submit'
|
||||
|
||||
- for aspect_id in @aspect_ids
|
||||
= hidden_field_tag 'aspect_ids[]', aspect_id.to_s
|
||||
|
|
|
|||
|
|
@ -51,7 +51,6 @@ module Diaspora
|
|||
config.filter_parameters += [:xml]
|
||||
config.filter_parameters += [:message]
|
||||
config.filter_parameters += [:text]
|
||||
config.filter_parameters += [:caption]
|
||||
config.filter_parameters += [:bio]
|
||||
|
||||
end
|
||||
|
|
|
|||
12
db/migrate/20110313015438_rename_text_fields.rb
Normal file
12
db/migrate/20110313015438_rename_text_fields.rb
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
class RenameTextFields < ActiveRecord::Migration
|
||||
def self.up
|
||||
rename_column :posts, :message, :text
|
||||
execute("UPDATE posts
|
||||
SET posts.text = posts.caption
|
||||
WHERE posts.caption IS NOT NULL;")
|
||||
remove_column :posts, :caption
|
||||
end
|
||||
|
||||
def self.down
|
||||
end
|
||||
end
|
||||
10
db/migrate/20110314043119_drop_import_tables.rb
Normal file
10
db/migrate/20110314043119_drop_import_tables.rb
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
require 'db/migrate/20110105051803_create_import_tables'
|
||||
class DropImportTables < ActiveRecord::Migration
|
||||
def self.up
|
||||
CreateImportTables.down
|
||||
end
|
||||
|
||||
def self.down
|
||||
CreateImportTables.up
|
||||
end
|
||||
end
|
||||
190
db/schema.rb
190
db/schema.rb
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20110311220249) do
|
||||
ActiveRecord::Schema.define(:version => 20110314043119) do
|
||||
|
||||
create_table "aspect_memberships", :force => true do |t|
|
||||
t.integer "aspect_id", :null => false
|
||||
|
|
@ -127,66 +127,6 @@ ActiveRecord::Schema.define(:version => 20110311220249) do
|
|||
|
||||
add_index "messages", ["author_id"], :name => "index_messages_on_author_id"
|
||||
|
||||
create_table "mongo_aspect_memberships", :force => true do |t|
|
||||
t.string "aspect_mongo_id"
|
||||
t.string "contact_mongo_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
add_index "mongo_aspect_memberships", ["aspect_mongo_id"], :name => "index_mongo_aspect_memberships_on_aspect_mongo_id"
|
||||
add_index "mongo_aspect_memberships", ["contact_mongo_id"], :name => "index_mongo_aspect_memberships_on_contact_mongo_id"
|
||||
|
||||
create_table "mongo_aspects", :force => true do |t|
|
||||
t.string "mongo_id"
|
||||
t.string "name"
|
||||
t.string "user_mongo_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
add_index "mongo_aspects", ["user_mongo_id"], :name => "index_mongo_aspects_on_user_mongo_id"
|
||||
|
||||
create_table "mongo_comments", :force => true do |t|
|
||||
t.text "text"
|
||||
t.string "mongo_id"
|
||||
t.string "post_mongo_id"
|
||||
t.string "person_mongo_id"
|
||||
t.string "guid"
|
||||
t.text "creator_signature"
|
||||
t.text "post_creator_signature"
|
||||
t.text "youtube_titles"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
add_index "mongo_comments", ["guid"], :name => "index_mongo_comments_on_guid", :unique => true
|
||||
add_index "mongo_comments", ["post_mongo_id"], :name => "index_mongo_comments_on_post_mongo_id"
|
||||
|
||||
create_table "mongo_contacts", :force => true do |t|
|
||||
t.string "mongo_id"
|
||||
t.string "user_mongo_id"
|
||||
t.string "person_mongo_id"
|
||||
t.boolean "pending", :default => true
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
add_index "mongo_contacts", ["person_mongo_id", "pending"], :name => "index_mongo_contacts_on_person_mongo_id_and_pending"
|
||||
add_index "mongo_contacts", ["user_mongo_id", "pending"], :name => "index_mongo_contacts_on_user_mongo_id_and_pending"
|
||||
|
||||
create_table "mongo_invitations", :force => true do |t|
|
||||
t.string "mongo_id"
|
||||
t.text "message"
|
||||
t.string "sender_mongo_id"
|
||||
t.string "recipient_mongo_id"
|
||||
t.string "aspect_mongo_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
add_index "mongo_invitations", ["sender_mongo_id"], :name => "index_mongo_invitations_on_sender_mongo_id"
|
||||
|
||||
create_table "mongo_notifications", :force => true do |t|
|
||||
t.string "mongo_id"
|
||||
t.string "target_type", :limit => 127
|
||||
|
|
@ -201,131 +141,6 @@ ActiveRecord::Schema.define(:version => 20110311220249) do
|
|||
|
||||
add_index "mongo_notifications", ["target_type", "target_mongo_id"], :name => "index_mongo_notifications_on_target_type_and_target_mongo_id"
|
||||
|
||||
create_table "mongo_people", :force => true do |t|
|
||||
t.string "mongo_id"
|
||||
t.string "guid"
|
||||
t.text "url"
|
||||
t.string "diaspora_handle"
|
||||
t.text "serialized_public_key"
|
||||
t.string "owner_mongo_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
add_index "mongo_people", ["diaspora_handle"], :name => "index_mongo_people_on_diaspora_handle", :unique => true
|
||||
add_index "mongo_people", ["guid"], :name => "index_mongo_people_on_guid", :unique => true
|
||||
add_index "mongo_people", ["owner_mongo_id"], :name => "index_mongo_people_on_owner_mongo_id", :unique => true
|
||||
|
||||
create_table "mongo_post_visibilities", :force => true do |t|
|
||||
t.string "aspect_mongo_id"
|
||||
t.string "post_mongo_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
add_index "mongo_post_visibilities", ["aspect_mongo_id"], :name => "index_mongo_post_visibilities_on_aspect_mongo_id"
|
||||
add_index "mongo_post_visibilities", ["post_mongo_id"], :name => "index_mongo_post_visibilities_on_post_mongo_id"
|
||||
|
||||
create_table "mongo_posts", :force => true do |t|
|
||||
t.string "person_mongo_id"
|
||||
t.boolean "public", :default => false
|
||||
t.string "diaspora_handle"
|
||||
t.string "guid"
|
||||
t.string "mongo_id"
|
||||
t.boolean "pending", :default => false
|
||||
t.string "type"
|
||||
t.text "message"
|
||||
t.string "status_message_mongo_id"
|
||||
t.text "caption"
|
||||
t.text "remote_photo_path"
|
||||
t.string "remote_photo_name"
|
||||
t.string "random_string"
|
||||
t.string "image"
|
||||
t.text "youtube_titles"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
add_index "mongo_posts", ["guid"], :name => "index_mongo_posts_on_guid"
|
||||
add_index "mongo_posts", ["person_mongo_id"], :name => "index_mongo_posts_on_person_mongo_id"
|
||||
add_index "mongo_posts", ["type"], :name => "index_mongo_posts_on_type"
|
||||
|
||||
create_table "mongo_profiles", :force => true do |t|
|
||||
t.string "diaspora_handle"
|
||||
t.string "first_name", :limit => 127
|
||||
t.string "last_name", :limit => 127
|
||||
t.string "image_url"
|
||||
t.string "image_url_small"
|
||||
t.string "image_url_medium"
|
||||
t.date "birthday"
|
||||
t.string "gender"
|
||||
t.text "bio"
|
||||
t.boolean "searchable", :default => true
|
||||
t.string "person_mongo_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
add_index "mongo_profiles", ["first_name", "last_name", "searchable"], :name => "index_mongo_profiles_on_first_name_and_last_name_and_searchable"
|
||||
add_index "mongo_profiles", ["first_name", "searchable"], :name => "index_mongo_profiles_on_first_name_and_searchable"
|
||||
add_index "mongo_profiles", ["last_name", "searchable"], :name => "index_mongo_profiles_on_last_name_and_searchable"
|
||||
add_index "mongo_profiles", ["person_mongo_id"], :name => "index_mongo_profiles_on_person_mongo_id", :unique => true
|
||||
|
||||
create_table "mongo_requests", :force => true do |t|
|
||||
t.string "mongo_id"
|
||||
t.string "sender_mongo_id", :limit => 127
|
||||
t.string "recipient_mongo_id", :limit => 127
|
||||
t.string "aspect_mongo_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
add_index "mongo_requests", ["recipient_mongo_id"], :name => "index_mongo_requests_on_recipient_mongo_id"
|
||||
add_index "mongo_requests", ["sender_mongo_id", "recipient_mongo_id"], :name => "index_mongo_requests_on_sender_mongo_id_and_recipient_mongo_id", :unique => true
|
||||
add_index "mongo_requests", ["sender_mongo_id"], :name => "index_mongo_requests_on_sender_mongo_id"
|
||||
|
||||
create_table "mongo_services", :force => true do |t|
|
||||
t.string "mongo_id"
|
||||
t.string "type"
|
||||
t.string "user_mongo_id"
|
||||
t.string "provider"
|
||||
t.string "uid"
|
||||
t.string "access_token"
|
||||
t.string "access_secret"
|
||||
t.string "nickname"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
add_index "mongo_services", ["user_mongo_id"], :name => "index_mongo_services_on_user_mongo_id"
|
||||
|
||||
create_table "mongo_users", :force => true do |t|
|
||||
t.string "username"
|
||||
t.text "serialized_private_key"
|
||||
t.integer "invites"
|
||||
t.boolean "getting_started"
|
||||
t.boolean "disable_mail"
|
||||
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"
|
||||
t.string "mongo_id"
|
||||
end
|
||||
|
||||
add_index "mongo_users", ["mongo_id"], :name => "index_mongo_users_on_mongo_id", :unique => true
|
||||
|
||||
create_table "notification_actors", :force => true do |t|
|
||||
t.integer "notification_id"
|
||||
t.integer "person_id"
|
||||
|
|
@ -385,9 +200,8 @@ ActiveRecord::Schema.define(:version => 20110311220249) do
|
|||
t.string "guid", :null => false
|
||||
t.boolean "pending", :default => false, :null => false
|
||||
t.string "type", :null => false
|
||||
t.text "message"
|
||||
t.text "text"
|
||||
t.integer "status_message_id"
|
||||
t.text "caption"
|
||||
t.text "remote_photo_path"
|
||||
t.string "remote_photo_name"
|
||||
t.string "random_string"
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ end
|
|||
|
||||
Given /^a user with email "([^\"]*)" has posted a status message "([^\"]*)" in all aspects$/ do |arg1, arg2|
|
||||
user = User.where(:email => arg1).first
|
||||
status_message = user.build_post(:status_message, :message => arg2)
|
||||
status_message = user.build_post(:status_message, :text => arg2)
|
||||
def status_message.socket_to_user(a1, a2); end
|
||||
user.add_to_streams(status_message, user.aspects)
|
||||
status_message.save!
|
||||
|
|
|
|||
|
|
@ -1,59 +0,0 @@
|
|||
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
module DataConversion
|
||||
class Base
|
||||
attr_accessor :start_time, :directory, :full_path
|
||||
|
||||
def initialize(start_time = Time.now)
|
||||
@start_time = start_time
|
||||
@directory = "tmp/export-for-mysql"
|
||||
@full_path = "#{Rails.root}/#{directory}"
|
||||
end
|
||||
def models
|
||||
@models ||= [
|
||||
{:name => :aspects,
|
||||
:main_attrs => ["mongo_id", "name", "user_mongo_id", "created_at", "updated_at"],
|
||||
:mongo_attrs => ["_id" , "name", "user_id" , "created_at", "updated_at"],
|
||||
:join_table_name => :post_visibilities,
|
||||
:join_table_attrs => ["aspect_mongo_id", "post_mongo_id"]},
|
||||
{:name => :comments,
|
||||
:attrs => ["mongo_id", "post_mongo_id", "person_mongo_id", "diaspora_handle", "text", "youtube_titles", "created_at", "updated_at"],
|
||||
:mongo_attrs => ["_id", "post_id", "person_id", "diaspora_handle", "text", "youtube_titles", "created_at", "updated_at"]},
|
||||
{:name => :contacts,
|
||||
:main_attrs => ["mongo_id", "user_mongo_id", "person_mongo_id", "pending", "created_at", "updated_at"],
|
||||
:main_mongo_attrs => ["_id" , "user_id" , "person_id" , "pending", "created_at", "updated_at"],
|
||||
:join_table_name => :aspect_memberships,
|
||||
:join_table_attrs => ["contact_mongo_id", "aspect_mongo_id"]},
|
||||
{:name => :invitations,
|
||||
:attrs => ["mongo_id", "recipient_mongo_id", "sender_mongo_id", "aspect_mongo_id", "message", "created_at", "updated_at"],
|
||||
:mongo_attrs => ["_id" , "to_id" , "from_id" , "into_id" , "message", "created_at", "updated_at"]},
|
||||
{:name => :notifications,
|
||||
:attrs => ["mongo_id", "target_mongo_id", "recipient_mongo_id", "actor_mongo_id", "action", "target_type", "unread", "created_at", "updated_at"],
|
||||
:mongo_attrs => ["_id" , "target_id" , "user_id" , "person_id" , "action", "kind" , "unread", "created_at", "updated_at"]},
|
||||
{:name => :people,
|
||||
:attrs => ["created_at", "updated_at", "serialized_public_key", "url", "mongo_id", "owner_mongo_id", "diaspora_handle"],
|
||||
:profile_attrs => ["image_url_medium", "searchable", "image_url", "person_mongo_id", "gender", "diaspora_handle", "birthday", "last_name", "bio", "image_url_small", "first_name"]},
|
||||
{:name => :posts,
|
||||
:attrs => ["youtube_titles", "pending", "created_at", "public", "updated_at", "status_message_mongo_id", "caption", "remote_photo_path", "remote_photo_name", "random_string", "image" , "mongo_id", "type", "diaspora_handle", "person_mongo_id", "message"],
|
||||
:mongo_attrs => ["youtube_titles", "pending", "created_at", "public", "updated_at", "status_message_id" , "caption", "remote_photo_path", "remote_photo_name", "random_string", "image_filename", "_id" , "_type", "diaspora_handle", "person_id" , "message"]},
|
||||
{:name => :requests,
|
||||
:attrs => ["mongo_id", "recipient_mongo_id", "sender_mongo_id", "aspect_mongo_id", "created_at", "updated_at"],
|
||||
:mongo_attrs => ["_id" , "to_id" , "from_id" , "into_id" , "created_at", "updated_at"]},
|
||||
{:name => :services,
|
||||
:attrs => ["mongo_id", "type", "user_mongo_id", "provider", "uid", "access_token", "access_secret", "nickname", "created_at", "updated_at"],
|
||||
:mongo_attrs => ["_id" , "_type", "user_id", "provider", "uid", "access_token", "access_secret", "nickname", "created_at", "updated_at"]},
|
||||
{:name => :users,
|
||||
:attrs => ["mongo_id","email", "username", "serialized_private_key", "encrypted_password", "invites", "invitation_token", "invitation_sent_at", "getting_started", "disable_mail", "language", "last_sign_in_ip", "last_sign_in_at", "reset_password_token", "password_salt", "created_at", "updated_at"],
|
||||
:mongo_attrs => ["_id" , "email","username", "serialized_private_key", "encrypted_password", "invites", "invitation_token", "invitation_sent_at", "getting_started", "disable_mail", "language", "last_sign_in_ip", "last_sign_in_at", "reset_password_token", "password_salt", "created_at", "updated_at"]},
|
||||
]
|
||||
end
|
||||
def log(message)
|
||||
if ['development', 'production'].include?(Rails.env)
|
||||
puts "#{sprintf("%.2f", Time.now - start_time)}s #{message}"
|
||||
end
|
||||
Rails.logger.debug(message) if Rails.logger
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,227 +0,0 @@
|
|||
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
require 'json'
|
||||
require 'csv'
|
||||
require File.join(Rails.root, 'lib/data_conversion/base')
|
||||
|
||||
module DataConversion
|
||||
class ExportFromMongo < DataConversion::Base
|
||||
def csv_options
|
||||
{:col_sep => ",",
|
||||
:row_sep => :auto,
|
||||
:quote_char => '"',
|
||||
:field_size_limit => nil,
|
||||
:converters => nil,
|
||||
:unconverted_fields => nil,
|
||||
:headers => false,
|
||||
:return_headers => false,
|
||||
:header_converters => nil,
|
||||
:skip_blanks => false,
|
||||
:force_quotes => false}
|
||||
end
|
||||
|
||||
def clear_dir
|
||||
["#{full_path}/json", "#{full_path}/csv"].each do |path|
|
||||
FileUtils.rm_rf(path)
|
||||
FileUtils.mkdir_p(path)
|
||||
end
|
||||
end
|
||||
|
||||
def db_name
|
||||
"diaspora-#{Rails.env}"
|
||||
end
|
||||
|
||||
|
||||
|
||||
def id_sed
|
||||
@id_sed = sed_replace('{\ \"$oid\"\ :\ \(\"[^"]*\"\)\ }')
|
||||
end
|
||||
|
||||
def date_sed
|
||||
@date_sed = sed_replace('{\ \"$date\"\ :\ \([0-9]*\)\ }')
|
||||
end
|
||||
|
||||
def sed_replace(regex)
|
||||
"sed 's/#{regex}/\\1/g'"
|
||||
end
|
||||
|
||||
def json_for_model model_name
|
||||
"mongoexport -d #{db_name} -c #{model_name} | #{id_sed} | #{date_sed}"
|
||||
end
|
||||
|
||||
def write_json_export
|
||||
log "Starting JSON export..."
|
||||
models.each do |model|
|
||||
log "Starting #{model[:name]} JSON export..."
|
||||
filename ="#{full_path}/json/#{model[:name]}.json"
|
||||
model[:json_file] = filename
|
||||
`#{json_for_model(model[:name])} > #{filename}`
|
||||
log "Completed #{model[:name]} JSON export to #{directory}/json/#{model[:name]}.json."
|
||||
end
|
||||
log "JSON export complete."
|
||||
end
|
||||
|
||||
def convert_json_files
|
||||
models.each do |model|
|
||||
self.send("#{model[:name]}_json_to_csv".to_sym, model)
|
||||
end
|
||||
end
|
||||
|
||||
def generic_json_to_csv model_hash
|
||||
log "Converting #{model_hash[:name]} json to csv"
|
||||
json_file = File.open(model_hash[:json_file])
|
||||
|
||||
csv = CSV.open("#{full_path}/csv/#{model_hash[:name]}.csv", 'w')
|
||||
csv << model_hash[:attrs]
|
||||
|
||||
json_file.each do |aspect_json|
|
||||
hash = JSON.parse(aspect_json)
|
||||
csv << yield(hash)
|
||||
end
|
||||
json_file.close
|
||||
csv.close
|
||||
end
|
||||
|
||||
def comments_json_to_csv model_hash
|
||||
generic_json_to_csv(model_hash) do |hash|
|
||||
model_hash[:mongo_attrs].map { |attr_name|
|
||||
attr_val = hash[attr_name]
|
||||
if (attr_name == "youtube_titles" && attr_val && !attr_val.empty?)
|
||||
attr_val.to_yaml
|
||||
else
|
||||
attr_val
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def contacts_json_to_csv model_hash
|
||||
generic_json_to_two_csvs(model_hash) do |hash|
|
||||
main_row = model_hash[:main_mongo_attrs].map { |attr_name| hash[attr_name] }
|
||||
if hash["aspect_ids"]
|
||||
aspect_membership_rows = hash["aspect_ids"].map { |id| [hash["_id"], id] }
|
||||
else
|
||||
aspect_membership_rows = []
|
||||
end
|
||||
[main_row, aspect_membership_rows]
|
||||
end
|
||||
#Also writes the aspect memberships csv
|
||||
end
|
||||
|
||||
def invitations_json_to_csv model_hash
|
||||
generic_json_to_csv(model_hash) do |hash|
|
||||
model_hash[:mongo_attrs].map { |attr_name| hash[attr_name] }
|
||||
end
|
||||
end
|
||||
|
||||
def notifications_json_to_csv model_hash
|
||||
generic_json_to_csv(model_hash) do |hash|
|
||||
model_hash[:mongo_attrs].map { |attr_name| hash[attr_name] }
|
||||
end
|
||||
end
|
||||
def services_json_to_csv model_hash
|
||||
generic_json_to_csv(model_hash) do |hash|
|
||||
model_hash[:mongo_attrs].map { |attr_name| hash[attr_name] }
|
||||
end
|
||||
end
|
||||
def people_json_to_csv model_hash
|
||||
#Also writes the profiles csv
|
||||
|
||||
log "Converting #{model_hash[:name]} json to csv"
|
||||
json_file = File.open(model_hash[:json_file])
|
||||
|
||||
people_csv = CSV.open("#{full_path}/csv/#{model_hash[:name]}.csv", 'w')
|
||||
people_csv << model_hash[:attrs]
|
||||
|
||||
profiles_csv = CSV.open("#{full_path}/csv/profiles.csv", 'w')
|
||||
profiles_csv << model_hash[:profile_attrs]
|
||||
|
||||
json_file.each do |aspect_json|
|
||||
hash = JSON.parse(aspect_json)
|
||||
person_row = model_hash[:attrs].map do |attr_name|
|
||||
attr_name = attr_name.gsub("mongo_", "")
|
||||
attr_name = "_id" if attr_name == "id"
|
||||
hash[attr_name]
|
||||
end
|
||||
people_csv << person_row
|
||||
|
||||
profile_row = model_hash[:profile_attrs].map do |attr_name|
|
||||
if attr_name == "person_mongo_id"
|
||||
hash["_id"] #set person_mongo_id to the person id
|
||||
else
|
||||
hash["profile"][attr_name]
|
||||
end
|
||||
end
|
||||
profiles_csv << profile_row
|
||||
end
|
||||
json_file.close
|
||||
people_csv.close
|
||||
profiles_csv.close
|
||||
end
|
||||
|
||||
def posts_json_to_csv model_hash
|
||||
generic_json_to_csv(model_hash) do |hash|
|
||||
model_hash[:mongo_attrs].map { |attr_name|
|
||||
attr_val = hash[attr_name]
|
||||
if (attr_name == "youtube_titles" && attr_val && !attr_val.empty?)
|
||||
attr_val.to_yaml
|
||||
else
|
||||
attr_val
|
||||
end
|
||||
}
|
||||
end
|
||||
#has to handle the polymorphic stuff
|
||||
end
|
||||
|
||||
def requests_json_to_csv model_hash
|
||||
generic_json_to_csv(model_hash) do |hash|
|
||||
model_hash[:mongo_attrs].map { |attr_name| hash[attr_name] }
|
||||
end
|
||||
end
|
||||
|
||||
def users_json_to_csv model_hash
|
||||
generic_json_to_csv(model_hash) do |hash|
|
||||
model_hash[:mongo_attrs].map { |attr_name| hash[attr_name] }
|
||||
end
|
||||
end
|
||||
|
||||
def aspects_json_to_csv model_hash
|
||||
log "Converting aspects json to aspects and post_visibilities csvs"
|
||||
|
||||
generic_json_to_two_csvs(model_hash) do |hash|
|
||||
main_row = model_hash[:mongo_attrs].map { |attr_name| hash[attr_name] }
|
||||
|
||||
if hash["post_ids"]
|
||||
post_visibility_rows = hash["post_ids"].map { |id| [hash["_id"], id] }
|
||||
else
|
||||
post_visibility_rows = []
|
||||
end
|
||||
|
||||
[main_row, post_visibility_rows]
|
||||
end
|
||||
end
|
||||
|
||||
def generic_json_to_two_csvs model_hash
|
||||
log "Converting #{model_hash[:name]} json to two csvs"
|
||||
json_file = File.open(model_hash[:json_file])
|
||||
|
||||
main_csv = CSV.open("#{full_path}/csv/#{model_hash[:name]}.csv", 'w')
|
||||
main_csv << model_hash[:main_attrs]
|
||||
|
||||
join_csv = CSV.open("#{full_path}/csv/#{model_hash[:join_table_name]}.csv", 'w')
|
||||
join_csv << model_hash[:join_table_attrs] unless model_hash[:join_table_attrs].empty?
|
||||
|
||||
json_file.each do |aspect_json|
|
||||
hash = JSON.parse(aspect_json)
|
||||
result = yield(hash)
|
||||
main_csv << result.first
|
||||
result.last.each { |row| join_csv << row }
|
||||
end
|
||||
json_file.close
|
||||
main_csv.close
|
||||
join_csv.close
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,551 +0,0 @@
|
|||
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
require File.join(Rails.root, 'lib/data_conversion/base')
|
||||
module DataConversion
|
||||
class ImportToMysql < DataConversion::Base
|
||||
|
||||
def import_raw
|
||||
truncate_tables
|
||||
|
||||
import_raw_users
|
||||
import_raw_aspects
|
||||
import_raw_aspect_memberships
|
||||
import_raw_comments
|
||||
import_raw_invitations
|
||||
import_raw_notifications
|
||||
import_raw_people
|
||||
import_raw_profiles
|
||||
import_raw_posts
|
||||
import_raw_contacts
|
||||
import_raw_post_visibilities
|
||||
import_raw_requests
|
||||
import_raw_services
|
||||
end
|
||||
|
||||
def process_raw_tables
|
||||
process_raw_users
|
||||
process_raw_aspects
|
||||
process_raw_services
|
||||
process_raw_people
|
||||
process_raw_contacts
|
||||
process_raw_aspect_memberships
|
||||
process_raw_invitations
|
||||
process_raw_requests
|
||||
process_raw_profiles
|
||||
process_raw_posts
|
||||
process_raw_comments
|
||||
process_raw_post_visibilities
|
||||
process_raw_notifications
|
||||
end
|
||||
|
||||
def truncate_tables
|
||||
Mongo::User.connection.execute "TRUNCATE TABLE mongo_users"
|
||||
Mongo::Aspect.connection.execute "TRUNCATE TABLE mongo_aspects"
|
||||
Mongo::AspectMembership.connection.execute "TRUNCATE TABLE mongo_aspect_memberships"
|
||||
Mongo::Comment.connection.execute "TRUNCATE TABLE mongo_comments"
|
||||
Mongo::Invitation.connection.execute "TRUNCATE TABLE mongo_invitations"
|
||||
Mongo::Notification.connection.execute "TRUNCATE TABLE mongo_notifications"
|
||||
Mongo::Person.connection.execute "TRUNCATE TABLE mongo_people"
|
||||
Mongo::Profile.connection.execute "TRUNCATE TABLE mongo_profiles"
|
||||
Mongo::Post.connection.execute "TRUNCATE TABLE mongo_posts"
|
||||
Mongo::Contact.connection.execute "TRUNCATE TABLE mongo_contacts"
|
||||
Mongo::PostVisibility.connection.execute "TRUNCATE TABLE mongo_post_visibilities"
|
||||
Mongo::Request.connection.execute "TRUNCATE TABLE mongo_requests"
|
||||
Mongo::Service.connection.execute "TRUNCATE TABLE mongo_services"
|
||||
end
|
||||
|
||||
def process_raw_users
|
||||
log "Importing users to main table..."
|
||||
User.connection.execute <<-SQL
|
||||
INSERT INTO users (username, serialized_private_key, invites, getting_started, disable_mail,
|
||||
language, email, encrypted_password, password_salt, invitation_token,
|
||||
invitation_sent_at, reset_password_token, remember_token, remember_created_at,
|
||||
sign_in_count, current_sign_in_at, last_sign_in_at, current_sign_in_ip,
|
||||
last_sign_in_ip, created_at, updated_at, mongo_id, invitation_service,
|
||||
invitation_identifier)
|
||||
SELECT username, serialized_private_key, invites, getting_started, disable_mail,
|
||||
language, email, encrypted_password, password_salt, invitation_token,
|
||||
invitation_sent_at, reset_password_token, remember_token, remember_created_at,
|
||||
sign_in_count, current_sign_in_at, last_sign_in_at, current_sign_in_ip,
|
||||
last_sign_in_ip, created_at, updated_at, mongo_id, 'email',
|
||||
email
|
||||
FROM mongo_users
|
||||
SQL
|
||||
User.connection.execute <<-SQL
|
||||
UPDATE users
|
||||
SET users.invitation_service = NULL, users.invitation_identifier = NULL
|
||||
WHERE users.invitation_token IS NULL AND users.mongo_id IS NOT NULL
|
||||
SQL
|
||||
log "Imported #{User.count} users."
|
||||
end
|
||||
|
||||
def process_raw_posts
|
||||
log "Importing posts to main table..."
|
||||
Post.connection.execute <<-SQL
|
||||
INSERT INTO posts
|
||||
SELECT mongo_posts.id,
|
||||
people.id,
|
||||
mongo_posts.public,
|
||||
mongo_posts.diaspora_handle,
|
||||
mongo_posts.guid,
|
||||
mongo_posts.pending,
|
||||
mongo_posts.type,
|
||||
mongo_posts.message,
|
||||
NULL,
|
||||
mongo_posts.caption,
|
||||
mongo_posts.remote_photo_path,
|
||||
mongo_posts.remote_photo_name,
|
||||
mongo_posts.random_string,
|
||||
mongo_posts.image,
|
||||
mongo_posts.youtube_titles,
|
||||
mongo_posts.created_at,
|
||||
mongo_posts.updated_at,
|
||||
mongo_posts.mongo_id
|
||||
FROM mongo_posts
|
||||
INNER JOIN people ON (people.mongo_id = mongo_posts.person_mongo_id)
|
||||
SQL
|
||||
log "Imported #{Post.count} posts."
|
||||
|
||||
log "Setting Photo -> StatusMessage relation column..."
|
||||
Photo.connection.execute <<-SQL
|
||||
UPDATE posts AS photos, mongo_posts, posts AS statuses
|
||||
SET photos.status_message_id = statuses.id
|
||||
WHERE photos.type = "Photo" AND mongo_posts.mongo_id = photos.mongo_id AND statuses.mongo_id = mongo_posts.status_message_mongo_id
|
||||
SQL
|
||||
log "Processed #{Photo.count} photos."
|
||||
end
|
||||
|
||||
def process_raw_aspects
|
||||
log "Importing aspects to main table..."
|
||||
Aspect.connection.execute <<-SQL
|
||||
INSERT INTO aspects
|
||||
SELECT mongo_aspects.id,
|
||||
mongo_aspects.name,
|
||||
users.id,
|
||||
mongo_aspects.created_at,
|
||||
mongo_aspects.updated_at,
|
||||
mongo_aspects.mongo_id,
|
||||
mongo_aspects.user_mongo_id,
|
||||
false,
|
||||
false
|
||||
FROM mongo_aspects
|
||||
INNER JOIN users ON (users.mongo_id = mongo_aspects.user_mongo_id)
|
||||
SQL
|
||||
log "Imported #{Aspect.count} aspects."
|
||||
end
|
||||
def process_raw_contacts
|
||||
log "Importing contacts to main table..."
|
||||
Contact.connection.execute <<-SQL
|
||||
INSERT INTO contacts
|
||||
SELECT mongo_contacts.id,
|
||||
users.id,
|
||||
people.id,
|
||||
mongo_contacts.pending,
|
||||
mongo_contacts.created_at,
|
||||
mongo_contacts.updated_at,
|
||||
mongo_contacts.mongo_id
|
||||
FROM mongo_contacts
|
||||
INNER JOIN (users, people) ON (users.mongo_id = mongo_contacts.user_mongo_id
|
||||
AND people.mongo_id = mongo_contacts.person_mongo_id)
|
||||
SQL
|
||||
log "Imported #{Contact.count} contacts."
|
||||
end
|
||||
def process_raw_profiles
|
||||
log "Importing profiles to main table..."
|
||||
Profile.connection.execute <<-SQL
|
||||
INSERT INTO profiles
|
||||
SELECT mongo_profiles.id,
|
||||
mongo_profiles.diaspora_handle,
|
||||
mongo_profiles.first_name,
|
||||
mongo_profiles.last_name,
|
||||
mongo_profiles.image_url,
|
||||
mongo_profiles.image_url_small,
|
||||
mongo_profiles.image_url_medium,
|
||||
mongo_profiles.birthday,
|
||||
mongo_profiles.gender,
|
||||
mongo_profiles.bio,
|
||||
mongo_profiles.searchable,
|
||||
people.id,
|
||||
mongo_profiles.created_at,
|
||||
mongo_profiles.updated_at,
|
||||
mongo_profiles.person_mongo_id
|
||||
FROM mongo_profiles
|
||||
INNER JOIN (people) ON (people.mongo_id = mongo_profiles.person_mongo_id)
|
||||
SQL
|
||||
log "Imported #{Profile.count} profiles."
|
||||
end
|
||||
def process_raw_aspect_memberships
|
||||
log "Importing aspect_memberships to main table..."
|
||||
AspectMembership.connection.execute <<-SQL
|
||||
INSERT INTO aspect_memberships
|
||||
SELECT mongo_aspect_memberships.id,
|
||||
aspects.id,
|
||||
contacts.id,
|
||||
mongo_aspect_memberships.created_at,
|
||||
mongo_aspect_memberships.updated_at
|
||||
FROM mongo_aspect_memberships INNER JOIN (aspects, contacts)
|
||||
ON (aspects.mongo_id = mongo_aspect_memberships.aspect_mongo_id AND contacts.mongo_id = mongo_aspect_memberships.contact_mongo_id)
|
||||
SQL
|
||||
log "Imported #{AspectMembership.count} aspect_memberships."
|
||||
end
|
||||
def process_raw_invitations
|
||||
log "Importing invitations to main table..."
|
||||
Invitation.connection.execute <<-SQL
|
||||
INSERT INTO invitations
|
||||
SELECT m_inv.id,
|
||||
m_inv.message,
|
||||
senders.id,
|
||||
recipients.id,
|
||||
aspects.id,
|
||||
m_inv.created_at,
|
||||
m_inv.updated_at,
|
||||
m_inv.mongo_id
|
||||
FROM mongo_invitations AS m_inv
|
||||
INNER JOIN users AS senders ON m_inv.sender_mongo_id = senders.mongo_id
|
||||
INNER JOIN users AS recipients ON m_inv.recipient_mongo_id = recipients.mongo_id
|
||||
INNER JOIN aspects ON m_inv.aspect_mongo_id = aspects.mongo_id
|
||||
SQL
|
||||
log "Imported #{Invitation.count} invitations."
|
||||
end
|
||||
def process_raw_requests
|
||||
log "Importing requests to main table..."
|
||||
Request.connection.execute <<-SQL
|
||||
INSERT INTO requests
|
||||
SELECT m_r.id,
|
||||
senders.id,
|
||||
recipients.id,
|
||||
aspects.id,
|
||||
m_r.created_at,
|
||||
m_r.updated_at,
|
||||
m_r.mongo_id
|
||||
FROM mongo_requests AS m_r
|
||||
INNER JOIN people AS senders ON m_r.sender_mongo_id = senders.mongo_id
|
||||
INNER JOIN people AS recipients ON m_r.recipient_mongo_id = recipients.mongo_id
|
||||
LEFT JOIN aspects ON m_r.aspect_mongo_id = aspects.mongo_id
|
||||
SQL
|
||||
log "Imported #{Request.count} requests."
|
||||
end
|
||||
def process_raw_services
|
||||
log "Importing services to main table..."
|
||||
Service.connection.execute <<-SQL
|
||||
INSERT INTO services
|
||||
SELECT mongo_services.id,
|
||||
mongo_services.type,
|
||||
users.id,
|
||||
mongo_services.uid,
|
||||
mongo_services.access_token,
|
||||
mongo_services.access_secret,
|
||||
mongo_services.nickname,
|
||||
mongo_services.created_at,
|
||||
mongo_services.updated_at,
|
||||
mongo_services.mongo_id,
|
||||
mongo_services.user_mongo_id
|
||||
FROM mongo_services INNER JOIN users ON (users.mongo_id = mongo_services.user_mongo_id)
|
||||
SQL
|
||||
log "Imported #{Service.count} services."
|
||||
end
|
||||
def process_raw_comments
|
||||
log "Importing comments to main table..."
|
||||
Comment.connection.execute <<-SQL
|
||||
INSERT INTO comments
|
||||
SELECT mongo_comments.id,
|
||||
mongo_comments.text,
|
||||
posts.id,
|
||||
people.id,
|
||||
mongo_comments.guid,
|
||||
mongo_comments.creator_signature,
|
||||
mongo_comments.post_creator_signature,
|
||||
mongo_comments.youtube_titles,
|
||||
mongo_comments.created_at,
|
||||
mongo_comments.updated_at,
|
||||
mongo_comments.mongo_id
|
||||
FROM mongo_comments INNER JOIN (posts, people)
|
||||
ON (posts.mongo_id = mongo_comments.post_mongo_id AND people.mongo_id = mongo_comments.person_mongo_id)
|
||||
SQL
|
||||
log "Imported #{Comment.count} comments."
|
||||
end
|
||||
def process_raw_people
|
||||
log "Importing people to main table..."
|
||||
Person.connection.execute <<-SQL
|
||||
INSERT INTO people
|
||||
SELECT mongo_people.id,
|
||||
mongo_people.guid,
|
||||
mongo_people.url,
|
||||
mongo_people.diaspora_handle,
|
||||
mongo_people.serialized_public_key,
|
||||
users.id,
|
||||
mongo_people.created_at,
|
||||
mongo_people.updated_at,
|
||||
mongo_people.mongo_id
|
||||
FROM mongo_people LEFT JOIN users ON (users.mongo_id = mongo_people.owner_mongo_id)
|
||||
SQL
|
||||
log "Imported #{Person.count} people."
|
||||
end
|
||||
def process_raw_post_visibilities
|
||||
log "Importing post_visibilities to main table..."
|
||||
PostVisibility.connection.execute <<-SQL
|
||||
INSERT INTO post_visibilities
|
||||
SELECT mongo_post_visibilities.id,
|
||||
aspects.id,
|
||||
posts.id,
|
||||
mongo_post_visibilities.created_at,
|
||||
mongo_post_visibilities.updated_at
|
||||
FROM mongo_post_visibilities INNER JOIN (aspects, posts)
|
||||
ON (aspects.mongo_id = mongo_post_visibilities.aspect_mongo_id AND posts.mongo_id = mongo_post_visibilities.post_mongo_id)
|
||||
SQL
|
||||
log "Imported #{PostVisibility.count} post_visibilities."
|
||||
end
|
||||
|
||||
def process_raw_notifications
|
||||
log "Not importing notifications."
|
||||
end
|
||||
|
||||
def import_raw_users
|
||||
log "Loading users file..."
|
||||
Mongo::User.connection.execute set_time_zone_to_utc
|
||||
Mongo::User.connection.execute <<-SQL
|
||||
#{load_string("users")}
|
||||
#{infile_opts}
|
||||
(mongo_id, email, @username, serialized_private_key, encrypted_password,
|
||||
invites, @invitation_token, @invitation_sent_at, @getting_started,
|
||||
@disable_mail, language, @last_sign_in_ip, @last_sign_in_at,
|
||||
@reset_password_token, password_salt)
|
||||
SET #{unix_time("last_sign_in_at")},
|
||||
#{nil_es("invitation_token")},
|
||||
#{nil_es("username")},
|
||||
#{nil_es("last_sign_in_ip")},
|
||||
#{nil_es("reset_password_token")},
|
||||
#{unix_time("created_at")},
|
||||
#{unix_time("updated_at")},
|
||||
#{boolean_set("getting_started")},
|
||||
#{boolean_set("disable_mail")};
|
||||
SQL
|
||||
log "Finished. Imported #{Mongo::User.count} users."
|
||||
end
|
||||
|
||||
|
||||
def import_raw_aspects
|
||||
log "Loading aspects file..."
|
||||
Mongo::Aspect.connection.execute set_time_zone_to_utc
|
||||
Mongo::Aspect.connection.execute <<-SQL
|
||||
#{load_string("aspects")}
|
||||
#{infile_opts}
|
||||
(mongo_id, name, user_mongo_id, @created_at, @updated_at)
|
||||
SET #{unix_time("created_at")},
|
||||
#{unix_time("updated_at")};
|
||||
SQL
|
||||
log "Finished. Imported #{Mongo::Aspect.count} aspects."
|
||||
end
|
||||
|
||||
def import_raw_aspect_memberships
|
||||
log "Loading aspect memberships file..."
|
||||
Mongo::AspectMembership.connection.execute set_time_zone_to_utc
|
||||
Mongo::AspectMembership.connection.execute <<-SQL
|
||||
#{load_string("aspect_memberships")}
|
||||
#{infile_opts}
|
||||
(contact_mongo_id, aspect_mongo_id)
|
||||
SQL
|
||||
log "Finished. Imported #{Mongo::AspectMembership.count} aspect memberships."
|
||||
end
|
||||
|
||||
def import_raw_comments
|
||||
log "Loading comments file..."
|
||||
Mongo::Comment.connection.execute set_time_zone_to_utc
|
||||
Mongo::Comment.connection.execute <<-SQL
|
||||
#{load_string("comments")}
|
||||
#{infile_opts}
|
||||
(mongo_id, post_mongo_id, person_mongo_id, @diaspora_handle, text, @youtube_titles, @created_at, @updated_at)
|
||||
SET guid = mongo_id,
|
||||
#{unix_time("created_at")},
|
||||
#{unix_time("updated_at")},
|
||||
#{nil_es("youtube_titles")};
|
||||
SQL
|
||||
log "Finished. Imported #{Mongo::Comment.count} comments."
|
||||
end
|
||||
|
||||
def import_raw_posts
|
||||
log "Loading posts file..."
|
||||
Mongo::Post.connection.execute set_time_zone_to_utc
|
||||
Mongo::Post.connection.execute <<-SQL
|
||||
#{load_string("posts")}
|
||||
#{infile_opts}
|
||||
(@youtube_titles, @pending, @created_at, @public, @updated_at, @status_message_mongo_id, @caption,
|
||||
@remote_photo_path, @remote_photo_name, @random_string, @image, mongo_id, type, diaspora_handle, person_mongo_id, @message)
|
||||
SET guid = mongo_id,
|
||||
#{nil_es("youtube_titles")},
|
||||
#{nil_es("status_message_mongo_id")},
|
||||
#{nil_es("caption")},
|
||||
#{nil_es("remote_photo_path")},
|
||||
#{nil_es("remote_photo_name")},
|
||||
#{nil_es("random_string")},
|
||||
#{nil_es("image")},
|
||||
#{nil_es("message")},
|
||||
#{unix_time("created_at")},
|
||||
#{unix_time("updated_at")},
|
||||
#{boolean_set("pending")},
|
||||
#{boolean_set("public")};
|
||||
SQL
|
||||
log "Finished. Imported #{Mongo::Post.count} posts."
|
||||
end
|
||||
|
||||
def import_raw_contacts
|
||||
log "Loading contacts file..."
|
||||
Mongo::Contact.connection.execute set_time_zone_to_utc
|
||||
Mongo::Contact.connection.execute <<-SQL
|
||||
#{load_string("contacts")}
|
||||
#{infile_opts}
|
||||
(mongo_id, user_mongo_id, person_mongo_id, @pending, @created_at, @updated_at)
|
||||
SET #{boolean_set("pending")},
|
||||
#{unix_time("created_at")},
|
||||
#{unix_time("updated_at")};
|
||||
SQL
|
||||
log "Finished. Imported #{Mongo::Contact.count} contacts."
|
||||
end
|
||||
|
||||
def import_raw_services
|
||||
log "Loading services file..."
|
||||
Mongo::Service.connection.execute set_time_zone_to_utc
|
||||
Mongo::Service.connection.execute <<-SQL
|
||||
#{load_string("services")}
|
||||
#{infile_opts}
|
||||
(mongo_id, type,user_mongo_id,@provider,@uid,@access_token,@access_secret,@nickname, @created_at, @updated_at)
|
||||
SET #{nil_es("provider")},
|
||||
#{nil_es("uid")},
|
||||
#{unix_time("created_at")},
|
||||
#{unix_time("updated_at")},
|
||||
#{nil_es("access_token")},
|
||||
#{nil_es("access_secret")},
|
||||
#{nil_es("nickname")};
|
||||
SQL
|
||||
log "Finished. Imported #{Mongo::Service.count} services."
|
||||
end
|
||||
|
||||
def import_raw_post_visibilities
|
||||
log "Loading post visibilities file..."
|
||||
Mongo::PostVisibility.connection.execute set_time_zone_to_utc
|
||||
Mongo::PostVisibility.connection.execute <<-SQL
|
||||
#{load_string("post_visibilities")}
|
||||
#{infile_opts}
|
||||
(aspect_mongo_id, post_mongo_id)
|
||||
SQL
|
||||
log "Finished. Imported #{Mongo::PostVisibility.count} post visibilities."
|
||||
end
|
||||
|
||||
def import_raw_requests
|
||||
log "Loading requests file..."
|
||||
Mongo::Request.connection.execute set_time_zone_to_utc
|
||||
Mongo::Request.connection.execute <<-SQL
|
||||
#{load_string("requests")}
|
||||
#{infile_opts}
|
||||
(mongo_id, recipient_mongo_id, sender_mongo_id, @aspect_mongo_id, @created_at, @updated_at)
|
||||
SET #{nil_es("aspect_mongo_id")},
|
||||
#{unix_time("created_at")},
|
||||
#{unix_time("updated_at")};
|
||||
SQL
|
||||
log "Finished. Imported #{Mongo::Request.count} requests."
|
||||
end
|
||||
|
||||
def import_raw_invitations
|
||||
log "Loading invitations file..."
|
||||
Mongo::Invitation.connection.execute set_time_zone_to_utc
|
||||
Mongo::Invitation.connection.execute <<-SQL
|
||||
#{load_string("invitations")}
|
||||
#{infile_opts}
|
||||
(mongo_id, recipient_mongo_id, sender_mongo_id, aspect_mongo_id, message, @created_at, @updated_at)
|
||||
SET #{unix_time("created_at")},
|
||||
#{unix_time("updated_at")};
|
||||
SQL
|
||||
log "Finished. Imported #{Mongo::Invitation.count} invitations."
|
||||
end
|
||||
|
||||
def import_raw_notifications
|
||||
log "Loading notifications file..."
|
||||
Mongo::Notification.connection.execute set_time_zone_to_utc
|
||||
Mongo::Notification.connection.execute <<-SQL
|
||||
#{load_string("notifications")}
|
||||
#{infile_opts}
|
||||
(mongo_id,target_mongo_id,recipient_mongo_id,actor_mongo_id,@null_action,action,@unread, @created_at, @updated_at)
|
||||
SET #{boolean_set("unread")},
|
||||
#{unix_time("created_at")},
|
||||
#{unix_time("updated_at")};
|
||||
SQL
|
||||
log "Finished. Imported #{Mongo::Notification.count} notifications."
|
||||
{"new_request" => "Request",
|
||||
"request_accepted" => "Request",
|
||||
"comment_on_post" => "Comment",
|
||||
"also_commented" => "Comment"}.each_pair do |key, value|
|
||||
Mongo::Notification.where(:action => key).update_all(:target_type => value)
|
||||
end
|
||||
log "Notification target types set."
|
||||
end
|
||||
|
||||
def import_raw_people
|
||||
log "Loading people file..."
|
||||
Mongo::Person.connection.execute set_time_zone_to_utc
|
||||
Mongo::Person.connection.execute <<-SQL
|
||||
#{load_string("people")}
|
||||
#{infile_opts}
|
||||
(@created_at,@updated_at,serialized_public_key,url,mongo_id,@owner_mongo_id,diaspora_handle)
|
||||
SET guid = mongo_id,
|
||||
#{nil_es("owner_mongo_id")},
|
||||
#{unix_time("created_at")},
|
||||
#{unix_time("updated_at")};
|
||||
SQL
|
||||
log "Finished. Imported #{Mongo::Person.count} people."
|
||||
end
|
||||
|
||||
def import_raw_profiles
|
||||
log "Loading profiles file..."
|
||||
Mongo::Profile.connection.execute set_time_zone_to_utc
|
||||
Mongo::Profile.connection.execute <<-SQL
|
||||
#{load_string("profiles")}
|
||||
#{infile_opts}
|
||||
(@image_url_medium,@searchable,@image_url,person_mongo_id,
|
||||
@gender,@diaspora_handle,@birthday,@last_name,@bio,
|
||||
@image_url_small,@first_name)
|
||||
SET #{boolean_set("searchable")},
|
||||
#{unix_time("birthday")},
|
||||
#{nil_es("image_url_medium")},
|
||||
#{nil_es("image_url")},
|
||||
#{nil_es("gender")},
|
||||
#{nil_es("diaspora_handle")},
|
||||
#{nil_es("last_name")},
|
||||
#{nil_es("bio")},
|
||||
#{nil_es("image_url_small")},
|
||||
#{nil_es("first_name")};
|
||||
SQL
|
||||
#STRCMP returns 0 if the arguments are the same
|
||||
log "Finished. Imported #{Mongo::Profile.count} profiles."
|
||||
end
|
||||
|
||||
def boolean_set(string)
|
||||
"#{string}= IF(STRCMP(@#{string},'false'), TRUE, FALSE)"
|
||||
end
|
||||
|
||||
def nil_es(string)
|
||||
"#{string} = NULLIF(@#{string}, '')"
|
||||
end
|
||||
|
||||
def unix_time(string)
|
||||
"#{string} = FROM_UNIXTIME(@#{string} / 1000)"
|
||||
end
|
||||
|
||||
def infile_opts
|
||||
<<-OPTS
|
||||
FIELDS TERMINATED BY ','
|
||||
ENCLOSED BY '"'
|
||||
IGNORE 1 LINES
|
||||
OPTS
|
||||
end
|
||||
|
||||
def load_string model_name
|
||||
"LOAD DATA INFILE '#{full_path}/#{model_name}.csv' INTO TABLE mongo_#{model_name}"
|
||||
end
|
||||
|
||||
def set_time_zone_to_utc
|
||||
"set time_zone = '+0:00'"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -2,38 +2,7 @@
|
|||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
require File.join(Rails.root, 'lib', 'data_conversion', 'base')
|
||||
require File.join(Rails.root, 'lib', 'data_conversion', 'export_from_mongo')
|
||||
require File.join(Rails.root, 'lib', 'data_conversion', 'import_to_mysql')
|
||||
|
||||
namespace :migrations do
|
||||
desc 'export data for mysql import'
|
||||
task :export_for_mysql do
|
||||
migrator = DataConversion::ExportFromMongo.new
|
||||
migrator.full_path = "/tmp/data_conversion"
|
||||
migrator.log("**** Starting export for MySQL ****")
|
||||
migrator.clear_dir
|
||||
migrator.write_json_export
|
||||
migrator.convert_json_files
|
||||
migrator.log("**** Export finished! ****")
|
||||
migrator.log("total elapsed time")
|
||||
end
|
||||
|
||||
desc 'import data to mysql'
|
||||
task :import_to_mysql do
|
||||
require File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment')
|
||||
migrator = DataConversion::ImportToMysql.new
|
||||
migrator.full_path = "/tmp/data_conversion/csv"
|
||||
migrator.log("**** Starting import to MySQL database #{ActiveRecord::Base.connection.current_database} ****")
|
||||
migrator.import_raw
|
||||
migrator.process_raw_tables
|
||||
migrator.log("**** Import finished! ****")
|
||||
migrator.log("total elapsed time")
|
||||
end
|
||||
|
||||
desc 'execute mongo to mysql migration. Requires mongoexport to be accessible.'
|
||||
task :migrate_to_mysql => [:export_for_mysql, :import_to_mysql]
|
||||
|
||||
desc 'absolutify all existing image references'
|
||||
task :absolutify_image_references do
|
||||
require File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment')
|
||||
|
|
@ -43,7 +12,7 @@ namespace :migrations do
|
|||
# extract root
|
||||
#
|
||||
pod = URI::parse(photo.person.url)
|
||||
pod_url = "#{pod.scheme}://#{pod.host}"
|
||||
pod_url = "#{pod.scheme}://#{pod.host}"
|
||||
|
||||
if photo.image.url
|
||||
remote_path = "#{photo.image.url}"
|
||||
|
|
@ -65,11 +34,11 @@ namespace :migrations do
|
|||
task :upload_photos_to_s3 do
|
||||
require File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment')
|
||||
puts AppConfig[:s3_key]
|
||||
|
||||
|
||||
connection = Aws::S3.new( AppConfig[:s3_key], AppConfig[:s3_secret])
|
||||
bucket = connection.bucket('joindiaspora')
|
||||
dir_name = File.dirname(__FILE__) + "/../../public/uploads/images/"
|
||||
|
||||
|
||||
count = Dir.foreach(dir_name).count
|
||||
current = 0
|
||||
|
||||
|
|
@ -85,7 +54,7 @@ namespace :migrations do
|
|||
puts "error #{e} on #{current} (#{file_name}), retrying"
|
||||
retry
|
||||
end
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ $(document).ready(function() {
|
|||
|
||||
$('.edit_photo').bind('ajax:success', function(data, json, xhr) {
|
||||
json = $.parseJSON(json);
|
||||
$(".edit_photo input:text").val(json.photo.caption);
|
||||
$("#caption").html(json.photo.caption);
|
||||
$(".edit_photo input:text").val(json.photo.text);
|
||||
$("#caption").html(json.photo.text);
|
||||
$("#show_photo").find("img").fadeTo(200,1);
|
||||
$("#photo_spinner").hide();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ var Publisher = {
|
|||
cachedInput : false,
|
||||
input: function(){
|
||||
if(!Publisher.cachedInput){
|
||||
Publisher.cachedInput = Publisher.form().find('#status_message_fake_message');
|
||||
Publisher.cachedInput = Publisher.form().find('#status_message_fake_text');
|
||||
}
|
||||
return Publisher.cachedInput;
|
||||
},
|
||||
|
|
@ -39,7 +39,7 @@ var Publisher = {
|
|||
cachedHiddenInput : false,
|
||||
hiddenInput: function(){
|
||||
if(!Publisher.cachedHiddenInput){
|
||||
Publisher.cachedHiddenInput = Publisher.form().find('#status_message_message');
|
||||
Publisher.cachedHiddenInput = Publisher.form().find('#status_message_text');
|
||||
}
|
||||
return Publisher.cachedHiddenInput;
|
||||
},
|
||||
|
|
@ -315,7 +315,7 @@ var Publisher = {
|
|||
Publisher.bindServiceIcons();
|
||||
Publisher.bindPublicIcon();
|
||||
|
||||
if ($("#status_message_fake_message").val() == "") {
|
||||
if ($("#status_message_fake_text").val() == "") {
|
||||
Publisher.close();
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,177 +0,0 @@
|
|||
@start_time = Time.now.to_i
|
||||
@count = 0
|
||||
|
||||
def sanitize_user(user)
|
||||
log "Sanitizing user #{@count += 1}: #{user.username}"
|
||||
people = Person.all(:owner_id => user.id)
|
||||
log "#{user.username} has #{people.count} person objects."
|
||||
|
||||
people.sort_by {|person| contact_count(person)}
|
||||
|
||||
keep_person = people.last
|
||||
dumb_people = people[0..(people.count)]
|
||||
d_p_ids = dumb_people.map{|p| "ObjectId('#{p.id.to_s}')"}
|
||||
d_p_ids_json = "[#{d_p_ids.join(',')}]"
|
||||
|
||||
["posts", "comments", "contacts"].each do |table_name|
|
||||
eval_string = <<-JS
|
||||
db.#{table_name}.find({ "person_id" : {"$in" : #{d_p_ids_json}}}).forEach(function(document){
|
||||
db.#{table_name}.update({"_id" : document["_id"]}, {"$set" : { "person_id" : ObjectId("#{keep_person.id.to_s}")}});
|
||||
});
|
||||
JS
|
||||
MongoMapper.database.eval eval_string
|
||||
end
|
||||
|
||||
['from_id', 'to_id'].each do |key|
|
||||
eval_string = <<-JS
|
||||
db.requests.find({ "#{key}" : {"$in" : #{d_p_ids_json}}}).forEach(function(document){
|
||||
db.requests.update({"_id" : document["_id"]}, {"$set" : { "#{key}" : ObjectId("#{keep_person.id.to_s}")}});
|
||||
});
|
||||
JS
|
||||
MongoMapper.database.eval eval_string
|
||||
end
|
||||
|
||||
"Ids for user #{user.username} set to one person"
|
||||
|
||||
dumb_people.each{|dumb| dumb.delete}
|
||||
if user.serialized_private_key
|
||||
keep_person.serialized_public_key = OpenSSL::PKey::RSA.new(user.serialized_private_key).public_key
|
||||
keep_person.save
|
||||
else
|
||||
log "#{user.username} HAS NO ENCRYPTION KEY"
|
||||
end
|
||||
end
|
||||
|
||||
def log string
|
||||
time_diff = Time.now.to_i - @start_time
|
||||
puts "#{time_diff}s; #{string}"
|
||||
end
|
||||
|
||||
def contact_count person
|
||||
@contact_counts ||= {}
|
||||
return @contact_counts[person.id] if @contact_counts[person.id]
|
||||
query_result = @contacts_for_people_collection.find("_id" => person.id).first
|
||||
|
||||
if query_result
|
||||
@contact_counts[person.id] = query_result["value"]
|
||||
else
|
||||
@contact_counts[person.id] = 0
|
||||
end
|
||||
|
||||
@contact_counts[person.id]
|
||||
end
|
||||
def get_user_ids
|
||||
cmd = BSON::OrderedHash.new
|
||||
cmd["mapreduce"] = "people"
|
||||
cmd["map"] = 'function(){ emit(this["owner_id"], 1)};'
|
||||
cmd["reduce"] = 'function(key, vals) {' +
|
||||
'var sum=0;' +
|
||||
'for(var i in vals) sum += vals[i];' +
|
||||
'return sum;' +
|
||||
'};'
|
||||
result = MongoMapper.database.command(cmd)
|
||||
collection = MongoMapper.database.collection(result["result"])
|
||||
collection.find("value" => {"$gte" => 2}).map{|r| r["_id"]}
|
||||
end
|
||||
|
||||
def contacts_for_people_collection
|
||||
cmd = BSON::OrderedHash.new
|
||||
cmd["mapreduce"] = "contacts"
|
||||
cmd["map"] = 'function(){ emit(this["person_id"], 1)};'
|
||||
cmd["reduce"] = 'function(key, vals) {' +
|
||||
'var sum=0;' +
|
||||
'for(var i in vals) sum += vals[i];' +
|
||||
'return sum;' +
|
||||
'};'
|
||||
result = MongoMapper.database.command(cmd)
|
||||
MongoMapper.database.collection(result["result"])
|
||||
end
|
||||
|
||||
user_ids = get_user_ids
|
||||
|
||||
@contacts_for_people_collection = contacts_for_people_collection
|
||||
users = User.where(:id.in => user_ids).all
|
||||
log "#{users.size} Users retreived."
|
||||
users.each{ |user| sanitize_user(user) }
|
||||
|
||||
log "Eliminating local people with no corresponding user."
|
||||
|
||||
MongoMapper.database.eval <<-MOREJS
|
||||
db.people.find().forEach(
|
||||
function(doc){
|
||||
if(doc["owner_id"] != null && db.users.count({"_id" : doc["owner_id"]}) == 0){
|
||||
db.people.remove({"_id" : doc["_id"]});
|
||||
}
|
||||
}
|
||||
);
|
||||
MOREJS
|
||||
|
||||
def dup_user_emails
|
||||
cmd = BSON::OrderedHash.new
|
||||
cmd["mapreduce"] = "users"
|
||||
cmd["map"] = 'function(){ emit(this["email"], 1)};'
|
||||
cmd["reduce"] = 'function(key, vals) {' +
|
||||
'var sum=0;' +
|
||||
'for(var i in vals) sum += vals[i];' +
|
||||
'return sum;' +
|
||||
'};'
|
||||
result = MongoMapper.database.command(cmd)
|
||||
coll = MongoMapper.database.collection(result["result"])
|
||||
user_emails = coll.find("value" => {"$gte" => 2}).map{|r| r["_id"]}
|
||||
end
|
||||
|
||||
emails = dup_user_emails
|
||||
log "Eliminating #{emails.count} users with duplicate emails"
|
||||
|
||||
users_coll = MongoMapper.database.collection("users")
|
||||
users_coll.remove("email" => {"$in" => emails})
|
||||
|
||||
def dup_requests
|
||||
cmd = BSON::OrderedHash.new
|
||||
cmd["mapreduce"] = "requests"
|
||||
cmd["map"] = 'function(){ emit(this["from_id"].toString() + "," + this["to_id"].toString(), {"array" : [this["_id"]], "count" : 1 })};'
|
||||
cmd["reduce"] = 'function(key, vals) {' +
|
||||
'var result = {"array" : [], "count" : 0};' +
|
||||
'for(var i in vals){' +
|
||||
'result["array"] = result["array"].concat(vals[i]["array"]);' +
|
||||
'result["count"] += vals[i]["count"];' +
|
||||
'}' +
|
||||
'return result;' +
|
||||
'};'
|
||||
result = MongoMapper.database.command(cmd)
|
||||
coll = MongoMapper.database.collection(result["result"])
|
||||
#FIND WHERE "array" size is greater than 1
|
||||
coll.find({"value.count" => {"$gte" => 2}}).map{|r| r["value"]["array"]}
|
||||
end
|
||||
non_unique_requests = dup_requests
|
||||
non_unique_requests.each{|request_id_array| request_id_array.pop}
|
||||
non_unique_requests.flatten!
|
||||
|
||||
log "Eliminating #{non_unique_requests.length} duplicate requests"
|
||||
req_coll = MongoMapper.database.collection("requests")
|
||||
req_coll.remove("_id" => {"$in" => non_unique_requests})
|
||||
|
||||
def dup_contacts
|
||||
cmd = BSON::OrderedHash.new
|
||||
cmd["mapreduce"] = "contacts"
|
||||
cmd["map"] = 'function(){ emit(this["person_id"].toString() + "," + this["user_id"].toString(), {"array" : [this["_id"]], "count" : 1 })};'
|
||||
cmd["reduce"] = 'function(key, vals) {' +
|
||||
'var result = {"array" : [], "count" : 0};' +
|
||||
'for(var i in vals){' +
|
||||
'result["array"] = result["array"].concat(vals[i]["array"]);' +
|
||||
'result["count"] += vals[i]["count"];' +
|
||||
'}' +
|
||||
'return result;' +
|
||||
'};'
|
||||
result = MongoMapper.database.command(cmd)
|
||||
coll = MongoMapper.database.collection(result["result"])
|
||||
#FIND WHERE "array" size is greater than 1
|
||||
coll.find({"value.count" => {"$gte" => 2}}).map{|r| r["value"]["array"]}
|
||||
end
|
||||
non_unique_contacts = dup_contacts
|
||||
non_unique_contacts.each{|contact_id_array| contact_id_array.pop}
|
||||
non_unique_contacts.flatten!
|
||||
|
||||
log "Eliminating #{non_unique_contacts.length} duplicate contacts"
|
||||
req_coll = MongoMapper.database.collection("contacts")
|
||||
req_coll.remove("_id" => {"$in" => non_unique_contacts})
|
||||
|
|
@ -64,7 +64,7 @@ describe AspectsController do
|
|||
save_fixture(html_for("body"), "aspects_index_services")
|
||||
end
|
||||
it 'generates a jasmine fixture with posts' do
|
||||
@alice.post(:status_message, :message => "hello", :to => @alices_aspect_2.id)
|
||||
@alice.post(:status_message, :text => "hello", :to => @alices_aspect_2.id)
|
||||
get :index
|
||||
save_fixture(html_for("body"), "aspects_index_with_posts")
|
||||
end
|
||||
|
|
@ -76,7 +76,7 @@ describe AspectsController do
|
|||
aspect = user.aspects.create(:name => 'people')
|
||||
connect_users(@alice, @alices_aspect_1, user, aspect)
|
||||
target_aspect = n.even? ? @alices_aspect_1 : @alices_aspect_2
|
||||
post = @alice.post(:status_message, :message => "hello#{n}", :to => target_aspect)
|
||||
post = @alice.post(:status_message, :text=> "hello#{n}", :to => target_aspect)
|
||||
post.created_at = Time.now - (2 - n).seconds
|
||||
post.save!
|
||||
@posts << post
|
||||
|
|
@ -120,7 +120,7 @@ describe AspectsController do
|
|||
user = Factory.create(:user)
|
||||
aspect = user.aspects.create(:name => 'people')
|
||||
connect_users(@alice, @alices_aspect_1, user, aspect)
|
||||
post = @alice.post(:status_message, :message => "hello#{n}", :to => @alices_aspect_2.id)
|
||||
post = @alice.post(:status_message, :text => "hello#{n}", :to => @alices_aspect_2.id)
|
||||
8.times do |n|
|
||||
user.comment "yo#{post.message}", :on => post
|
||||
end
|
||||
|
|
@ -272,7 +272,7 @@ describe AspectsController do
|
|||
response.should be_success
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe "#toggle_contact_visibility" do
|
||||
it 'sets contacts visible' do
|
||||
@alices_aspect_1.contacts_visible = false
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ describe CommentsController do
|
|||
}
|
||||
context "on my own post" do
|
||||
before do
|
||||
@post = @user1.post :status_message, :message => 'GIANTS', :to => @aspect1.id
|
||||
@post = @user1.post :status_message, :text => 'GIANTS', :to => @aspect1.id
|
||||
end
|
||||
it 'responds to format js' do
|
||||
post :create, comment_hash.merge(:format => 'js')
|
||||
|
|
@ -35,7 +35,7 @@ describe CommentsController do
|
|||
|
||||
context "on a post from a contact" do
|
||||
before do
|
||||
@post = @user2.post :status_message, :message => 'GIANTS', :to => @aspect2.id
|
||||
@post = @user2.post :status_message, :text => 'GIANTS', :to => @aspect2.id
|
||||
end
|
||||
it 'comments' do
|
||||
post :create, comment_hash
|
||||
|
|
@ -56,7 +56,7 @@ describe CommentsController do
|
|||
end
|
||||
context 'on a post from a stranger' do
|
||||
before do
|
||||
@post = eve.post :status_message, :message => 'GIANTS', :to => eve.aspects.first.id
|
||||
@post = eve.post :status_message, :text => 'GIANTS', :to => eve.aspects.first.id
|
||||
end
|
||||
it 'posts no comment' do
|
||||
@user1.should_not_receive(:comment)
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ describe PeopleController do
|
|||
aspect = user.aspects.create(:name => 'people')
|
||||
connect_users(@user, @user.aspects.first, user, aspect)
|
||||
|
||||
@posts << @user.post(:status_message, :message => "hello#{n}", :to => aspect.id)
|
||||
@posts << @user.post(:status_message, :text => "hello#{n}", :to => aspect.id)
|
||||
end
|
||||
@posts.each do |post|
|
||||
@users.each do |user|
|
||||
|
|
@ -113,16 +113,16 @@ describe PeopleController do
|
|||
|
||||
it "assigns all the user's posts" do
|
||||
@user.posts.should be_empty
|
||||
@user.post(:status_message, :message => "to one aspect", :to => @aspect.id)
|
||||
@user.post(:status_message, :message => "to all aspects", :to => 'all')
|
||||
@user.post(:status_message, :message => "public", :to => 'all', :public => true)
|
||||
@user.post(:status_message, :text => "to one aspect", :to => @aspect.id)
|
||||
@user.post(:status_message, :text => "to all aspects", :to => 'all')
|
||||
@user.post(:status_message, :text => "public", :to => 'all', :public => true)
|
||||
@user.reload.posts.length.should == 3
|
||||
get :show, :id => @user.person.to_param
|
||||
assigns(:posts).should =~ @user.posts
|
||||
end
|
||||
|
||||
it "renders the comments on the user's posts" do
|
||||
message = @user.post :status_message, :message => 'test more', :to => @aspect.id
|
||||
message = @user.post :status_message, :text => 'test more', :to => @aspect.id
|
||||
@user.comment 'I mean it', :on => message
|
||||
get :show, :id => @user.person.id
|
||||
response.should be_success
|
||||
|
|
@ -140,10 +140,10 @@ describe PeopleController do
|
|||
end
|
||||
it "assigns only public posts" do
|
||||
public_posts = []
|
||||
public_posts << bob.post(:status_message, :message => "first public ", :to => bob.aspects[0].id, :public => true)
|
||||
bob.post(:status_message, :message => "to an aspect @user is not in", :to => bob.aspects[1].id)
|
||||
bob.post(:status_message, :message => "to all aspects", :to => 'all')
|
||||
public_posts << bob.post(:status_message, :message => "public", :to => 'all', :public => true)
|
||||
public_posts << bob.post(:status_message, :text => "first public ", :to => bob.aspects[0].id, :public => true)
|
||||
bob.post(:status_message, :text => "to an aspect @user is not in", :to => bob.aspects[1].id)
|
||||
bob.post(:status_message, :text => "to all aspects", :to => 'all')
|
||||
public_posts << bob.post(:status_message, :text => "public", :to => 'all', :public => true)
|
||||
|
||||
get :show, :id => @person.id
|
||||
|
||||
|
|
@ -163,10 +163,10 @@ describe PeopleController do
|
|||
it "assigns only the posts the current user can see" do
|
||||
bob.posts.should be_empty
|
||||
posts_user_can_see = []
|
||||
posts_user_can_see << bob.post(:status_message, :message => "to an aspect @user is in", :to => bob.aspects[0].id)
|
||||
bob.post(:status_message, :message => "to an aspect @user is not in", :to => bob.aspects[1].id)
|
||||
posts_user_can_see << bob.post(:status_message, :message => "to all aspects", :to => 'all')
|
||||
posts_user_can_see << bob.post(:status_message, :message => "public", :to => 'all', :public => true)
|
||||
posts_user_can_see << bob.post(:status_message, :text => "to an aspect @user is in", :to => bob.aspects[0].id)
|
||||
bob.post(:status_message, :text => "to an aspect @user is not in", :to => bob.aspects[1].id)
|
||||
posts_user_can_see << bob.post(:status_message, :text => "to all aspects", :to => 'all')
|
||||
posts_user_can_see << bob.post(:status_message, :text => "public", :to => 'all', :public => true)
|
||||
bob.reload.posts.length.should == 4
|
||||
|
||||
get :show, :id => @person.id
|
||||
|
|
@ -186,9 +186,9 @@ describe PeopleController do
|
|||
|
||||
it "assigns only public posts" do
|
||||
eve.posts.should be_empty
|
||||
eve.post(:status_message, :message => "to an aspect @user is not in", :to => eve.aspects.first.id)
|
||||
eve.post(:status_message, :message => "to all aspects", :to => 'all')
|
||||
public_post = eve.post(:status_message, :message => "public", :to => 'all', :public => true)
|
||||
eve.post(:status_message, :text => "to an aspect @user is not in", :to => eve.aspects.first.id)
|
||||
eve.post(:status_message, :text => "to all aspects", :to => 'all')
|
||||
public_post = eve.post(:status_message, :text => "public", :to => 'all', :public => true)
|
||||
eve.reload.posts.length.should == 3
|
||||
|
||||
get :show, :id => @person.id
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ describe PhotosController do
|
|||
post :create, @params
|
||||
}.should change(Photo, :count).by(1)
|
||||
end
|
||||
|
||||
|
||||
it 'can set the photo as the profile photo' do
|
||||
old_url = @alice.person.profile.image_url
|
||||
@params[:photo][:set_profile_photo] = true
|
||||
|
|
@ -137,19 +137,19 @@ describe PhotosController do
|
|||
|
||||
describe "#update" do
|
||||
it "updates the caption of a photo" do
|
||||
put :update, :id => @alices_photo.id, :photo => { :caption => "now with lasers!" }
|
||||
put :update, :id => @alices_photo.id, :photo => { :text => "now with lasers!" }
|
||||
@alices_photo.reload.caption.should == "now with lasers!"
|
||||
end
|
||||
|
||||
it "doesn't overwrite random attributes" do
|
||||
new_user = Factory.create(:user)
|
||||
params = { :caption => "now with lasers!", :author_id => new_user.id }
|
||||
params = { :text => "now with lasers!", :author_id => new_user.id }
|
||||
put :update, :id => @alices_photo.id, :photo => params
|
||||
@alices_photo.reload.author_id.should == @alice.person.id
|
||||
end
|
||||
|
||||
it 'redirects if you do not have access to the post' do
|
||||
params = { :caption => "now with lasers!" }
|
||||
params = { :text => "now with lasers!" }
|
||||
put :update, :id => @bobs_photo.id, :photo => params
|
||||
response.should redirect_to(:action => :index, :person_id => @alice.person.id.to_s)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -23,9 +23,9 @@ describe PostsController do
|
|||
pending
|
||||
posts = []
|
||||
2.times do
|
||||
posts << @user.post(:status_message, :message => "#what", :to => 'all')
|
||||
posts << @user.post(:status_message, :text => "#what", :to => 'all')
|
||||
end
|
||||
eve.post(:status_message, :message => "#what", :to => 'all')
|
||||
eve.post(:status_message, :text => "#what", :to => 'all')
|
||||
|
||||
get :index
|
||||
assigns[:posts].should =~ posts
|
||||
|
|
@ -34,9 +34,9 @@ describe PostsController do
|
|||
pending
|
||||
posts = []
|
||||
2.times do
|
||||
posts << bob.post(:status_message, :message => "#what", :to => 'all')
|
||||
posts << bob.post(:status_message, :text => "#what", :to => 'all')
|
||||
end
|
||||
eve.post(:status_message, :message => "#what", :to => 'all')
|
||||
eve.post(:status_message, :text => "#what", :to => 'all')
|
||||
|
||||
get :index
|
||||
assigns[:posts].should =~ posts
|
||||
|
|
@ -45,10 +45,10 @@ describe PostsController do
|
|||
it 'restricts the posts by tag' do
|
||||
posts = []
|
||||
2.times do
|
||||
posts << @user.post(:status_message, :message => "#what", :public => true, :to => 'all')
|
||||
posts << @user.post(:status_message, :text => "#what", :public => true, :to => 'all')
|
||||
end
|
||||
2.times do
|
||||
@user.post(:status_message, :message => "#hello", :public => true, :to => 'all')
|
||||
@user.post(:status_message, :text => "#hello", :public => true, :to => 'all')
|
||||
end
|
||||
|
||||
get :index, :tag => 'what'
|
||||
|
|
@ -59,7 +59,7 @@ describe PostsController do
|
|||
pending
|
||||
posts = []
|
||||
3.times do
|
||||
posts << @user.post(:status_message, :message => "hello", :public => true, :to => 'all')
|
||||
posts << @user.post(:status_message, :text => "hello", :public => true, :to => 'all')
|
||||
end
|
||||
get :index
|
||||
assigns[:posts].should =~ posts
|
||||
|
|
@ -67,7 +67,7 @@ describe PostsController do
|
|||
it' shows only local posts' do
|
||||
pending
|
||||
3.times do
|
||||
@user.post(:status_message, :message => "hello", :public => true, :to => 'all')
|
||||
@user.post(:status_message, :text => "hello", :public => true, :to => 'all')
|
||||
end
|
||||
@user.person.update_attributes(:owner_id => nil)
|
||||
get :index
|
||||
|
|
@ -76,14 +76,14 @@ describe PostsController do
|
|||
end
|
||||
describe '#show' do
|
||||
it 'shows a public post' do
|
||||
status = @user.post(:status_message, :message => "hello", :public => true, :to => 'all')
|
||||
status = @user.post(:status_message, :text => "hello", :public => true, :to => 'all')
|
||||
|
||||
get :show, :id => status.id
|
||||
response.status= 200
|
||||
end
|
||||
|
||||
it 'does not show a private post' do
|
||||
status = @user.post(:status_message, :message => "hello", :public => false, :to => 'all')
|
||||
status = @user.post(:status_message, :text => "hello", :public => false, :to => 'all')
|
||||
get :show, :id => status.id
|
||||
response.status = 302
|
||||
end
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ describe PublicsController do
|
|||
|
||||
it 'unescapes the xml before sending it to receive_salmon' do
|
||||
aspect = @user.aspects.create(:name => 'foo')
|
||||
post1 = @user.post(:status_message, :message => 'moms', :to => [aspect.id])
|
||||
post1 = @user.post(:status_message, :text => 'moms', :to => [aspect.id])
|
||||
xml2 = post1.to_diaspora_xml
|
||||
user2 = Factory(:user)
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ describe SocketsController do
|
|||
describe 'actionhash' do
|
||||
before do
|
||||
@aspect = @user.aspects.first
|
||||
@message = @user.post :status_message, :message => "post through user for victory", :to => @aspect.id
|
||||
@message = @user.post :status_message, :text => "post through user for victory", :to => @aspect.id
|
||||
@fixture_name = File.dirname(__FILE__) + '/../fixtures/button.png'
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ describe StatusMessagesController do
|
|||
|
||||
describe '#show' do
|
||||
before do
|
||||
@message = @user1.build_post :status_message, :message => "ohai", :to => @aspect1.id
|
||||
@message = @user1.build_post :status_message, :text => "ohai", :to => @aspect1.id
|
||||
@message.save!
|
||||
|
||||
@user1.add_to_streams(@message, [@aspect1])
|
||||
|
|
@ -55,7 +55,7 @@ describe StatusMessagesController do
|
|||
let(:status_message_hash) {
|
||||
{ :status_message => {
|
||||
:public => "true",
|
||||
:message => "facebook, is that you?",
|
||||
:text => "facebook, is that you?",
|
||||
},
|
||||
:aspect_ids => [@aspect1.id.to_s] }
|
||||
}
|
||||
|
|
@ -72,7 +72,7 @@ describe StatusMessagesController do
|
|||
end
|
||||
it 'escapes XSS' do
|
||||
xss = "<script> alert('hi browser') </script>"
|
||||
post :create, status_message_hash.merge(:format => 'js', :message => xss)
|
||||
post :create, status_message_hash.merge(:format => 'js', :text => xss)
|
||||
json = JSON.parse(response.body)
|
||||
json['html'].should_not =~ /<script>/
|
||||
end
|
||||
|
|
@ -90,12 +90,12 @@ describe StatusMessagesController do
|
|||
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 = StatusMessage.find_by_text(status_message_hash[:status_message][:text])
|
||||
new_message.author_id.should == @user1.person.id
|
||||
end
|
||||
|
||||
it "doesn't overwrite id" do
|
||||
old_status_message = @user1.post(:status_message, :message => "hello", :to => @aspect1.id)
|
||||
old_status_message = @user1.post(:status_message, :text => "hello", :to => @aspect1.id)
|
||||
status_message_hash[:status_message][:id] = old_status_message.id
|
||||
post :create, status_message_hash
|
||||
old_status_message.reload.message.should == 'hello'
|
||||
|
|
@ -108,7 +108,7 @@ describe StatusMessagesController do
|
|||
post :create, status_message_hash
|
||||
end
|
||||
it 'sends the errors in the body on js' do
|
||||
post :create, status_message_hash.merge!(:format => 'js', :status_message => {:message => ''})
|
||||
post :create, status_message_hash.merge!(:format => 'js', :status_message => {:text => ''})
|
||||
response.body.should include('Status message requires a message or at least one photo')
|
||||
end
|
||||
|
||||
|
|
@ -128,7 +128,7 @@ describe StatusMessagesController do
|
|||
@hash[:photos] = [@photo1.id.to_s, @photo2.id.to_s]
|
||||
end
|
||||
it "will post a photo without text" do
|
||||
@hash.delete :message
|
||||
@hash.delete :text
|
||||
post :create, @hash
|
||||
response.should be_redirect
|
||||
end
|
||||
|
|
@ -145,8 +145,8 @@ describe StatusMessagesController do
|
|||
end
|
||||
|
||||
describe '#destroy' do
|
||||
let!(:message) {@user1.post(:status_message, :message => "hey", :to => @aspect1.id)}
|
||||
let!(:message2) {@user2.post(:status_message, :message => "hey", :to => @aspect2.id)}
|
||||
let!(:message) {@user1.post(:status_message, :text => "hey", :to => @aspect1.id)}
|
||||
let!(:message2) {@user2.post(:status_message, :text => "hey", :to => @aspect2.id)}
|
||||
|
||||
it 'let a user delete his photos' do
|
||||
delete :destroy, :id => message.id
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ Factory.define :aspect do |aspect|
|
|||
end
|
||||
|
||||
Factory.define(:status_message) do |m|
|
||||
m.sequence(:message) { |n| "jimmy's #{n} whales" }
|
||||
m.sequence(:text) { |n| "jimmy's #{n} whales" }
|
||||
m.association :author, :factory => :person
|
||||
m.after_build do|m|
|
||||
m.diaspora_handle = m.author.diaspora_handle
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ describe StreamHelper do
|
|||
before do
|
||||
@user = alice
|
||||
@aspect = @user.aspects.first
|
||||
@post = @user.post(:status_message, :message => "hi", :to => @aspect.id)
|
||||
@post = @user.post(:status_message, :text => "hi", :to => @aspect.id)
|
||||
end
|
||||
it 'renders a new comment form' do
|
||||
new_comment_form(@post.id, @user).should ==
|
||||
|
|
|
|||
|
|
@ -27,14 +27,14 @@ describe 'a user receives a post' do
|
|||
it 'streams only one message to the everyone aspect when a multi-aspected contacts posts' do
|
||||
contact = @user1.contact_for(@user2.person)
|
||||
@user1.add_contact_to_aspect(contact, @user1.aspects.create(:name => "villains"))
|
||||
status = @user2.build_post(:status_message, :message => "Users do things", :to => @aspect2.id)
|
||||
status = @user2.build_post(:status_message, :text => "Users do things", :to => @aspect2.id)
|
||||
Diaspora::WebSocket.should_receive(:queue_to_user).exactly(:once)
|
||||
zord = Postzord::Receiver.new(@user1, :object => status, :person => @user2.person)
|
||||
zord.receive_object
|
||||
end
|
||||
|
||||
it 'should be able to parse and store a status message from xml' do
|
||||
status_message = @user2.post :status_message, :message => 'store this!', :to => @aspect2.id
|
||||
status_message = @user2.post :status_message, :text => 'store this!', :to => @aspect2.id
|
||||
|
||||
xml = status_message.to_diaspora_xml
|
||||
@user2.delete
|
||||
|
|
@ -49,7 +49,7 @@ describe 'a user receives a post' do
|
|||
num_aspects = @user1.aspects.size
|
||||
|
||||
2.times do |n|
|
||||
status_message = @user2.post :status_message, :message => "store this #{n}!", :to => @aspect2.id
|
||||
status_message = @user2.post :status_message, :text => "store this #{n}!", :to => @aspect2.id
|
||||
end
|
||||
|
||||
@user1.aspects.size.should == num_aspects
|
||||
|
|
@ -57,7 +57,7 @@ describe 'a user receives a post' do
|
|||
|
||||
it "should show bob's post to alice" do
|
||||
fantasy_resque do
|
||||
sm = bob.build_post(:status_message, :message => "hi")
|
||||
sm = bob.build_post(:status_message, :text => "hi")
|
||||
sm.save!
|
||||
sm.stub!(:socket_to_user)
|
||||
bob.aspects.reload
|
||||
|
|
@ -73,7 +73,7 @@ describe 'a user receives a post' do
|
|||
Notification.should_receive(:notify).with(@user1, anything(), @user2.person)
|
||||
Notification.should_receive(:notify).with(@user3, anything(), @user2.person)
|
||||
|
||||
@sm = @user2.build_post(:status_message, :message => "@{#{@user1.name}; #{@user1.diaspora_handle}} stuff @{#{@user3.name}; #{@user3.diaspora_handle}}")
|
||||
@sm = @user2.build_post(:status_message, :text => "@{#{@user1.name}; #{@user1.diaspora_handle}} stuff @{#{@user3.name}; #{@user3.diaspora_handle}}")
|
||||
@sm.stub!(:socket_to_user)
|
||||
@user2.add_to_streams(@sm, [@user2.aspects.first])
|
||||
@sm.save
|
||||
|
|
@ -91,7 +91,7 @@ describe 'a user receives a post' do
|
|||
|
||||
Notification.should_receive(:notify).with(@user1, anything(), @remote_person)
|
||||
|
||||
@sm = Factory.build(:status_message, :message => "hello @{#{@user1.name}; #{@user1.diaspora_handle}}", :diaspora_handle => @remote_person.diaspora_handle, :author => @remote_person)
|
||||
@sm = Factory.build(:status_message, :text => "hello @{#{@user1.name}; #{@user1.diaspora_handle}}", :diaspora_handle => @remote_person.diaspora_handle, :author => @remote_person)
|
||||
@sm.stub!(:socket_to_user)
|
||||
@sm.save
|
||||
|
||||
|
|
@ -102,7 +102,7 @@ describe 'a user receives a post' do
|
|||
it 'does not notify the mentioned user if the mentioned user is not friends with the post author' do
|
||||
Notification.should_not_receive(:notify).with(@user1, anything(), @user3.person)
|
||||
|
||||
@sm = @user3.build_post(:status_message, :message => "should not notify @{#{@user1.name}; #{@user1.diaspora_handle}}")
|
||||
@sm = @user3.build_post(:status_message, :text => "should not notify @{#{@user1.name}; #{@user1.diaspora_handle}}")
|
||||
@sm.stub!(:socket_to_user)
|
||||
@user3.add_to_streams(@sm, [@user3.aspects.first])
|
||||
@sm.save
|
||||
|
|
@ -114,8 +114,8 @@ describe 'a user receives a post' do
|
|||
|
||||
context 'update posts' do
|
||||
it 'does not update posts not marked as mutable' do
|
||||
status = @user1.post :status_message, :message => "store this!", :to => @aspect.id
|
||||
status.message = 'foo'
|
||||
status = @user1.post :status_message, :text => "store this!", :to => @aspect.id
|
||||
status.text = 'foo'
|
||||
xml = status.to_diaspora_xml
|
||||
|
||||
receive_with_zord(@user2, @user1.person, xml)
|
||||
|
|
@ -124,20 +124,20 @@ describe 'a user receives a post' do
|
|||
end
|
||||
|
||||
it 'updates posts marked as mutable' do
|
||||
photo = @user1.post(:photo, :user_file => uploaded_photo, :caption => "Original", :to => @aspect.id)
|
||||
photo.caption = 'foo'
|
||||
photo = @user1.post(:photo, :user_file => uploaded_photo, :text => "Original", :to => @aspect.id)
|
||||
photo.text = 'foo'
|
||||
xml = photo.to_diaspora_xml
|
||||
@user2.reload
|
||||
|
||||
receive_with_zord(@user2, @user1.person, xml)
|
||||
|
||||
photo.reload.caption.should match(/foo/)
|
||||
photo.reload.text.should match(/foo/)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'post refs' do
|
||||
before do
|
||||
@status_message = @user2.post :status_message, :message => "hi", :to => @aspect2.id
|
||||
@status_message = @user2.post :status_message, :text => "hi", :to => @aspect2.id
|
||||
@user1.reload
|
||||
@aspect.reload
|
||||
end
|
||||
|
|
@ -210,7 +210,7 @@ describe 'a user receives a post' do
|
|||
context 'remote' do
|
||||
before do
|
||||
connect_users(@user1, @aspect, @user3, @aspect3)
|
||||
@post = @user1.post :status_message, :message => "hello", :to => @aspect.id
|
||||
@post = @user1.post :status_message, :text => "hello", :to => @aspect.id
|
||||
|
||||
xml = @post.to_diaspora_xml
|
||||
|
||||
|
|
@ -263,7 +263,7 @@ describe 'a user receives a post' do
|
|||
|
||||
context 'local' do
|
||||
before do
|
||||
@post = @user1.post :status_message, :message => "hello", :to => @aspect.id
|
||||
@post = @user1.post :status_message, :text => "hello", :to => @aspect.id
|
||||
|
||||
xml = @post.to_diaspora_xml
|
||||
|
||||
|
|
@ -286,11 +286,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, :author=> @remote_raphael, :created_at => 5.days.ago, :updated_at => 5.days.ago)
|
||||
@post = Factory.build(:status_message, :text => '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, :author=> @remote_raphael, :created_at => 5.days.ago, :updated_at => 5.days.ago)
|
||||
@post = Factory.build(:status_message, :text => '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)
|
||||
|
|
@ -301,11 +301,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, :author => @remote_raphael, :created_at => 5.days.ago)
|
||||
@post = Factory.build(:status_message, :text => '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, :author => @remote_raphael, :created_at => 2.days.ago)
|
||||
@post = Factory.build(:status_message, :text => '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
|
||||
|
|
@ -313,7 +313,7 @@ describe 'a user receives a post' do
|
|||
|
||||
|
||||
describe 'salmon' do
|
||||
let(:post){@user1.post :status_message, :message => "hello", :to => @aspect.id}
|
||||
let(:post){@user1.post :status_message, :text => "hello", :to => @aspect.id}
|
||||
let(:salmon){@user1.salmon( post )}
|
||||
|
||||
it 'processes a salmon for a post' do
|
||||
|
|
@ -329,7 +329,7 @@ describe 'a user receives a post' do
|
|||
|
||||
context 'retractions' do
|
||||
it 'should accept retractions' do
|
||||
message = @user2.post(:status_message, :message => "cats", :to => @aspect2.id)
|
||||
message = @user2.post(:status_message, :text => "cats", :to => @aspect2.id)
|
||||
retraction = Retraction.for(message)
|
||||
xml = retraction.to_diaspora_xml
|
||||
|
||||
|
|
|
|||
|
|
@ -1,25 +0,0 @@
|
|||
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
require 'spec_helper'
|
||||
Dir.glob(File.join(Rails.root, 'lib', 'data_conversion', '*.rb')).each { |f| require f }
|
||||
|
||||
describe DataConversion::ExportFromMongo do
|
||||
before do
|
||||
@migrator = DataConversion::ExportFromMongo.new
|
||||
end
|
||||
describe '#sed_replace' do
|
||||
before do
|
||||
@test_string = '{ "_id" : { "$oid" : "4d0916c4cc8cb40e93000009" }, "name" : "Work", "created_at" : { "$date" : 1292441284000 }, "updated_at" : { "$date" : 1292546796000 }, "post_ids" : [ { "$oid" : "4d0aa87acc8cb4144b000009" }, { "$oid" : "4d0ab02ccc8cb41628000010" }, { "$oid" : "4d0ab2eccc8cb41628000011" } ], "user_id" : { "$oid" : "4d0916c2cc8cb40e93000006" } }'
|
||||
end
|
||||
it '#id_sed gets rid of the mongo id type specifier' do
|
||||
post_sed = `echo '#{@test_string}' | #{@migrator.id_sed}`
|
||||
post_sed.strip.match('"_id" : "4d0916c4cc8cb40e93000009", "name" : "Work",').should be_true
|
||||
end
|
||||
it '#date_sed gets rid of the mongo date type specifier' do
|
||||
post_sed = `echo '#{@test_string}' | #{@migrator.date_sed}`
|
||||
post_sed.strip.match('ork", "created_at" : 1292441284000, "updated_at" : 1292546796000, "post_ids" :').should be_true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,770 +0,0 @@
|
|||
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
require 'spec_helper'
|
||||
Dir.glob(File.join(Rails.root, 'lib', 'data_conversion', '*.rb')).each { |f| require f }
|
||||
|
||||
describe DataConversion::ImportToMysql do
|
||||
|
||||
# load data infile messes with transactional rollback
|
||||
self.use_transactional_fixtures = false
|
||||
|
||||
def copy_fixture_for(table_name)
|
||||
FileUtils.cp("#{Rails.root}/spec/fixtures/data_conversion/#{table_name}.csv",
|
||||
"#{@migrator.full_path}/#{table_name}.csv")
|
||||
end
|
||||
|
||||
def import_and_process(table_name)
|
||||
copy_fixture_for(table_name)
|
||||
@migrator.send("import_raw_#{table_name}".to_sym)
|
||||
@migrator.send("process_raw_#{table_name}".to_sym)
|
||||
end
|
||||
|
||||
def delete_everything
|
||||
Mongo::User.delete_all
|
||||
Mongo::Aspect.delete_all
|
||||
Mongo::AspectMembership.delete_all
|
||||
Mongo::Comment.delete_all
|
||||
Mongo::Invitation.delete_all
|
||||
Mongo::Notification.delete_all
|
||||
Mongo::Person.delete_all
|
||||
Mongo::Profile.delete_all
|
||||
Mongo::Post.delete_all
|
||||
Mongo::Contact.delete_all
|
||||
Mongo::PostVisibility.delete_all
|
||||
Mongo::Request.delete_all
|
||||
Mongo::Service.delete_all
|
||||
|
||||
User.delete_all
|
||||
AspectMembership.delete_all
|
||||
Aspect.delete_all
|
||||
Comment.delete_all
|
||||
Invitation.delete_all
|
||||
Notification.delete_all
|
||||
Person.delete_all
|
||||
Profile.delete_all
|
||||
Post.delete_all
|
||||
Contact.delete_all
|
||||
PostVisibility.delete_all
|
||||
Request.delete_all
|
||||
Service.delete_all
|
||||
end
|
||||
|
||||
before do
|
||||
delete_everything
|
||||
@migrator = DataConversion::ImportToMysql.new
|
||||
@migrator.full_path = "/tmp/data_conversion"
|
||||
system("rm -rf #{@migrator.full_path}")
|
||||
FileUtils.mkdir_p(@migrator.full_path)
|
||||
end
|
||||
|
||||
describe "#process_raw" do
|
||||
describe "users" do
|
||||
before do
|
||||
copy_fixture_for("users")
|
||||
@migrator.import_raw_users
|
||||
end
|
||||
it "imports data into the users table" do
|
||||
lambda {
|
||||
@migrator.process_raw_users
|
||||
}.should change(User, :count).by(Mongo::User.count)
|
||||
end
|
||||
it "imports all the columns" do
|
||||
@migrator.process_raw_users
|
||||
bob = User.where(:mongo_id => "4d2b6eb6cc8cb43cc2000007").first
|
||||
bob.username.should == "bob1d2f837"
|
||||
bob.email.should == "bob1a25dee@pivotallabs.com"
|
||||
bob.serialized_private_key.should_not be_nil
|
||||
bob.encrypted_password.should_not be_nil
|
||||
bob.invites.should == 4
|
||||
bob.invitation_token.should be_nil
|
||||
bob.invitation_sent_at.should be_nil
|
||||
bob.getting_started.should be_true
|
||||
bob.disable_mail.should be_false
|
||||
bob.language.should == 'en'
|
||||
bob.last_sign_in_ip.should be_nil
|
||||
bob.last_sign_in_at.to_i.should_not be_nil
|
||||
bob.reset_password_token.should be_nil
|
||||
bob.password_salt.should_not be_nil
|
||||
end
|
||||
end
|
||||
describe "aspects" do
|
||||
before do
|
||||
import_and_process("users")
|
||||
copy_fixture_for("aspects")
|
||||
@migrator.import_raw_aspects
|
||||
end
|
||||
it "imports data into the aspects table" do
|
||||
lambda {
|
||||
@migrator.process_raw_aspects
|
||||
}.should change(Aspect, :count).by(Mongo::Aspect.count)
|
||||
end
|
||||
it "imports all the columns" do
|
||||
@migrator.process_raw_aspects
|
||||
aspect = Aspect.where(:mongo_id => "4d2b6eb6cc8cb43cc2000008").first
|
||||
aspect.name.should == "generic"
|
||||
aspect.contacts_visible.should == false
|
||||
aspect.user_mongo_id.should == "4d2b6eb6cc8cb43cc2000007"
|
||||
end
|
||||
it "sets the relation column" do
|
||||
@migrator.process_raw_aspects
|
||||
aspect = Aspect.where(:mongo_id => "4d2b6eb6cc8cb43cc2000008").first
|
||||
aspect.user.should == User.where(:mongo_id => aspect.user_mongo_id).first
|
||||
end
|
||||
end
|
||||
|
||||
describe "services" do
|
||||
before do
|
||||
import_and_process("users")
|
||||
copy_fixture_for("services")
|
||||
@migrator.import_raw_services
|
||||
end
|
||||
|
||||
it "imports data into the services table" do
|
||||
lambda {
|
||||
@migrator.process_raw_services
|
||||
}.should change(Service, :count).by(Mongo::Service.count)
|
||||
end
|
||||
|
||||
it "imports all the columns" do
|
||||
@migrator.process_raw_services
|
||||
service = Service.where(:mongo_id => "4d2b6ec4cc8cb43cc200003e").first
|
||||
service.type_before_type_cast.should == "Services::Facebook"
|
||||
service.user_mongo_id.should == "4d2b6eb7cc8cb43cc2000014"
|
||||
service.uid.should be_nil
|
||||
service.access_token.should == "yeah"
|
||||
service.access_secret.should be_nil
|
||||
service.nickname.should be_nil
|
||||
end
|
||||
it 'sets the relation column' do
|
||||
@migrator.process_raw_services
|
||||
service = Service.where(:mongo_id => "4d2b6ec4cc8cb43cc200003e").first
|
||||
service.user_id.should == User.where(:mongo_id => service.user_mongo_id).first.id
|
||||
end
|
||||
end
|
||||
|
||||
describe "invitations" do
|
||||
before do
|
||||
import_and_process("users")
|
||||
import_and_process("aspects")
|
||||
copy_fixture_for("invitations")
|
||||
@migrator.import_raw_invitations
|
||||
end
|
||||
|
||||
it "imports data into the mongo_invitations table" do
|
||||
Mongo::Invitation.count.should == 1
|
||||
Invitation.count.should == 0
|
||||
@migrator.process_raw_invitations
|
||||
Invitation.count.should == 1
|
||||
end
|
||||
|
||||
it "imports all the columns" do
|
||||
@migrator.process_raw_invitations
|
||||
invitation = Invitation.first
|
||||
invitation.mongo_id.should == "4d2b6ebecc8cb43cc2000026"
|
||||
invitation.message.should == "Hello!"
|
||||
end
|
||||
it 'sets the relation columns' do
|
||||
@migrator.process_raw_invitations
|
||||
invitation = Invitation.first
|
||||
mongo_invitation = Mongo::Invitation.where(:mongo_id => invitation.mongo_id).first
|
||||
invitation.sender_id.should == User.where(:mongo_id => mongo_invitation.sender_mongo_id).first.id
|
||||
invitation.recipient_id.should == User.where(:mongo_id => mongo_invitation.recipient_mongo_id).first.id
|
||||
end
|
||||
end
|
||||
describe "requests" do
|
||||
before do
|
||||
import_and_process("users")
|
||||
import_and_process("people")
|
||||
import_and_process("aspects")
|
||||
copy_fixture_for("requests")
|
||||
@migrator.import_raw_requests
|
||||
end
|
||||
|
||||
it "imports data into the mongo_requests table" do
|
||||
Mongo::Request.count.should == 2
|
||||
Request.count.should == 0
|
||||
@migrator.process_raw_requests
|
||||
Request.count.should == 2
|
||||
end
|
||||
|
||||
it "imports all the columns" do
|
||||
@migrator.process_raw_requests
|
||||
request = Request.first
|
||||
request.mongo_id.should == "4d2b6eb8cc8cb43cc200001e"
|
||||
end
|
||||
it 'sets the relation columns' do
|
||||
@migrator.process_raw_requests
|
||||
request = Request.first
|
||||
mongo_request = Mongo::Request.where(:mongo_id => request.mongo_id).first
|
||||
request.sender_id.should == Person.where(:mongo_id => mongo_request.sender_mongo_id).first.id
|
||||
request.recipient_id.should == Person.where(:mongo_id => mongo_request.recipient_mongo_id).first.id
|
||||
end
|
||||
end
|
||||
describe "people" do
|
||||
before do
|
||||
import_and_process("users")
|
||||
copy_fixture_for("people")
|
||||
@migrator.import_raw_people
|
||||
end
|
||||
|
||||
it "imports data into the people table" do
|
||||
lambda {
|
||||
@migrator.process_raw_people
|
||||
}.should change(Person, :count).by(Mongo::Person.count)
|
||||
end
|
||||
|
||||
it "imports all the columns of a non-owned person" do
|
||||
@migrator.process_raw_people
|
||||
mongo_person = Mongo::Person.where(:mongo_id => "4d2b6eb6cc8cb43cc2000001").first
|
||||
person = Person.where(:mongo_id => "4d2b6eb6cc8cb43cc2000001").first
|
||||
person.owner_id.should be_nil
|
||||
person.guid.should == person.mongo_id
|
||||
person.url.should == "http://google-1b05052.com/"
|
||||
person.diaspora_handle.should == "bob-person-1fe12fb@aol.com"
|
||||
person.serialized_public_key.should_not be_nil
|
||||
person.created_at.should == mongo_person.created_at
|
||||
end
|
||||
|
||||
it "imports all the columns of an owned person" do
|
||||
@migrator.process_raw_people
|
||||
mongo_person = Mongo::Person.first
|
||||
person = Person.where(:mongo_id => mongo_person.mongo_id).first
|
||||
person.guid.should == mongo_person.mongo_id
|
||||
person.url.should == mongo_person.url
|
||||
person.diaspora_handle.should == mongo_person.diaspora_handle
|
||||
person.serialized_public_key.should == mongo_person.serialized_public_key
|
||||
person.created_at.should == mongo_person.created_at
|
||||
end
|
||||
it 'sets the relational column of an owned person' do
|
||||
@migrator.process_raw_people
|
||||
mongo_person = Mongo::Person.where("mongo_people.owner_mongo_id IS NOT NULL").first
|
||||
person = Person.where(:mongo_id => mongo_person.mongo_id).first
|
||||
person.owner.should_not be_nil
|
||||
person.diaspora_handle.should include(person.owner.username)
|
||||
end
|
||||
end
|
||||
|
||||
describe "contacts" do
|
||||
before do
|
||||
import_and_process("users")
|
||||
import_and_process("people")
|
||||
copy_fixture_for("contacts")
|
||||
@migrator.import_raw_contacts
|
||||
end
|
||||
|
||||
it "imports data into the mongo_contacts table" do
|
||||
original_contact_count = Contact.unscoped.count
|
||||
@migrator.process_raw_contacts
|
||||
Contact.unscoped.count.should == original_contact_count + Mongo::Contact.count
|
||||
end
|
||||
|
||||
it "imports all the columns" do
|
||||
@migrator.process_raw_contacts
|
||||
mongo_contact = Mongo::Contact.first
|
||||
contact = Contact.where(:mongo_id => mongo_contact.mongo_id).first
|
||||
contact.user_id.should == User.where(:mongo_id => mongo_contact.user_mongo_id).first.id
|
||||
contact.person_id.should == Person.where(:mongo_id => mongo_contact.person_mongo_id).first.id
|
||||
contact.pending.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe "aspect_memberships" do
|
||||
before do
|
||||
import_and_process("users")
|
||||
import_and_process("people")
|
||||
import_and_process("contacts")
|
||||
import_and_process("aspects")
|
||||
copy_fixture_for("aspect_memberships")
|
||||
@migrator.import_raw_aspect_memberships
|
||||
end
|
||||
|
||||
it "imports data into the mongo_aspect_memberships table" do
|
||||
lambda {
|
||||
@migrator.process_raw_aspect_memberships
|
||||
}.should change(AspectMembership, :count).by(Mongo::AspectMembership.count)
|
||||
end
|
||||
|
||||
it "imports all the columns" do
|
||||
@migrator.process_raw_aspect_memberships
|
||||
mongo_aspectm = Mongo::AspectMembership.first
|
||||
aspectm = AspectMembership.where(
|
||||
:contact_id => Contact.where(:mongo_id => mongo_aspectm.contact_mongo_id).first.id,
|
||||
:aspect_id => Aspect.where(:mongo_id => mongo_aspectm.aspect_mongo_id).first.id).first
|
||||
aspectm.should_not be_nil
|
||||
end
|
||||
end
|
||||
describe "profiles" do
|
||||
before do
|
||||
import_and_process("users")
|
||||
import_and_process("people")
|
||||
copy_fixture_for("profiles")
|
||||
@migrator.import_raw_profiles
|
||||
end
|
||||
|
||||
it "processs data into the mongo_profiles table" do
|
||||
lambda {
|
||||
@migrator.process_raw_profiles
|
||||
}.should change(Profile, :count).by(Mongo::Profile.count)
|
||||
end
|
||||
|
||||
it "processs all the columns" do
|
||||
@migrator.process_raw_profiles
|
||||
profile = Profile.where(:mongo_id => "4d2b6eb6cc8cb43cc2000001").first
|
||||
profile.image_url_medium.should be_nil
|
||||
profile.searchable.should == true
|
||||
profile[:image_url].should be_nil
|
||||
profile.gender.should be_nil
|
||||
profile.diaspora_handle.should == profile.person.diaspora_handle
|
||||
profile.last_name.should == 'weinstien'
|
||||
profile.bio.should be_nil
|
||||
profile.image_url_small.should be_nil
|
||||
profile.first_name.should == 'eugene'
|
||||
end
|
||||
it "sets the relation to person" do
|
||||
@migrator.process_raw_profiles
|
||||
profile = Profile.first
|
||||
profile.person_id.should == Person.where(:mongo_id => profile.mongo_id).first.id
|
||||
end
|
||||
end
|
||||
describe "posts" do
|
||||
before do
|
||||
import_and_process("users")
|
||||
import_and_process("people")
|
||||
copy_fixture_for("posts")
|
||||
@migrator.import_raw_posts
|
||||
end
|
||||
|
||||
it "imports data into the posts table" do
|
||||
lambda {
|
||||
@migrator.process_raw_posts
|
||||
}.should change(Post, :count).by(Mongo::Post.count)
|
||||
end
|
||||
|
||||
it "imports all the columns" do
|
||||
@migrator.process_raw_posts
|
||||
post = StatusMessage.first
|
||||
mongo_post = Mongo::Post.where(:mongo_id => post.mongo_id).first
|
||||
post.youtube_titles.should be_nil
|
||||
post.pending.should == false
|
||||
post.public.should == false
|
||||
post.status_message_id.should be_nil
|
||||
post.caption.should be_nil
|
||||
post.remote_photo_path.should be_nil
|
||||
post.remote_photo_name.should be_nil
|
||||
post.random_string.should be_nil
|
||||
post.image.should be_nil
|
||||
post.mongo_id.should == "4d2b6ebecc8cb43cc2000027"
|
||||
post.guid.should == post.mongo_id
|
||||
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
|
||||
end
|
||||
|
||||
it "imports the columns of a photo" do
|
||||
@migrator.process_raw_posts
|
||||
post = Photo.where(:mongo_id => "4d2b6ebfcc8cb43cc200002d").first
|
||||
mongo_post = Mongo::Post.where(:mongo_id => post.mongo_id).first
|
||||
post.youtube_titles.should be_nil
|
||||
post.pending.should == false
|
||||
post.public.should == false
|
||||
post.status_message_id.should == StatusMessage.where(:mongo_id => mongo_post.status_message_mongo_id).first.id
|
||||
post.caption.should be_nil
|
||||
post.remote_photo_path.should be_nil
|
||||
post.remote_photo_name.should be_nil
|
||||
post.random_string.should == "mUKUIxkYlV"
|
||||
post.image.file.file.should =~ /mUKUIxkYlV4d2b6ebfcc8cb43cc200002d\.png/
|
||||
post.mongo_id.should == "4d2b6ebfcc8cb43cc200002d"
|
||||
post.guid.should == post.mongo_id
|
||||
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
|
||||
end
|
||||
end
|
||||
describe "comments" do
|
||||
before do
|
||||
import_and_process("users")
|
||||
import_and_process("people")
|
||||
import_and_process("posts")
|
||||
copy_fixture_for("comments")
|
||||
@migrator.import_raw_comments
|
||||
end
|
||||
|
||||
it "imports data into the comments table" do
|
||||
lambda {
|
||||
@migrator.process_raw_comments
|
||||
}.should change(Comment, :count).by(Mongo::Comment.count)
|
||||
end
|
||||
|
||||
it "processes all the columns" do
|
||||
@migrator.process_raw_comments
|
||||
comment = Comment.first
|
||||
comment.mongo_id.should == "4d2b6ebfcc8cb43cc200002b"
|
||||
comment.text.should == "Hey me!"
|
||||
comment.youtube_titles.should be_nil
|
||||
end
|
||||
it 'sets the relations' do
|
||||
@migrator.process_raw_comments
|
||||
comment = Comment.first
|
||||
comment.post_id.should == Post.where(:mongo_id => "4d2b6ebecc8cb43cc2000029").first.id
|
||||
comment.author_id.should == Person.where(:mongo_id => "4d2b6eb7cc8cb43cc2000017").first.id
|
||||
end
|
||||
end
|
||||
describe "notifications" do
|
||||
before do
|
||||
import_and_process("users")
|
||||
import_and_process("people")
|
||||
import_and_process("posts")
|
||||
import_and_process("aspects")
|
||||
import_and_process("requests")
|
||||
copy_fixture_for("notifications")
|
||||
@migrator.import_raw_notifications
|
||||
end
|
||||
|
||||
it "does not import notifications" do
|
||||
Mongo::Notification.count.should == 2
|
||||
Notification.count.should == 0
|
||||
@migrator.process_raw_notifications
|
||||
Notification.count.should == 0
|
||||
end
|
||||
end
|
||||
describe "post_visibilities" do
|
||||
before do
|
||||
import_and_process("users")
|
||||
import_and_process("people")
|
||||
import_and_process("aspects")
|
||||
import_and_process("posts")
|
||||
copy_fixture_for("post_visibilities")
|
||||
@migrator.import_raw_post_visibilities
|
||||
end
|
||||
|
||||
it "imports data into the post_visibilities table" do
|
||||
Mongo::PostVisibility.count.should == 8
|
||||
PostVisibility.count.should == 0
|
||||
@migrator.process_raw_post_visibilities
|
||||
PostVisibility.count.should == 8
|
||||
end
|
||||
|
||||
it "processes all the columns" do
|
||||
@migrator.process_raw_post_visibilities
|
||||
pv = PostVisibility.first
|
||||
mongo_pv = Mongo::PostVisibility.first
|
||||
pv.aspect.mongo_id.should == mongo_pv.aspect_mongo_id
|
||||
pv.post.mongo_id.should == mongo_pv.post_mongo_id
|
||||
end
|
||||
end
|
||||
end
|
||||
describe "#import_raw" do
|
||||
describe "aspects" do
|
||||
before do
|
||||
copy_fixture_for("aspects")
|
||||
end
|
||||
|
||||
it "imports data into the mongo_aspects table" do
|
||||
Mongo::Aspect.count.should == 0
|
||||
@migrator.import_raw_aspects
|
||||
Mongo::Aspect.count.should == 4
|
||||
end
|
||||
|
||||
it "imports all the columns" do
|
||||
@migrator.import_raw_aspects
|
||||
aspect = Mongo::Aspect.first
|
||||
aspect.name.should == "generic"
|
||||
aspect.mongo_id.should == "4d2b6eb6cc8cb43cc2000008"
|
||||
aspect.user_mongo_id.should == "4d2b6eb6cc8cb43cc2000007"
|
||||
end
|
||||
end
|
||||
|
||||
describe "aspect_memberships" do
|
||||
before do
|
||||
copy_fixture_for("aspect_memberships")
|
||||
end
|
||||
|
||||
it "imports data into the mongo_aspect_memberships table" do
|
||||
Mongo::AspectMembership.count.should == 0
|
||||
@migrator.import_raw_aspect_memberships
|
||||
Mongo::AspectMembership.count.should == 6
|
||||
end
|
||||
|
||||
it "imports all the columns" do
|
||||
@migrator.import_raw_aspect_memberships
|
||||
aspectm = Mongo::AspectMembership.first
|
||||
aspectm.contact_mongo_id.should == "4d2b6eb7cc8cb43cc200000f"
|
||||
aspectm.aspect_mongo_id.should == "4d2b6eb6cc8cb43cc2000008"
|
||||
end
|
||||
end
|
||||
|
||||
describe "comments" do
|
||||
before do
|
||||
copy_fixture_for("comments")
|
||||
end
|
||||
|
||||
it "imports data into the mongo_comments table" do
|
||||
Mongo::Comment.count.should == 0
|
||||
@migrator.import_raw_comments
|
||||
Mongo::Comment.count.should == 2
|
||||
end
|
||||
|
||||
it "imports all the columns" do
|
||||
@migrator.import_raw_comments
|
||||
comment = Mongo::Comment.first
|
||||
comment.mongo_id.should == "4d2b6ebfcc8cb43cc200002b"
|
||||
comment.text.should == "Hey me!"
|
||||
comment.post_mongo_id.should == "4d2b6ebecc8cb43cc2000029"
|
||||
comment.person_mongo_id.should == "4d2b6eb7cc8cb43cc2000017"
|
||||
comment.youtube_titles.should be_nil
|
||||
end
|
||||
end
|
||||
describe "contacts" do
|
||||
before do
|
||||
copy_fixture_for("contacts")
|
||||
end
|
||||
|
||||
it "imports data into the mongo_contacts table" do
|
||||
Mongo::Contact.count.should == 0
|
||||
@migrator.import_raw_contacts
|
||||
Mongo::Contact.count.should == 6
|
||||
end
|
||||
|
||||
it "imports all the columns" do
|
||||
@migrator.import_raw_contacts
|
||||
contact = Mongo::Contact.first
|
||||
contact.mongo_id.should == "4d2b6eb7cc8cb43cc200000f"
|
||||
contact.user_mongo_id.should =="4d2b6eb6cc8cb43cc2000007"
|
||||
contact.person_mongo_id.should == "4d2b6eb7cc8cb43cc200000e"
|
||||
contact.pending.should be_false
|
||||
end
|
||||
end
|
||||
describe "invitations" do
|
||||
before do
|
||||
copy_fixture_for("invitations")
|
||||
end
|
||||
|
||||
it "imports data into the mongo_invitations table" do
|
||||
Mongo::Invitation.count.should == 0
|
||||
@migrator.import_raw_invitations
|
||||
Mongo::Invitation.count.should == 1
|
||||
end
|
||||
|
||||
it "imports all the columns" do
|
||||
@migrator.import_raw_invitations
|
||||
invitation = Mongo::Invitation.first
|
||||
invitation.mongo_id.should == "4d2b6ebecc8cb43cc2000026"
|
||||
invitation.recipient_mongo_id.should =="4d2b6ebccc8cb43cc2000025"
|
||||
invitation.sender_mongo_id.should == "4d2b6eb6cc8cb43cc2000007"
|
||||
invitation.aspect_mongo_id.should == '4d2b6eb6cc8cb43cc2000008'
|
||||
invitation.message.should == "Hello!"
|
||||
end
|
||||
end
|
||||
|
||||
describe "posts" do
|
||||
before do
|
||||
copy_fixture_for("posts")
|
||||
end
|
||||
|
||||
it "imports data into the mongo_posts table" do
|
||||
Mongo::Post.count.should == 0
|
||||
@migrator.import_raw_posts
|
||||
Mongo::Post.count.should == 6
|
||||
end
|
||||
|
||||
it "imports all the columns" do
|
||||
@migrator.import_raw_posts
|
||||
post = Mongo::Post.first
|
||||
post.youtube_titles.should be_nil
|
||||
post.pending.should == false
|
||||
post.public.should == false
|
||||
post.status_message_mongo_id.should be_nil
|
||||
post.caption.should be_nil
|
||||
post.remote_photo_path.should be_nil
|
||||
post.remote_photo_name.should be_nil
|
||||
post.random_string.should be_nil
|
||||
post.image.should be_nil
|
||||
post.mongo_id.should == "4d2b6ebecc8cb43cc2000027"
|
||||
post.guid.should == post.mongo_id
|
||||
post.type.should == "StatusMessage"
|
||||
post.diaspora_handle.should == "bob1d2f837@localhost"
|
||||
post.person_mongo_id.should == "4d2b6eb6cc8cb43cc200000a"
|
||||
post.message.should == "User2 can see this"
|
||||
Mongo::Post.where(:mongo_id => "4d2b6ebfcc8cb43cc200002d").first.status_message_mongo_id.should == post.mongo_id
|
||||
# puts post.created_at.utc? # == true
|
||||
post.created_at.utc.to_i.should == 1294692030 # got 1294663230- minus 8 hours
|
||||
post.updated_at.to_i.should == 1294692030
|
||||
end
|
||||
|
||||
end
|
||||
describe "notifications" do
|
||||
before do
|
||||
copy_fixture_for("notifications")
|
||||
end
|
||||
|
||||
it "imports data into the mongo_notifications table" do
|
||||
Mongo::Notification.count.should == 0
|
||||
@migrator.import_raw_notifications
|
||||
Mongo::Notification.count.should == 2
|
||||
end
|
||||
|
||||
it "imports all the columns" do
|
||||
@migrator.import_raw_notifications
|
||||
notification = Mongo::Notification.first
|
||||
notification.mongo_id.should == "4d2b6eb8cc8cb43cc200001f"
|
||||
notification.target_mongo_id.should == '4d2b6eb8cc8cb43cc200001e'
|
||||
notification.recipient_mongo_id.should == "4d2b6eb7cc8cb43cc2000018"
|
||||
notification.actor_mongo_id.should == "4d2b6eb7cc8cb43cc2000017"
|
||||
notification.action.should == "new_request"
|
||||
notification.unread.should be_true
|
||||
notification.target_type.should == "Request"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe "people" do
|
||||
before do
|
||||
copy_fixture_for("people")
|
||||
end
|
||||
|
||||
it "imports data into the mongo_people table" do
|
||||
Mongo::Person.count.should == 0
|
||||
@migrator.import_raw_people
|
||||
Mongo::Person.count.should == 10
|
||||
end
|
||||
|
||||
it "imports all the columns" do
|
||||
@migrator.import_raw_people
|
||||
person = Mongo::Person.first
|
||||
person.owner_mongo_id.should be_nil
|
||||
person.mongo_id.should == "4d2b6eb6cc8cb43cc2000001"
|
||||
person.guid.should == person.mongo_id
|
||||
person.url.should == "http://google-1b05052.com/"
|
||||
person.diaspora_handle.should == "bob-person-1fe12fb@aol.com"
|
||||
person.serialized_public_key.should_not be_nil
|
||||
person.created_at.to_i.should == 1294692022
|
||||
end
|
||||
end
|
||||
describe "post_visibilities" do
|
||||
before do
|
||||
copy_fixture_for("post_visibilities")
|
||||
end
|
||||
|
||||
it "imports data into the mongo_post_visibilities table" do
|
||||
Mongo::PostVisibility.count.should == 0
|
||||
@migrator.import_raw_post_visibilities
|
||||
Mongo::PostVisibility.count.should == 8
|
||||
end
|
||||
|
||||
it "imports all the columns" do
|
||||
@migrator.import_raw_post_visibilities
|
||||
pv = Mongo::PostVisibility.first
|
||||
pv.aspect_mongo_id.should == "4d2b6eb6cc8cb43cc2000008"
|
||||
pv.post_mongo_id.should == "4d2b6ebecc8cb43cc2000027"
|
||||
end
|
||||
end
|
||||
describe "profiles" do
|
||||
before do
|
||||
copy_fixture_for("profiles")
|
||||
end
|
||||
|
||||
it "imports data into the mongo_profiles table" do
|
||||
Mongo::Profile.count.should == 0
|
||||
@migrator.import_raw_profiles
|
||||
Mongo::Profile.count.should == 10
|
||||
end
|
||||
|
||||
it "imports all the columns" do
|
||||
@migrator.import_raw_profiles
|
||||
profile = Mongo::Profile.first
|
||||
profile.image_url_medium.should be_nil
|
||||
profile.searchable.should == true
|
||||
profile.image_url.should be_nil
|
||||
profile.person_mongo_id.should == "4d2b6eb6cc8cb43cc2000001"
|
||||
profile.gender.should be_nil
|
||||
profile.diaspora_handle.should be_nil
|
||||
profile.last_name.should == 'weinstien'
|
||||
profile.bio.should be_nil
|
||||
profile.image_url_small.should be_nil
|
||||
profile.first_name.should == 'eugene'
|
||||
end
|
||||
end
|
||||
|
||||
describe "requests" do
|
||||
before do
|
||||
copy_fixture_for("requests")
|
||||
end
|
||||
|
||||
it "imports data into the mongo_requests table" do
|
||||
Mongo::Request.count.should == 0
|
||||
@migrator.import_raw_requests
|
||||
Mongo::Request.count.should == 2
|
||||
end
|
||||
|
||||
it "imports all the columns" do
|
||||
@migrator.import_raw_requests
|
||||
request = Mongo::Request.first
|
||||
request.mongo_id.should == "4d2b6eb8cc8cb43cc200001e"
|
||||
request.recipient_mongo_id.should == "4d2b6eb7cc8cb43cc200001b"
|
||||
request.sender_mongo_id.should == "4d2b6eb7cc8cb43cc2000017"
|
||||
request.aspect_mongo_id.should be_nil
|
||||
end
|
||||
end
|
||||
describe "services" do
|
||||
before do
|
||||
copy_fixture_for("services")
|
||||
end
|
||||
|
||||
it "imports data into the mongo_services table" do
|
||||
Mongo::Service.count.should == 0
|
||||
@migrator.import_raw_services
|
||||
Mongo::Service.count.should == 2
|
||||
end
|
||||
|
||||
it "imports all the columns" do
|
||||
@migrator.import_raw_services
|
||||
service = Mongo::Service.first
|
||||
service.mongo_id.should == "4d2b6ec4cc8cb43cc200003e"
|
||||
service.type_before_type_cast.should == "Services::Facebook"
|
||||
service.user_mongo_id.should == "4d2b6eb7cc8cb43cc2000014"
|
||||
service.uid.should be_nil
|
||||
service.access_token.should == "yeah"
|
||||
service.access_secret.should be_nil
|
||||
service.nickname.should be_nil
|
||||
end
|
||||
end
|
||||
describe "users" do
|
||||
before do
|
||||
copy_fixture_for("users")
|
||||
end
|
||||
it "imports data into the mongo_users table" do
|
||||
Mongo::User.count.should == 0
|
||||
@migrator.import_raw_users
|
||||
Mongo::User.count.should == 6
|
||||
end
|
||||
it "imports all the columns" do
|
||||
@migrator.import_raw_users
|
||||
bob = Mongo::User.first
|
||||
bob.mongo_id.should == "4d2b6eb6cc8cb43cc2000007"
|
||||
bob.username.should == "bob1d2f837"
|
||||
bob.email.should == "bob1a25dee@pivotallabs.com"
|
||||
bob.serialized_private_key.should_not be_nil
|
||||
bob.encrypted_password.should_not be_nil
|
||||
bob.invites.should == 4
|
||||
bob.invitation_token.should be_nil
|
||||
bob.invitation_sent_at.should be_nil
|
||||
bob.getting_started.should be_true
|
||||
bob.disable_mail.should be_false
|
||||
bob.language.should == 'en'
|
||||
bob.last_sign_in_ip.should be_nil
|
||||
bob.last_sign_in_at.to_i.should_not be_nil
|
||||
bob.reset_password_token.should be_nil
|
||||
bob.password_salt.should_not be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Otherwise, subsequent tests can't load the fixtures
|
||||
self.use_transactional_fixtures = true
|
||||
end
|
||||
|
|
@ -17,9 +17,9 @@ describe Diaspora::Exporter do
|
|||
@aspect2 = @user2.aspects.create(:name => "Family")
|
||||
@aspect3 = @user3.aspects.first
|
||||
|
||||
@status_message1 = @user1.post(:status_message, :message => "One", :public => true, :to => @aspect1.id)
|
||||
@status_message2 = @user1.post(:status_message, :message => "Two", :public => true, :to => @aspect1.id)
|
||||
@status_message3 = @user2.post(:status_message, :message => "Three", :public => false, :to => @aspect2.id)
|
||||
@status_message1 = @user1.post(:status_message, :text => "One", :public => true, :to => @aspect1.id)
|
||||
@status_message2 = @user1.post(:status_message, :text => "Two", :public => true, :to => @aspect1.id)
|
||||
@status_message3 = @user2.post(:status_message, :text => "Three", :public => false, :to => @aspect2.id)
|
||||
end
|
||||
|
||||
def exported
|
||||
|
|
|
|||
|
|
@ -12,13 +12,13 @@ describe Diaspora::OstatusBuilder do
|
|||
let(:aspect) { user.aspects.first }
|
||||
let!(:public_status_messages) {
|
||||
3.times.inject([]) do |arr,n|
|
||||
s = user.post(:status_message, :message => "hey#{n}", :public => true, :to => aspect.id)
|
||||
s = user.post(:status_message, :text => "hey#{n}", :public => true, :to => aspect.id)
|
||||
arr << s
|
||||
end
|
||||
}
|
||||
let!(:private_status_messages) {
|
||||
3.times.inject([]) do |arr,n|
|
||||
s = user.post(:status_message, :message => "secret_ney#{n}", :public => false, :to => aspect.id)
|
||||
s = user.post(:status_message, :text => "secret_ney#{n}", :public => false, :to => aspect.id)
|
||||
arr << s
|
||||
end
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ describe Diaspora::Parser do
|
|||
|
||||
describe "parsing compliant XML object" do
|
||||
it 'should be able to correctly parse comment fields' do
|
||||
post = @user1.post :status_message, :message => "hello", :to => @aspect1.id
|
||||
post = @user1.post :status_message, :text => "hello", :to => @aspect1.id
|
||||
comment = Factory.create(:comment, :post => post, :author => @person, :diaspora_handle => @person.diaspora_handle, :text => "Freedom!")
|
||||
comment.delete
|
||||
xml = comment.to_diaspora_xml
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ describe Diaspora::Socketable do
|
|||
before do
|
||||
@user = alice
|
||||
@aspect = @user.aspects.first
|
||||
@post = @user.build_post(:status_message, :message => "hey", :to => @aspect.id)
|
||||
@post = @user.build_post(:status_message, :text => "hey", :to => @aspect.id)
|
||||
@post.save
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ describe Postzord::Dispatch do
|
|||
|
||||
context "local luke's post is commented on by" do
|
||||
before do
|
||||
@post = @local_luke.post(:status_message, :message => "hello", :to => @local_luke.aspects.first)
|
||||
@post = @local_luke.post(:status_message, :text => "hello", :to => @local_luke.aspects.first)
|
||||
end
|
||||
context "local leia" do
|
||||
before do
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ describe Postzord::Receiver do
|
|||
aspect1 = @user.aspects.first
|
||||
aspect2 = @user2.aspects.first
|
||||
|
||||
@original_post = @user2.build_post(:status_message, :message => "hey", :aspect_ids => [aspect2.id])
|
||||
@original_post = @user2.build_post(:status_message, :text => "hey", :aspect_ids => [aspect2.id])
|
||||
@salmon_xml = @user2.salmon(@original_post).xml_for(@user.person)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ describe Salmon do
|
|||
let(:user){alice}
|
||||
let(:user2) {eve}
|
||||
let(:user3) {Factory.create(:user)}
|
||||
let(:post){ user.post :status_message, :message => "hi", :to => user.aspects.create(:name => "sdg").id }
|
||||
let(:post){ user.post :status_message, :text => "hi", :to => user.aspects.create(:name => "sdg").id }
|
||||
|
||||
let!(:created_salmon) {Salmon::SalmonSlap.create(user, post.to_diaspora_xml)}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ describe YoutubeTitles do
|
|||
Net::HTTP.stub!(:new).with('gdata.youtube.com', 80).and_return(mock_http)
|
||||
mock_http.should_receive(:get).with(@api_path, nil).and_return(
|
||||
[nil, "Foobar <title>#{@expected_title}</title> hallo welt <asd><dasdd><a>dsd</a>"])
|
||||
@post = Factory.create(:status_message, :message => @url)
|
||||
@post = Factory.create(:status_message, :text => @url)
|
||||
end
|
||||
it 'can be re-marshalled' do
|
||||
lambda {
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ describe Notifier do
|
|||
|
||||
@create_hash = { :author => @user2.person, :participant_ids => @participant_ids ,
|
||||
:subject => "cool stuff", :text => 'hey'}
|
||||
|
||||
|
||||
@cnv = Conversation.create(@create_hash)
|
||||
|
||||
@mail = Notifier.private_message(user.id, @cnv.author.id, @cnv.messages.first.id)
|
||||
|
|
@ -148,7 +148,7 @@ describe Notifier do
|
|||
end
|
||||
context "comments" do
|
||||
let!(:connect) { connect_users(user, aspect, user2, aspect2)}
|
||||
let!(:sm) {user.post(:status_message, :message => "Sunny outside", :to => :all)}
|
||||
let!(:sm) {user.post(:status_message, :text => "Sunny outside", :to => :all)}
|
||||
let!(:comment) { user2.comment("Totally is", :on => sm )}
|
||||
describe ".comment_on_post" do
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ describe 'making sure the spec runner works' do
|
|||
end
|
||||
|
||||
it 'allows posting after running' do
|
||||
message = @user1.post(:status_message, :message => "Connection!", :to => @aspect1.id)
|
||||
message = @user1.post(:status_message, :text => "Connection!", :to => @aspect1.id)
|
||||
@user2.reload.visible_posts.should include message
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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, :text => "hey", :to => aspect.id)
|
||||
|
||||
aspect.reload
|
||||
aspect.posts.include?(status_message).should be true
|
||||
|
|
@ -125,7 +125,7 @@ describe Aspect do
|
|||
aspect2 = user2.aspects.create(:name => 'winners')
|
||||
connect_users(user, aspect, user2, aspect2)
|
||||
|
||||
message = user2.post(:status_message, :message => "Hey Dude", :to => aspect2.id)
|
||||
message = user2.post(:status_message, :text => "Hey Dude", :to => aspect2.id)
|
||||
|
||||
aspect.reload
|
||||
aspect.posts.include?(message).should be true
|
||||
|
|
@ -137,7 +137,7 @@ describe Aspect do
|
|||
aspect2 = user2.aspects.create(:name => 'winners')
|
||||
connect_users(user, aspect, user2, aspect2)
|
||||
|
||||
message = user2.post(:status_message, :message => "Hey Dude", :to => aspect2.id)
|
||||
message = user2.post(:status_message, :text => "Hey Dude", :to => aspect2.id)
|
||||
|
||||
aspect.reload.post_ids.include?(message.id).should be true
|
||||
|
||||
|
|
@ -171,7 +171,7 @@ describe Aspect do
|
|||
end
|
||||
context 'moving and removing posts' do
|
||||
before do
|
||||
@message = user2.post(:status_message, :message => "Hey Dude", :to => aspect2.id)
|
||||
@message = user2.post(:status_message, :text => "Hey Dude", :to => aspect2.id)
|
||||
aspect.reload
|
||||
user.reload
|
||||
end
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ describe Comment do
|
|||
|
||||
@bob = bob
|
||||
@eve = eve
|
||||
@status = alice.post(:status_message, :message => "hello", :to => @alices_aspect.id)
|
||||
@status = alice.post(:status_message, :text => "hello", :to => @alices_aspect.id)
|
||||
end
|
||||
|
||||
describe 'comment#notification_type' do
|
||||
|
|
@ -65,7 +65,7 @@ describe Comment do
|
|||
@commenter = Factory.create(:user)
|
||||
@commenter_aspect = @commenter.aspects.create(:name => "bruisers")
|
||||
connect_users(alice, @alices_aspect, @commenter, @commenter_aspect)
|
||||
@post = alice.post :status_message, :message => "hello", :to => @alices_aspect.id
|
||||
@post = alice.post :status_message, :text => "hello", :to => @alices_aspect.id
|
||||
@comment = @commenter.comment "Fool!", :on => @post
|
||||
@xml = @comment.to_xml.to_s
|
||||
end
|
||||
|
|
@ -90,7 +90,7 @@ describe Comment do
|
|||
|
||||
describe 'youtube' do
|
||||
before do
|
||||
@message = alice.post :status_message, :message => "hi", :to => @alices_aspect.id
|
||||
@message = alice.post :status_message, :text => "hi", :to => @alices_aspect.id
|
||||
end
|
||||
it 'should process youtube titles on the way in' do
|
||||
video_id = "ABYnqp-bxvg"
|
||||
|
|
@ -113,7 +113,7 @@ describe Comment do
|
|||
before do
|
||||
@local_luke, @local_leia, @remote_raphael = set_up_friends
|
||||
@remote_parent = Factory.create(:status_message, :author => @remote_raphael)
|
||||
@local_parent = @local_luke.post :status_message, :message => "hi", :to => @local_luke.aspects.first
|
||||
@local_parent = @local_luke.post :status_message, :text => "hi", :to => @local_luke.aspects.first
|
||||
|
||||
@object_by_parent_author = @local_luke.comment("yo", :on => @local_parent)
|
||||
@object_by_recipient = @local_leia.build_comment("yo", :on => @local_parent)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ describe Job::PostToService do
|
|||
it 'calls service#post with the given service' do
|
||||
user = alice
|
||||
aspect = user.aspects.create(:name => "yeah")
|
||||
post = user.post(:status_message, :message => 'foo', :to => aspect.id)
|
||||
post = user.post(:status_message, :text => 'foo', :to => aspect.id)
|
||||
User.stub!(:find_by_id).with(user.id.to_s).and_return(user)
|
||||
m = mock()
|
||||
url = "foobar"
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ describe Mention do
|
|||
@mentioned_user = bob
|
||||
@non_friend = eve
|
||||
|
||||
@sm = @user.build_post(:status_message, :message => "hi @{#{@mentioned_user.name}; #{@mentioned_user.diaspora_handle}}", :to => @user.aspects.first)
|
||||
@sm = @user.build_post(:status_message, :text => "hi @{#{@mentioned_user.name}; #{@mentioned_user.diaspora_handle}}", :to => @user.aspects.first)
|
||||
end
|
||||
|
||||
it 'notifies the person being mentioned' do
|
||||
|
|
@ -24,7 +24,7 @@ describe Mention do
|
|||
connect_users(@user, @aspect1, @non_friend, @non_friend.aspects.first)
|
||||
|
||||
Notification.should_not_receive(:notify).with(@mentioned_user, anything(), @user.person)
|
||||
sm2 = @user.post(:status_message, :message => "stuff @{#{@non_friend.name}; #{@non_friend.diaspora_handle}}", :to => @user.aspects.first)
|
||||
sm2 = @user.post(:status_message, :text => "stuff @{#{@non_friend.name}; #{@non_friend.diaspora_handle}}", :to => @user.aspects.first)
|
||||
sm2.receive(@non_friend, @non_friend.person)
|
||||
end
|
||||
end
|
||||
|
|
@ -40,7 +40,7 @@ describe Mention do
|
|||
@user = alice
|
||||
@mentioned_user = bob
|
||||
|
||||
@sm = @user.post(:status_message, :message => "hi", :to => @user.aspects.first)
|
||||
@sm = @user.post(:status_message, :text => "hi", :to => @user.aspects.first)
|
||||
@m = Mention.create!(:person => @mentioned_user.person, :post => @sm)
|
||||
@m.notify_recipient
|
||||
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ describe Notification do
|
|||
|
||||
before do
|
||||
@user3 = bob
|
||||
@sm = @user3.post(:status_message, :message => "comment!", :to => :all)
|
||||
@sm = @user3.post(:status_message, :text => "comment!", :to => :all)
|
||||
Postzord::Receiver.new(@user3, :person => @user2.person, :object => @user2.comment("hey", :on => @sm)).receive_object
|
||||
Postzord::Receiver.new(@user3, :person => @user.person, :object => @user.comment("hey", :on => @sm)).receive_object
|
||||
end
|
||||
|
|
|
|||
|
|
@ -28,10 +28,10 @@ describe Photo do
|
|||
@photo.update_attributes(:author_id => Factory(:person).id)
|
||||
@photo.reload.author.should == @user.person
|
||||
end
|
||||
it 'allows assignmant of caption' do
|
||||
it 'allows assignment of text' do
|
||||
@photo.save!
|
||||
@photo.update_attributes(:caption => "this is awesome!!")
|
||||
@photo.reload.caption.should == "this is awesome!!"
|
||||
@photo.update_attributes(:text => "this is awesome!!")
|
||||
@photo.reload.text.should == "this is awesome!!"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -80,8 +80,8 @@ describe Photo do
|
|||
before do
|
||||
@photo.image.store! File.open(@fixture_name)
|
||||
end
|
||||
it 'should have a caption' do
|
||||
@photo.caption = "cool story, bro"
|
||||
it 'should have text' do
|
||||
@photo.text= "cool story, bro"
|
||||
@photo.save.should be_true
|
||||
end
|
||||
|
||||
|
|
@ -157,7 +157,7 @@ describe Photo do
|
|||
|
||||
context "deletion" do
|
||||
before do
|
||||
@status_message = @user.build_post(:status_message, :message => "", :to => @aspect.id)
|
||||
@status_message = @user.build_post(:status_message, :text => "", :to => @aspect.id)
|
||||
@status_message.photos << @photo2
|
||||
@status_message.save
|
||||
@status_message.reload
|
||||
|
|
@ -188,7 +188,7 @@ describe Photo do
|
|||
|
||||
it 'does not delete the parent if the parent has a message' do
|
||||
pending
|
||||
@status_message.message = "hello there kids"
|
||||
@status_message.text = "hello there kids"
|
||||
@status_message.save
|
||||
|
||||
proc {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ describe Post do
|
|||
|
||||
describe 'serialization' do
|
||||
it 'should serialize the handle and not the sender' do
|
||||
post = @user.post :status_message, :message => "hello", :to => @aspect.id
|
||||
post = @user.post :status_message, :text => "hello", :to => @aspect.id
|
||||
xml = post.to_diaspora_xml
|
||||
|
||||
xml.include?("person_id").should be false
|
||||
|
|
@ -32,7 +32,7 @@ describe Post do
|
|||
|
||||
describe '#mutable?' do
|
||||
it 'should be false by default' do
|
||||
post = @user.post :status_message, :message => "hello", :to => @aspect.id
|
||||
post = @user.post :status_message, :text => "hello", :to => @aspect.id
|
||||
post.mutable?.should == false
|
||||
end
|
||||
end
|
||||
|
|
@ -40,7 +40,7 @@ describe Post do
|
|||
describe '#subscribers' do
|
||||
it 'returns the people contained in the aspects the post appears in' do
|
||||
|
||||
post = @user.post :status_message, :message => "hello", :to => @aspect.id
|
||||
post = @user.post :status_message, :text => "hello", :to => @aspect.id
|
||||
|
||||
post.subscribers(@user).should == []
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ describe Retraction do
|
|||
let(:person) { Factory(:person) }
|
||||
let(:aspect) { user.aspects.create(:name => "Bruisers") }
|
||||
let!(:activation) { user.activate_contact(person, aspect) }
|
||||
let!(:post) { user.post :status_message, :message => "Destroy!", :to => aspect.id }
|
||||
let!(:post) { user.post :status_message, :text => "Destroy!", :to => aspect.id }
|
||||
|
||||
describe 'serialization' do
|
||||
it 'should have a post id after serialization' do
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ describe Services::Facebook do
|
|||
|
||||
before do
|
||||
@user = alice
|
||||
@post = @user.post(:status_message, :message => "hello", :to =>@user.aspects.first.id)
|
||||
@post = @user.post(:status_message, :text => "hello", :to =>@user.aspects.first.id)
|
||||
@service = Services::Facebook.new(:access_token => "yeah")
|
||||
@user.services << @service
|
||||
end
|
||||
|
|
@ -103,7 +103,7 @@ JSON
|
|||
it 'caches the sender' do
|
||||
@service.finder["#{@user2_fb_id}"][:request].sender.loaded?.should be_true
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
it 'contains a contact object if connected' do
|
||||
|
|
@ -124,7 +124,7 @@ JSON
|
|||
@service.finder(:remote => true)["#{@user2_fb_id}"].should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context 'already invited' do
|
||||
before do
|
||||
@user2.invitation_service = 'facebook'
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ describe Services::Twitter do
|
|||
|
||||
before do
|
||||
@user = alice
|
||||
@post = @user.post(:status_message, :message => "hello", :to =>@user.aspects.first.id)
|
||||
@post = @user.post(:status_message, :text => "hello", :to =>@user.aspects.first.id)
|
||||
@service = Services::Twitter.new(:access_token => "yeah", :access_secret => "foobar")
|
||||
@user.services << @service
|
||||
end
|
||||
|
|
|
|||
|
|
@ -39,15 +39,15 @@ describe StatusMessage do
|
|||
end
|
||||
end
|
||||
it "should have either a message or at least one photo" do
|
||||
n = Factory.build(:status_message, :message => nil)
|
||||
n = Factory.build(:status_message, :text => nil)
|
||||
n.valid?.should be_false
|
||||
|
||||
n.message = ""
|
||||
n.text = ""
|
||||
n.valid?.should be_false
|
||||
|
||||
n.message = "wales"
|
||||
n.text = "wales"
|
||||
n.valid?.should be_true
|
||||
n.message = nil
|
||||
n.text = nil
|
||||
|
||||
photo = @user.build_post(:photo, :user_file => uploaded_photo, :to => @aspect.id)
|
||||
photo.save!
|
||||
|
|
@ -59,7 +59,7 @@ describe StatusMessage do
|
|||
|
||||
it 'should be postable through the user' do
|
||||
message = "Users do things"
|
||||
status = @user.post(:status_message, :message => message, :to => @aspect.id)
|
||||
status = @user.post(:status_message, :text => message, :to => @aspect.id)
|
||||
db_status = StatusMessage.find(status.id)
|
||||
db_status.message.should == message
|
||||
end
|
||||
|
|
@ -67,7 +67,7 @@ describe StatusMessage do
|
|||
it 'should require status messages to be less than 1000 characters' do
|
||||
message = ''
|
||||
1001.times do message = message +'1';end
|
||||
status = Factory.build(:status_message, :message => message)
|
||||
status = Factory.build(:status_message, :text => message)
|
||||
|
||||
status.should_not be_valid
|
||||
end
|
||||
|
|
@ -79,7 +79,7 @@ describe StatusMessage do
|
|||
@{Raphael; #{@people[0].diaspora_handle}} can mention people like Raphael @{Ilya; #{@people[1].diaspora_handle}}
|
||||
can mention people like Raphaellike Raphael @{Daniel; #{@people[2].diaspora_handle}} can mention people like Raph
|
||||
STR
|
||||
@sm = Factory.create(:status_message, :message => @test_string )
|
||||
@sm = Factory.create(:status_message, :text => @test_string )
|
||||
end
|
||||
|
||||
describe '#format_mentions' do
|
||||
|
|
@ -92,7 +92,7 @@ STR
|
|||
|
||||
context 'with :plain_text option' do
|
||||
it 'removes the mention syntax and displays the unformatted name' do
|
||||
status = Factory(:status_message, :message => "@{Barack Obama; barak@joindiaspora.com } is so cool @{Barack Obama; barak@joindiaspora.com } ")
|
||||
status = Factory(:status_message, :text => "@{Barack Obama; barak@joindiaspora.com } is so cool @{Barack Obama; barak@joindiaspora.com } ")
|
||||
status.format_mentions(status.raw_message, :plain_text => true).should == 'Barack Obama is so cool Barack Obama '
|
||||
end
|
||||
end
|
||||
|
|
@ -181,7 +181,7 @@ STR
|
|||
describe '#format_tags' do
|
||||
before do
|
||||
@str = '#what #hey'
|
||||
@sm.message = @str
|
||||
@sm.text = @str
|
||||
@sm.build_tags
|
||||
@sm.save
|
||||
@sm.reload
|
||||
|
|
@ -196,7 +196,7 @@ STR
|
|||
end
|
||||
describe '#build_tags' do
|
||||
it 'builds the tags' do
|
||||
@sm.message = '#what'
|
||||
@sm.text = '#what'
|
||||
@sm.build_tags
|
||||
@sm.tag_list.should == ['what']
|
||||
lambda {
|
||||
|
|
@ -209,32 +209,32 @@ STR
|
|||
str = '#what #hey #that"smybike. #@hey ##boo # #THATWASMYBIKE #hey#there #135440we #abc/23 ###'
|
||||
arr = ['what', 'hey', 'that', 'THATWASMYBIKE', '135440we', 'abc']
|
||||
|
||||
@sm.message = str
|
||||
@sm.text = str
|
||||
@sm.tag_strings.should =~ arr
|
||||
end
|
||||
it 'returns no duplicates' do
|
||||
str = '#what #what #what #whaaaaaaaaaat'
|
||||
arr = ['what','whaaaaaaaaaat']
|
||||
|
||||
@sm.message = str
|
||||
@sm.text = str
|
||||
@sm.tag_strings.should =~ arr
|
||||
end
|
||||
it 'is case insensitive' do
|
||||
str = '#what #wHaT #WHAT'
|
||||
arr = ['what']
|
||||
|
||||
@sm.message = str
|
||||
@sm.text = str
|
||||
@sm.tag_strings.should =~ arr
|
||||
end
|
||||
end
|
||||
end
|
||||
describe "XML" do
|
||||
before do
|
||||
@message = Factory.create(:status_message, :message => "I hate WALRUSES!", :author => @user.person)
|
||||
@message = Factory.create(:status_message, :text => "I hate WALRUSES!", :author => @user.person)
|
||||
@xml = @message.to_xml.to_s
|
||||
end
|
||||
it 'serializes the unescaped, unprocessed message' do
|
||||
@message.message = "<script> alert('xss should be federated');</script>"
|
||||
@message.text = "<script> alert('xss should be federated');</script>"
|
||||
@message.to_xml.to_s.should include @message.message
|
||||
end
|
||||
it 'serializes the message' do
|
||||
|
|
@ -282,7 +282,7 @@ STR
|
|||
mock_http.should_receive(:get).with('/feeds/api/videos/'+video_id+'?v=2', nil).and_return(
|
||||
[nil, 'Foobar <title>'+expected_title+'</title> hallo welt <asd><dasdd><a>dsd</a>'])
|
||||
|
||||
post = @user.build_post :status_message, :message => url, :to => @aspect.id
|
||||
post = @user.build_post :status_message, :text => url, :to => @aspect.id
|
||||
|
||||
post.save!
|
||||
Post.find(post.id).youtube_titles.should == {video_id => CGI::escape(expected_title)}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ describe "attack vectors" do
|
|||
context 'non-contact valid user' do
|
||||
|
||||
it 'does not save a post from a non-contact' do
|
||||
post_from_non_contact = bad_user.build_post( :status_message, :message => 'hi')
|
||||
post_from_non_contact = bad_user.build_post( :status_message, :text => 'hi')
|
||||
salmon_xml = bad_user.salmon(post_from_non_contact).xml_for(user.person)
|
||||
|
||||
post_from_non_contact.delete
|
||||
|
|
@ -39,7 +39,7 @@ describe "attack vectors" do
|
|||
it 'does not let a user attach to posts previously in the db unless its received from the author' do
|
||||
connect_users(user, aspect, user3, aspect3)
|
||||
|
||||
original_message = user2.post :status_message, :message => 'store this!', :to => aspect2.id
|
||||
original_message = user2.post :status_message, :text => 'store this!', :to => aspect2.id
|
||||
|
||||
original_message.diaspora_handle = user.diaspora_handle
|
||||
|
||||
|
|
@ -60,14 +60,14 @@ describe "attack vectors" do
|
|||
|
||||
describe 'mass assignment on id' do
|
||||
it "does not save a message over an old message with a different author" do
|
||||
original_message = user2.post :status_message, :message => 'store this!', :to => aspect2.id
|
||||
original_message = user2.post :status_message, :text => 'store this!', :to => aspect2.id
|
||||
|
||||
salmon_xml = user2.salmon(original_message).xml_for(user.person)
|
||||
|
||||
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml)
|
||||
zord.perform
|
||||
|
||||
malicious_message = Factory.build(:status_message, :id => original_message.id, :message => 'BAD!!!', :author => user3.person)
|
||||
malicious_message = Factory.build(:status_message, :id => original_message.id, :text => '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
|
||||
|
|
@ -76,14 +76,14 @@ describe "attack vectors" do
|
|||
end
|
||||
|
||||
it 'does not save a message over an old message with the same author' do
|
||||
original_message = user2.post :status_message, :message => 'store this!', :to => aspect2.id
|
||||
original_message = user2.post :status_message, :text => 'store this!', :to => aspect2.id
|
||||
|
||||
salmon_xml = user2.salmon(original_message).xml_for(user.person)
|
||||
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml)
|
||||
zord.perform
|
||||
|
||||
lambda {
|
||||
malicious_message = Factory.build( :status_message, :id => original_message.id, :message => 'BAD!!!', :author => user2.person)
|
||||
malicious_message = Factory.build( :status_message, :id => original_message.id, :text => 'BAD!!!', :author => user2.person)
|
||||
|
||||
salmon_xml2 = user3.salmon(malicious_message).xml_for(user.person)
|
||||
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml)
|
||||
|
|
@ -113,7 +113,7 @@ describe "attack vectors" do
|
|||
|
||||
it "ignores retractions on a post not owned by the retraction's sender" do
|
||||
StatusMessage.delete_all
|
||||
original_message = user2.post :status_message, :message => 'store this!', :to => aspect2.id
|
||||
original_message = user2.post :status_message, :text => 'store this!', :to => aspect2.id
|
||||
|
||||
salmon_xml = user2.salmon(original_message).xml_for(user.person)
|
||||
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml)
|
||||
|
|
@ -137,7 +137,7 @@ describe "attack vectors" do
|
|||
|
||||
it "disregards retractions for non-existent posts that are from someone other than the post's author" do
|
||||
StatusMessage.delete_all
|
||||
original_message = user2.post :status_message, :message => 'store this!', :to => aspect2.id
|
||||
original_message = user2.post :status_message, :text => 'store this!', :to => aspect2.id
|
||||
id = original_message.reload.id
|
||||
|
||||
ret = Retraction.new
|
||||
|
|
@ -156,7 +156,7 @@ describe "attack vectors" do
|
|||
end
|
||||
|
||||
it 'should not receive retractions where the retractor and the salmon author do not match' do
|
||||
original_message = user2.post :status_message, :message => 'store this!', :to => aspect2.id
|
||||
original_message = user2.post :status_message, :text => 'store this!', :to => aspect2.id
|
||||
|
||||
salmon_xml = user2.salmon(original_message).xml_for(user.person)
|
||||
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml)
|
||||
|
|
@ -209,21 +209,21 @@ describe "attack vectors" do
|
|||
end
|
||||
|
||||
it 'does not let me update other persons post' do
|
||||
original_message = user2.post(:photo, :user_file => uploaded_photo, :caption => "store this!", :to => aspect2.id)
|
||||
original_message = user2.post(:photo, :user_file => uploaded_photo, :text => "store this!", :to => aspect2.id)
|
||||
|
||||
salmon_xml = user2.salmon(original_message).xml_for(user.person)
|
||||
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml)
|
||||
zord.perform
|
||||
|
||||
original_message.diaspora_handle = user3.diaspora_handle
|
||||
original_message.caption = "bad bad bad"
|
||||
original_message.text= "bad bad bad"
|
||||
|
||||
salmon_xml = user3.salmon(original_message).xml_for(user.person)
|
||||
|
||||
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml)
|
||||
zord.perform
|
||||
|
||||
original_message.reload.caption.should == "store this!"
|
||||
original_message.reload.text.should == "store this!"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -282,7 +282,7 @@ describe Diaspora::UserModules::Connecting do
|
|||
context 'with a post' do
|
||||
before do
|
||||
StatusMessage.delete_all
|
||||
@message = alice.post(:status_message, :message => "hi", :to => alice.aspects.first.id)
|
||||
@message = alice.post(:status_message, :text => "hi", :to => alice.aspects.first.id)
|
||||
end
|
||||
|
||||
it "deletes the disconnected user's posts from visible_posts" do
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ describe User do
|
|||
|
||||
describe '#add_to_streams' do
|
||||
before do
|
||||
@params = {:message => "hey", :to => [aspect.id, aspect1.id]}
|
||||
@params = {:text => "hey", :to => [aspect.id, aspect1.id]}
|
||||
@post = user.build_post(:status_message, @params)
|
||||
@post.save
|
||||
@aspect_ids = @params[:to]
|
||||
|
|
@ -61,11 +61,11 @@ describe User do
|
|||
|
||||
describe '#build_post' do
|
||||
it 'sets status_message#message' do
|
||||
post = user.build_post(:status_message, :message => "hey", :to => aspect.id)
|
||||
post = user.build_post(:status_message, :text => "hey", :to => aspect.id)
|
||||
post.message.should == "hey"
|
||||
end
|
||||
it 'does not save a status_message' do
|
||||
post = user.build_post(:status_message, :message => "hey", :to => aspect.id)
|
||||
post = user.build_post(:status_message, :text => "hey", :to => aspect.id)
|
||||
post.persisted?.should be_false
|
||||
end
|
||||
|
||||
|
|
@ -79,11 +79,11 @@ describe User do
|
|||
|
||||
describe '#update_post' do
|
||||
it 'should update fields' do
|
||||
photo = user.post(:photo, :user_file => uploaded_photo, :caption => "Old caption", :to => aspect.id)
|
||||
update_hash = {:caption => "New caption"}
|
||||
photo = user.post(:photo, :user_file => uploaded_photo, :text => "Old caption", :to => aspect.id)
|
||||
update_hash = {:text => "New caption"}
|
||||
user.update_post(photo, update_hash)
|
||||
|
||||
photo.caption.should match(/New/)
|
||||
photo.text.should match(/New/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -16,10 +16,10 @@ describe User do
|
|||
describe "#raw_visible_posts" do
|
||||
it "returns all the posts the user can see" do
|
||||
connect_users(@eve, @eves_aspect, @alice, @alices_aspect)
|
||||
self_post = @alice.post(:status_message, :message => "hi", :to => @alices_aspect.id)
|
||||
visible_post = @eve.post(:status_message, :message => "hello", :to => @eves_aspect.id)
|
||||
self_post = @alice.post(:status_message, :text => "hi", :to => @alices_aspect.id)
|
||||
visible_post = @eve.post(:status_message, :text => "hello", :to => @eves_aspect.id)
|
||||
dogs = @eve.aspects.create(:name => "dogs")
|
||||
invisible_post = @eve.post(:status_message, :message => "foobar", :to => dogs.id)
|
||||
invisible_post = @eve.post(:status_message, :text => "foobar", :to => dogs.id)
|
||||
|
||||
stream = @alice.raw_visible_posts
|
||||
stream.should include(self_post)
|
||||
|
|
@ -32,13 +32,13 @@ describe User do
|
|||
before do
|
||||
connect_users(@eve, @eves_aspect, @alice, @alices_aspect)
|
||||
aspect3 = @alice.aspects.create(:name => "Snoozers")
|
||||
@status_message1 = @eve.post :status_message, :message => "hi", :to => @eves_aspect.id
|
||||
@status_message2 = @eve.post :status_message, :message => "hey", :public => true , :to => @eves_aspect.id
|
||||
@status_message3 = @alice.post :status_message, :message => "hey", :public => true , :to => @alices_aspect.id
|
||||
@status_message4 = @eve.post :status_message, :message => "blah", :public => true , :to => @eves_aspect.id
|
||||
@status_message5 = @alice.post :status_message, :message => "secrets", :to => aspect3.id
|
||||
@status_message1 = @eve.post :status_message, :text => "hi", :to => @eves_aspect.id
|
||||
@status_message2 = @eve.post :status_message, :text => "hey", :public => true , :to => @eves_aspect.id
|
||||
@status_message3 = @alice.post :status_message, :text => "hey", :public => true , :to => @alices_aspect.id
|
||||
@status_message4 = @eve.post :status_message, :text => "blah", :public => true , :to => @eves_aspect.id
|
||||
@status_message5 = @alice.post :status_message, :text => "secrets", :to => aspect3.id
|
||||
|
||||
@pending_status_message = @eve.post :status_message, :message => "hey", :public => true , :to => @eves_aspect.id, :pending => true
|
||||
@pending_status_message = @eve.post :status_message, :text => "hey", :public => true , :to => @eves_aspect.id, :pending => true
|
||||
end
|
||||
|
||||
describe "#visible_posts" do
|
||||
|
|
@ -70,7 +70,7 @@ describe User do
|
|||
end
|
||||
|
||||
it "selects by message contents" do
|
||||
query = @eve.visible_posts(:message => "hi")
|
||||
query = @eve.visible_posts(:text=> "hi")
|
||||
query.should == [@status_message1]
|
||||
end
|
||||
|
||||
|
|
@ -216,8 +216,8 @@ describe User 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)
|
||||
@public_message = @user3.post(:status_message, :text => "hey there", :to => 'all', :public => true)
|
||||
@private_message = @user3.post(:status_message, :text => "hey there", :to => @aspect3.id)
|
||||
end
|
||||
|
||||
it 'displays public posts for a non-contact' do
|
||||
|
|
@ -230,7 +230,7 @@ describe User do
|
|||
|
||||
it 'displays private and public posts for a non-contact after connecting' do
|
||||
connect_users(@alice, @alices_aspect, @user3, @aspect3)
|
||||
new_message = @user3.post(:status_message, :message => "hey there", :to => @aspect3.id)
|
||||
new_message = @user3.post(:status_message, :text=> "hey there", :to => @aspect3.id)
|
||||
|
||||
@alice.reload
|
||||
|
||||
|
|
@ -239,8 +239,8 @@ describe User do
|
|||
end
|
||||
|
||||
it 'displays recent posts first' do
|
||||
msg3 = @user3.post(:status_message, :message => "hey there", :to => 'all', :public => true)
|
||||
msg4 = @user3.post(:status_message, :message => "hey there", :to => 'all', :public => true)
|
||||
msg3 = @user3.post(:status_message, :text => "hey there", :to => 'all', :public => true)
|
||||
msg4 = @user3.post(:status_message, :text => "hey there", :to => 'all', :public => true)
|
||||
msg3.created_at = Time.now+10
|
||||
msg3.save!
|
||||
msg4.created_at = Time.now+14
|
||||
|
|
|
|||
|
|
@ -215,7 +215,7 @@ describe User do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe 'update_user_preferences' do
|
||||
it 'unsets disable mail and makes the right amount of prefs' do
|
||||
alice.disable_mail = true
|
||||
|
|
@ -328,8 +328,8 @@ describe User do
|
|||
m = mock()
|
||||
m.should_receive(:post)
|
||||
Postzord::Dispatch.should_receive(:new).and_return(m)
|
||||
photo = alice.build_post(:photo, :user_file => uploaded_photo, :caption => "hello", :to => alice.aspects.first.id)
|
||||
alice.update_post(photo, :caption => 'hellp')
|
||||
photo = alice.build_post(:photo, :user_file => uploaded_photo, :text => "hello", :to => alice.aspects.first.id)
|
||||
alice.update_post(photo, :text => 'hellp')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -419,7 +419,7 @@ describe User do
|
|||
end
|
||||
|
||||
it 'should remove the posts' do
|
||||
message = alice.post(:status_message, :message => "hi", :to => alice.aspects.first.id)
|
||||
message = alice.post(:status_message, :text => "hi", :to => alice.aspects.first.id)
|
||||
alice.reload
|
||||
alice.destroy
|
||||
proc { message.reload }.should raise_error ActiveRecord::RecordNotFound
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class User
|
|||
end
|
||||
|
||||
def post_at_time(time)
|
||||
p = self.post(:status_message, :message => 'hi', :to => self.aspects.first)
|
||||
p = self.post(:status_message, :text => 'hi', :to => self.aspects.first)
|
||||
p.created_at = time
|
||||
p.save!
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue