diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index c67e55f8a..edc5b20ee 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -77,64 +77,38 @@ describe Person do person_two.owns?(person_message).should be false end - it 'should delete all of user posts except comments upon user deletion' do + it "deletes all of a person's posts upon person deletion" do person = Factory.create(:person) - Factory.create(:status_message, :person => person) - Factory.create(:status_message, :person => person) - Factory.create(:status_message, :person => person) - Factory.create(:status_message, :person => person) + status = Factory.create(:status_message, :person => person) + Factory.create(:status_message, :person => @person) + + lambda {person.destroy}.should change(Post, :count).by(-1) + end + + it "does not delete a person's comments on person deletion" do + person = Factory.create(:person) status_message = Factory.create(:status_message, :person => @person) - Factory.create(:comment, :person_id => person.id, :text => "yes i do", :post => status_message) Factory.create(:comment, :person_id => person.id, :text => "i love you", :post => status_message) - Factory.create(:comment, :person_id => person.id, :text => "hello", :post => status_message) Factory.create(:comment, :person_id => @person.id, :text => "you are creepy", :post => status_message) - - person.destroy - - Post.count.should == 1 - Comment.all.count.should == 4 - status_message.comments.count.should == 4 + + lambda {person.destroy}.should_not change(Comment, :count) end describe "unfriending" do it 'should not delete an orphaned friend' do - request = @user.send_friend_request_to @person, @aspect - @user.activate_friend(@person, @aspect) - @user.reload - Person.all.count.should == 3 - @user.friends.count.should == 1 - @user.unfriend(@person) - @user.reload - @user.friends.count.should == 0 - Person.all.count.should == 3 + lambda {@user.unfriend(@person)}.should_not change(Person, :count) end it 'should not delete an un-orphaned friend' do - request = @user.send_friend_request_to @person, @aspect - request2 = @user2.send_friend_request_to @person, @aspect2 - @user.activate_friend(@person, @aspect) @user2.activate_friend(@person, @aspect2) - @user.reload - @user2.reload - - Person.all.count.should == 3 - @user.friends.count.should == 1 - @user2.friends.count.should == 1 - - @user.unfriend(@person) - @user.reload - @user2.reload - @user.friends.count.should == 0 - @user2.friends.count.should == 1 - - Person.all.count.should == 3 + lambda {@user.unfriend(@person)}.should_not change(Person, :count) end end diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index bc445af99..4c3daf4b6 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -6,8 +6,7 @@ require 'spec_helper' describe Post do before do - @user = Factory.create(:user, :email => "bob@aol.com") - @user.person.save + @user = Factory.create(:user) end describe 'xml' do diff --git a/spec/models/status_message_spec.rb b/spec/models/status_message_spec.rb index 2d8d0c5bf..8449b964c 100644 --- a/spec/models/status_message_spec.rb +++ b/spec/models/status_message_spec.rb @@ -6,7 +6,7 @@ require 'spec_helper' describe StatusMessage do before do - @user = Factory.create(:user, :email => "bob@aol.com") + @user = Factory.create(:user) @aspect = @user.aspect(:name => "losers") end diff --git a/spec/models/user/receive_spec.rb b/spec/models/user/receive_spec.rb index 779919587..c8e4891de 100644 --- a/spec/models/user/receive_spec.rb +++ b/spec/models/user/receive_spec.rb @@ -22,16 +22,13 @@ describe User do it 'should be able to parse and store a status message from xml' do status_message = user2.post :status_message, :message => 'store this!', :to => aspect2.id - person = user2.person xml = status_message.to_diaspora_xml user2.destroy status_message.destroy - StatusMessage.all.size.should == 0 - user.receive xml , user2.person - Post.all(:person_id => person.id).first.message.should == 'store this!' - StatusMessage.all.size.should == 1 + user + lambda {user.receive xml , user2.person}.should change (Post,:count).by(1) end it 'should not create new aspects on message receive' do