diff --git a/app/controllers/aspect_memberships_controller.rb b/app/controllers/aspect_memberships_controller.rb index 6c8c410ec..6e9f8edfc 100644 --- a/app/controllers/aspect_memberships_controller.rb +++ b/app/controllers/aspect_memberships_controller.rb @@ -64,4 +64,26 @@ class AspectMembershipsController < ApplicationController end end + + def update + @person = Person.find(params[:person_id]) + @from_aspect = current_user.aspects.where(:id => params[: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 + end diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index 74791e6aa..edd558933 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -146,25 +146,4 @@ class AspectsController < ApplicationController end @aspect.save end - - def move_contact - @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 end diff --git a/config/routes.rb b/config/routes.rb index 73b068de7..2701b6718 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,7 +8,6 @@ Diaspora::Application.routes.draw do resources :aspects do get 'manage' => :manage, :on => :collection - put 'move_contact' => :move_contact put 'toggle_contact_visibility' => :toggle_contact_visibility end @@ -70,7 +69,7 @@ Diaspora::Application.routes.draw do resources :requests, :only => [:destroy, :create] resources :contacts, :except => [:index, :update] - resources :aspect_memberships, :only => [:destroy, :create] + resources :aspect_memberships, :only => [:destroy, :create, :update] resources :people, :except => [:edit, :update] do resources :status_messages diff --git a/public/javascripts/aspect-edit.js b/public/javascripts/aspect-edit.js index 1c32bce05..e526ed3e0 100644 --- a/public/javascripts/aspect-edit.js +++ b/public/javascripts/aspect-edit.js @@ -64,7 +64,7 @@ var AspectEdit = { var aspect_id = person.attr('data-aspect_id') $.ajax({ type: "PUT", - url: "/aspects/" + aspect_id + "/move_contact", + url: "/aspect_memberships/" + aspect_id, data: { "person_id": person.attr('data-guid'), "to": dropzone.attr('data-aspect_id') diff --git a/spec/controllers/aspect_memberships_controller_spec.rb b/spec/controllers/aspect_memberships_controller_spec.rb index 6f518ac38..b3bfe7681 100644 --- a/spec/controllers/aspect_memberships_controller_spec.rb +++ b/spec/controllers/aspect_memberships_controller_spec.rb @@ -47,6 +47,16 @@ describe AspectMembershipsController do @aspect0.contacts.include?(@contact).should be false end + describe "#update" do + it 'calls the move_contact method' do + @controller.stub!(:current_user).and_return(@user) + @user.should_receive(:move_contact) + put :update, :person_id => @user.person.id, + :id => @aspect0.id, + :to => @aspect1.id + end + end + context 'aspect membership does not exist' do it 'person does not exist' do delete :destroy, diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index 41b0481f3..e7067c9c8 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -253,22 +253,6 @@ describe AspectsController do end end - describe "#move_contact" do - before do - @person = Factory.create(:person) - @opts = { - :person_id => @person.id, - :aspect_id => @alices_aspect_1.id, - :to => @alices_aspect_2.id - } - end - it 'calls the move_contact_method' do - @controller.stub!(:current_user).and_return(@alice) - @alice.should_receive(:move_contact) - put :move_contact, @opts - end - end - describe "#update" do before do @alices_aspect_1 = @alice.aspects.create(:name => "Bruisers")