got rid of more hash from

This commit is contained in:
zhitomirskiyi 2011-01-18 16:38:31 -08:00
parent 3e6a271ad8
commit ef1b7644f3
5 changed files with 0 additions and 149 deletions

View file

@ -23,24 +23,6 @@ class PeopleController < ApplicationController
end
end
def hashes_for_people people, aspects
ids = people.map{|p| p.id}
requests = {}
Request.where(:sender_id => ids, :recipient_id => current_user.person.id).each do |r|
requests[r.id] = r
end
contacts = {}
Contact.where(:user_id => current_user.id, :person_id => ids).each do |contact|
contacts[contact.person_id] = contact
end
people.map{|p|
{:person => p,
:contact => contacts[p.id],
:request => requests[p.id],
:aspects => aspects}
}
end
def show
@person = Person.where(:id => params[:id]).first
@post_type = :all
@ -130,25 +112,6 @@ class PeopleController < ApplicationController
end
private
def hashes_for_posts posts
post_ids = posts.map{|p| p.id}
comment_hash = Comment.hash_from_post_ids post_ids
person_hash = Person.from_post_comment_hash comment_hash
photo_hash = Photo.hash_from_post_ids post_ids
posts.map do |post|
{:post => post,
:person => @person,
:photos => photo_hash[post.id],
:comments => comment_hash[post.id].map do |comment|
{:comment => comment,
:person => person_hash[comment.person_id],
}
end,
}
end
end
def webfinger(account, opts = {})
Resque.enqueue(Jobs::SocketWebfinger, current_user.id, account, opts)
end

View file

@ -109,16 +109,4 @@ class Comment < ActiveRecord::Base
verify_signature(creator_signature, person)
end
def self.hash_from_post_ids post_ids
hash = {}
comments = where(:post_id => post_ids)
post_ids.each do |id|
hash[id] = []
end
comments.each do |comment|
hash[comment.post_id] << comment
end
hash.each_value {|comments| comments.sort!{|c1, c2| c1.created_at <=> c2.created_at }}
hash
end
end

View file

@ -94,22 +94,7 @@ class Photo < Post
}
end
def self.hash_from_post_ids post_ids
hash = {}
photos = self.on_statuses(post_ids)
post_ids.each do |id|
hash[id] = []
end
photos.each do |photo|
hash[photo.status_message_id] << photo
end
hash.each_value {|photos| photos.sort!{|p1, p2| p1.created_at <=> p2.created_at }}
hash
end
scope :on_statuses, lambda { |post_ids|
where(:status_message_id => post_ids)
}
end

View file

@ -76,47 +76,6 @@ describe PeopleController do
response.should be_success
end
end
describe '#hashes_from_people' do
before do
@everyone = []
10.times do
@everyone << Factory.create(:person)
end
user.send_contact_request_to(@everyone[3], aspect)
user.send_contact_request_to(@everyone[2], aspect)
user.activate_contact(@everyone[4], aspect)
user.activate_contact(@everyone[5], aspect)
user.reload
user.aspects.reload
@people = @everyone
@people.length.should == 10
@hashes = @controller.hashes_for_people(@people, user.aspects)
end
it 'has the correct result for no relationship' do
hash = @hashes.first
hash[:person].should == @people.first
hash[:contact].should be_false
hash[:request].should be_false
hash[:aspects].should == user.aspects
end
it 'has the correct result for a connected person' do
hash = @hashes[4]
hash[:person].should == @people[4]
hash[:contact].should be_true
hash[:contact].should_not be_pending
hash[:aspects].should == user.aspects
end
it 'has the correct result for a requested person' do
hash = @hashes[2]
hash[:person].should == @people[2]
hash[:contact].should be_true
hash[:contact].should be_pending
hash[:aspects].should == user.aspects
end
end
describe '#index' do
before do
@eugene = Factory.create(:person,
@ -127,15 +86,6 @@ describe PeopleController do
:last_name => "Korth"))
end
it "assigns hashes" do
eugene2 = Factory.create(:person,
:profile => Factory(:profile, :first_name => "Eugene",
:last_name => "w"))
get :index, :q => "Eu"
people = assigns[:hashes].map{|h| h[:person]}
people.should include @eugene
people.should include eugene2
end
it "assigns people" do
eugene2 = Factory.create(:person,
:profile => Factory(:profile, :first_name => "Eugene",

View file

@ -13,41 +13,6 @@ describe Comment do
let!(:connecting) { connect_users(user, aspect, user2, aspect2) }
describe '.hash_from_post_ids' do
before do
user.reload
@hello = user.post(:status_message, :message => "Hello.", :to => aspect.id)
@hi = user.post(:status_message, :message => "hi", :to => aspect.id)
@lonely = user.post(:status_message, :message => "Hello?", :to => aspect.id)
@c11 = user2.comment "why so formal?", :on => @hello
@c21 = user2.comment "lol hihihi", :on => @hi
@c12 = user.comment "I simply felt like issuing a greeting. Do step off.", :on => @hello
@c22 = user.comment "stfu noob", :on => @hi
@c12.created_at = Time.now+10
@c12.save!
@c22.created_at = Time.now+10
@c22.save!
end
it 'returns an empty array for posts with no comments' do
Comment.hash_from_post_ids([@lonely.id]).should ==
{@lonely.id => []}
end
it 'returns a hash from posts to comments' do
Comment.hash_from_post_ids([@hello.id, @hi.id]).should ==
{@hello.id => [@c11, @c12],
@hi.id => [@c21, @c22]
}
end
it 'gets the people from the db' do
hash = Comment.hash_from_post_ids([@hello.id, @hi.id])
Person.from_post_comment_hash(hash).should == {
user.person.id => user.person,
user2.person.id => user2.person,
}
end
end
describe 'comment#notification_type' do
let(:user3) {Factory(:user)}