From 585906d3d4263fc9d3ead9b0cce831c6d6bc16be Mon Sep 17 00:00:00 2001 From: danielvincent Date: Wed, 30 Jun 2010 13:47:26 -0700 Subject: [PATCH 1/3] DG IZ; db rake tasks ouput text; delete is now purge --- lib/tasks/db.rake | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index af9b5e476..fdcb9c1d3 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -1,12 +1,18 @@ namespace :db do desc 'Seed the current RAILS_ENV database from db/seeds.rb' task :seed do + + puts "Seeding the database for #{RAILS_ENV}..." + require 'db/seeds' end desc 'Delete the collections in the current RAILS_ENV database' - task :delete do + task :purge do require 'config/environment' + + puts "Purging the database for #{RAILS_ENV}..." + # Specifiy what models to remove Post.delete_all Person.delete_all @@ -15,7 +21,10 @@ namespace :db do desc 'Purge and seed the current RAILS_ENV database using information from db/seeds.rb' task :reset do - Rake::Task['db:delete'].invoke + + puts "Resetting the database for #{RAILS_ENV}".upcase + Rake::Task['db:purge'].invoke Rake::Task['db:seed'].invoke + puts "Success!" end end From fbd1195113d1012f295692dc54cddfd9900d9aae Mon Sep 17 00:00:00 2001 From: danielvincent Date: Wed, 30 Jun 2010 16:00:29 -0700 Subject: [PATCH 2/3] DG IZ; rake task for backer, can now pass in arguments [backer_num, password] --- db/seeds.rb | 64 ++++++++++++++++++++++++++-------------------- db/seeds/backer.rb | 38 +++++++++++++++++++++++++++ db/seeds/tom.rb | 51 ++++++++++++++++++++++++++++++++++++ lib/tasks/db.rake | 21 +++++++++------ 4 files changed, 138 insertions(+), 36 deletions(-) create mode 100644 db/seeds/backer.rb create mode 100644 db/seeds/tom.rb diff --git a/db/seeds.rb b/db/seeds.rb index 6870a63e7..7ed50cd10 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -9,35 +9,43 @@ require 'config/environment' # Create seed user -User.create( :email => "a@a.com", :password => "aaaaaa", :profile => Profile.create( :first_name => "Robert", :last_name => "Grimm" )) +user = User.create( :email => "tom@joindiaspora.com", :password => "aaaaaa", :profile => Profile.create( :first_name => "Diaspora", :last_name => "Tom" )) + +names = [ ["George", "Washington"], + ["John", "Adams"], + ["Thomas", "Jefferson"], + ["James", "Madison"], + ["James", "Monroe"], + ["John Quincy", "Adams"], + ["Andrew", "Jackson"], + ["Martin Van", "Buren"], + ["William Henry","Harrison"], + ["John", "Tyler"], + ["James K." , "Polk"], + ["Zachary", "Taylor"], + ["Millard", "Fillmore"], + ["Franklin", "Pierce"], + ["James", "Buchanan"], + ["Abraham", "Lincoln"] + ] # Make friends -friend_one = Friend.create( :email => "babycakes@a.com", :url => "http://babycakes.joindiaspora.com/", :profile =>Profile.create( :first_name => "Baby", :last_name => "Cakes") ) -friend_two = Friend.create( :email => "mario@a.com", :url => "http://mario.joindiaspora.com/", :profile => Profile.create( :first_name => "Mario", :last_name => "Cakes") ) -friend_three = Friend.create( :email => "stuff@a.com", :url => "http://stuff.joindiaspora.com/", :profile => Profile.create( :first_name => "Stuff", :last_name => "Cakes") ) +(1..10).each { |n| + Friend.create( :email => "b#{n}@joindiaspora.com", :url => "http://b#{n}.joindiaspora.com/", :profile => Profile.create(:first_name => names[n-1][0], :last_name => names[n-1][1])) +} # Populate feed -StatusMessage.create(:message => "There's a bomb in the lasagna!?", :person => friend_one ) - -Bookmark.create(:title => "xkcd", :link => "http://xkcd.com/743/", :person => friend_two ) - -StatusMessage.create(:message => "I switched to Motoroi today, a Motorola Android-based phone, in Korea. Now, I am using Android phones in both the U.S. and Korea", :person => friend_two ) - -StatusMessage.create(:message => "I had 5 hours to study for it :-( GREs on Thursday. Wunderbar.", :person => friend_two ) - -StatusMessage.create(:message => "Spotted in toy story 3: google maps, OSX, and windows XP. Two out of three isn't bad.", :person => friend_three ) - -Bookmark.create( :title => "Reddit", :link => "http://reddit.com", :person => friend_one ) -Blog.create(:title => "I Love Rock'N'Roll - Joan Jett & The Blackhearts", :body => "

