Write fixture for mysql export

This commit is contained in:
Raphael 2011-01-06 11:35:58 -08:00
parent f02ed1e3c4
commit 0284f0fd6d
3 changed files with 94 additions and 44 deletions

View file

@ -9,4 +9,56 @@ namespace :fixtures do
UserFixer.regenerate_user_fixtures UserFixer.regenerate_user_fixtures
puts "Fixture regeneration complete." puts "Fixture regeneration complete."
end end
task :for_mysql_export do
puts "Populating DB for export."
require File.join(Rails.root,"config/environment")
require File.join(Rails.root,"spec/helper_methods")
require File.join(Rails.root,"spec/factories")
require File.join(Rails.root,"spec/support/user_methods")
include HelperMethods
fantasy_resque do
Factory(:person)
Factory(:person)
Factory(:person)
user1 = Factory(:user_with_aspect)
user2 = Factory(:user_with_aspect)
connect_users(user1, user1.aspects.first, user2, user2.aspects.first)
user2.activate_contact(Factory(:person), user2.aspects.first)
user3 = Factory(:user_with_aspect)
user4 = Factory(:user_with_aspect)
user3.send_contact_request_to(user4.person, user3.aspects.first)
user3.send_contact_request_to(Factory(:person), user3.aspects.first)
batch_invitee = Invitation.create_invitee(:email => "random@example.com", :name => "Curious George", :invites => 3)
invitee = user1.invite_user("random2@example.net", user1.aspects.first.id, "Hello!")
u1post = user1.post(:status_message, :message => "User2 can see this", :to => [user1.aspects.first.id])
u3post = user3.post(:status_message, :message => "User3 can see this", :to => [user3.aspects.first.id])
user3.comment("Hey me!", :on => u3post)
user2.comment("Hey you!", :on => u1post)
user2.post(:photo, :user_file => uploaded_photo, :to => [user2.aspects.first.id])
user3.post(:photo, :user_file => uploaded_photo, :to => [user3.aspects.first.id])
remote_user = Factory(:user_with_aspect)
user4.activate_contact(remote_user.person, user4.aspects.first)
remote_message = remote_user.build_post(:photo, :user_file => uploaded_photo, :to => remote_user.aspects.first.id)
remote_photo = remote_user.build_post(:status_message, :message => "from another server!", :to => remote_user.aspects.first.id)
request = remote_user.send_contact_request_to(user2.person, remote_user.aspects.first)
remote_user.delete
Contact.where(:user_id => remote_user.id).each{|c| c.delete}
Aspect.where(:user_id => remote_user.id).each{|c| c.delete}
user4.receive(remote_message.to_diaspora_xml, remote_user.person)
user4.receive(remote_photo.to_diaspora_xml, remote_user.person)
remote_person = remote_user.person
remote_person.owner_id = nil
remote_person.save
end
puts "Done generating fixtures, you can now export"
end
end end

View file

@ -65,50 +65,6 @@ module Resque
end end
ImageUploader.enable_processing = false ImageUploader.enable_processing = false
class User
def send_contact_request_to(desired_contact, aspect)
fantasy_resque do
contact = Contact.new(:person => desired_contact,
:user => self,
:pending => true)
contact.aspects << aspect
if contact.save!
contact.dispatch_request
else
nil
end
end
end
def post(class_name, opts = {})
fantasy_resque do
p = build_post(class_name, opts)
if p.save!
raise 'MongoMapper failed to catch a failed save' unless p.id
self.aspects.reload
add_to_streams(p, opts[:to])
dispatch_post(p, :to => opts[:to])
end
p
end
end
def comment(text, options = {})
fantasy_resque do
c = build_comment(text, options)
if c.save!
raise 'MongoMapper failed to catch a failed save' unless c.id
dispatch_comment(c)
end
c
end
end
end
class FakeHttpRequest class FakeHttpRequest
def initialize(callback_wanted) def initialize(callback_wanted)

View file

@ -0,0 +1,42 @@
class User
def send_contact_request_to(desired_contact, aspect)
fantasy_resque do
contact = Contact.new(:person => desired_contact,
:user => self,
:pending => true)
contact.aspects << aspect
if contact.save!
contact.dispatch_request
else
nil
end
end
end
def post(class_name, opts = {})
fantasy_resque do
p = build_post(class_name, opts)
if p.save!
raise 'MongoMapper failed to catch a failed save' unless p.id
self.aspects.reload
add_to_streams(p, opts[:to])
dispatch_post(p, :to => opts[:to])
end
p
end
end
def comment(text, options = {})
fantasy_resque do
c = build_comment(text, options)
if c.save!
raise 'MongoMapper failed to catch a failed save' unless c.id
dispatch_comment(c)
end
c
end
end
end