First pass at removing order dependencies so specs will be reliable on postgres and mysql

This commit is contained in:
Sarah Mei 2011-09-05 17:51:45 -07:00
parent 0ec4d44cb4
commit f06b8c7a58
5 changed files with 63 additions and 49 deletions

View file

@ -6,18 +6,19 @@ require 'spec_helper'
describe User do describe User do
it 'should have a key' do describe "private key" do
alice.encryption_key.should_not be nil it 'has a key' do
end alice.encryption_key.should_not be nil
end
it 'the key should marshall to and from the db correctly' do it 'marshalls the key to and from the db correctly' do
user = User.build(:username => 'max', :email => 'foo@bar.com', :password => 'password', :password_confirmation => 'password') user = User.build(:username => 'max', :email => 'foo@bar.com', :password => 'password', :password_confirmation => 'password')
user.save! user.save!
expect{
user.reload.encryption_key
}.should_not raise_error
expect{
user.reload.encryption_key
}.should_not raise_error
end
end end
context 'callbacks' do context 'callbacks' do
@ -395,16 +396,16 @@ describe User do
it 'unsets disable mail and makes the right amount of prefs' do it 'unsets disable mail and makes the right amount of prefs' do
alice.disable_mail = true alice.disable_mail = true
proc { expect {
alice.update_user_preferences({}) alice.update_user_preferences({})
}.should change(alice.user_preferences, :count).by(@pref_count) }.to change(alice.user_preferences, :count).by(@pref_count)
end end
it 'still sets new prefs to false on update' do it 'still sets new prefs to false on update' do
alice.disable_mail = true alice.disable_mail = true
proc { expect {
alice.update_user_preferences({'mentioned' => false}) alice.update_user_preferences({'mentioned' => false})
}.should change(alice.user_preferences, :count).by(@pref_count-1) }.to change(alice.user_preferences, :count).by(@pref_count-1)
alice.reload.disable_mail.should be_false alice.reload.disable_mail.should be_false
end end
end end
@ -593,7 +594,7 @@ describe User do
message = alice.post(:status_message, :text => "hi", :to => alice.aspects.first.id) message = alice.post(:status_message, :text => "hi", :to => alice.aspects.first.id)
alice.reload alice.reload
alice.remove_person alice.remove_person
proc { message.reload }.should raise_error ActiveRecord::RecordNotFound expect { message.reload }.to raise_error ActiveRecord::RecordNotFound
end end
end end
@ -604,7 +605,7 @@ describe User do
mention = Mention.create(:person => person, :post=> sm) mention = Mention.create(:person => person, :post=> sm)
alice.reload alice.reload
alice.remove_mentions alice.remove_mentions
proc { mention.reload }.should raise_error ActiveRecord::RecordNotFound expect { mention.reload }.to raise_error ActiveRecord::RecordNotFound
end end
end end
@ -677,45 +678,46 @@ describe User do
context "aspect management" do context "aspect management" do
before do before do
@contact = alice.contact_for(bob.person) @contact = alice.contact_for(bob.person)
@aspect1 = alice.aspects.create(:name => 'two') @original_aspect = alice.aspects.where(:name => "generic").first
@new_aspect = alice.aspects.create(:name => 'two')
end end
describe "#add_contact_to_aspect" do describe "#add_contact_to_aspect" do
it 'adds the contact to the aspect' do it 'adds the contact to the aspect' do
lambda { lambda {
alice.add_contact_to_aspect(@contact, @aspect1) alice.add_contact_to_aspect(@contact, @new_aspect)
}.should change(@aspect1.contacts, :count).by(1) }.should change(@new_aspect.contacts, :count).by(1)
end end
it 'returns true if they are already in the aspect' do it 'returns true if they are already in the aspect' do
alice.add_contact_to_aspect(@contact, alice.aspects.first).should be_true alice.add_contact_to_aspect(@contact, @original_aspect).should be_true
end end
end end
context 'moving and removing posts' do context 'moving and removing posts' do
describe 'User#move_contact' do describe 'User#move_contact' do
it 'should be able to move a contact from one of users existing aspects to another' do it 'should be able to move a contact from one of users existing aspects to another' do
alice.move_contact(bob.person, @aspect1, alice.aspects.first) alice.move_contact(bob.person, @new_aspect, @original_aspect)
alice.aspects.first.contacts(true).include?(@contact).should be_false @original_aspect.contacts(true).include?(@contact).should be_false
@aspect1.contacts(true).include?(@contact).should be_true @new_aspect.contacts(true).include?(@contact).should be_true
end end
it "should not move a person who is not a contact" do it "should not move a person who is not a contact" do
non_contact = eve.person non_contact = eve.person
proc{ expect {
alice.move_contact(non_contact, @aspect1, alice.aspects.first) alice.move_contact(non_contact, @new_aspect, @original_aspect)
}.should raise_error }.to raise_error
alice.aspects.first.contacts.where(:person_id => non_contact.id).should be_empty @original_aspect.contacts.where(:person_id => non_contact.id).should be_empty
@aspect1.contacts.where(:person_id => non_contact.id).should be_empty @new_aspect.contacts.where(:person_id => non_contact.id).should be_empty
end end
it 'does not try to delete if add person did not go through' do it 'does not try to delete if add person did not go through' do
alice.should_receive(:add_contact_to_aspect).and_return(false) alice.should_receive(:add_contact_to_aspect).and_return(false)
alice.should_not_receive(:delete_person_from_aspect) alice.should_not_receive(:delete_person_from_aspect)
alice.move_contact(bob.person, @aspect1, alice.aspects.first) alice.move_contact(bob.person, @new_aspect, @original_aspect)
end end
end end
end end
@ -723,8 +725,10 @@ describe User do
context 'likes' do context 'likes' do
before do before do
@message = alice.post(:status_message, :text => "cool", :to => alice.aspects.first) alices_aspect = alice.aspects.where(:name => "generic").first
@message2 = bob.post(:status_message, :text => "uncool", :to => bob.aspects.first) bobs_aspect = bob.aspects.where(:name => "generic").first
@message = alice.post(:status_message, :text => "cool", :to => alices_aspect)
@message2 = bob.post(:status_message, :text => "uncool", :to => bobs_aspect)
@like = alice.like(true, :target => @message) @like = alice.like(true, :target => @message)
@like2 = bob.like(true, :target => @message) @like2 = bob.like(true, :target => @message)
end end
@ -890,14 +894,16 @@ describe User do
@invitation = Factory.create(:invitation, :sender => eve, :identifier => 'invitee@example.org', :aspect => eve.aspects.first) @invitation = Factory.create(:invitation, :sender => eve, :identifier => 'invitee@example.org', :aspect => eve.aspects.first)
end end
@invitation.reload @invitation.reload
@form_params = {:invitation_token => "abc", @form_params = {
:email => "a@a.com", :invitation_token => "abc",
:username => "user", :email => "a@a.com",
:password => "secret", :username => "user",
:password_confirmation => "secret", :password => "secret",
:person => {:profile => {:first_name => "Bob", :password_confirmation => "secret",
:last_name => "Smith"}}} :person => {
:profile => {:first_name => "Bob", :last_name => "Smith"}
}
}
end end
context 'after invitation acceptance' do context 'after invitation acceptance' do
@ -933,7 +939,6 @@ describe User do
describe '#retract' do describe '#retract' do
before do before do
@retraction = mock @retraction = mock
@post = Factory(:status_message, :author => bob.person, :public => true) @post = Factory(:status_message, :author => bob.person, :public => true)
end end

