From 31584eed844d6d2ae77b7e811bd640581e413ad0 Mon Sep 17 00:00:00 2001 From: Raphael Sofaer Date: Thu, 18 Aug 2011 13:41:27 -0700 Subject: [PATCH 1/2] It turns out find_for_database_authentication calls find_for_authentication, not the other way around. --- spec/models/user_spec.rb | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 283470736..a3e898d38 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -39,7 +39,7 @@ describe User do addr = '12345@alice.com' alice.invitation_service = 'email' alice.invitation_identifier = addr - + lambda { alice.infer_email_from_invitation_provider }.should change(alice, :email) @@ -49,7 +49,7 @@ describe User do addr = '1233123' alice.invitation_service = 'facebook' alice.invitation_identifier = addr - + lambda { alice.infer_email_from_invitation_provider }.should_not change(alice, :email) @@ -359,7 +359,7 @@ describe User do context 'not on server (not yet invited)' do it 'returns nil' do @recipient = nil - @identifier = 'foo@bar.com' + @identifier = 'foo@bar.com' @type = 'email' invited_user.should be_nil end @@ -368,14 +368,14 @@ describe User do end describe '.find_or_create_by_invitation' do - + end describe '.create_from_invitation!' do before do @identifier = 'max@foobar.com' @inv = Factory.build(:invitation, :admin => true, :service => 'email', :identifier => @identifier) - @user = User.create_from_invitation!(@inv) + @user = User.create_from_invitation!(@inv) end it 'creates a persisted user' do @@ -409,18 +409,22 @@ describe User do end end - describe ".find_for_authentication" do + describe ".find_for_database_authentication" do it 'finds a user' do - User.find_for_authentication(:username => alice.username).should == alice + User.find_for_database_authentication(:username => alice.username).should == alice + end + + it 'finds a user by email' do + User.find_for_database_authentication(:username => alice.email).should == alice end it "does not preserve case" do - User.find_for_authentication(:username => alice.username.upcase).should == alice + User.find_for_database_authentication(:username => alice.username.upcase).should == alice end it 'errors out when passed a non-hash' do lambda { - User.find_for_authentication(alice.username) + User.find_for_database_authentication(alice.username) }.should raise_error end end @@ -892,7 +896,7 @@ describe User do :password => "secret", :password_confirmation => "secret", :person => {:profile => {:first_name => "Bob", - :last_name => "Smith"}}} + :last_name => "Smith"}}} end From 60e9fd54e2fadb78cec7410ccc208f317b6b35a5 Mon Sep 17 00:00:00 2001 From: Raphael Sofaer Date: Thu, 18 Aug 2011 16:04:55 -0700 Subject: [PATCH 2/2] Fix a problem with re-saving deleted objects in a spec in postgres, add postgres to test group in gemfile --- Gemfile | 2 ++ Gemfile.lock | 2 ++ spec/integration/receiving_spec.rb | 25 +++++++++++-------------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Gemfile b/Gemfile index baed1cd43..137303975 100644 --- a/Gemfile +++ b/Gemfile @@ -101,6 +101,8 @@ group :test, :development do end group :test do + gem 'mysql2', '0.2.6' + gem 'pg' gem 'factory_girl_rails' gem 'fixture_builder', '0.2.2' gem 'selenium-webdriver', '2.4' diff --git a/Gemfile.lock b/Gemfile.lock index 1e8a31b37..091cdf07d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -319,6 +319,7 @@ GEM oa-openid (= 0.2.6) open4 (1.1.0) orm_adapter (0.0.5) + pg (0.11.0) polyglot (0.3.2) pyu-ruby-sasl (0.0.3.3) rack (1.2.3) @@ -498,6 +499,7 @@ DEPENDENCIES oauth2-provider (= 0.0.16) ohai (= 0.5.8) omniauth (= 0.2.6) + pg rails (= 3.0.9) rails-i18n rcov diff --git a/spec/integration/receiving_spec.rb b/spec/integration/receiving_spec.rb index 4e6d9315d..a4dc06eee 100644 --- a/spec/integration/receiving_spec.rb +++ b/spec/integration/receiving_spec.rb @@ -233,10 +233,10 @@ describe 'a user receives a post' do receive_with_zord(bob, alice.person, xml) receive_with_zord(eve, alice.person, xml) - @comment = eve.comment('tada',:post => @post) - @comment.parent_author_signature = @comment.sign_with_key(alice.encryption_key) - @xml = @comment.to_diaspora_xml - @comment.delete + comment = eve.comment('tada',:post => @post) + comment.parent_author_signature = comment.sign_with_key(alice.encryption_key) + @xml = comment.to_diaspora_xml + comment.delete end it 'should correctly attach the user already on the pod' do @@ -254,17 +254,14 @@ describe 'a user receives a post' do eve.delete Person.where(:id => remote_person.id).delete_all Profile.where(:person_id => remote_person.id).delete_all - remote_person.id = nil + remote_person.attributes.delete(:id) # leaving a nil id causes it to try to save with id set to NULL in postgres - Person.should_receive(:by_account_identifier).twice.and_return{ |handle| - if handle == alice.person.diaspora_handle - alice.person.save - alice.person - else - remote_person.save(:validate => false) - remote_person.profile = Factory(:profile, :person => remote_person) - remote_person - end + m = mock() + Webfinger.should_receive(:new).twice.with(eve.person.diaspora_handle).and_return(m) + m.should_receive(:fetch).twice.and_return{ + remote_person.save(:validate => false) + remote_person.profile = Factory(:profile, :person => remote_person) + remote_person } bob.reload.visible_posts.size.should == 1