From 004094d66fdf523f69925716a102d03870aa4b06 Mon Sep 17 00:00:00 2001 From: zhitomirskiyi Date: Tue, 18 Jan 2011 16:21:14 -0800 Subject: [PATCH] fixed the querying in the controllers got rid of hashes --- app/controllers/aspects_controller.rb | 71 +++---------------- app/controllers/comments_controller.rb | 5 +- app/controllers/people_controller.rb | 1 - app/controllers/photos_controller.rb | 7 -- app/controllers/status_messages_controller.rb | 7 -- app/helpers/sockets_helper.rb | 2 +- app/models/comment.rb | 1 + app/models/contact.rb | 1 + app/models/post.rb | 1 + app/models/request.rb | 11 +-- app/views/aspects/_aspect.haml | 8 +-- app/views/aspects/_aspect_listings.haml | 10 +-- app/views/aspects/_aspect_stream.haml | 4 +- app/views/aspects/_edit_aspect_pane.html.haml | 2 +- app/views/aspects/edit.html.haml | 4 +- app/views/aspects/index.html.haml | 4 +- app/views/aspects/index.js.erb | 4 +- app/views/aspects/index.mobile.haml | 2 +- app/views/aspects/manage.html.haml | 28 ++++---- app/views/aspects/show.html.haml | 2 +- app/views/aspects/show.js.erb | 2 +- app/views/comments/_comment.haml | 10 +-- app/views/comments/_comments.haml | 15 ++-- app/views/people/show.html.haml | 2 +- app/views/photos/show.html.haml | 2 +- .../requests/_manage_aspect_contacts.haml | 2 +- app/views/shared/_contact_list.html.haml | 10 +-- app/views/shared/_stream.haml | 4 +- app/views/shared/_stream_element.haml | 12 ++-- app/views/status_messages/show.html.haml | 2 +- spec/controllers/aspects_controller_spec.rb | 66 +---------------- spec/lib/diaspora/parser_spec.rb | 2 +- spec/misc_spec.rb | 4 +- spec/models/request_spec.rb | 22 ------ 34 files changed, 85 insertions(+), 245 deletions(-) diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index 2d3851d23..64a3d15e4 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -11,9 +11,9 @@ class AspectsController < ApplicationController def index if params[:a_ids] - @aspects = current_user.aspects_from_ids(params[:a_ids]) + @aspects = current_user.aspects.where(:id => params[:a_ids]).includes(:contacts) #linit 16 else - @aspects = current_user.aspects + @aspects = current_user.aspects.includes(:contacts) end # redirect to signup @@ -24,13 +24,11 @@ class AspectsController < ApplicationController @aspect_ids = @aspects.map{|a| a.id} post_ids = @aspects.map{|a| a.post_ids}.flatten! - @posts = Post.where(:id => post_ids, :type => "StatusMessage").paginate( - :page => params[:page], :per_page => 15, :order => 'created_at DESC') - @post_hashes = hashes_for_posts @posts + @posts = StatusMessage.joins(:aspects).where(:pending => false, + :aspects => {:id => @aspect_ids}).includes(:person, :comments, :photos).select('DISTINCT `posts`.*').paginate( + :page => params[:page], :per_page => 15, :order => 'created_at DESC') @contacts = current_user.contacts.includes(:person).where(:pending => false) - @contact_hashes = hashes_for_contacts @contacts - @aspect_hashes = hashes_for_aspects @aspects, @contacts, :limit => 16 @aspect = :all unless params[:a_ids] @@ -77,17 +75,13 @@ class AspectsController < ApplicationController end def edit - @aspect = current_user.aspects.where(:id => params[:id]).first + @aspect = current_user.aspects.where(:id => params[:id]).includes(:contacts).first @contacts = current_user.contacts.where(:pending => false) unless @aspect render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404 else @aspect_ids = [@aspect.id] - @aspect_contacts = hashes_for_contacts @aspect.contacts.where(:pending => false) - @aspect_contacts_count = @aspect_contacts.count - - @all_contacts = hashes_for_contacts @contacts - + @aspect_contacts_count = @aspect.contacts.count render :layout => false end end @@ -95,8 +89,8 @@ class AspectsController < ApplicationController def manage @aspect = :manage @contacts = current_user.contacts.where(:pending => false) - @remote_requests = Request.hashes_for_person(current_user.person) - @aspect_hashes = hashes_for_aspects @all_aspects, @contacts + @remote_requests = Request.where(:recipient_id => current_user.person.id) + @aspects = @all_aspects.includes(:contacts) end def update @@ -184,51 +178,4 @@ class AspectsController < ApplicationController end end end - - private - def hashes_for_contacts contacts - contacts.includes(:person).map{|c| {:contact => c, :person => c.person}} - end - - def hashes_for_aspects aspects, contacts, opts = {} - contact_hashes = hashes_for_contacts contacts - aspects.map do |a| - hash = {:aspect => a} - aspect_contact_hashes = contact_hashes.select{|c| - c[:contact].aspects.include?(a)} - hash[:contact_count] = aspect_contact_hashes.count - if opts[:limit] - hash[:contacts] = aspect_contact_hashes.slice(0,opts[:limit]) - else - hash[:contacts] = aspect_contact_hashes - end - hash - end - end - def hashes_for_posts posts - post_ids = [] - post_person_ids = [] - posts.each{|p| post_ids << p.id; post_person_ids << p.person_id} - - comment_hash = Comment.hash_from_post_ids post_ids - commenters_hash = Person.from_post_comment_hash comment_hash - photo_hash = Photo.hash_from_post_ids post_ids - - post_person_ids.uniq! - posters = Person.where(:id => post_person_ids) - posters_hash = {} - posters.each{|poster| posters_hash[poster.id] = poster} - - posts.map do |post| - {:post => post, - :photos => photo_hash[post.id], - :person => posters_hash[post.person_id], - :comments => comment_hash[post.id].map do |comment| - {:comment => comment, - :person => commenters_hash[comment.person_id], - } - end, - } - end - end end diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index a69368c0d..e8a502c66 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -26,10 +26,9 @@ class CommentsController < ApplicationController :comment_id => @comment.id, :html => render_to_string( :partial => 'comments/comment', - :locals => { :hash => { - :comment => @comment, + :locals => { :comment => @comment, :person => current_user.person, - }} + } ) } render(:json => json, :status => 201) diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index cd1bc23b7..70a27acf7 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -64,7 +64,6 @@ class PeopleController < ApplicationController end @posts = current_user.posts_from(@person).where(:type => "StatusMessage").paginate :page => params[:page] - @post_hashes = hashes_for_posts @posts respond_with @person, :locals => {:post_type => :all} diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index c01e46b5b..2b0f9ed38 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -156,13 +156,6 @@ class PhotosController < ApplicationController @object_aspect_ids = @parent.aspects.map{|a| a.id} end - comments_hash = Comment.hash_from_post_ids [@parent.id] - person_hash = Person.from_post_comment_hash comments_hash - @comment_hashes = comments_hash[@parent.id].map do |comment| - {:comment => comment, - :person => person_hash[comment.person_id] - } - end @ownership = current_user.owns? @photo end diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index 69a06b6c1..78b772952 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -70,13 +70,6 @@ class StatusMessagesController < ApplicationController def show @status_message = current_user.find_visible_post_by_id params[:id] - comments_hash = Comment.hash_from_post_ids [@status_message.id] - person_hash = Person.from_post_comment_hash comments_hash - @comment_hashes = comments_hash[@status_message.id].map do |comment| - {:comment => comment, - :person => person_hash[comment.person_id] - } - end @object_aspect_ids = @status_message.aspects.map{|a| a.id} diff --git a/app/helpers/sockets_helper.rb b/app/helpers/sockets_helper.rb index e19ecdafe..ac8ef29e0 100644 --- a/app/helpers/sockets_helper.rb +++ b/app/helpers/sockets_helper.rb @@ -48,7 +48,7 @@ module SocketsHelper v = render_to_string(:partial => 'people/person', :locals => person_hash) elsif object.is_a? Comment - v = render_to_string(:partial => 'comments/comment', :locals => {:hash => {:comment => object, :person => object.person}}) + v = render_to_string(:partial => 'comments/comment', :locals => {:comment => object, :person => object.person}) elsif object.is_a? Notification v = render_to_string(:partial => 'notifications/popup', :locals => {:note => object, :person => object.actor}) diff --git a/app/models/comment.rb b/app/models/comment.rb index 2ef53465d..73e9aabfd 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -3,6 +3,7 @@ # the COPYRIGHT file. class Comment < ActiveRecord::Base + default_scope :include => :person require File.join(Rails.root, 'lib/diaspora/web_socket') require File.join(Rails.root, 'lib/youtube_titles') include YoutubeTitles diff --git a/app/models/contact.rb b/app/models/contact.rb index 71b5f638f..366fe898c 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -3,6 +3,7 @@ # the COPYRIGHT file. class Contact < ActiveRecord::Base + default_scope :include => :person belongs_to :user validates_presence_of :user diff --git a/app/models/post.rb b/app/models/post.rb index 456fce36e..48f8f9a1d 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -3,6 +3,7 @@ # the COPYRIGHT file. class Post < ActiveRecord::Base + default_scope :include => [:person, :comments] require File.join(Rails.root, 'lib/encryptable') require File.join(Rails.root, 'lib/diaspora/web_socket') include ApplicationHelper diff --git a/app/models/request.rb b/app/models/request.rb index 90ec412ad..1cb98c816 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -9,6 +9,8 @@ class Request < ActiveRecord::Base include Diaspora::Webhooks include ROXML + default_scope :include => :sender + xml_accessor :sender_handle xml_accessor :recipient_handle @@ -54,15 +56,6 @@ class Request < ActiveRecord::Base sender_handle end - def self.hashes_for_person person - requests = Request.where(:recipient_id => person.id) - senders = Person.where(:id => requests.map{|r| r.sender_id}) - senders_hash = {} - senders.each{|sender| senders_hash[sender.id] = sender} - requests.map{|r| {:request => r, :sender => senders_hash[r.sender_id]}} - end - - def notification_type(user, person) if Contact.where(:user_id => user.id, :person_id => person.id).first "request_accepted" diff --git a/app/views/aspects/_aspect.haml b/app/views/aspects/_aspect.haml index 1d9879a88..3ce6292ce 100644 --- a/app/views/aspects/_aspect.haml +++ b/app/views/aspects/_aspect.haml @@ -1,12 +1,12 @@ %li{:data=>{:guid=>aspect.id}, :class => ("dull" if contacts.length == 0)} .right %b - = link_to t('contacts', :count => contact_count), edit_aspect_path(aspect), :rel => 'facebox' + = link_to t('contacts', :count => aspect.contacts.count), edit_aspect_path(aspect), :rel => 'facebox' %b = aspect.name %br - - if contacts.length > 0 + - if aspect.contacts.length > 0 .contacts - - for hash in contacts - = person_image_link(hash[:person]) + - for contact in aspect.contacts + = person_image_link(contact.person) diff --git a/app/views/aspects/_aspect_listings.haml b/app/views/aspects/_aspect_listings.haml index db352abfd..3a9fb2735 100644 --- a/app/views/aspects/_aspect_listings.haml +++ b/app/views/aspects/_aspect_listings.haml @@ -5,14 +5,14 @@ %h4 .right - = link_to t('contacts', :count => @contacts.count), aspects_manage_path, :title => t('aspects.manage.manage_aspects') + = link_to t('contacts', :count => contacts.count), aspects_manage_path, :title => t('aspects.manage.manage_aspects') - = @aspect_hashes.count - - if @aspect_hashes.count == 1 + = aspects.count + - if aspects.count == 1 = t('_aspect') - else = t('_aspects') %ul - - for a_hash in aspect_hashes - = render :partial => 'aspects/aspect', :locals => a_hash + - for aspect in aspects + = render 'aspects/aspect', :aspect => aspect, :contacts => aspect.contacts diff --git a/app/views/aspects/_aspect_stream.haml b/app/views/aspects/_aspect_stream.haml index 383ae62a4..e1d313535 100644 --- a/app/views/aspects/_aspect_stream.haml +++ b/app/views/aspects/_aspect_stream.haml @@ -5,5 +5,5 @@ = render 'shared/publisher', :aspect => aspect, :aspect_ids => aspect_ids #main_stream.stream{:data => {:guids => aspect_ids.join(',')}} - = render 'shared/stream', :posts => post_hashes -= will_paginate @posts + = render 'shared/stream', :posts => posts += will_paginate posts diff --git a/app/views/aspects/_edit_aspect_pane.html.haml b/app/views/aspects/_edit_aspect_pane.html.haml index e472d17cb..7d1365747 100644 --- a/app/views/aspects/_edit_aspect_pane.html.haml +++ b/app/views/aspects/_edit_aspect_pane.html.haml @@ -8,7 +8,7 @@ #edit_aspect_pane - if @contacts.count > 0 %h4= t('aspects.edit.add_existing') - = render 'shared/contact_list', :aspect_id => aspect.id, :contact_hashes => contacts, :manage => defined?(manage) + = render 'shared/contact_list', :aspect_id => aspect.id, :contacts => contacts, :manage => defined?(manage) = render 'shared/add_contact', :aspect_id => aspect.id diff --git a/app/views/aspects/edit.html.haml b/app/views/aspects/edit.html.haml index f4a1fe9fc..d12d91c4a 100644 --- a/app/views/aspects/edit.html.haml +++ b/app/views/aspects/edit.html.haml @@ -10,7 +10,7 @@ %h4 = @aspect .description - = t('contacts', :count =>@aspect_contacts.count) + = t('contacts', :count =>@aspect_contacts_count) .person_tiles{:style => "display:none;"} - for contact in @aspect.contacts @@ -26,7 +26,7 @@ = button_to t('.remove_aspect'), @aspect, :method => "delete", :confirm => t('.confirm_remove_aspect'), :class => 'button' - if @contacts.count > 0 - = render 'shared/contact_list', :aspect_id => @aspect.id, :contact_hashes => @all_contacts + = render 'shared/contact_list', :aspect_id => @aspect.id, :contacts => @contacts #aspect_edit_controls = link_to t('.rename'), '#' diff --git a/app/views/aspects/index.html.haml b/app/views/aspects/index.html.haml index e5d2d0504..a3d548233 100644 --- a/app/views/aspects/index.html.haml +++ b/app/views/aspects/index.html.haml @@ -13,7 +13,7 @@ = render 'aspect_stream', :aspect => @aspect, :aspect_ids => @aspect_ids, - :post_hashes => @post_hashes + :posts => @posts .span-7.last #home_user_badge @@ -38,7 +38,7 @@ %hr #aspect_listings.section - = render 'aspects/aspect_listings', :aspect_hashes => @aspect_hashes + = render 'aspects/aspect_listings', :aspects => @aspects, :contacts => @contacts .section %h4= t('shared.invitations.invites') diff --git a/app/views/aspects/index.js.erb b/app/views/aspects/index.js.erb index d4dd81c79..b856a017c 100644 --- a/app/views/aspects/index.js.erb +++ b/app/views/aspects/index.js.erb @@ -1,5 +1,5 @@ -$('#aspect_stream_container').html("<%= escape_javascript(render('aspects/aspect_stream', :aspect => @aspect, :aspect_ids => @aspect_ids, :post_hashes => @post_hashes)) %>"); -$('#aspect_listings').html("<%= escape_javascript(render('aspects/aspect_listings', :aspect_hashes => @aspect_hashes)) %>"); +$('#aspect_stream_container').html("<%= escape_javascript(render('aspects/aspect_stream', :aspect => @aspect, :aspect_ids => @aspect_ids, :posts => @posts)) %>"); +$('#aspect_listings').html("<%= escape_javascript(render('aspects/aspect_listings', :aspects => @aspects)) %>"); $('a[rel*=facebox]').facebox(); $(document).ready(function() { diff --git a/app/views/aspects/index.mobile.haml b/app/views/aspects/index.mobile.haml index c71345411..bbcd3ab8b 100644 --- a/app/views/aspects/index.mobile.haml +++ b/app/views/aspects/index.mobile.haml @@ -8,4 +8,4 @@ %div{:data => {:role => 'fieldcontain'}} =render 'shared/publisher', :aspect => @aspect -= render 'shared/stream', :posts => @post_hashes += render 'shared/stream', :posts => @posts diff --git a/app/views/aspects/manage.html.haml b/app/views/aspects/manage.html.haml index a94ad57d6..ff44e3054 100644 --- a/app/views/aspects/manage.html.haml +++ b/app/views/aspects/manage.html.haml @@ -24,13 +24,13 @@ - if @remote_requests.size < 1 %li=t('.no_requests') - else - - for hash in @remote_requests - %li.person.request{:data=>{:guid=>hash[:request].id, :person_id=>hash[:sender].id}} + - for req in @remote_requests + %li.person.request{:data=>{:guid=> req.id, :person_id=> req.sender.id}} .delete .x X .circle - = link_to person_image_tag(hash[:sender]), hash[:sender] + = link_to person_image_tag(req.sender), req.sender - if @remote_requests.size > 0 %p @@ -42,30 +42,30 @@ \. .span-19.last - - for hash in @aspect_hashes - .aspect.span-9{:data=>{:guid=>hash[:aspect].id}} + - for aspect in @aspects + .aspect.span-9{:data=>{:guid => aspect.id}} .aspect_name %span.edit_name_field %h3{:contenteditable=>true} - = hash[:aspect].name + = aspect.name %span.tip click to edit %ul.tools - %li= link_to t('.add_a_new_contact'), "#manage_aspect_contacts_pane_#{hash[:aspect].id}", :class => 'manage_aspect_contacts_button', :rel => "facebox" - %li!= remove_link(hash[:aspect]) + %li= link_to t('.add_a_new_contact'), "#manage_aspect_contacts_pane_#{aspect.id}", :class => 'manage_aspect_contacts_button', :rel => "facebox" + %li!= remove_link(aspect) - %ul.dropzone{:data=>{:aspect_id=>hash[:aspect].id}} - -for contact_hash in hash[:contacts] - %li.person{:data=>{:guid=>contact_hash[:person].id, :aspect_id=>hash[:aspect].id}} + %ul.dropzone{:data => {:aspect_id => aspect.id}} + -for contact in aspect.contacts + %li.person{:data => {:guid => contact.person.id, :aspect_id => aspect.id}} .delete .x X .circle - = link_to person_image_tag(contact_hash[:person]), contact_hash[:person] + = link_to person_image_tag(contact.person), contact.person .draggable_info =t('.drag_to_add') .facebox_content - %div{:id => "manage_aspect_contacts_pane_#{hash[:aspect].id}"} - = render "requests/manage_aspect_contacts", :aspect => hash[:aspect], :manage => true, :contact_hashes => hash[:contacts] + %div{:id => "manage_aspect_contacts_pane_#{ aspect.id}"} + = render "requests/manage_aspect_contacts", :aspect => aspect, :manage => true, :contacts => @contacts diff --git a/app/views/aspects/show.html.haml b/app/views/aspects/show.html.haml index f9a3e9ce2..a7f618211 100644 --- a/app/views/aspects/show.html.haml +++ b/app/views/aspects/show.html.haml @@ -25,5 +25,5 @@ = render 'shared/publisher', :aspect => @aspect #main_stream.stream{:data => {:guids => @aspect.id}} - = render 'shared/stream', :posts => @post_hashes + = render 'shared/stream', :posts => @posts =will_paginate @posts diff --git a/app/views/aspects/show.js.erb b/app/views/aspects/show.js.erb index aa27af5a0..7d2f1b8cd 100644 --- a/app/views/aspects/show.js.erb +++ b/app/views/aspects/show.js.erb @@ -1 +1 @@ -$('#main_stream').html("<%= escape_javascript(render('shared/stream', :posts => @post_hashes)) %>"); +$('#main_stream').html("<%= escape_javascript(render('shared/stream', :posts => @posts)) %>"); diff --git a/app/views/comments/_comment.haml b/app/views/comments/_comment.haml index 75ff19a27..33c2fc918 100644 --- a/app/views/comments/_comment.haml +++ b/app/views/comments/_comment.haml @@ -2,13 +2,13 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -%li.comment{:data=>{:guid=>hash[:comment].id}, :class => ("hidden" if(defined? hidden))} - = person_image_link(hash[:person]) +%li.comment{:data=>{:guid => comment.id}, :class => ("hidden" if(defined? hidden))} + = person_image_link(comment.person) .content .from - = person_link(hash[:person]) - = markdownify(hash[:comment].text, :youtube_maps => hash[:comment][:youtube_titles]) + = person_link(comment.person) + = markdownify(comment.text, :youtube_maps => comment.youtube_titles) .info %span.time - = hash[:comment].created_at ? timeago(hash[:comment].created_at) : timeago(Time.now) + = comment.created_at ? timeago(comment.created_at) : timeago(Time.now) diff --git a/app/views/comments/_comments.haml b/app/views/comments/_comments.haml index 499986095..2c6142171 100644 --- a/app/views/comments/_comments.haml +++ b/app/views/comments/_comments.haml @@ -4,20 +4,19 @@ - unless defined?(always_expanded) && always_expanded - %ul.show_comments{:class => ("hidden" if comment_hashes.size == 0)} + %ul.show_comments{:class => ("hidden" if comments.size == 0)} %li = image_tag 'icons/spechbubble_2.png', :class => 'more_comments_icon' - %b= comment_toggle(comment_hashes.size) + %b= comment_toggle(comments.size) -%ul.comments{:id => post_id, :class => ("hidden" if comment_hashes.size == 0)} - -if comment_hashes.size > 3 +%ul.comments{:id => post_id, :class => ("hidden" if comments.size == 0)} + -if comments.size > 3 .older_comments{:class => ("hidden inactive" if defined?(condensed) && condensed)} - = render :partial => 'comments/comment', :collection => comment_hashes[0..-4], :as => :hash - = render :partial => 'comments/comment', :collection => comment_hashes[-3, 3], :as => :hash + = render :partial => 'comments/comment', :collection => comments[0..-4] + = render :partial => 'comments/comment', :collection => comments[-3, 3] -else - = render :partial => 'comments/comment', :collection => comment_hashes, :as => :hash + = render :partial => 'comments/comment', :collection => comments - unless @commenting_disabled %li.comment.show = new_comment_form(post_id) - diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index 06af5bc34..c64c4f8de 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -55,7 +55,7 @@ = render 'photos/index', :photos => @posts - else #main_stream.stream - = render 'shared/stream', :posts => @post_hashes + = render 'shared/stream', :posts => @posts = will_paginate @posts diff --git a/app/views/photos/show.html.haml b/app/views/photos/show.html.haml index 80bd43b39..269ce942d 100644 --- a/app/views/photos/show.html.haml +++ b/app/views/photos/show.html.haml @@ -63,4 +63,4 @@ #photo_stream.stream.show %div{:data=>{:guid=>@parent.id}} - = render "comments/comments", :post_id => @parent.id, :comment_hashes => @comment_hashes, :always_expanded => true + = render "comments/comments", :post_id => @parent.id, :comments => @parent.comments, :always_expanded => true diff --git a/app/views/requests/_manage_aspect_contacts.haml b/app/views/requests/_manage_aspect_contacts.haml index 2d0dd0fa6..b92145e16 100644 --- a/app/views/requests/_manage_aspect_contacts.haml +++ b/app/views/requests/_manage_aspect_contacts.haml @@ -9,7 +9,7 @@ %i= aspect.name .span-6.append-1.last %h3= t('.existing') - = render 'shared/contact_list', :aspect_id => aspect.id, :contact_hashes => contact_hashes, :manage => defined?(manage) + = render 'shared/contact_list', :aspect_id => aspect.id, :contacts => contacts, :manage => defined?(manage) .span-7.last = render 'shared/add_contact', :aspect_id => aspect.id diff --git a/app/views/shared/_contact_list.html.haml b/app/views/shared/_contact_list.html.haml index 1334b2e45..4cc16027c 100644 --- a/app/views/shared/_contact_list.html.haml +++ b/app/views/shared/_contact_list.html.haml @@ -6,13 +6,13 @@ .contact_list = search_field_tag :contact_search, "", :class => 'contact_list_search', :results => 5, :placeholder => t('.all_contacts') %ul - - for hash in contact_hashes + - for contact in contacts %li - = person_image_tag hash[:person] + = person_image_tag contact.person %h4.name - = link_to hash[:person].name, hash[:person] + = link_to contact.person.name, contact.person .description - = hash[:person].diaspora_handle + = contact.person.diaspora_handle .right - = aspect_membership_button(aspect_id, hash[:contact], hash[:person]) + = aspect_membership_button(aspect_id, contact, contact.person) diff --git a/app/views/shared/_stream.haml b/app/views/shared/_stream.haml index d3b2dea9f..5595513c2 100644 --- a/app/views/shared/_stream.haml +++ b/app/views/shared/_stream.haml @@ -4,8 +4,8 @@ - if posts.length > 0 - - for post_hash in posts - = render 'shared/stream_element', post_hash.merge(:all_aspects => @all_aspects, :commenting_disabled => defined?(@commenting_disabled)) + - for post in posts + = render 'shared/stream_element', :post => post, :all_aspects => @all_aspects, :commenting_disabled => defined?(@commenting_disabled) - else = render 'aspects/no_posts_message', :post_count => posts.length diff --git a/app/views/shared/_stream_element.haml b/app/views/shared/_stream_element.haml index 05f394bd9..ded969c3e 100644 --- a/app/views/shared/_stream_element.haml +++ b/app/views/shared/_stream_element.haml @@ -3,19 +3,19 @@ -# the COPYRIGHT file. .stream_element{:data=>{:guid=>post.id}} - - if person.owner_id == current_user.id + - if post.person.owner_id == current_user.id .right.hidden.controls - reshare_aspects = aspects_without_post(all_aspects, post) - unless reshare_aspects.empty? = render 'shared/reshare', :aspects => reshare_aspects, :post => post = link_to image_tag('deletelabel.png'), status_message_path(post), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete", :title => t('delete') - = person_image_link(person, :size => :thumb_small) + = person_image_link(post.person, :size => :thumb_small) .content .from %h5 - =person_link(person) + =person_link(post.person) - if post.public? %span.arrow ➔ @@ -23,15 +23,15 @@ %span.aspect_badge.public = t('the_world') - - elsif person.owner_id == current_user.id + - elsif post.person.owner_id == current_user.id %span.arrow ➔ %span.aspect_badges = aspect_badges(aspects_with_post(all_aspects, post)) - = render 'status_messages/status_message', :post => post, :photos => photos + = render 'status_messages/status_message', :post => post, :photos => post.photos .info %span.timeago= link_to(how_long_ago(post), status_message_path(post)) = link_to t('comments.new_comment.comment').downcase, '#', :class => 'focus_comment_textarea' - = render "comments/comments", :post_id => post.id, :comment_hashes => comments, :condensed => true, :commenting_disabled => defined?(@commenting_disabled) + = render "comments/comments", :post_id => post.id, :comments => post.comments, :condensed => true, :commenting_disabled => defined?(@commenting_disabled) diff --git a/app/views/status_messages/show.html.haml b/app/views/status_messages/show.html.haml index d61742f07..0bc6b590b 100644 --- a/app/views/status_messages/show.html.haml +++ b/app/views/status_messages/show.html.haml @@ -29,4 +29,4 @@ #status_message_stream.stream.show %div{:data=>{:guid=>@status_message.id}} - = render "comments/comments", :post_id => @status_message.id, :comment_hashes => @comment_hashes, :always_expanded => true + = render "comments/comments", :post_id => @status_message.id, :comments => @status_message.comments, :always_expanded => true diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index e3445f2d4..10470ff7b 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -193,7 +193,7 @@ describe AspectsController do :person_id => @person.id, :from => @aspect0.id, :to => - {:to => @aspect1.id} + {:to => @aspect1.id} } end it 'calls the move_contact_method' do @@ -203,70 +203,6 @@ describe AspectsController do end end - describe "#hashes_for_contacts" do - before do - @people = [] - 10.times {@people << Factory.create(:person)} - @people.each{|p| @user.reload.activate_contact(p, @user.aspects.first.reload)} - @hashes = @controller.send(:hashes_for_contacts,@user.reload.contacts) - @hash = @hashes.first - end - it 'has as many hashes as contacts' do - @hashes.length.should == @user.contacts.length - end - it 'has a contact' do - @hash[:contact].should == @user.contacts.first - end - it 'has a person' do - @hash[:person].should == @user.contacts.first.person - end - it "does not select the person's rsa key" do - pending "Don't select RSA keys for views" - @hash[:person].serialized_public_key.should be_nil - end - end - describe "#hashes_for_aspects" do - before do - @aspect1 = @user.aspects.create(:name => "SecondAspect") - @people = [] - 10.times {@people << Factory.create(:person)} - - @people.each do |p| - @user.reload.activate_contact(p, @user.aspects.first.reload) - @user.add_contact_to_aspect(@user.contact_for(p), @aspect1) - end - @user.reload - @hashes = @controller.send(:hashes_for_aspects, @user.aspects, @user.contacts, :limit => 9) - @hash = @hashes.first - @aspect0 = @user.aspects.first - end - it 'has aspects' do - @hashes.length.should == @user.aspects.count - @hash[:aspect].should == @aspect0 - end - it 'has a contact_count' do - @hash[:contact_count].should == @aspect0.contacts.count - end - it 'takes a limit on contacts returned' do - @hash[:contacts].count.should == 9 - end - it 'has a person in each hash' do - @aspect0.contacts.map{|c| c.person}.include?(@hash[:contacts].first[:person]).should be_true - end - it "does not return the rsa key" do - pending "Don't select RSA keys for views" - @hash[:contacts].first[:person].serialized_public_key.should be_nil - end - it 'has a contact in each hash' do - @aspect0.contacts.include?(@hash[:contacts].first[:contact]).should be_true - end - it 'does not retreive duplicate contacts' do - @hashes = @controller.send(:hashes_for_aspects, @user.aspects, @user.contacts) - @hash = @hashes.first - flattened = @hash[:contacts].map{|c| c[:person].id} - flattened.uniq.should == flattened - end - end describe "#update" do before do diff --git a/spec/lib/diaspora/parser_spec.rb b/spec/lib/diaspora/parser_spec.rb index b174948a6..7cb13050e 100644 --- a/spec/lib/diaspora/parser_spec.rb +++ b/spec/lib/diaspora/parser_spec.rb @@ -47,7 +47,7 @@ describe Diaspora::Parser do @aspect.reload new_contact = @user.contact_for(@user2.person) @aspect.contacts.include?(new_contact).should be true - @user.contacts.include?(new_contact).should be true + @user.contacts.reload.include?(new_contact).should be true end it 'should process retraction for a person' do diff --git a/spec/misc_spec.rb b/spec/misc_spec.rb index 43a83c866..e99d6db11 100644 --- a/spec/misc_spec.rb +++ b/spec/misc_spec.rb @@ -35,7 +35,7 @@ describe 'making sure the spec runner works' do it 'connects the first user to the second' do contact = @user1.contact_for @user2.person contact.should_not be_nil - @user1.contacts.include?(contact).should be_true + @user1.contacts.reload.include?(contact).should be_true @aspect1.contacts.include?(contact).should be_true contact.aspects.include?(@aspect1).should be_true end @@ -43,7 +43,7 @@ describe 'making sure the spec runner works' do it 'connects the second user to the first' do contact = @user2.contact_for @user1.person contact.should_not be_nil - @user2.contacts.include?(contact).should be_true + @user2.contacts.reload.include?(contact).should be_true @aspect2.contacts.include?(contact).should be_true contact.aspects.include?(@aspect2).should be_true end diff --git a/spec/models/request_spec.rb b/spec/models/request_spec.rb index e94a85f1a..ffa1ce6f3 100644 --- a/spec/models/request_spec.rb +++ b/spec/models/request_spec.rb @@ -71,28 +71,6 @@ describe Request do end end - describe '.hashes_for_person' do - before do - @user = Factory.create(:user) - @user2 = Factory.create(: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.where(:sender_id => @user2.person.id, :recipient_id => @user.person.id).first - end - it 'gives back people' do - @hash[:sender].should == @user2.person - end - it 'does not retrieve keys' do - pending "don't retrieve keys" - @hash[:sender].serialized_public_key.should be_nil - end - end - describe 'xml' do before do @request = Request.new(:sender => @user.person, :recipient => @user2.person, :aspect => @aspect)