Services are in mysql, contact_for and add_contact_to_aspect work again

This commit is contained in:
Raphael 2010-12-19 13:11:41 -08:00
parent 232de40457
commit 0c67e271df
6 changed files with 35 additions and 17 deletions

View file

@ -2,19 +2,11 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class Service
include MongoMapper::Document
class Service < ActiveRecord::Base
include ActionView::Helpers::TextHelper
belongs_to :user
key :provider, String
key :uid, String
key :access_token, String
key :access_secret, String
key :nickname, String
timestamps!
def public_message(post, length, url = "")
url = "" if post.respond_to?(:photos) && post.photos.count == 0
space_for_url = url.blank? ? 0 : (url.length + 1)

View file

@ -38,6 +38,7 @@ class User < ActiveRecord::Base
has_many :aspect_memberships, :through => :aspects
has_many :contacts
has_many :contact_people, :through => :contacts
has_many :services
# many :visible_people, :in => :visible_person_ids, :class => Person # One of these needs to go
# many :raw_visible_posts, :in => :visible_post_ids, :class => Post
@ -88,9 +89,8 @@ class User < ActiveRecord::Base
end
def add_contact_to_aspect(contact, aspect)
return true if contact.aspect_ids.include?(aspect.id)
contact.aspects << aspect
contact.save!
return true if contact.aspect_memberships.where(:aspect_id => aspect.id).count > 0
contact.aspect_memberships.create!(:aspect => aspect)
end
def delete_person_from_aspect(person_id, aspect_id, opts = {})

View file

@ -123,6 +123,18 @@ class CreateSchema < ActiveRecord::Migration
add_index :requests, :recipient_id
add_index :requests, [:sender_id, :recipient_id], :unique => true
create_table :services do |t|
t.string :_type
t.integer :user_id
t.string :provider
t.string :uid
t.string :access_token
t.string :access_secret
t.string :nickname
t.timestamps
end
add_index :services, :user_id
create_table :users do |t|
t.string :username
t.text :serialized_private_key

View file

@ -157,6 +157,20 @@ ActiveRecord::Schema.define(:version => 0) do
add_index "requests", ["sender_id", "recipient_id"], :name => "index_requests_on_sender_id_and_recipient_id", :unique => true
add_index "requests", ["sender_id"], :name => "index_requests_on_sender_id"
create_table "services", :force => true do |t|
t.string "_type"
t.integer "user_id"
t.string "provider"
t.string "uid"
t.string "access_token"
t.string "access_secret"
t.string "nickname"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "services", ["user_id"], :name => "index_services_on_user_id"
create_table "users", :force => true do |t|
t.string "username"
t.text "serialized_private_key"

View file

@ -42,13 +42,11 @@ module Diaspora
end
def contact_for(person)
id = person.id
contact_for_person_id(id)
contact_for_person_id(person.id)
end
def contact_for_person_id(person_id)
contacts.first(:person_id => person_id) if person_id
Contact.where(:user_id => self.id, :person_id => person_id).first if person_id
end
def contacts_not_in_aspect( aspect )

View file

@ -25,8 +25,10 @@ describe User do
end
it 'saves post into visible post ids' do
pp user.raw_visible_posts
proc {
user.add_to_streams(@post, @aspect_ids)
pp user.raw_visible_posts
}.should change(user.raw_visible_posts, :count).by(1)
user.reload.raw_visible_posts.should include @post
end