Get another couple specs green on pg

This commit is contained in:
Raphael Sofaer 2011-06-15 20:30:08 -07:00
parent f0cb2159c7
commit 2d3eeb9c46
3 changed files with 12 additions and 3 deletions

View file

@ -58,12 +58,17 @@ class ConversationsController < ApplicationController
def new def new
all_contacts_and_ids = Contact.connection.execute(current_user.contacts.joins(:person => :profile all_contacts_and_ids = Contact.connection.execute(current_user.contacts.joins(:person => :profile
).select("contacts.id, profiles.first_name, profiles.last_name, people.diaspora_handle").to_sql).map do |r| ).select("contacts.id, profiles.first_name, profiles.last_name, people.diaspora_handle").to_sql).map do |r|
{:value => r[0], person_json_from_row r
:name => Person.name_from_attrs(r[1], r[2], r[3]).gsub(/(")/, "'")}
end end
@contacts_json = all_contacts_and_ids.to_json.gsub!(/(")/, '\\"') @contacts_json = all_contacts_and_ids.to_json.gsub!(/(")/, '\\"')
@contact = current_user.contacts.find(params[:contact_id]) if params[:contact_id] @contact = current_user.contacts.find(params[:contact_id]) if params[:contact_id]
render :layout => false render :layout => false
end end
def person_json_from_row r
r = [r["id"], r["first_name"], r["last_name"], r["diaspora_handle"]] if defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) && ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
{:value => r[0],
:name => Person.name_from_attrs(r[1], r[2], r[3]).gsub(/(")/, "'")}
end
end end

View file

@ -5,6 +5,10 @@
module Diaspora module Diaspora
module UserModules module UserModules
module Connecting module Connecting
# This will create a contact on the side of the sharer and the sharee.
# @param [Person] person The person to start sharing with.
# @param [Aspect] aspect The aspect to add them to.
# @return [Contact] The newly made contact for the passed in person.
def share_with(person, aspect) def share_with(person, aspect)
contact = self.contacts.find_or_initialize_by_person_id(person.id) contact = self.contacts.find_or_initialize_by_person_id(person.id)
unless contact.receiving? unless contact.receiving?

View file

@ -98,7 +98,7 @@ describe Contact do
end end
it "returns the target local user's contacts that are in the same aspect" do it "returns the target local user's contacts that are in the same aspect" do
@contact.contacts.map{|p| p.id}.should == [@eve.person].concat(@people1).map{|p| p.id} @contact.contacts.map{|p| p.id}.should =~ [@eve.person].concat(@people1).map{|p| p.id}
end end
it 'returns nothing if contacts_visible is false in that aspect' do it 'returns nothing if contacts_visible is false in that aspect' do