View file

@ -25,9 +25,10 @@ unless Server.all.empty?
Server[1].in_scope do Server[1].in_scope do
recipient = Factory.create(:user_with_aspect, :username => "recipient") recipient = Factory.create(:user_with_aspect, :username => "recipient")
recipients_aspect = recipient.aspects.where(:name => "generic").first
person = Webfinger.new("poster@localhost:#{Server[0].port}").fetch person = Webfinger.new("poster@localhost:#{Server[0].port}").fetch
person.save! person.save!
recipient.share_with(person, recipient.aspects.first) recipient.share_with(person, recipients_aspect)
end end
end end
@ -48,8 +49,9 @@ unless Server.all.empty?
it 'sends public posts to remote friends' do it 'sends public posts to remote friends' do
Server[0].in_scope do Server[0].in_scope do
poster = User.find_by_username("poster") poster = User.find_by_username("poster")
posters_aspect = poster.aspects.where(:name => "generic").first
person = Person.find_by_diaspora_handle("recipient@localhost:#{Server[1].port}") person = Person.find_by_diaspora_handle("recipient@localhost:#{Server[1].port}")
poster.share_with(person, poster.aspects.first) poster.share_with(person, posters_aspect)
@post = poster. @post = poster.
post(:status_message, post(:status_message,
:public => true, :public => true,

View file

@ -39,13 +39,15 @@ unless Server.all.empty?
Server[0].in_scope do Server[0].in_scope do
r = User.find_by_username("resharer") r = User.find_by_username("resharer")
rs_aspect = r.aspects.where(:name => "generic").first
person = Webfinger.new("recipient@localhost:#{Server[1].port}").fetch person = Webfinger.new("recipient@localhost:#{Server[1].port}").fetch
r.share_with(person, r.aspects.first) r.share_with(person, rs_aspect)
end end
Server[1].in_scope do Server[1].in_scope do
r = User.find_by_username("recipient") r = User.find_by_username("recipient")
rs_aspect = r.aspects.where(:name => "generic").first
person = Webfinger.new("resharer@localhost:#{Server[0].port}").fetch person = Webfinger.new("resharer@localhost:#{Server[0].port}").fetch
r.share_with(person, r.aspects.first) r.share_with(person, rs_aspect)
end end
Server[0].in_scope do Server[0].in_scope do

View file

@ -20,15 +20,19 @@ FixtureBuilder.configure do |fbuilder|
connect_users(bob, bobs_aspect, alice, alices_aspect) connect_users(bob, bobs_aspect, alice, alices_aspect)
connect_users(bob, bobs_aspect, eve, eves_aspect) connect_users(bob, bobs_aspect, eve, eves_aspect)
# Set up friends - 2 local, 1 remote
# Set up friends
local_luke = Factory(:user_with_aspect, :username => "luke") local_luke = Factory(:user_with_aspect, :username => "luke")
lukes_aspect = local_luke.aspects.where(:name => "generic").first
local_leia = Factory(:user_with_aspect, :username => "leia") local_leia = Factory(:user_with_aspect, :username => "leia")
leias_aspect = local_leia.aspects.where(:name => "generic").first
remote_raphael = Factory(:person, :diaspora_handle => "raphael@remote.net") remote_raphael = Factory(:person, :diaspora_handle => "raphael@remote.net")
connect_users_with_aspects(local_luke, local_leia) connect_users_with_aspects(local_luke, local_leia)
local_leia.contacts.create(:person => remote_raphael, :aspects => [local_leia.aspects.first]) local_leia.contacts.create(:person => remote_raphael, :aspects => [leias_aspect])
local_luke.contacts.create(:person => remote_raphael, :aspects => [local_luke.aspects.first]) local_luke.contacts.create(:person => remote_raphael, :aspects => [lukes_aspect])
end end
end end

View file

@ -53,7 +53,8 @@ class User
end end
def post_at_time(time) def post_at_time(time)
p = self.post(:status_message, :text => 'hi', :to => self.aspects.first) to_aspect = self.aspects.length == 1 ? self.aspects.first : self.aspects.where(:name => "generic")
p = self.post(:status_message, :text => 'hi', :to => to_aspect)
p.created_at = time p.created_at = time
p.save! p.save!
end end