removed ensure_bson in user. added to_id method to String and ObjectID classes
This commit is contained in:
parent
3a91858bcf
commit
00f8a3e628
5 changed files with 21 additions and 17 deletions
|
|
@ -7,7 +7,7 @@ module SocketsHelper
|
|||
|
||||
def action_hash(uid, object, opts={})
|
||||
begin
|
||||
user = User.find_by_id(User.ensure_bson uid)
|
||||
user = User.find_by_id uid
|
||||
v = render_to_string(:partial => type_partial(object), :locals => {:post => object, :current_user => user}) unless object.is_a? Retraction
|
||||
rescue Exception => e
|
||||
Rails.logger.error("web socket view rendering failed for object #{object.inspect}.")
|
||||
|
|
|
|||
|
|
@ -73,7 +73,6 @@ class User
|
|||
if group_ids == :all || group_ids == "all"
|
||||
groups = self.groups
|
||||
else
|
||||
group_ids.map!{|gid| User.ensure_bson gid }
|
||||
groups = self.groups.find_all_by_id( group_ids )
|
||||
end
|
||||
#send to the groups
|
||||
|
|
@ -157,7 +156,7 @@ class User
|
|||
else
|
||||
object.perform self.id
|
||||
groups = self.groups_with_person(object.person)
|
||||
groups.each{ |group| group.post_ids.delete(User.ensure_bson(object.post_id))
|
||||
groups.each{ |group| group.post_ids.delete(object.post_id.to_id)
|
||||
group.save
|
||||
}
|
||||
end
|
||||
|
|
@ -215,29 +214,28 @@ class User
|
|||
end
|
||||
|
||||
def visible_person_by_id( id )
|
||||
id = User.ensure_bson id
|
||||
id = id.to_id
|
||||
return self.person if id == self.person.id
|
||||
friends.detect{|x| x.id == id }
|
||||
end
|
||||
|
||||
def group_by_id( id )
|
||||
id = User.ensure_bson id
|
||||
id = id.to_id
|
||||
groups.detect{|x| x.id == id }
|
||||
end
|
||||
|
||||
def album_by_id( id )
|
||||
id = User.ensure_bson id
|
||||
id = id.to_id
|
||||
albums.detect{|x| x.id == id }
|
||||
end
|
||||
|
||||
def groups_with_post( id )
|
||||
id = User.ensure_bson id
|
||||
self.groups.find_all_by_post_ids( id )
|
||||
end
|
||||
|
||||
def groups_with_person person
|
||||
id = User.ensure_bson person.id
|
||||
groups.select {|group| group.person_ids.include? id}
|
||||
id = person.id.to_id
|
||||
groups.select { |g| g.person_ids.include? id}
|
||||
end
|
||||
|
||||
def setup_person
|
||||
|
|
@ -258,7 +256,4 @@ class User
|
|||
OpenSSL::PKey::RSA::generate 1024
|
||||
end
|
||||
|
||||
def self.ensure_bson id
|
||||
id.class == String ? BSON::ObjectID(id) : id
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,11 +3,11 @@ require File.expand_path('../boot', __FILE__)
|
|||
require "action_controller/railtie"
|
||||
require "action_mailer/railtie"
|
||||
require "active_resource/railtie"
|
||||
|
||||
# If you have a Gemfile, require the gems listed there, including any gems
|
||||
# you've limited to :test, :development, or :production.
|
||||
Bundler.require(:default, Rails.env) if defined?(Bundler)
|
||||
|
||||
require 'lib/mongo_mapper/bson_id'
|
||||
module Diaspora
|
||||
class Application < Rails::Application
|
||||
# Settings in config/environments/* take precedence over those specified here.
|
||||
|
|
|
|||
10
lib/mongo_mapper/bson_id.rb
Normal file
10
lib/mongo_mapper/bson_id.rb
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
class String
|
||||
def to_id
|
||||
BSON::ObjectID self
|
||||
end
|
||||
end
|
||||
class BSON::ObjectID
|
||||
def to_id
|
||||
self
|
||||
end
|
||||
end
|
||||
|
|
@ -3,15 +3,14 @@ require File.dirname(__FILE__) + '/../spec_helper'
|
|||
describe Photo do
|
||||
before do
|
||||
@user = Factory.create(:user)
|
||||
@user.person.save
|
||||
@group = @user.group(:name => "losers")
|
||||
@album = @user.post :album, :name => "foo", :to => @group.id
|
||||
|
||||
@fixture_filename = 'button.png'
|
||||
@fixture_name = File.dirname(__FILE__) + '/../fixtures/button.png'
|
||||
@fail_fixture_name = File.dirname(__FILE__) + '/../fixtures/msg.xml'
|
||||
|
||||
@group = @user.group(:name => "losers")
|
||||
|
||||
@album = Album.create(:name => "foo", :person => @user.person)
|
||||
@photo = Photo.new(:person => @user.person, :album => @album)
|
||||
end
|
||||
|
||||
|
|
@ -88,7 +87,7 @@ describe Photo do
|
|||
end
|
||||
|
||||
it 'should save a signed photo' do
|
||||
photo = @user.post(:photo, :album => @album, :user_file => [File.open(@fixture_name)], :to => @group.id)
|
||||
photo = @user.post(:photo, :album_id => @album.id, :user_file => [File.open(@fixture_name)])
|
||||
photo.save.should == true
|
||||
photo.signature_valid?.should be true
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue