From e6e2ba9cfb40623afcc7797e136805e8effb08b0 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 18 Jan 2011 16:46:35 -0800 Subject: [PATCH 1/3] Take out default scopes --- app/controllers/aspects_controller.rb | 14 +++++++------- app/controllers/photos_controller.rb | 6 +++--- app/controllers/posts_controller.rb | 2 +- app/models/comment.rb | 1 - app/models/contact.rb | 1 - app/models/post.rb | 1 - 6 files changed, 11 insertions(+), 14 deletions(-) diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index 64a3d15e4..ca2d7e4b1 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -11,7 +11,7 @@ class AspectsController < ApplicationController def index if params[:a_ids] - @aspects = current_user.aspects.where(:id => params[:a_ids]).includes(:contacts) #linit 16 + @aspects = current_user.aspects.where(:id => params[:a_ids]).includes(:contacts) else @aspects = current_user.aspects.includes(:contacts) end @@ -25,7 +25,7 @@ class AspectsController < ApplicationController post_ids = @aspects.map{|a| a.post_ids}.flatten! @posts = StatusMessage.joins(:aspects).where(:pending => false, - :aspects => {:id => @aspect_ids}).includes(:person, :comments, :photos).select('DISTINCT `posts`.*').paginate( + :aspects => {:id => @aspect_ids}).includes(:person, :comments => :person, :photos).select('DISTINCT `posts`.*').paginate( :page => params[:page], :per_page => 15, :order => 'created_at DESC') @contacts = current_user.contacts.includes(:person).where(:pending => false) @@ -70,13 +70,13 @@ class AspectsController < ApplicationController end def show - @aspect = current_user.aspects.where(:id => params[:id]).first + @aspect = current_user.aspects.where(:id => params[:id]).includes(:contacts => :person).first redirect_to aspects_path('a_ids[]' => @aspect.id) end def edit - @aspect = current_user.aspects.where(:id => params[:id]).includes(:contacts).first - @contacts = current_user.contacts.where(:pending => false) + @aspect = current_user.aspects.where(:id => params[:id]).first + @contacts = current_user.contacts.includes(:person).where(:pending => false) unless @aspect render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404 else @@ -88,9 +88,9 @@ class AspectsController < ApplicationController def manage @aspect = :manage - @contacts = current_user.contacts.where(:pending => false) + @contacts = current_user.contacts.includes(:person).where(:pending => false) @remote_requests = Request.where(:recipient_id => current_user.person.id) - @aspects = @all_aspects.includes(:contacts) + @aspects = @all_aspects.includes(:contacts => :person) end def update diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 2b0f9ed38..7bc451d0c 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -135,7 +135,7 @@ class PhotosController < ApplicationController end def show - @photo = current_user.visible_photos.where(:id => params[:id]).first + @photo = current_user.visible_photos.where(:id => params[:id]).includes(:person, :status_message => :photos).first if @photo @parent = @photo.status_message @@ -152,8 +152,8 @@ class PhotosController < ApplicationController end @object_aspect_ids = [] - if @parent.aspects - @object_aspect_ids = @parent.aspects.map{|a| a.id} + if @parent_aspects = @parent.aspects.where(:user_id => current_user.id) + @object_aspect_ids = @parent_aspects.map{|a| a.id} end @ownership = current_user.owns? @photo diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index caa3a934a..aaf7a66ac 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -9,7 +9,7 @@ class PostsController < ApplicationController skip_before_filter :set_locale def show - @post = Post.where(:id => params[:id], :public => true).first + @post = Post.where(:id => params[:id], :public => true).includes(:person, :comments => :person).first if @post @landing_page = true diff --git a/app/models/comment.rb b/app/models/comment.rb index 8b5816abf..10027719b 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -3,7 +3,6 @@ # 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 366fe898c..71b5f638f 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -3,7 +3,6 @@ # 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 48f8f9a1d..456fce36e 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -3,7 +3,6 @@ # 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 From 3b394c1c89c65294814b6cf543e6e0212a869c7b Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 18 Jan 2011 16:48:02 -0800 Subject: [PATCH 2/3] One more defualt scope out --- app/controllers/aspects_controller.rb | 2 +- app/models/request.rb | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index ca2d7e4b1..3599c106e 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -89,7 +89,7 @@ class AspectsController < ApplicationController def manage @aspect = :manage @contacts = current_user.contacts.includes(:person).where(:pending => false) - @remote_requests = Request.where(:recipient_id => current_user.person.id) + @remote_requests = Request.where(:recipient_id => current_user.person.id).includes(:sender) @aspects = @all_aspects.includes(:contacts => :person) end diff --git a/app/models/request.rb b/app/models/request.rb index 1cb98c816..6f8c58a85 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -9,8 +9,6 @@ class Request < ActiveRecord::Base include Diaspora::Webhooks include ROXML - default_scope :include => :sender - xml_accessor :sender_handle xml_accessor :recipient_handle From 511a48adde2e6edad2363f856bc2e4025900b090 Mon Sep 17 00:00:00 2001 From: danielvincent Date: Tue, 18 Jan 2011 16:52:03 -0800 Subject: [PATCH 3/3] fixed publicscontroller specs --- app/controllers/publics_controller.rb | 2 +- spec/controllers/publics_controller_spec.rb | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/controllers/publics_controller.rb b/app/controllers/publics_controller.rb index 2ff1ddc05..b39f7c557 100644 --- a/app/controllers/publics_controller.rb +++ b/app/controllers/publics_controller.rb @@ -15,7 +15,7 @@ class PublicsController < ApplicationController caches_page :host_meta def hcard - @person = Person.where(:guid => params[:guid]) + @person = Person.where(:guid => params[:guid]).first unless @person.nil? || @person.owner.nil? render 'publics/hcard' else diff --git a/spec/controllers/publics_controller_spec.rb b/spec/controllers/publics_controller_spec.rb index fe714b2be..3509445d6 100644 --- a/spec/controllers/publics_controller_spec.rb +++ b/spec/controllers/publics_controller_spec.rb @@ -8,19 +8,19 @@ describe PublicsController do render_views let(:user) { Factory.create(:user) } - let(:person) { Factory(:person) } + let(:person) { Factory.create(:person) } describe '#receive' do let(:xml) { "" } it 'succeeds' do - post :receive, "id" => user.person.id.to_s, "xml" => xml + post :receive, "guid" => user.person.guid.to_s, "xml" => xml response.should be_success end it 'enqueues a receive job' do Resque.should_receive(:enqueue).with(Jobs::ReceiveSalmon, user.id, xml).once - post :receive, "id" => user.person.id.to_s, "xml" => xml + post :receive, "guid" => user.person.guid.to_s, "xml" => xml end it 'unescapes the xml before sending it to receive_salmon' do @@ -34,33 +34,33 @@ describe PublicsController do Resque.should_receive(:enqueue).with(Jobs::ReceiveSalmon, user.id, enc_xml).once - post :receive, "id" => user.person.id.to_s, "xml" => CGI::escape(enc_xml) + post :receive, "guid" => user.person.guid.to_s, "xml" => CGI::escape(enc_xml) end it 'returns a 422 if no xml is passed' do - post :receive, "id" => person.id.to_s + post :receive, "guid" => person.guid.to_s response.code.should == '422' end it 'returns a 404 if no user is found' do - post :receive, "id" => person.id.to_s, "xml" => xml + post :receive, "guid" => person.guid.to_s, "xml" => xml response.should be_not_found end end describe '#hcard' do it "succeeds" do - post :hcard, "id" => user.person.id.to_s + post :hcard, "guid" => user.person.guid.to_s response.should be_success end it 'sets the person' do - post :hcard, "id" => user.person.id.to_s + post :hcard, "guid" => user.person.guid.to_s assigns[:person].should == user.person end it 'does not query by user id' do - post :hcard, "id" => user.id.to_s + post :hcard, "guid" => user.id.to_s assigns[:person].should be_nil response.should be_not_found end