diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index fad80aad539753f5521f7995b5188ebe00062a30..1d4f974915306601e99b85696f2f410924add63e 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -22,8 +22,8 @@ class StatusMessagesController < ApplicationController aspects = current_user.aspects_from_ids(params[:aspect_ids]) if @status_message.save - current_user.add_to_streams(@status_message, aspects) current_user.dispatch_post(@status_message, :url => post_url(@status_message)) + current_user.add_to_streams(@status_message, aspects) if !photos.empty? @status_message.photos += photos for photo in photos diff --git a/app/models/post.rb b/app/models/post.rb index 9068eb05b6d1bd6d09cc5793701be51231c838af..20d1b4ed6f0fec3fbb467baf6100beaf9174535d 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -37,9 +37,6 @@ class Post < ActiveRecord::Base def self.diaspora_initialize params new_post = self.new params.to_hash new_post.person = params[:person] - params[:aspect_ids].each do |aspect_id| - new_post.aspects << Aspect.find_by_id(aspect_id) - end if params[:aspect_ids] new_post.public = params[:public] if params[:public] new_post.pending = params[:pending] if params[:pending] new_post.diaspora_handle = new_post.person.diaspora_handle diff --git a/db/migrate/20110211001859_unique_post_visibilities.rb b/db/migrate/20110211001859_unique_post_visibilities.rb new file mode 100644 index 0000000000000000000000000000000000000000..f9006b6f2dbabd49aabdd7bcc19b439c2eece072 --- /dev/null +++ b/db/migrate/20110211001859_unique_post_visibilities.rb @@ -0,0 +1,11 @@ +class UniquePostVisibilities < ActiveRecord::Migration + def self.up + remove_index :post_visibilities, [:aspect_id, :post_id] + add_index :post_visibilities, [:aspect_id, :post_id], :unique => true + end + + def self.down + remove_index :post_visibilities, [:aspect_id, :post_id] + add_index :post_visibilities, [:aspect_id, :post_id] + end +end diff --git a/db/schema.rb b/db/schema.rb index c3c50f55ff7b4c2ee1aeef01325cdc7efebf3e40..d0a033c541c1142716217080461b0d02dcb11bfc 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -351,7 +351,7 @@ ActiveRecord::Schema.define(:version => 20110211021926) do t.datetime "updated_at" end - add_index "post_visibilities", ["aspect_id", "post_id"], :name => "index_post_visibilities_on_aspect_id_and_post_id" + add_index "post_visibilities", ["aspect_id", "post_id"], :name => "index_post_visibilities_on_aspect_id_and_post_id", :unique => true add_index "post_visibilities", ["aspect_id"], :name => "index_post_visibilities_on_aspect_id" add_index "post_visibilities", ["post_id"], :name => "index_post_visibilities_on_post_id" diff --git a/spec/intergration/receiving_spec.rb b/spec/intergration/receiving_spec.rb index d28461b27ca3858486d27a903c036ea21439f1fe..559d1b5dd1fa69dd318ae158f7e493124042183a 100644 --- a/spec/intergration/receiving_spec.rb +++ b/spec/intergration/receiving_spec.rb @@ -134,14 +134,14 @@ describe 'a user receives a post' do end it 'should not override userrefs on receive by another person' do - new_user = Factory(:user) + new_user = Factory(:user_with_aspect) @status_message.post_visibilities.reset @status_message.user_refs.should == 3 - new_user.activate_contact(@user2.person, @aspect3) + new_user.activate_contact(@user2.person, new_user.aspects.first) xml = @status_message.to_diaspora_xml - receive_with_zord(new_user, @user2.person, xml) + receive_with_zord(new_user, @user2.person, xml) @status_message.post_visibilities.reset @status_message.user_refs.should == 4 @@ -231,7 +231,7 @@ describe 'a user receives a post' do describe 'receiving mulitple versions of the same post from a remote pod' do - before 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 @@ -243,8 +243,8 @@ describe 'a user receives a post' do 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 + (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