diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index 53a696a47589bafaab7ceb0f45f3644d5a0a1afa..18c8bd12d05a217c5fab7e228056accc2b4aa20e 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -78,20 +78,6 @@ class AspectsController < ApplicationController respond_with @aspect end - def move_friends - params[:moves].each{ |move| - move = move[1] - unless current_user.move_friend(move) - flash[:error] = I18n.t 'aspects.move_friends.failure', :real_name => Person.find_by_id( move[:friend_id] ).real_name - redirect_to aspects_manage_path - return - end - } - - flash[:notice] = I18n.t 'aspects.move_friends.success' - redirect_to aspects_manage_path - end - def move_friend unless current_user.move_friend( :friend_id => params[:friend_id], :from => params[:from], :to => params[:to][:to]) flash[:error] = I18n.t 'aspects.move_friend.error',:inspect => params.inspect @@ -105,11 +91,20 @@ class AspectsController < ApplicationController end end + def add_to_aspect + if current_user.add_person_to_aspect( params[:friend_id], params[:to_aspect_id]) + flash[:notice] = I18n.t 'aspects.add_to_aspect.success' + render :nothing => true + else + flash[:notice] = I18n.t 'aspects.add_to_aspect.success' + render :nothing => true, :status => 500 + end + end + private def clean_hash(params) return { :name => params[:name] } end - end diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 5f09b603ce67915def1ebea2d8f3dc377b13298f..ab6021d8f3098c1ccad5438a731b5e6c278c55a1 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -104,12 +104,12 @@ en: success: "%{name} was successfully removed." update: success: "Your aspect, %{name}, has been successfully edited." - move_friends: - failure: "Aspect editing failed for friend %{real_name}." - success: "Aspects edited successfully." move_friend: failure: "didn't work %{inspect}" - success: "You are now showing your friend a different aspect of yourself." + success: "Person moved to new aspect" + add_to_aspect: + failure: "Failed to add friend to aspect." + success: "Successfully added friend to aspect." helper: remove: "remove" aspect_not_empty: "Aspect not empty" diff --git a/config/routes.rb b/config/routes.rb index 47e73807ba1c7c1f004e20d974c7630435af5556..166e1492d7881fd3b48733ee13ec1e843dfebf4c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,8 +20,8 @@ Diaspora::Application.routes.draw do match 'users/export_photos', :to => 'users#export_photos' resources :users, :except => [:create, :new, :show] - match 'aspects/move_friends', :to => 'aspects#move_friends', :as => 'move_friends' match 'aspects/move_friend', :to => 'aspects#move_friend', :as => 'move_friend' + match 'aspects/add_to_aspect',:to => 'aspects#add_to_aspect', :as => 'add_to_aspect' match 'aspects/manage', :to => 'aspects#manage' match 'aspects/public', :to => 'aspects#public' resources :aspects, :except => [:edit] diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index 7f5c4bdd135fab8647a4d57c907351fa568db1e4..14314f8d61f1583c53a2730e6f99ae8ea4d573db 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -10,7 +10,10 @@ describe AspectsController do before do @user = Factory.create(:user) @aspect = @user.aspect(:name => "lame-os") - @person = Factory.create(:person) + @aspect1 = @user.aspect(:name => "another aspect") + @user2 = Factory.create(:user) + @aspect2 = @user2.aspect(:name => "party people") + friend_users(@user,@aspect, @user2, @aspect2) sign_in :user, @user end @@ -25,9 +28,9 @@ describe AspectsController do describe "#create" do describe "with valid params" do it "creates an aspect" do - @user.aspects.count.should == 1 + @user.aspects.count.should == 2 post :create, "aspect" => {"name" => "new aspect"} - @user.reload.aspects.count.should == 2 + @user.reload.aspects.count.should == 3 end it "redirects to the aspect page" do post :create, "aspect" => {"name" => "new aspect"} @@ -36,9 +39,9 @@ describe AspectsController do end describe "with invalid params" do it "does not create an aspect" do - @user.aspects.count.should == 1 + @user.aspects.count.should == 2 post :create, "aspect" => {"name" => ""} - @user.reload.aspects.count.should == 1 + @user.reload.aspects.count.should == 2 end it "goes back to manage aspects" do post :create, "aspect" => {"name" => ""} @@ -68,4 +71,14 @@ describe AspectsController do Aspect.find(@aspect.id).user_id.should == @user.id end end + + describe "#add_to_aspect" do + it 'adds the users to the aspect' do + @aspect1.reload + @aspect1.people.include?(@user2.person).should be false + post 'add_to_aspect', {'friend_id' => @user2.person.id, 'to_aspect_id' => @aspect1.id } + @aspect1.reload + @aspect1.people.include?(@user2.person).should be true + end + end end