From 11309574cff683824bf2e461add215d0a114d19f Mon Sep 17 00:00:00 2001 From: danielvincent Date: Tue, 1 Mar 2011 12:12:08 -0800 Subject: [PATCH] messages are now relayable, a comment has an author as opposed to a person. --- app/controllers/conversations_controller.rb | 14 ++----- app/helpers/sockets_helper.rb | 2 +- app/models/comment.rb | 8 ++-- app/models/conversation.rb | 20 ++++++---- app/models/message.rb | 6 ++- app/models/post.rb | 7 ++++ app/models/user.rb | 2 +- app/views/comments/_comment.html.haml | 4 +- ...ersations_and_messages_and_visibilities.rb | 1 + .../20110301014507_rename_person_to_author.rb | 13 ++++++ db/schema.rb | 9 +++-- lib/diaspora/relayable.rb | 2 +- lib/diaspora/user/querying.rb | 2 +- lib/fake.rb | 14 +++---- lib/postzord/dispatch.rb | 4 +- spec/controllers/comments_controller_spec.rb | 6 +-- ...nversation_visibilities_controller_spec.rb | 6 +-- .../conversations_controller_spec.rb | 40 ++++++++++--------- spec/factories.rb | 4 +- spec/intergration/receiving_spec.rb | 4 +- .../data_conversion/import_to_mysql_spec.rb | 2 +- spec/lib/diaspora/parser_spec.rb | 2 +- spec/lib/fake_spec.rb | 4 +- spec/lib/postzord/dispatch_spec.rb | 2 +- spec/models/comment_spec.rb | 4 +- spec/models/conversation_spec.rb | 10 +---- spec/models/message_spec.rb | 27 +++++-------- spec/models/person_spec.rb | 4 +- .../relayable.rb} | 1 + 29 files changed, 120 insertions(+), 104 deletions(-) create mode 100644 db/migrate/20110301014507_rename_person_to_author.rb rename spec/{lib/diaspora/relayable_spec.rb => shared_behaviors/relayable.rb} (99%) diff --git a/app/controllers/conversations_controller.rb b/app/controllers/conversations_controller.rb index 72825017a..2718e12f1 100644 --- a/app/controllers/conversations_controller.rb +++ b/app/controllers/conversations_controller.rb @@ -9,20 +9,14 @@ class ConversationsController < ApplicationController end def create - person_ids = Contact.where(:id => params[:conversation][:contact_ids]).map! do |contact| + person_ids = Contact.where(:id => params[:conversation].delete(:contact_ids)).map! do |contact| contact.person_id end - person_ids = person_ids | [current_user.person.id] + params[:conversation][:participant_ids] = person_ids | [current_user.person.id] + params[:conversation][:author] = current_user.person - @conversation = Conversation.new(:subject => params[:conversation][:subject], :participant_ids => person_ids) - - if @conversation.save - @message = Message.new(:text => params[:message][:text], :author => current_user.person, :conversation_id => @conversation.id ) - unless @message.save - @conversation.destroy - end - end + @conversation = Conversation.create(params[:conversation]) respond_with @conversation end diff --git a/app/helpers/sockets_helper.rb b/app/helpers/sockets_helper.rb index 1c6ee13ac..b48f5d9a7 100644 --- a/app/helpers/sockets_helper.rb +++ b/app/helpers/sockets_helper.rb @@ -48,7 +48,7 @@ module SocketsHelper v = render_to_string(:partial => 'people/person', :locals => person_hash) elsif object.is_a? Comment - v = render_to_string(:partial => 'comments/comment', :locals => {:comment => object, :person => object.person}) + v = render_to_string(:partial => 'comments/comment', :locals => {:comment => object, :person => object.author}) elsif object.is_a? Notification v = render_to_string(:partial => 'notifications/popup', :locals => {:note => object, :person => opts[:actor]}) diff --git a/app/models/comment.rb b/app/models/comment.rb index f9e9c2bcb..08ec011e7 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -29,16 +29,16 @@ class Comment < ActiveRecord::Base self.text.strip! unless self.text.nil? end def diaspora_handle - person.diaspora_handle + self.author.diaspora_handle end def diaspora_handle= nh - self.person = Webfinger.new(nh).fetch + self.author = Webfinger.new(nh).fetch end def notification_type(user, person) - if self.post.person == user.person + if self.post.author == user.person return Notifications::CommentOnPost - elsif self.post.comments.where(:person_id => user.person.id) != [] && self.person_id != user.person.id + elsif self.post.comments.where(:author_id => user.person.id) != [] && self.author_id != user.person.id return Notifications::AlsoCommented else return false diff --git a/app/models/conversation.rb b/app/models/conversation.rb index a8741fea1..d21eccd2c 100644 --- a/app/models/conversation.rb +++ b/app/models/conversation.rb @@ -4,16 +4,20 @@ class Conversation < ActiveRecord::Base include Diaspora::Webhooks xml_attr :subject - xml_attr :messages, :as => [Message] xml_attr :created_at + xml_attr :messages, :as => [Message] + xml_reader :diaspora_handle xml_reader :participant_handles has_many :conversation_visibilities has_many :participants, :class_name => 'Person', :through => :conversation_visibilities, :source => :person has_many :messages, :order => 'created_at ASC' + belongs_to :author, :class_name => 'Person' + def self.create(opts={}) - msg_opts = opts.delete(:message) + opts = opts.dup + msg_opts = {:author => opts[:author], :text => opts.delete(:text)} cnv = super(opts) message = Message.new(msg_opts.merge({:conversation_id => cnv.id})) @@ -21,18 +25,20 @@ class Conversation < ActiveRecord::Base cnv end - def author - self.messages.first.author - end - def recipients self.participants - [self.author] end + def diaspora_handle + self.author.diaspora_handle + end + def diaspora_handle= nh + self.author = Webfinger.new(nh).fetch + end + def participant_handles self.participants.map{|p| p.diaspora_handle}.join(";") end - def participant_handles= handles handles.split(';').each do |handle| self.participants << Webfinger.new(handle).fetch diff --git a/app/models/message.rb b/app/models/message.rb index 5d093456d..9ebc262d6 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -13,14 +13,16 @@ class Message < ActiveRecord::Base belongs_to :author, :class_name => 'Person' belongs_to :conversation - after_initialize do + after_create do #sign comment as commenter self.author_signature = self.sign_with_key(self.author.owner.encryption_key) if self.author.owner - if !self.parent.blank? && self.parent.author.person.owns?(self.parent) + if !self.parent.blank? && self.author.owns?(self.parent) #sign comment as post owner self.parent_author_signature = self.sign_with_key( self.parent.author.owner.encryption_key) if self.parent.author.owner end + self.save! + self end def diaspora_handle diff --git a/app/models/post.rb b/app/models/post.rb index 180e444d8..bd044b5ac 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -24,6 +24,13 @@ class Post < ActiveRecord::Base after_destroy :propogate_retraction + def author + self.person + end + def author= author + self.person = author + end + def user_refs self.post_visibilities.count end diff --git a/app/models/user.rb b/app/models/user.rb index 0ef27da51..3b8f58c5e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -133,7 +133,7 @@ class User < ActiveRecord::Base ######## Commenting ######## def build_comment(text, options = {}) - comment = Comment.new(:person_id => self.person.id, + comment = Comment.new(:author_id => self.person.id, :text => text, :post => options[:on]) comment.set_guid diff --git a/app/views/comments/_comment.html.haml b/app/views/comments/_comment.html.haml index 66bb9e906..3d8a56173 100644 --- a/app/views/comments/_comment.html.haml +++ b/app/views/comments/_comment.html.haml @@ -3,10 +3,10 @@ -# the COPYRIGHT file. %li.comment{:data=>{:guid => comment.id}, :class => ("hidden" if(defined? hidden))} - = person_image_link(comment.person) + = person_image_link(comment.author) .content %strong - = person_link(comment.person) + = person_link(comment.author) = markdownify(comment.text, :youtube_maps => comment.youtube_titles) diff --git a/db/migrate/20110225190919_create_conversations_and_messages_and_visibilities.rb b/db/migrate/20110225190919_create_conversations_and_messages_and_visibilities.rb index 397ded1f3..7c3f880d7 100644 --- a/db/migrate/20110225190919_create_conversations_and_messages_and_visibilities.rb +++ b/db/migrate/20110225190919_create_conversations_and_messages_and_visibilities.rb @@ -20,6 +20,7 @@ class CreateConversationsAndMessagesAndVisibilities < ActiveRecord::Migration create_table :conversations do |t| t.string :subject t.string :guid, :null => false + t.integer :author_id, :null => false t.timestamps end diff --git a/db/migrate/20110301014507_rename_person_to_author.rb b/db/migrate/20110301014507_rename_person_to_author.rb new file mode 100644 index 000000000..30bbdadff --- /dev/null +++ b/db/migrate/20110301014507_rename_person_to_author.rb @@ -0,0 +1,13 @@ +class RenamePersonToAuthor < ActiveRecord::Migration + def self.up + remove_foreign_key(:comments, :people) + rename_column :comments, :person_id, :author_id + add_foreign_key(:comments, :people, :column => :author_id, :dependent => :delete) + end + + def self.down + remove_foreign_key(:comments, :people, :column => :author_id) + rename_column :comments, :author_id, :person_id + add_foreign_key(:comments, :people, :dependent => :delete) + end +end diff --git a/db/schema.rb b/db/schema.rb index f5dd1653a..469ad4f92 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20110228233419) do +ActiveRecord::Schema.define(:version => 20110301014507) do create_table "aspect_memberships", :force => true do |t| t.integer "aspect_id", :null => false @@ -41,7 +41,7 @@ ActiveRecord::Schema.define(:version => 20110228233419) do create_table "comments", :force => true do |t| t.text "text", :null => false t.integer "post_id", :null => false - t.integer "person_id", :null => false + t.integer "author_id", :null => false t.string "guid", :null => false t.text "author_signature" t.text "parent_author_signature" @@ -51,9 +51,9 @@ ActiveRecord::Schema.define(:version => 20110228233419) do t.string "mongo_id" end + add_index "comments", ["author_id"], :name => "index_comments_on_person_id" add_index "comments", ["guid"], :name => "index_comments_on_guid", :unique => true add_index "comments", ["mongo_id"], :name => "index_comments_on_mongo_id" - add_index "comments", ["person_id"], :name => "index_comments_on_person_id" add_index "comments", ["post_id"], :name => "index_comments_on_post_id" create_table "contacts", :force => true do |t| @@ -85,6 +85,7 @@ ActiveRecord::Schema.define(:version => 20110228233419) do create_table "conversations", :force => true do |t| t.string "subject" t.string "guid", :null => false + t.integer "author_id", :null => false t.datetime "created_at" t.datetime "updated_at" end @@ -511,7 +512,7 @@ ActiveRecord::Schema.define(:version => 20110228233419) do add_foreign_key "aspect_memberships", "aspects", :name => "aspect_memberships_aspect_id_fk" add_foreign_key "aspect_memberships", "contacts", :name => "aspect_memberships_contact_id_fk", :dependent => :delete - add_foreign_key "comments", "people", :name => "comments_person_id_fk", :dependent => :delete + add_foreign_key "comments", "people", :name => "comments_author_id_fk", :column => "author_id", :dependent => :delete add_foreign_key "comments", "posts", :name => "comments_post_id_fk", :dependent => :delete add_foreign_key "contacts", "people", :name => "contacts_person_id_fk", :dependent => :delete diff --git a/lib/diaspora/relayable.rb b/lib/diaspora/relayable.rb index 6916fc7bf..bbab96963 100644 --- a/lib/diaspora/relayable.rb +++ b/lib/diaspora/relayable.rb @@ -89,7 +89,7 @@ module Diaspora accessors = self.class.roxml_attrs.collect do |definition| definition.accessor end - ['author', 'author_signature', 'parent_author_signature'].each do |acc| + ['author_signature', 'parent_author_signature'].each do |acc| accessors.delete acc end accessors diff --git a/lib/diaspora/user/querying.rb b/lib/diaspora/user/querying.rb index 3a23a31c4..e20245267 100644 --- a/lib/diaspora/user/querying.rb +++ b/lib/diaspora/user/querying.rb @@ -7,7 +7,7 @@ module Diaspora module Querying def find_visible_post_by_id( id ) - self.raw_visible_posts.where(:id => id).includes({:person => :profile}, {:comments => {:person => :profile}}, :photos).first + self.raw_visible_posts.where(:id => id).includes({:person => :profile}, {:comments => {:author => :profile}}, :photos).first end def raw_visible_posts diff --git a/lib/fake.rb b/lib/fake.rb index bb0475cdc..fbf25e66b 100644 --- a/lib/fake.rb +++ b/lib/fake.rb @@ -6,22 +6,22 @@ class PostsFake end def initialize(posts) - person_ids = [] - posts.each do |p| - person_ids << p.person_id + author_ids = [] + posts.each do |p| + author_ids << p.person_id p.comments.each do |c| - person_ids << c.person_id + author_ids << c.author_id end end - people = Person.where(:id => person_ids).includes(:profile) + people = Person.where(:id => author_ids).includes(:profile) @people_hash = {} people.each{|person| @people_hash[person.id] = person} @post_fakes = posts.map do |post| - f = Fake.new(post, self) + f = Fake.new(post, self) f.comments = post.comments.map do |comment| - Fake.new(comment, self) + Fake.new(comment, self) end f end diff --git a/lib/postzord/dispatch.rb b/lib/postzord/dispatch.rb index 244f1bb5d..65369d9e4 100644 --- a/lib/postzord/dispatch.rb +++ b/lib/postzord/dispatch.rb @@ -26,7 +26,7 @@ class Postzord::Dispatch user_ids = [*local_people].map{|x| x.owner_id } local_users = User.where(:id => user_ids) self.notify_users(local_users) - local_users << @sender if @object.person.local? + local_users << @sender if @object.author.local? self.socket_to_users(local_users) else self.deliver_to_local(local_people) @@ -73,7 +73,7 @@ class Postzord::Dispatch def notify_users(users) users.each do |user| - Resque.enqueue(Job::NotifyLocalUsers, user.id, @object.class.to_s, @object.id, @object.person_id) + Resque.enqueue(Job::NotifyLocalUsers, user.id, @object.class.to_s, @object.id, @object.author.id) end end def socket_to_users(users) diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index 80325a028..f003ae71c 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -41,11 +41,11 @@ describe CommentsController do post :create, comment_hash response.code.should == '201' end - it "doesn't overwrite person_id" do + it "doesn't overwrite author_id" do new_user = Factory.create(:user) - comment_hash[:person_id] = new_user.person.id.to_s + comment_hash[:author_id] = new_user.person.id.to_s post :create, comment_hash - Comment.find_by_text(comment_hash[:text]).person_id.should == @user1.person.id + Comment.find_by_text(comment_hash[:text]).author_id.should == @user1.person.id end it "doesn't overwrite id" do old_comment = @user1.comment("hello", :on => @post) diff --git a/spec/controllers/conversation_visibilities_controller_spec.rb b/spec/controllers/conversation_visibilities_controller_spec.rb index c2458ec05..f2002cdd9 100644 --- a/spec/controllers/conversation_visibilities_controller_spec.rb +++ b/spec/controllers/conversation_visibilities_controller_spec.rb @@ -11,9 +11,9 @@ describe ConversationVisibilitiesController do @user1 = alice sign_in :user, @user1 - @create_hash = { :participant_ids => [@user1.contacts.first.person.id, @user1.person.id], - :subject => "cool stuff" } - @conversation = Conversation.create(@create_hash) + hash = { :author => @user1.person, :participant_ids => [@user1.contacts.first.person.id, @user1.person.id], + :subject => 'not spam', :text => 'cool stuff'} + @conversation = Conversation.create(hash) end describe '#destroy' do diff --git a/spec/controllers/conversations_controller_spec.rb b/spec/controllers/conversations_controller_spec.rb index 0dce62b9d..d567d9b62 100644 --- a/spec/controllers/conversations_controller_spec.rb +++ b/spec/controllers/conversations_controller_spec.rb @@ -21,14 +21,12 @@ describe ConversationsController do response.should be_success end - it 'retrieves all messages for a user' do - @conversation_hash = { :participant_ids => [@user1.contacts.first.person.id, @user1.person.id], - :subject => 'not spam' } - @message_hash = {:author => @user1.person, :text => 'cool stuff'} + it 'retrieves all conversations for a user' do + hash = { :author => @user1.person, :participant_ids => [@user1.contacts.first.person.id, @user1.person.id], + :subject => 'not spam', :text => 'cool stuff'} 3.times do - cnv = Conversation.create(@conversation_hash) - Message.create(@message_hash.merge({:conversation_id => cnv.id})) + cnv = Conversation.create(hash) end get :index @@ -38,34 +36,38 @@ describe ConversationsController do describe '#create' do before do - @message_hash = {:conversation => { - :contact_ids => [@user1.contacts.first.id], - :subject => "secret stuff"}, - :message => {:text => "text"} - } + @hash = {:conversation => { + :contact_ids => [@user1.contacts.first.id], + :subject => "secret stuff", + :text => 'text'}} end it 'creates a conversation' do lambda { - post :create, @message_hash + post :create, @hash }.should change(Conversation, :count).by(1) end it 'creates a message' do lambda { - post :create, @message_hash + post :create, @hash }.should change(Message, :count).by(1) end + + it 'sets the author to the current_user' do + pending + @hash[:author] = Factory.create(:user) + post :create, @hash + Message.first.author.should == @user1.person + Conversation.first.author.should == @user1.person + end end describe '#show' do before do - conversation_hash = { :participant_ids => [@user1.contacts.first.person.id, @user1.person.id], - :subject => 'not spam' } - message_hash = {:author => @user1.person, :text => 'cool stuff'} - - @conversation = Conversation.create(conversation_hash) - @message = Message.create(message_hash.merge({:conversation_id => @conversation.id})) + hash = { :author => @user1.person, :participant_ids => [@user1.contacts.first.person.id, @user1.person.id], + :subject => 'not spam', :text => 'cool stuff'} + @conversation = Conversation.create(hash) end it 'succeeds' do diff --git a/spec/factories.rb b/spec/factories.rb index 1e784e761..9c6485da7 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -85,8 +85,8 @@ end Factory.define(:comment) do |comment| comment.sequence(:text) {|n| "#{n} cats"} - comment.association(:person) - comment.association :post, :factory => :status_message + comment.association(:author, :factory => :person) + comment.association(:post, :factory => :status_message) end Factory.define(:notification) do |n| diff --git a/spec/intergration/receiving_spec.rb b/spec/intergration/receiving_spec.rb index 5c0b52b03..703e9707d 100644 --- a/spec/intergration/receiving_spec.rb +++ b/spec/intergration/receiving_spec.rb @@ -197,7 +197,7 @@ describe 'a user receives a post' do post_in_db.comments.should == [] receive_with_zord(@user2, @user1.person, @xml) - post_in_db.comments(true).first.person.should == @user3.person + post_in_db.comments(true).first.author.should == @user3.person end it 'should correctly marshal a stranger for the downstream user' do @@ -225,7 +225,7 @@ describe 'a user receives a post' do receive_with_zord(@user2, @user1.person, @xml) - post_in_db.comments(true).first.person.should == remote_person + post_in_db.comments(true).first.author.should == remote_person end end diff --git a/spec/lib/data_conversion/import_to_mysql_spec.rb b/spec/lib/data_conversion/import_to_mysql_spec.rb index 639ff7efb..8d55ad6a0 100644 --- a/spec/lib/data_conversion/import_to_mysql_spec.rb +++ b/spec/lib/data_conversion/import_to_mysql_spec.rb @@ -412,7 +412,7 @@ describe DataConversion::ImportToMysql do @migrator.process_raw_comments comment = Comment.first comment.post_id.should == Post.where(:mongo_id => "4d2b6ebecc8cb43cc2000029").first.id - comment.person_id.should == Person.where(:mongo_id => "4d2b6eb7cc8cb43cc2000017").first.id + comment.author_id.should == Person.where(:mongo_id => "4d2b6eb7cc8cb43cc2000017").first.id end end describe "notifications" do diff --git a/spec/lib/diaspora/parser_spec.rb b/spec/lib/diaspora/parser_spec.rb index 5645726dc..b680c5b37 100644 --- a/spec/lib/diaspora/parser_spec.rb +++ b/spec/lib/diaspora/parser_spec.rb @@ -20,7 +20,7 @@ describe Diaspora::Parser do describe "parsing compliant XML object" do it 'should be able to correctly parse comment fields' do post = @user1.post :status_message, :message => "hello", :to => @aspect1.id - comment = Factory.create(:comment, :post => post, :person => @person, :diaspora_handle => @person.diaspora_handle, :text => "Freedom!") + comment = Factory.create(:comment, :post => post, :author => @person, :diaspora_handle => @person.diaspora_handle, :text => "Freedom!") comment.delete xml = comment.to_diaspora_xml comment_from_xml = Diaspora::Parser.from_xml(xml) diff --git a/spec/lib/fake_spec.rb b/spec/lib/fake_spec.rb index c8d8c1f98..9ea25519e 100644 --- a/spec/lib/fake_spec.rb +++ b/spec/lib/fake_spec.rb @@ -8,7 +8,7 @@ describe PostsFake do @people << post.person 4.times do comment = Factory(:comment, :post => post) - @people << comment.person + @people << comment.author end @posts << post end @@ -30,7 +30,7 @@ describe PostsFake do end end describe PostsFake::Fake do - include Rails.application.routes.url_helpers + include Rails.application.routes.url_helpers before do @post = mock() @fakes = mock() diff --git a/spec/lib/postzord/dispatch_spec.rb b/spec/lib/postzord/dispatch_spec.rb index 6886311d7..6fa20bccb 100644 --- a/spec/lib/postzord/dispatch_spec.rb +++ b/spec/lib/postzord/dispatch_spec.rb @@ -134,7 +134,7 @@ describe Postzord::Dispatch do end context "remote raphael" do before do - @comment = Factory.build(:comment, :person => @remote_raphael, :post => @post) + @comment = Factory.build(:comment, :author => @remote_raphael, :post => @post) @comment.save @mailman = Postzord::Dispatch.new(@local_luke, @comment) end diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index 895319c30..ee4b66289 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -3,7 +3,7 @@ # the COPYRIGHT file. require 'spec_helper' -require File.join(Rails.root, "spec", "lib", "diaspora", "relayable_spec") +require File.join(Rails.root, "spec", "shared_behaviors", "relayable") describe Comment do before do @@ -80,7 +80,7 @@ describe Comment do @marshalled_comment = Comment.from_xml(@xml) end it 'marshals the author' do - @marshalled_comment.person.should == @commenter.person + @marshalled_comment.author.should == @commenter.person end it 'marshals the post' do @marshalled_comment.post.should == @post diff --git a/spec/models/conversation_spec.rb b/spec/models/conversation_spec.rb index e500d4b85..96ee16a36 100644 --- a/spec/models/conversation_spec.rb +++ b/spec/models/conversation_spec.rb @@ -9,14 +9,8 @@ describe Conversation do @user1 = alice @user2 = bob - @create_hash = { :participant_ids => [@user1.contacts.first.person.id, @user1.person.id], :subject => "cool stuff", - :message => {:author => @user1.person, :text => 'hey'}} -=begin - @message = Message.new(:author => @user1.person, :text => "stuff") - @cnv.messages << @message - @message.save - @xml = @cnv.to_diaspora_xml -=end + @create_hash = { :author => @user1.person, :participant_ids => [@user1.contacts.first.person.id, @user1.person.id], + :subject => "cool stuff", :text => 'hey'} end it 'creates a message on create' do diff --git a/spec/models/message_spec.rb b/spec/models/message_spec.rb index b02b1470c..7c09921fb 100644 --- a/spec/models/message_spec.rb +++ b/spec/models/message_spec.rb @@ -3,34 +3,28 @@ # the COPYRIGHT file. require 'spec_helper' -require File.join(Rails.root, "spec", "lib", "diaspora", "relayable_spec") +require File.join(Rails.root, "spec", "shared_behaviors", "relayable") describe Message do before do @user1 = alice @user2 = bob - @create_hash = { :participant_ids => [@user1.contacts.first.person.id, @user1.person.id], :subject => "cool stuff", - :message => {:author => @user1.person, :text => "stuff"} } + @create_hash = { :author => @user1.person, :participant_ids => [@user1.contacts.first.person.id, @user1.person.id], + :subject => "cool stuff", :text => "stuff"} + @cnv = Conversation.create(@create_hash) @message = @cnv.messages.first @xml = @message.to_diaspora_xml end - describe '#after_initialize' do - before do - @create_hash = { :participant_ids => [@user1.contacts.first.person.id, @user1.person.id], :subject => "cool stuff"} - - @cnv = Conversation.new(@create_hash) - @cnv.save - @msg = Message.new(:text => "21312", :conversation => @cnv) - end + describe '#before_create' do it 'signs the message' do - @msg.author_signature.should_not be_blank + @message.author_signature.should_not be_blank end it 'signs the message author if author of conversation' do - @msg.parent_author_signature.should_not be_blank + @message.parent_author_signature.should_not be_blank end end @@ -46,6 +40,7 @@ describe Message do it 'serializes the created_at time' do @xml.should include(@message.created_at.to_s) end + it 'serializes the conversation_guid time' do @xml.should include(@message.conversation.guid) end @@ -55,12 +50,12 @@ describe Message do before do @local_luke, @local_leia, @remote_raphael = set_up_friends - cnv_hash = {:subject => 'cool story, bro', :participant_ids => [@local_luke.person, @local_leia.person, @remote_raphael].map(&:id), - :message => {:author => @remote_raphael, :text => 'hey'}} + cnv_hash = {:author => @remote_raphael, :participant_ids => [@local_luke.person, @local_leia.person, @remote_raphael].map(&:id), + :subject => 'cool story, bro', :text => 'hey'} @remote_parent = Conversation.create(cnv_hash.dup) - cnv_hash[:message][:author] = @local_luke.person + cnv_hash[:author] = @local_luke.person @local_parent = Conversation.create(cnv_hash) msg_hash = {:author => @local_luke.person, :text => 'yo', :conversation => @local_parent} diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index 0d799e207..ab1778f0c 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -154,8 +154,8 @@ describe Person do end it "deletes a person's comments on person deletion" do - Factory.create(:comment, :person_id => @deleter.id, :diaspora_handle => @deleter.diaspora_handle, :text => "i love you", :post => @other_status) - Factory.create(:comment, :person_id => @person.id,:diaspora_handle => @person.diaspora_handle, :text => "you are creepy", :post => @other_status) + Factory.create(:comment, :author_id => @deleter.id, :diaspora_handle => @deleter.diaspora_handle, :text => "i love you", :post => @other_status) + Factory.create(:comment, :author_id => @person.id,:diaspora_handle => @person.diaspora_handle, :text => "you are creepy", :post => @other_status) lambda {@deleter.destroy}.should change(Comment, :count).by(-1) end diff --git a/spec/lib/diaspora/relayable_spec.rb b/spec/shared_behaviors/relayable.rb similarity index 99% rename from spec/lib/diaspora/relayable_spec.rb rename to spec/shared_behaviors/relayable.rb index 0f3d99f25..b24a3a507 100644 --- a/spec/lib/diaspora/relayable_spec.rb +++ b/spec/shared_behaviors/relayable.rb @@ -61,6 +61,7 @@ describe Diaspora::Relayable do end it 'sockets to the user' do + pending @object_by_recipient.should_receive(:socket_to_user).exactly(3).times @object_by_recipient.receive(@local_luke, @local_leia.person) end