From a649d18cd753eaeaef643e1b911d8400f5a5cc0a Mon Sep 17 00:00:00 2001 From: maxwell Date: Tue, 8 Feb 2011 14:07:25 -0800 Subject: [PATCH] add tests to see if timestamps are updated on recevie...they are not --- app/models/post.rb | 5 ++--- spec/intergration/receiving_spec.rb | 31 ++++++++++++++++++++++++++++- spec/lib/postzord/dispatch_spec.rb | 8 ++------ spec/spec_helper.rb | 12 +++++++++++ 4 files changed, 46 insertions(+), 10 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index 66bb866fe..df2834370 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -65,7 +65,6 @@ class Post < ActiveRecord::Base def receive(user, person) #exists locally, but you dont know about it #does not exsist locally, and you dont know about it - #exists_locally? #you know about it, and it is mutable #you know about it, and it is not mutable @@ -82,13 +81,13 @@ class Post < ActiveRecord::Base else user.add_post_to_aspects(local_post) Rails.logger.info("event=receive payload_type=#{self.class} update=true status=complete sender=#{self.diaspora_handle} existing_post=#{local_post.id}") - local_post + return local_post end elsif !local_post self.save user.add_post_to_aspects(self) Rails.logger.info("event=receive payload_type=#{self.class} update=false status=complete sender=#{self.diaspora_handle}") - self + return self else Rails.logger.info("event=receive payload_type=#{self.class} update=true status=abort sender=#{self.diaspora_handle} reason='update not from post owner' existing_post=#{self.id}") end diff --git a/spec/intergration/receiving_spec.rb b/spec/intergration/receiving_spec.rb index f08e85b0c..d4fa78a7e 100644 --- a/spec/intergration/receiving_spec.rb +++ b/spec/intergration/receiving_spec.rb @@ -20,7 +20,6 @@ describe 'a user receives a post' do @user3 = eve @aspect3 = @user3.aspects.first - end it 'streams only one message to the everyone aspect when a multi-aspected contacts posts' do @@ -230,6 +229,36 @@ describe 'a user receives a post' do end end + + describe 'receiving mulitple versions of the same post from a remote pod' do + before do + @local_luke, @local_leia, @remote_raphael = set_up_friends + @post = Factory.build(:status_message, :message => 'hey', :guid => 12313123, :person => @remote_raphael, :created_at => 5.days.ago, :updated_at => 5.days.ago) + end + + it 'does not update created_at or updated_at when two people save the same post' do + @post = Factory.build(:status_message, :message => 'hey', :guid => 12313123, :person => @remote_raphael, :created_at => 5.days.ago, :updated_at => 5.days.ago) + xml = @post.to_diaspora_xml + receive_with_zord(@local_luke, @remote_raphael, xml) + sleep(2) + old_time = Time.now + receive_with_zord(@local_leia, @remote_raphael, xml) + (Post.find_by_guid @post.guid).updated_at.should be < old_time + (Post.find_by_guid @post.guid).created_at.should be < old_time + end + + it 'does not update the post if a new one is sent with a new created_at' do + @post = Factory.build(:status_message, :message => 'hey', :guid => 12313123, :person => @remote_raphael, :created_at => 5.days.ago) + old_time = @post.created_at + xml = @post.to_diaspora_xml + receive_with_zord(@local_luke, @remote_raphael, xml) + @post = Factory.build(:status_message, :message => 'hey', :guid => 12313123, :person => @remote_raphael, :created_at => 2.days.ago) + receive_with_zord(@local_luke, @remote_raphael, xml) + (Post.find_by_guid @post.guid).created_at.day.should == old_time.day + end + end + + describe 'salmon' do let(:post){@user1.post :status_message, :message => "hello", :to => @aspect.id} let(:salmon){@user1.salmon( post )} diff --git a/spec/lib/postzord/dispatch_spec.rb b/spec/lib/postzord/dispatch_spec.rb index a85f9f134..fab082890 100644 --- a/spec/lib/postzord/dispatch_spec.rb +++ b/spec/lib/postzord/dispatch_spec.rb @@ -76,13 +76,9 @@ describe Postzord::Dispatch do context "comments" do before do - @local_luke = Factory(:user_with_aspect, :username => "luke") - @local_leia = Factory(:user_with_aspect, :username => "leia") - @remote_raphael = Factory(:person, :diaspora_handle => "raphael@remote.net") - connect_users_with_aspects(@local_luke, @local_leia) - @local_leia.activate_contact(@remote_raphael, @local_leia.aspects.first) - @local_luke.activate_contact(@remote_raphael, @local_luke.aspects.first) + @local_luke, @local_leia, @remote_raphael = set_up_friends end + 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) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2eb3c978b..f2a30b80e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -34,6 +34,18 @@ RSpec.configure do |config| end end +def set_up_friends + local_luke = Factory(:user_with_aspect, :username => "luke") + local_leia = Factory(:user_with_aspect, :username => "leia") + remote_raphael = Factory(:person, :diaspora_handle => "raphael@remote.net") + connect_users_with_aspects(local_luke, local_leia) + local_leia.activate_contact(remote_raphael, local_leia.aspects.first) + local_luke.activate_contact(remote_raphael, local_luke.aspects.first) + + [local_luke, local_leia, remote_raphael] +end + + def alice #users(:alice) User.where(:username => 'alice').first