one cuke failing. wip

This commit is contained in:
danielgrippi 2011-05-12 20:41:56 -07:00
parent 60a60733df
commit a9a1280e17
7 changed files with 67 additions and 15 deletions

View file

@ -57,10 +57,17 @@ class AspectsController < ApplicationController
redirect_to :back
elsif request.env['HTTP_REFERER'].include?("aspects/manage")
redirect_to :back
elsif params[:aspect][:share_with]
@contact = Contact.where(:id => params[:aspect][:contact_id]).first
elsif params[:aspect][:person_id]
@person = Person.where(:id => params[:aspect][:person_id]).first
@contact = current_user.contact_for(@person) || Contact.new
if @contact = current_user.contact_for(@person)
@contact.aspects << @aspect
else
@contact = current_user.share_with(@person, @aspect)
end
else
respond_with @aspect
end

View file

@ -81,4 +81,14 @@ module AspectGlobalHelper
aspects_path
end
end
end
def aspect_dropdown_list_item(aspect, contact, person)
checked = contact.persisted? && aspect.contacts.include?(contact) ? "checked=\"checked\"" : ""
str = "<li data-aspect_id=#{aspect.id}>"
str << "<input #{checked} id=\"in_aspect\" name=\"in_aspect\" type=\"checkbox\" value=\"in_aspect\" />"
str << aspect.name
str << "<div class=\"hidden\">"
str << aspect_membership_button(aspect, contact, person)
str.html_safe
end
end

View file

@ -1,3 +1,2 @@
$('#aspects_list ul').append("<%= escape_javascript( render('aspects/aspect_list_item', :aspect => @aspect, :person => @person, :contact => @contact)) %>");
$("#aspects_list ul li[data-guid='<%= @aspect.id %>'] .add.button").click();
$('ul.dropdown_list[data-person_id=<%= @person.id %>] .newItem').before("<%= escape_javascript( render('contacts/aspect_dropdown_list_item', :aspect => @aspect, :person => @person, :contact => @contact)) %>");

View file

@ -8,12 +8,21 @@
&#9660;
.wrapper
%ul.dropdown_list{:unSelectable => 'on'}
%ul.dropdown_list{:unSelectable => 'on', 'data-person_id' => ((@person.id) if @person)}
- for aspect in @all_aspects
%li{:data => {:aspect_id => aspect.id}}
= check_box_tag "in_aspect", "in_aspect", (contact.persisted? && aspect.contacts.include?(contact))
= aspect.name
.hidden
= aspect_membership_button(aspect, contact, person)
= aspect_dropdown_list_item(aspect, contact, person)
%li.newItem
.add_aspect
= form_for(Aspect.new, :remote => true) do |aspect|
= aspect.error_messages
= aspect.hidden_field :person_id, :value => person.id if person
= aspect.hidden_field :share_with, :value => true
%p
= aspect.text_field :name, :style => "display:inline;"
%p.checkbox_select
= aspect.label :contacts_visible, t('aspects.edit.make_aspect_list_visible')
= aspect.check_box :contacts_visible, :checked => true, :default => true
.right
= aspect.submit t('contacts.share_with_pane.add_new_aspect'), :class => 'button'

View file

@ -0,0 +1,6 @@
-# Copyright (c) 2011, Diaspora Inc. This file is
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
= aspect_dropdown_list_item(aspect, contact, person)

View file

@ -11,13 +11,14 @@
}
};
var processClick = function(li, evt){
var button = li.find('.button');
if(button.hasClass('disabled') || li.hasClass('newItem')){ return; }
evt.preventDefault();
if(li.find('.button').hasClass('disabled')){ return; }
var checkbox = li.find('input[type=checkbox]');
toggleCheckbox(checkbox);
$.fn.callRemote.apply(li.find(".button"));
$.fn.callRemote.apply(button);
};
$(document).ready(function(){

View file

@ -221,6 +221,26 @@ describe AspectsController do
post :create, "aspect" => {"name" => "new aspect"}
response.should redirect_to(aspect_path(Aspect.find_by_name("new aspect")))
end
context "with person_id param" do
it "creates a contact if one does not already exist" do
lambda {
post :create, :format => 'js', :aspect => {:name => "new", :person_id => eve.person.id}
}.should change{
alice.contacts.count
}.by(1)
end
it "adds a new contact to the new aspect" do
post :create, :format => 'js', :aspect => {:name => "new", :person_id => eve.person.id}
alice.aspects.find_by_name("new").contacts.count.should == 1
end
it "adds an existing contact to the new aspect" do
post :create, :format => 'js', :aspect => {:name => "new", :person_id => bob.person.id}
alice.aspects.find_by_name("new").contacts.count.should == 1
end
end
end
context "with invalid params" do
it "does not create an aspect" do