The loudspeakers played this song as we walked into the city pool for the first time this summer. Those loudspeakers make every song sound fresh even if I have heard it a thousand times and their effect on this song was no different. Joan sounded young and strong and ready, and for a moment I forgot where or when I was.

also i can tell it won’t be long and also happy summer imaginary constructs -mumblelard

", :person => friend_one ) - - -StatusMessage.create(:message => "Commercials for IE make me SO MAD and my friends just don't get why.", :person => friend_one ) -Bookmark.create(:title => "Zombo.com", :link => "http://zombo.com", :person => friend_three ) - -StatusMessage.create(:message => "Why do I have \"No More Heroes\" by Westlife on repeat all day?", :person => friend_two ) -StatusMessage.create(:message => "Mmm. Friday night. Acknowledged.", :person => friend_three ) - -StatusMessage.create(:message => "Getting a universal remote is the epitome of laziness, I do declare.", :person => friend_one ) - -StatusMessage.create(:message => "Does anyone know how to merge two Skype contact entries of the same person? (i.e. one Skype ID and one mobile number)", :person => friend_two ) -StatusMessage.create(:message => "A cool, cool morning for once.", :person => friend_one ) +StatusMessage.create(:message => "There's a bomb in the lasagna!?", :person => user) +Bookmark.create(:title => "xkcd", :link => "http://xkcd.com/743/", :person => user ) +StatusMessage.create(:message => "I switched to Motoroi today, a Motorola Android-based phone, in Korea. Now, I am using Android phones in both the U.S. and Korea", :person => user, :created_at => Time.now-930) +StatusMessage.create(:message => "I had 5 hours to study for it :-( GREs on Thursday. Wunderbar.", :person => user, :created_at => Time.now-43990) +StatusMessage.create(:message => "Spotted in toy story 3: google maps, OSX, and windows XP. Two out of three isn't bad.", :person => user, :created_at => Time.now-4390) +Bookmark.create( :title => "Reddit", :link => "http://reddit.com", :person => user, :created_at => Time.now-54390) +Blog.create(:title => "I Love Rock'N'Roll - Joan Jett & The Blackhearts", :body => "

The loudspeakers played this song as we walked into the city pool for the first time this summer. Those loudspeakers make every song sound fresh even if I have heard it a thousand times and their effect on this song was no different. Joan sounded young and strong and ready, and for a moment I forgot where or when I was.

also i can tell it won’t be long and also happy summer imaginary constructs -mumblelard

