Skip to content

Commit

Permalink
Fixes on groups
Browse files Browse the repository at this point in the history
  • Loading branch information
atd committed Jun 30, 2011
1 parent be95f99 commit acd7f6a
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 15 deletions.
4 changes: 2 additions & 2 deletions app/controllers/contacts_controller.rb
Expand Up @@ -4,7 +4,7 @@ class ContactsController < ApplicationController
def index
@contacts =
current_subject.
contacts(:direction => :sent, :relations => params[:relation]){ |q|
contact_subjects(:direction => :sent, :relations => params[:relation]){ |q|
q.alphabetic.
letter(params[:letter]).
search(params[:search])
Expand All @@ -13,7 +13,7 @@ def index
respond_to do |format|
format.html { @contacts = Kaminari.paginate_array(@contacts).page(params[:page]).per(10) }
format.js { @contacts = Kaminari.paginate_array(@contacts).page(params[:page]).per(10) }
format.json { render :text => @contacts.map{ |c| { 'key' => c.id.to_s, 'value' => c.name } }.to_json }
format.json { render :text => @contacts.map{ |c| { 'key' => c.actor_id.to_s, 'value' => c.name } }.to_json }
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/models/actor.rb
Expand Up @@ -198,7 +198,7 @@ def contact_actors(options = {})
# options before the mapping to subjects
#
# See #contact_actors for options
def contacts(options = {})
def contact_subjects(options = {})
as = contact_actors(options)

if block_given?
Expand Down Expand Up @@ -240,7 +240,7 @@ def suggestion(options = {})
# Candidates are all the instance of "type" minus all the subjects
# that are receiving any tie from this actor
candidates = candidates_classes.inject([]) do |cs, klass|
cs += klass.all - contacts(:type => klass.to_s.underscore, :direction => :sent)
cs += klass.all - contact_subjects(:type => klass.to_s.underscore, :direction => :sent)
cs -= Array(subject) if subject.is_a?(klass)
cs
end
Expand Down
11 changes: 5 additions & 6 deletions app/models/group.rb
Expand Up @@ -12,11 +12,11 @@ def profile!
end

def followers
contacts(:subject_type => :user, :direction => :received)
contact_subjects(:subject_type => :user, :direction => :received)
end

def recent_groups
contacts(:type => :group, :direction => :sent) do |q|
contact_subjects(:type => :group, :direction => :sent) do |q|
q.select("contacts.created_at").
merge(Contact.recent)
end
Expand All @@ -39,11 +39,10 @@ def create_participants

@_participants.each do |participant|

#participant_actor = Actor.find_by_slug!(participant)
participant_actor = Actor.find_by_id!(participant)
participant_actor = Actor.find(participant)

sent_contacts.create! :receiver => participant_actor,
:relation_ids => Array(relation_customs.sort.first)
sent_contacts.create! :receiver => participant_actor,
:relation_ids => Array(relation_customs.sort.first.id)
end
end
end
4 changes: 2 additions & 2 deletions app/models/user.rb
Expand Up @@ -19,15 +19,15 @@ class User < ActiveRecord::Base
end

def recent_groups
contacts(:type => :group, :direction => :sent) do |q|
contact_subjects(:type => :group, :direction => :sent) do |q|
q.select("contacts.created_at").
merge(Contact.recent)
end
end

# Subjects this user can acts as
def represented
contacts(:direction => :received) do |q|
contact_subjects(:direction => :received) do |q|
q.joins(:sent_ties => { :relation => :permissions }).merge(Permission.represent)
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/contacts/index.html.erb
Expand Up @@ -17,7 +17,7 @@
<div class="space_center"></div>
<div class="row" >
<div class="center">
<%= link_to t('contact.all_n', :count => current_subject.contacts(:direction => :sent).count), contacts_path %> -
<%= link_to t('contact.all_n', :count => current_subject.contact_subjects(:direction => :sent).count), contacts_path %> -
<% Actor.distinct_initials.
contacted_from(current_subject).
merge(Tie.related_by(current_subject.relation_customs.find_by_id(params[:relation]))).
Expand Down
2 changes: 1 addition & 1 deletion app/views/subjects/_contacts.html.erb
@@ -1,4 +1,4 @@
<% if (cs = subject.contacts(:direction => :sent)).present? %>
<% if (cs = subject.contact_subjects(:direction => :sent)).present? %>
<div class="block">
<div class="header">
<%=image_tag("btn/btn_friend.png", :class => "header_icon")%>
Expand Down
29 changes: 28 additions & 1 deletion spec/controllers/groups_controller_spec.rb
Expand Up @@ -81,7 +81,6 @@
context "a new own group" do
before do
model_attributes[:_founder] = @user.slug
model_attributes[:_participants] = [Factory(:user).id]
end

it "should allow creating" do
Expand All @@ -95,6 +94,34 @@
assigns(:current_subject).should eq(group)
response.should redirect_to(:home)
end

context "with participants" do
before do
@user_participant = Factory(:user)
@group_participant = Factory(:group)

model_attributes[:_participants] = [@user_participant.actor_id, @group_participant.actor_id]
end

it "should allow creating" do
count = Group.count
post :create, attributes

group = assigns(:group)

group.should be_valid
Group.count.should eq(count + 1)
assigns(:current_subject).should eq(group)

participants = group.contact_subjects(:direction => :sent)

participants.should include(@user_participant)
participants.should include(@group_participant)

group.contacts(:direction => :received)
response.should redirect_to(:home)
end
end
end

context "a new fake group" do
Expand Down

0 comments on commit acd7f6a

Please sign in to comment.