diff --git a/lib/tasks/fixtures.rake b/lib/tasks/fixtures.rake index e10882cf5..5c4f18edc 100644 --- a/lib/tasks/fixtures.rake +++ b/lib/tasks/fixtures.rake @@ -9,4 +9,56 @@ namespace :fixtures do UserFixer.regenerate_user_fixtures puts "Fixture regeneration complete." 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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2d9901dae..ad8332b49 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -65,50 +65,6 @@ module Resque end 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 def initialize(callback_wanted) diff --git a/spec/support/user_methods.rb b/spec/support/user_methods.rb new file mode 100644 index 000000000..d0288d7fa --- /dev/null +++ b/spec/support/user_methods.rb @@ -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