", :person => user, :created_at => Time.now-3090) +StatusMessage.create(:message => "Commercials for IE make me SO MAD and my friends just don't get why.", :person => user, :created_at => Time.now-30900) +Bookmark.create(:title => "Zombo.com", :link => "http://zombo.com", :person => user, :created_at => Time.now-9090) +StatusMessage.create(:message => "Why do I have \"No More Heroes\" by Westlife on repeat all day?", :person => user, :created_at => Time.now-590000) +StatusMessage.create(:message => "Mmm. Friday night. Acknowledged.", :person => user, :created_at => Time.now-503900) +StatusMessage.create(:message => "Getting a universal remote is the epitome of laziness, I do declare.", :person => user, :created_at => Time.now-4400) +StatusMessage.create(:message => "Does anyone know how to merge two Skype contact entries of the same person? (i.e. one Skype ID and one mobile number)", :person => user, :created_at => Time.now-400240) +StatusMessage.create(:message => "A cool, cool morning for once.", :person => user, :created_at => Time.now-150000) diff --git a/db/seeds/backer.rb b/db/seeds/backer.rb new file mode 100644 index 000000000..9e9a22ec3 --- /dev/null +++ b/db/seeds/backer.rb @@ -0,0 +1,38 @@ +# This file should contain all the record creation needed to seed the database with its default values. +# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). +# +# Examples: +# +# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }]) +# Mayor.create(:name => 'Daley', :city => citie + +require 'config/environment' + + + +def create(backer_number, password) + names = [ ["George", "Washington"], + ["John", "Adams"], + ["Thomas", "Jefferson"], + ["James", "Madison"], + ["James", "Monroe"], + ["John Quincy", "Adams"], + ["Andrew", "Jackson"], + ["Martin Van", "Buren"], + ["William Henry","Harrison"], + ["John", "Tyler"], + ["James K." , "Polk"], + ["Zachary", "Taylor"], + ["Millard", "Fillmore"], + ["Franklin", "Pierce"], + ["James", "Buchanan"], + ["Abraham", "Lincoln"] + ] + + # Create seed user + user = User.create( :email => "b#{backer_number}@joindiaspora.com", :password => "#{password}", :profile => Profile.create( :first_name => names[backer_number][0], :last_name => names[backer_number][1] )) + + # Make friends with Diaspora Tom + Friend.create( :email => "tom@joindiaspora.com", :url => "http://tom.joindiaspora.com/", :profile => Profile.create(:first_name => "Diaspora", :last_name => "Tom")) +end + diff --git a/db/seeds/tom.rb b/db/seeds/tom.rb new file mode 100644 index 000000000..7ed50cd10 --- /dev/null +++ b/db/seeds/tom.rb @@ -0,0 +1,51 @@ +# This file should contain all the record creation needed to seed the database with its default values. +# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). +# +# Examples: +# +# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }]) +# Mayor.create(:name => 'Daley', :city => citie + +require 'config/environment' + +# Create seed user +user = User.create( :email => "tom@joindiaspora.com", :password => "aaaaaa", :profile => Profile.create( :first_name => "Diaspora", :last_name => "Tom" )) + +names = [ ["George", "Washington"], + ["John", "Adams"], + ["Thomas", "Jefferson"], + ["James", "Madison"], + ["James", "Monroe"], + ["John Quincy", "Adams"], + ["Andrew", "Jackson"], + ["Martin Van", "Buren"], + ["William Henry","Harrison"], + ["John", "Tyler"], + ["James K." , "Polk"], + ["Zachary", "Taylor"], + ["Millard", "Fillmore"], + ["Franklin", "Pierce"], + ["James", "Buchanan"], + ["Abraham", "Lincoln"] + ] + +# Make friends +(1..10).each { |n| + Friend.create( :email => "b#{n}@joindiaspora.com", :url => "http://b#{n}.joindiaspora.com/", :profile => Profile.create(:first_name => names[n-1][0], :last_name => names[n-1][1])) +} + +# Populate feed +StatusMessage.create(:message => "There's a bomb in the lasagna!?", :person => user) +Bookmark.create(:title => "xkcd", :link => "http://xkcd.com/743/", :person => user ) +StatusMessage.create(:message => "I switched to Motoroi today, a Motorola Android-based phone, in Korea. Now, I am using Android phones in both the U.S. and Korea", :person => user, :created_at => Time.now-930) +StatusMessage.create(:message => "I had 5 hours to study for it :-( GREs on Thursday. Wunderbar.", :person => user, :created_at => Time.now-43990) +StatusMessage.create(:message => "Spotted in toy story 3: google maps, OSX, and windows XP. Two out of three isn't bad.", :person => user, :created_at => Time.now-4390) +Bookmark.create( :title => "Reddit", :link => "http://reddit.com", :person => user, :created_at => Time.now-54390) +Blog.create(:title => "I Love Rock'N'Roll - Joan Jett & The Blackhearts", :body => "

The loudspeakers played this song as we walked into the city pool for the first time this summer. Those loudspeakers make every song sound fresh even if I have heard it a thousand times and their effect on this song was no different. Joan sounded young and strong and ready, and for a moment I forgot where or when I was.

also i can tell it won’t be long and also happy summer imaginary constructs -mumblelard

