wip
This commit is contained in:
parent
17a801394e
commit
8ae23f5705
6 changed files with 110 additions and 89 deletions
|
|
@ -47,4 +47,27 @@ class AspectMembershipsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@person = Person.find(params[:person_id])
|
||||||
|
@aspect = current_user.aspects.find(params[:aspect_id])
|
||||||
|
@contact = current_user.contact_for(@person)
|
||||||
|
|
||||||
|
|
||||||
|
current_user.add_contact_to_aspect(contact, aspect)
|
||||||
|
|
||||||
|
flash.now[:notice] = I18n.t 'aspects.add_to_aspect.success'
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.js { render :json => {
|
||||||
|
:button_html => render_to_string(:partial => 'aspects/add_to_aspect',
|
||||||
|
:locals => {:aspect_id => @aspect.id,
|
||||||
|
:person_id => @person.id}),
|
||||||
|
:badge_html => render_to_string(:partial => 'aspects/aspect_badge',
|
||||||
|
:locals => {:aspect => @aspect})
|
||||||
|
}}
|
||||||
|
format.html{ redirect_to aspect_path(@aspect.id)}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -55,8 +55,6 @@ class AspectsController < ApplicationController
|
||||||
@person = Person.where(:id => params[:aspect][:person_id]).first
|
@person = Person.where(:id => params[:aspect][:person_id]).first
|
||||||
@contact = current_user.contact_for(@person)
|
@contact = current_user.contact_for(@person)
|
||||||
|
|
||||||
invite_or_add_contact_to_aspect(@aspect, @person, @contact)
|
|
||||||
|
|
||||||
@contact = current_user.contact_for(@person)
|
@contact = current_user.contact_for(@person)
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.js { render :json => {:html => render_to_string(
|
format.js { render :json => {:html => render_to_string(
|
||||||
|
|
@ -155,41 +153,4 @@ class AspectsController < ApplicationController
|
||||||
|
|
||||||
render :text => response_hash.to_json
|
render :text => response_hash.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_to_aspect
|
|
||||||
@person = Person.find(params[:person_id])
|
|
||||||
@aspect = current_user.aspects.find(params[:aspect_id])
|
|
||||||
@contact = current_user.contact_for(@person)
|
|
||||||
|
|
||||||
invite_or_add_contact_to_aspect(@aspect, @person, @contact)
|
|
||||||
|
|
||||||
flash.now[:notice] = I18n.t 'aspects.add_to_aspect.success'
|
|
||||||
|
|
||||||
respond_to do |format|
|
|
||||||
format.js { render :json => {
|
|
||||||
:button_html => render_to_string(:partial => 'aspects/add_to_aspect',
|
|
||||||
:locals => {:aspect_id => @aspect.id,
|
|
||||||
:person_id => @person.id}),
|
|
||||||
:badge_html => render_to_string(:partial => 'aspects/aspect_badge',
|
|
||||||
:locals => {:aspect => @aspect})
|
|
||||||
}}
|
|
||||||
format.html{ redirect_to aspect_path(@aspect.id)}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
def invite_or_add_contact_to_aspect( aspect, person, contact)
|
|
||||||
if contact
|
|
||||||
current_user.add_contact_to_aspect(contact, aspect)
|
|
||||||
else
|
|
||||||
current_user.send_contact_request_to(person, aspect)
|
|
||||||
contact = current_user.contact_for(person)
|
|
||||||
|
|
||||||
if request = Request.where(:sender_id => person.id, :recipient_id => current_user.person.id).first
|
|
||||||
request.destroy
|
|
||||||
contact.update_attributes(:pending => false)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -8,4 +8,37 @@ class ContactsController < ApplicationController
|
||||||
def new
|
def new
|
||||||
render :nothing => true
|
render :nothing => true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@person = Person.find(params[:person_id])
|
||||||
|
@aspect = current_user.aspects.find(params[:aspect_id])
|
||||||
|
|
||||||
|
request_to_aspect(@aspect, @person)
|
||||||
|
|
||||||
|
flash.now[:notice] = I18n.t 'aspects.add_to_aspect.success'
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.js { render :json => {
|
||||||
|
:button_html => render_to_string(:partial => 'aspects/add_to_aspect',
|
||||||
|
:locals => {:aspect_id => @aspect.id,
|
||||||
|
:person_id => @person.id}),
|
||||||
|
:badge_html => render_to_string(:partial => 'aspects/aspect_badge',
|
||||||
|
:locals => {:aspect => @aspect})
|
||||||
|
}}
|
||||||
|
format.html{ redirect_to aspect_path(@aspect.id)}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def request_to_aspect( aspect, person)
|
||||||
|
current_user.send_contact_request_to(person, aspect)
|
||||||
|
contact = current_user.contact_for(person)
|
||||||
|
|
||||||
|
if request = Request.where(:sender_id => person.id, :recipient_id => current_user.person.id).first
|
||||||
|
request.destroy
|
||||||
|
contact.update_attributes(:pending => false)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,18 @@ describe AspectMembershipsController do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#create' do
|
||||||
|
it 'creates an aspect membership' do
|
||||||
|
@user.should_receive(:add_contact_to_aspect)
|
||||||
|
post :create,
|
||||||
|
:format => 'js',
|
||||||
|
:person_id => @user2.person.id,
|
||||||
|
:aspect_id => @aspect1.id
|
||||||
|
response.should be_success
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
describe "#destroy" do
|
describe "#destroy" do
|
||||||
it 'removes contacts from an aspect' do
|
it 'removes contacts from an aspect' do
|
||||||
@user.add_contact_to_aspect(@contact, @aspect1)
|
@user.add_contact_to_aspect(@contact, @aspect1)
|
||||||
|
|
|
||||||
|
|
@ -262,56 +262,6 @@ describe AspectsController do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#add_to_aspect" do
|
|
||||||
context 'with an incoming request' do
|
|
||||||
before do
|
|
||||||
@user3 = Factory.create(:user)
|
|
||||||
@user3.send_contact_request_to(@user.person, @user3.aspects.create(:name => "Walruses"))
|
|
||||||
end
|
|
||||||
it 'deletes the request' do
|
|
||||||
post 'add_to_aspect',
|
|
||||||
:format => 'js',
|
|
||||||
:person_id => @user3.person.id,
|
|
||||||
:aspect_id => @aspect1.id
|
|
||||||
Request.where(:sender_id => @user3.person.id, :recipient_id => @user.person.id).first.should be_nil
|
|
||||||
end
|
|
||||||
it 'does not leave the contact pending' do
|
|
||||||
post 'add_to_aspect',
|
|
||||||
:format => 'js',
|
|
||||||
:person_id => @user3.person.id,
|
|
||||||
:aspect_id => @aspect1.id
|
|
||||||
@user.contact_for(@user3.person).should_not be_pending
|
|
||||||
end
|
|
||||||
end
|
|
||||||
context 'with a non-contact' do
|
|
||||||
before do
|
|
||||||
@person = Factory(:person)
|
|
||||||
end
|
|
||||||
it 'calls send_contact_request_to' do
|
|
||||||
@user.should_receive(:send_contact_request_to).with(@person, @aspect1)
|
|
||||||
post 'add_to_aspect',
|
|
||||||
:format => 'js',
|
|
||||||
:person_id => @person.id,
|
|
||||||
:aspect_id => @aspect1.id
|
|
||||||
end
|
|
||||||
it 'does not call add_contact_to_aspect' do
|
|
||||||
@user.should_not_receive(:add_contact_to_aspect)
|
|
||||||
post 'add_to_aspect',
|
|
||||||
:format => 'js',
|
|
||||||
:person_id => @person.id,
|
|
||||||
:aspect_id => @aspect1.id
|
|
||||||
end
|
|
||||||
end
|
|
||||||
it 'adds the users to the aspect' do
|
|
||||||
@user.should_receive(:add_contact_to_aspect)
|
|
||||||
post 'add_to_aspect',
|
|
||||||
:format => 'js',
|
|
||||||
:person_id => @user2.person.id,
|
|
||||||
:aspect_id => @aspect1.id
|
|
||||||
response.should be_success
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#edit' do
|
describe '#edit' do
|
||||||
it 'renders' do
|
it 'renders' do
|
||||||
get :edit, :id => @aspect0.id
|
get :edit, :id => @aspect0.id
|
||||||
|
|
|
||||||
|
|
@ -21,4 +21,46 @@ describe ContactsController do
|
||||||
response.should be_success
|
response.should be_success
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'create' do
|
||||||
|
context 'with an incoming request' do
|
||||||
|
before do
|
||||||
|
@user3 = Factory.create(:user)
|
||||||
|
@user3.send_contact_request_to(@user.person, @user3.aspects.create(:name => "Walruses"))
|
||||||
|
end
|
||||||
|
it 'deletes the request' do
|
||||||
|
post :create,
|
||||||
|
:format => 'js',
|
||||||
|
:person_id => @user3.person.id,
|
||||||
|
:aspect_id => @aspect1.id
|
||||||
|
Request.where(:sender_id => @user3.person.id, :recipient_id => @user.person.id).first.should be_nil
|
||||||
|
end
|
||||||
|
it 'does not leave the contact pending' do
|
||||||
|
post :create,
|
||||||
|
:format => 'js',
|
||||||
|
:person_id => @user3.person.id,
|
||||||
|
:aspect_id => @aspect1.id
|
||||||
|
@user.contact_for(@user3.person).should_not be_pending
|
||||||
|
end
|
||||||
|
end
|
||||||
|
context 'with a non-contact' do
|
||||||
|
before do
|
||||||
|
@person = Factory(:person)
|
||||||
|
end
|
||||||
|
it 'calls send_contact_request_to' do
|
||||||
|
@user.should_receive(:send_contact_request_to).with(@person, @aspect1)
|
||||||
|
post :create,
|
||||||
|
:format => 'js',
|
||||||
|
:person_id => @person.id,
|
||||||
|
:aspect_id => @aspect1.id
|
||||||
|
end
|
||||||
|
it 'does not call add_contact_to_aspect' do
|
||||||
|
@user.should_not_receive(:add_contact_to_aspect)
|
||||||
|
post :create,
|
||||||
|
:format => 'js',
|
||||||
|
:person_id => @person.id,
|
||||||
|
:aspect_id => @aspect1.id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue