From a7d36615e68ce54b6e6a8da8bc177cd57031525b Mon Sep 17 00:00:00 2001 From: maxwell Date: Wed, 15 Dec 2010 12:11:37 -0800 Subject: [PATCH] adding basic notification class --- app/models/notification.rb | 18 ++++++++++++++++++ dump.rdb | Bin 0 -> 66 bytes spec/models/notfication_spec.rb | 5 +++++ spec/models/notification.rb | 3 +++ spec/models/notification_spec.rb | 29 +++++++++++++++++++++++++++++ spec/models/user/receive_spec.rb | 13 ++++++++++--- 6 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 app/models/notification.rb create mode 100644 dump.rdb create mode 100644 spec/models/notfication_spec.rb create mode 100644 spec/models/notification.rb create mode 100644 spec/models/notification_spec.rb diff --git a/app/models/notification.rb b/app/models/notification.rb new file mode 100644 index 000000000..dd71884e5 --- /dev/null +++ b/app/models/notification.rb @@ -0,0 +1,18 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. +# +class Notification + include MongoMapper::Document + + + key :object_id, ObjectId + key :kind, String + + belongs_to :user + belongs_to :person + + timestamps! + + attr_accessible :object_id, :kind, :user, :person +end diff --git a/dump.rdb b/dump.rdb new file mode 100644 index 0000000000000000000000000000000000000000..04bb32a05ad042c1f519b5c6eb609097e1f696dd GIT binary patch literal 66 zcmWG?b@2=~FfcIu$G{+3lv-R^nrc;Cl2~F@P?VpXT3no(a)6167b*diEKMzDV#!U+ P%waD|O-{`$OZ^W3>y8(r literal 0 HcmV?d00001 diff --git a/spec/models/notfication_spec.rb b/spec/models/notfication_spec.rb new file mode 100644 index 000000000..f2f6d240f --- /dev/null +++ b/spec/models/notfication_spec.rb @@ -0,0 +1,5 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +require 'spec_helper' diff --git a/spec/models/notification.rb b/spec/models/notification.rb new file mode 100644 index 000000000..b0ae52638 --- /dev/null +++ b/spec/models/notification.rb @@ -0,0 +1,3 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb new file mode 100644 index 000000000..d74333965 --- /dev/null +++ b/spec/models/notification_spec.rb @@ -0,0 +1,29 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +require 'spec_helper' + + +describe Notification do + before do + @sm = Factory(:status_message) + @person = Factory(:person) + @user = make_user + @note = Notification.new(:object_id => @sm.id, :kind => @sm.class.name, :person => @person, :user => @user) + puts @note.inspect + end + + it 'contains a type' do + @note.kind.should == StatusMessage.name + end + + it 'contains a object_id' do + @note.object_id.should == @sm.id + end + + it 'contains a person_id' do + @note.person.id == @person.id + end +end + diff --git a/spec/models/user/receive_spec.rb b/spec/models/user/receive_spec.rb index b76c3b28f..50b7dba70 100644 --- a/spec/models/user/receive_spec.rb +++ b/spec/models/user/receive_spec.rb @@ -58,14 +58,22 @@ describe User do end end - context 'update posts' do + describe '#receive_object' do + it 'adds a notification for an object' do + Notification.should_receive(:new) + user = make_user + user.receive_object(Factory(:status_message), Factory(:person)) + user.should_receive(:receive_post).and_return(true) + + end + end + context 'update posts' do it 'does not update posts not marked as mutable' do status = user.post :status_message, :message => "store this!", :to => aspect.id status.message = 'foo' xml = status.to_diaspora_xml user2.receive(xml, user.person) - status.reload.message.should == 'store this!' end @@ -76,7 +84,6 @@ describe User do user2.reload.receive(xml, user.person) photo.reload.caption.should match(/foo/) end - end describe 'post refs' do