make user/receive spec less repetitive

This commit is contained in:
Raphael 2010-10-19 22:55:11 -07:00
parent 74ec629b01
commit 197bd8eb49

View file

@ -47,96 +47,52 @@ describe User do
end end
describe 'post refs' do describe 'post refs' do
it "should add a received post to the aspect and visible_posts array" do before do
status_message = user.post :status_message, :message => "hi", :to =>aspect.id @status_message = user2.post :status_message, :message => "hi", :to =>aspect2.id
user.receive @status_message.to_diaspora_xml, user2.person
user.reload user.reload
salmon = user.salmon(status_message).xml_for user2.person end
user2.receive_salmon salmon
user2.reload it "should add a received post to the aspect and visible_posts array" do
user2.raw_visible_posts.include?(status_message).should be true user.raw_visible_posts.include?(@status_message).should be true
aspect2.reload aspect.reload
aspect2.posts.include?(status_message).should be_true aspect.posts.include?(@status_message).should be_true
end end
it 'should be removed on unfriending' do it 'should be removed on unfriending' do
status_message = user2.post :status_message, :message => "hi", :to => aspect2.id
user.receive status_message.to_diaspora_xml, user2.person
user.reload
user.raw_visible_posts.count.should == 1
user.unfriend(user2.person) user.unfriend(user2.person)
user.reload user.reload
user.raw_visible_posts.count.should == 0 user.raw_visible_posts.count.should == 0
Post.count.should be 1
end end
it 'should be remove a post if the noone links to it' do it 'should be remove a post if the noone links to it' do
status_message = user2.post :status_message, :message => "hi", :to => aspect2.id
user.receive status_message.to_diaspora_xml, user2.person
user.reload
user.raw_visible_posts.count.should == 1
person = user2.person person = user2.person
user2.delete user2.delete
user.unfriend(person)
lambda {user.unfriend(person)}.should change(Post, :count).by(-1)
user.reload user.reload
user.raw_visible_posts.count.should == 0 user.raw_visible_posts.count.should == 0
Post.count.should be 0
end end
it 'should keep track of user references for one person ' do it 'should keep track of user references for one person ' do
status_message = user2.post :status_message, :message => "hi", :to => aspect2.id @status_message.reload
user.receive status_message.to_diaspora_xml, user2.person @status_message.user_refs.should == 1
user.reload
user.raw_visible_posts.count.should == 1
status_message.reload
status_message.user_refs.should == 1
user.unfriend(user2.person) user.unfriend(user2.person)
status_message.reload @status_message.reload
@status_message.user_refs.should == 0
user.reload
user.raw_visible_posts.count.should == 0
status_message.reload
status_message.user_refs.should == 0
Post.count.should be 1
end end
it 'should not override userrefs on receive by another person' do it 'should not override userrefs on receive by another person' do
user3.activate_friend(user2.person, aspect3) user3.activate_friend(user2.person, aspect3)
user3.receive @status_message.to_diaspora_xml, user2.person
status_message = user2.post :status_message, :message => "hi", :to => aspect2.id @status_message.reload
user.receive status_message.to_diaspora_xml, user2.person @status_message.user_refs.should == 2
user3.receive status_message.to_diaspora_xml, user2.person
user.reload
user3.reload
user.raw_visible_posts.count.should == 1
status_message.reload
status_message.user_refs.should == 2
user.unfriend(user2.person) user.unfriend(user2.person)
status_message.reload @status_message.reload
@status_message.user_refs.should == 1
user.reload
user.raw_visible_posts.count.should == 0
status_message.reload
status_message.user_refs.should == 1
Post.count.should be 1
end end
end end