", :person => user, :created_at => Time.now-3090) +StatusMessage.create(:message => "Commercials for IE make me SO MAD and my friends just don't get why.", :person => user, :created_at => Time.now-30900) +Bookmark.create(:title => "Zombo.com", :link => "http://zombo.com", :person => user, :created_at => Time.now-9090) +StatusMessage.create(:message => "Why do I have \"No More Heroes\" by Westlife on repeat all day?", :person => user, :created_at => Time.now-590000) +StatusMessage.create(:message => "Mmm. Friday night. Acknowledged.", :person => user, :created_at => Time.now-503900) +StatusMessage.create(:message => "Getting a universal remote is the epitome of laziness, I do declare.", :person => user, :created_at => Time.now-4400) +StatusMessage.create(:message => "Does anyone know how to merge two Skype contact entries of the same person? (i.e. one Skype ID and one mobile number)", :person => user, :created_at => Time.now-400240) +StatusMessage.create(:message => "A cool, cool morning for once.", :person => user, :created_at => Time.now-150000) diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index fdcb9c1d3..6f1a47c2c 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -1,17 +1,22 @@ namespace :db do desc 'Seed the current RAILS_ENV database from db/seeds.rb' - task :seed do - - puts "Seeding the database for #{RAILS_ENV}..." - - require 'db/seeds' + namespace :seed do + task :tom do + puts "Seeding the database for #{Rails.env}..." + require 'db/seeds/tom' + end + task :backer, :num, :password do |t, args| + puts "Seeding the database for #{Rails.env}..." + require 'db/seeds/backer' + create( Integer(args.num), args.password ) + end end desc 'Delete the collections in the current RAILS_ENV database' task :purge do require 'config/environment' - puts "Purging the database for #{RAILS_ENV}..." + puts "Purging the database for #{Rails.env}..." # Specifiy what models to remove Post.delete_all @@ -22,9 +27,9 @@ namespace :db do desc 'Purge and seed the current RAILS_ENV database using information from db/seeds.rb' task :reset do - puts "Resetting the database for #{RAILS_ENV}".upcase + puts "Resetting the database for #{Rails.env}".upcase Rake::Task['db:purge'].invoke - Rake::Task['db:seed'].invoke + Rake::Task['db:seed:tom'].invoke puts "Success!" end end From e696ef7023c1c57225f5686db732e0063e5da38f Mon Sep 17 00:00:00 2001 From: maxwell Date: Wed, 30 Jun 2010 16:24:44 -0700 Subject: [PATCH 3/3] comments now go go go and are tested RS MS --- app/models/comment.rb | 16 +++++++--- lib/common.rb | 10 +++--- spec/lib/common_spec.rb | 7 ++--- spec/{helpers => lib}/parser_spec.rb | 14 --------- spec/models/comments_spec.rb | 46 ++++++++++++++++++++++------ 5 files changed, 57 insertions(+), 36 deletions(-) rename spec/{helpers => lib}/parser_spec.rb (93%) diff --git a/app/models/comment.rb b/app/models/comment.rb index 35f5ace2f..6aa5049ba 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -3,6 +3,7 @@ class Comment include ROXML include Diaspora::Webhooks + xml_accessor :text xml_accessor :person, :as => Person xml_accessor :post_id @@ -17,11 +18,18 @@ class Comment key :person_id, ObjectId belongs_to :person, :class_name => "Person" - + after_save :send_friends_comments_on_my_posts def ==(other) (self.message == other.message) && (self.person.email == other.person.email) end - -end - + + + protected + + def send_friends_comments_on_my_posts + if (User.first.mine?(self.post) && self.person.is_a?(Friend)) + self.push_to(self.post.friends_with_permissions) + end + end +end \ No newline at end of file diff --git a/lib/common.rb b/lib/common.rb index 16d84f2d6..76c2cccc0 100644 --- a/lib/common.rb +++ b/lib/common.rb @@ -69,10 +69,12 @@ module Diaspora def push_to(recipients) - recipients.map!{|x| x = x.url + "receive/"} - xml = self.class.build_xml_for([self]) - @@queue.add_post_request( recipients, xml ) - @@queue.process + unless recipients.empty? + recipients.map!{|x| x = x.url + "receive/"} + xml = self.class.build_xml_for([self]) + @@queue.add_post_request( recipients, xml ) + @@queue.process + end end diff --git a/spec/lib/common_spec.rb b/spec/lib/common_spec.rb index 8a37fc20a..61e7fa3cc 100644 --- a/spec/lib/common_spec.rb +++ b/spec/lib/common_spec.rb @@ -8,6 +8,7 @@ describe Diaspora do describe Webhooks do before do @user = Factory.create(:user, :email => "bob@aol.com") + @friend = Factory.create(:friend) end describe "header" do @@ -53,9 +54,7 @@ describe Diaspora do Factory.create(:friend, :url => "http://www.alice.com/") Factory.create(:friend, :url => "http://www.jane.com/") - @post.friends_with_permissions.should include("http://www.bob.com/receive/") - @post.friends_with_permissions.should include("http://www.alice.com/receive/") - @post.friends_with_permissions.should include("http://www.jane.com/receive/") + @post.friends_with_permissions.should == Friend.all end it "should send an owners post to their friends" do @@ -73,7 +72,7 @@ describe Diaspora do it "should ensure one url is created for every friend" do 5.times {Factory.create(:friend)} - @post.friends_with_permissions.size.should == 5 + @post.friends_with_permissions.size.should == 6 end it "should build an xml object containing multiple Post types" do diff --git a/spec/helpers/parser_spec.rb b/spec/lib/parser_spec.rb similarity index 93% rename from spec/helpers/parser_spec.rb rename to spec/lib/parser_spec.rb index fc9e0e885..a9e3e7e45 100644 --- a/spec/helpers/parser_spec.rb +++ b/spec/lib/parser_spec.rb @@ -103,20 +103,6 @@ describe "parser in application helper" do comment.post.should == post end - - - - it 'should parse a person out of a post' do - @user.comment "foo", :on => @status_messages.first - xml = Comment.build_xml_for([Comment.first]) - puts xml - objs = parse_objects_from_xml(xml) - - puts objs.inspect - - - - end end end diff --git a/spec/models/comments_spec.rb b/spec/models/comments_spec.rb index 00f8c1240..b5ebaf23c 100644 --- a/spec/models/comments_spec.rb +++ b/spec/models/comments_spec.rb @@ -15,21 +15,47 @@ describe Comment do it "should be able to comment on a friend's status" do friend = Factory.create :friend - status = Factory.create(:status_message, :person => @friend) + status = Factory.create(:status_message, :person => friend) @user.comment "sup dog", :on => status StatusMessage.first.comments.first.text.should == "sup dog" StatusMessage.first.comments.first.person.should == @user end - - - it 'should be able to send a post owner any new comments a user adds' do - friend = Factory.create(:friend) - status = Factory.create(:status_message, :person => friend) - - Comment.send(:class_variable_get, :@@queue).should_receive(:add_post_request) - @user.comment "yo", :on => status + it 'should not send out comments when we have no friends' do + status = Factory.create(:status_message, :person => @user) + Comment.send(:class_variable_get, :@@queue).should_not_receive(:add_post_request) + @user.comment "sup dog", :on => status end + describe 'comment propagation' do + before do + @friend = Factory.create(:friend) + @friend_two = Factory.create(:friend) + @friend_status = Factory.create(:status_message, :person => @friend) + @user_status = Factory.create(:status_message, :person => @user) + end + + it "should send a user's comment on a friend's post to that friend" do + Comment.send(:class_variable_get, :@@queue).should_receive(:add_post_request) + @user.comment "yo", :on => @friend_status + end + + it 'should send a user comment on his own post to lots of friends' do + allowed_urls = @user_status.friends_with_permissions.map!{|x| x = x.url + "receive/"} + Comment.send(:class_variable_get, :@@queue).should_receive(:add_post_request).with(allowed_urls, anything ) + @user.comment "yo", :on => @user_status + end + + it 'should send a comment a friend made on your post to all friends' do + Comment.send(:class_variable_get, :@@queue).should_receive(:add_post_request) + com = Comment.create(:person => @friend, :text => "balls", :post => @user_status) + end + + it 'should not send a comment a friend made on a friend post to anyone' do + Comment.send(:class_variable_get, :@@queue).should_not_receive(:add_post_request) + com = Comment.create(:person => @friend, :text => "balls", :post => @friend_status) + end + + end end -end +end \ No newline at end of file