Remove query from aspects manage, correct spec in User spec

This commit is contained in:
Raphael 2010-12-09 19:11:36 -08:00
parent 778c62e0b0
commit 2be0666d80
6 changed files with 37 additions and 10 deletions

View file

@ -77,7 +77,7 @@ class AspectsController < ApplicationController
def manage def manage
@aspect = :manage @aspect = :manage
@remote_requests = current_user.requests_for_me @remote_requests = Request.hashes_for_person(current_user.person)
@aspect_hashes = hashes_for_aspects @aspects, @contacts @aspect_hashes = hashes_for_aspects @aspects, @contacts
end end

View file

@ -18,7 +18,7 @@ class StatusMessagesController < ApplicationController
public_flag = params[:status_message][:public] public_flag = params[:status_message][:public]
public_flag.to_s.match(/(true)/) ? public_flag = true : public_flag = false public_flag.to_s.match(/(true)/) ? public_flag = true : public_flag = false
params[:status_message][:public] = public_flag params[:status_message][:public] = public_flag
@status_message = current_user.build_post(:status_message, params[:status_message]) @status_message = current_user.build_post(:status_message, params[:status_message])
@ -28,7 +28,7 @@ class StatusMessagesController < ApplicationController
@status_message.photos += photos unless photos.nil? @status_message.photos += photos unless photos.nil?
current_user.add_to_streams(@status_message, params[:status_message][:aspect_ids]) current_user.add_to_streams(@status_message, params[:status_message][:aspect_ids])
current_user.dispatch_post(@status_message, :to => params[:status_message][:aspect_ids], :url => post_url(@status_message)) current_user.dispatch_post(@status_message, :to => params[:status_message][:aspect_ids], :url => post_url(@status_message))
for photo in photos for photo in photos
photo.public = public_flag photo.public = public_flag
@ -40,13 +40,13 @@ class StatusMessagesController < ApplicationController
respond_to do |format| respond_to do |format|
format.js{ render :json => { :post_id => @status_message.id, format.js{ render :json => { :post_id => @status_message.id,
:html => render_to_string( :html => render_to_string(
:partial => 'shared/stream_element', :partial => 'shared/stream_element',
:locals => { :locals => {
:post => @status_message, :post => @status_message,
:person => @status_message.person, :person => @status_message.person,
:photos => @status_message.photos, :photos => @status_message.photos,
:comments => [], :comments => [],
:aspects => current_user.aspects, :aspects => current_user.aspects,
:current_user => current_user :current_user => current_user
} }
) )

View file

@ -68,6 +68,13 @@ class Request
self.from.diaspora_handle self.from.diaspora_handle
end end
def self.hashes_for_person person
requests = Request.to(person).all(:sent => false)
senders = Person.all(:id.in => requests.map{|r| r.from_id}, :fields => [:profile])
senders_hash = {}
senders.each{|sender| senders_hash[sender.id] = sender}
requests.map{|r| {:request => r, :sender => senders_hash[r.from_id]}}
end
private private
def no_pending_request def no_pending_request
if Request.first(:from_id => from_id, :to_id => to_id) if Request.first(:from_id => from_id, :to_id => to_id)

View file

@ -22,13 +22,13 @@
- if @remote_requests.size < 1 - if @remote_requests.size < 1
%li=t('.no_requests') %li=t('.no_requests')
- else - else
- for request in @remote_requests - for hash in @remote_requests
%li.person.request{:data=>{:guid=>request.id, :person_id=>request.from.id}} %li.person.request{:data=>{:guid=>hash[:request].id, :person_id=>hash[:sender].id}}
.delete .delete
.x .x
X X
.circle .circle
= link_to person_image_tag(request.from), request.from = link_to person_image_tag(hash[:sender]), hash[:sender]
= render 'shared/invitations', :invites => @invites = render 'shared/invitations', :invites => @invites

View file

@ -108,6 +108,26 @@ describe Request do
end end
end end
describe '.hashes_for_person' do
before do
@user = make_user
@user2 = make_user
@user2.send_contact_request_to @user.person, @user2.aspects.create(:name => "hi")
@user.reload
@user2.reload
@hashes = Request.hashes_for_person(@user.person)
@hash = @hashes.first
end
it 'gives back requests' do
@hash[:request].should == Request.from(@user2).to(@user).first
end
it 'gives back people' do
@hash[:sender].should == @user2.person
end
it 'does not retrieve keys' do
@hash[:sender].serialized_public_key.should be_nil
end
end
describe 'xml' do describe 'xml' do
before do before do
@request = Request.new(:from => user.person, :to => user2.person, :into => aspect) @request = Request.new(:from => user.person, :to => user2.person, :into => aspect)

View file

@ -127,7 +127,7 @@ describe User do
end end
it 'should not contain periods' do it 'should not contain periods' do
user = Factory.build(:user, :username => "kittens;") user = Factory.build(:user, :username => "kittens.")
user.should_not be_valid user.should_not be_valid
end end