From aed413b4632f239fa77b46d19e7d2cb841e78788 Mon Sep 17 00:00:00 2001 From: danielgrippi <danielgrippi@gmail.com> Date: Fri, 13 Jan 2012 12:15:32 -0800 Subject: [PATCH] remove unused method and controller action (move_contact) --- .../aspect_memberships_controller.rb | 22 -------------- app/models/user.rb | 11 ------- config/routes.rb | 2 +- spec/models/user/querying_spec.rb | 6 ++-- spec/models/user_spec.rb | 30 +------------------ 5 files changed, 5 insertions(+), 66 deletions(-) diff --git a/app/controllers/aspect_memberships_controller.rb b/app/controllers/aspect_memberships_controller.rb index d75832bbfc..89327f4207 100644 --- a/app/controllers/aspect_memberships_controller.rb +++ b/app/controllers/aspect_memberships_controller.rb @@ -54,29 +54,7 @@ class AspectMembershipsController < ApplicationController end end - def update - @person = Person.find(params[:person_id]) - @from_aspect = current_user.aspects.where(:id => params[:aspect_id]).first - @to_aspect = current_user.aspects.where(:id => params[:to]).first - - response_hash = { } - - unless current_user.move_contact( @person, @to_aspect, @from_aspect) - flash[:error] = I18n.t 'aspects.move_contact.error',:inspect => params.inspect - end - if aspect = current_user.aspects.where(:id => params[:to]).first - response_hash[:notice] = I18n.t 'aspects.move_contact.success' - response_hash[:success] = true - else - response_hash[:notice] = I18n.t 'aspects.move_contact.failure' - response_hash[:success] = false - end - - render :text => response_hash.to_json - end - rescue_from ActiveRecord::StatementInvalid do render :text => "Duplicate record rejected.", :status => 400 end - end diff --git a/app/models/user.rb b/app/models/user.rb index 2b9bc2362c..7c91f29bdb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -172,17 +172,6 @@ class User < ActiveRecord::Base end ######### Aspects ###################### - - def move_contact(person, to_aspect, from_aspect) - return true if to_aspect == from_aspect - contact = contact_for(person) - - add_contact_to_aspect(contact, to_aspect) - - membership = contact ? AspectMembership.where(:contact_id => contact.id, :aspect_id => from_aspect.id).first : nil - return(membership && membership.destroy) - end - def add_contact_to_aspect(contact, aspect) return true if AspectMembership.exists?(:contact_id => contact.id, :aspect_id => aspect.id) contact.aspect_memberships.create!(:aspect => aspect) diff --git a/config/routes.rb b/config/routes.rb index 99cce0ee34..b55ea95bdb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -114,7 +114,7 @@ Diaspora::Application.routes.draw do resources :contacts, :except => [:update, :create] do get :sharing, :on => :collection end - resources :aspect_memberships, :only => [:destroy, :create, :update] + resources :aspect_memberships, :only => [:destroy, :create] resources :share_visibilities, :only => [:update] resources :blocks, :only => [:create, :destroy] diff --git a/spec/models/user/querying_spec.rb b/spec/models/user/querying_spec.rb index d70b9500a5..a0314aa281 100644 --- a/spec/models/user/querying_spec.rb +++ b/spec/models/user/querying_spec.rb @@ -182,7 +182,7 @@ describe User do time = Time.now Time.stub(:now).and_return(time) alice.send(:prep_opts, Post, {}).should == { - :type => Stream::Base::TYPES_OF_POST_IN_STREAM, + :type => Stream::Base::TYPES_OF_POST_IN_STREAM, :order => 'created_at DESC', :limit => 15, :hidden => false, @@ -198,9 +198,9 @@ describe User do Factory(:status_message, :public => true) bob.visible_shareables(Post).count.should == 0 end + context 'with many posts' do before do - bob.move_contact(eve.person, @bobs_aspect, bob.aspects.create(:name => 'new aspect')) time_interval = 1000 time_past = 1000000 (1..25).each do |n| @@ -229,7 +229,7 @@ describe User do # It should respect the order option opts = {:order => 'updated_at DESC'} bob.visible_shareables(Post, opts).first.updated_at.should > bob.visible_shareables(Post, opts).last.updated_at - + # It should respect the limit option opts = {:limit => 40} bob.visible_shareables(Post, opts).length.should == 40 diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index ff6269599c..c2b513d19d 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -708,34 +708,6 @@ describe User do alice.add_contact_to_aspect(@contact, @original_aspect).should be_true end end - - context 'moving and removing posts' do - describe 'User#move_contact' do - it 'should be able to move a contact from one of users existing aspects to another' do - alice.move_contact(bob.person, @new_aspect, @original_aspect) - - @original_aspect.contacts(true).include?(@contact).should be_false - @new_aspect.contacts(true).include?(@contact).should be_true - end - - it "should not move a person who is not a contact" do - non_contact = eve.person - - expect { - alice.move_contact(non_contact, @new_aspect, @original_aspect) - }.to raise_error - - @original_aspect.contacts.where(:person_id => non_contact.id).should be_empty - @new_aspect.contacts.where(:person_id => non_contact.id).should be_empty - end - - it 'does not try to delete if add person did not go through' do - alice.should_receive(:add_contact_to_aspect).and_return(false) - alice.should_not_receive(:delete_person_from_aspect) - alice.move_contact(bob.person, @new_aspect, @original_aspect) - end - end - end end context 'likes' do @@ -1000,7 +972,7 @@ describe User do user.should_not_receive(:generate_reset_password_token) user.send_reset_password_instructions end - + it "queues up a job to send the reset password instructions" do user = Factory :user Resque.should_receive(:enqueue).with(Jobs::ResetPassword, user.id) -- GitLab