AspectsController#move_contact -> AspectMembershipsController#update
This commit is contained in:
parent
d50cfe8d5d
commit
55417cf9e3
6 changed files with 34 additions and 40 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
Loading…
Reference in a new issue