Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
activity_ties_*
  • Loading branch information
atd committed Jun 20, 2011
1 parent f9c136c commit 05770b7
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 20 deletions.
18 changes: 9 additions & 9 deletions app/models/actor.rb
Expand Up @@ -257,7 +257,7 @@ def ties_to(a)
def ties_to!(a)
ties_to(a).present? ?
ties_to(a) :
Array(sent_ties.create!(:receiver => a,
Array(sent_ties.create!(:receiver => Actor.normalize(a),
:relation => relation_public))
end

Expand Down Expand Up @@ -313,17 +313,17 @@ def active_ties
@active_ties ||= {}
end

# This {Actor} #allow s subject to create activities and subject has at least one tie to subject
def activity_ties_for(subject)
# subject must {#allow} this {Actor} to create activities in one of the ties to him
def activity_ties_to(subject)
active_ties[subject] ||=
( allow?(subject, 'create', 'activity') ?
subject.ties_to!(self) :
( subject.allow?(self, 'create', 'activity') ?
ties_to!(subject) :
[] )
end

# Builds a hash of options their spheres as keys
def grouped_activity_ties_for(subject)
ties = activity_ties_for(subject)
def grouped_activity_ties_to(subject)
ties = activity_ties_to(subject)

spheres =
ties.map{ |t| t.relation.respond_to?(:sphere) ? t.relation.sphere : I18n.t('relation_public.name') }.uniq
Expand Down Expand Up @@ -353,8 +353,8 @@ def grouped_activity_ties_for(subject)
end

# Is there any {Tie} for subject to create an activity to this {Actor} ?
def activity_ties_for?(subject)
activity_ties_for(subject).any?
def activity_ties_to?(subject)
activity_ties_to(subject).any?
end

def pending_ties
Expand Down
8 changes: 4 additions & 4 deletions app/views/activities/_new.html.erb
@@ -1,4 +1,4 @@
<% if receiver.activity_ties_for?(current_subject) %>
<% if user_signed_in? && current_subject.activity_ties_to?(receiver) %>
<% content_for :javascript do %>

securityImage = "<%= escape_javascript(image_tag('btn/btn_security.png', :id => 'security_image', :alt => 'security')) %>";
Expand All @@ -11,15 +11,15 @@

<div id="activities_header" class="content_size">
<%= form_for Post.new(:text => t('activity.input'),
:_activity_tie_id => receiver.activity_ties_for(current_subject).first.id),
:_activity_tie_id => current_subject.activity_ties_to(receiver).first.id),
:remote => true do |f| %>
<%= f.text_field :text, :id => "input_activities", :size => 85 %>
<div id="activities_share_btn">

<% if receiver.activity_ties_for(current_subject).count > 1 %>
<% if current_subject.activity_ties_to(receiver).count > 1 %>
<div id="securities">
<%= f.select :_activity_tie_id,
grouped_options_for_select(receiver.grouped_activity_ties_for(current_subject)),
grouped_options_for_select(current_subject.grouped_activity_ties_to(receiver)),
{}, :id => 'security' %>
</div>
<% else %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/activities/_options.html.erb
@@ -1,7 +1,7 @@
<div class="activity_options">
<ul class="activity_options" >
<li><div class="post_time_ago"><%= t('time.ago', :time => time_ago_in_words(activity.created_at)) %></div></li>
<% if activity.is_root? && activity.receiver.activity_ties_for?(current_subject) %>
<% if activity.is_root? && current_subject.activity_ties_to?(activity.receiver) %>
<li><div class="verb_comment"> · <%= link_to t('activity.to_comment'), "#", :class => "to_comment" %> </div></li>
<% end %>
<li><div class="verb_like" id="like_<%= dom_id(activity) %>"> · <%= link_like(activity)%></div></li>
Expand Down
6 changes: 3 additions & 3 deletions app/views/comments/_new.html.erb
@@ -1,8 +1,8 @@
<% if activity.receiver.activity_ties_for?(current_subject) %>
<% if user_signed_in? && current_subject.activity_ties_to?(activity.receiver) %>
<div class="activity_new_comment">
<%= form_for Comment.new(:text => t('comment.input'),
:_activity_tie_id =>
activity.receiver.activity_ties_for(current_subject).first.id,
current_subject.activity_ties_to(activity.receiver).first.id,
:_activity_parent_id => activity.id
),
:html => { :class => "new_comment", :id => "new_comment"+dom_id(activity) },
Expand All @@ -16,4 +16,4 @@
</div>
<% end %>
</div>
<% end %>
<% end %>
4 changes: 2 additions & 2 deletions spec/controllers/posts_controller_spec.rb
Expand Up @@ -53,7 +53,7 @@
before do
friend = Factory(:friend, :receiver => @user.actor).sender

model_assigned_to friend.activity_ties_for(@user).first
model_assigned_to @user.activity_ties_to(friend).first
end

it_should_behave_like "Allow Creating"
Expand All @@ -76,7 +76,7 @@

describe "with public relation" do
before do
tie = @group.activity_ties_for(@user).first
tie = @user.activity_ties_to(@group).first
model_assigned_to tie
@current_model = Factory(:post, :_activity_tie_id => tie)
end
Expand Down
12 changes: 11 additions & 1 deletion spec/controllers/users_controller_spec.rb
Expand Up @@ -46,12 +46,22 @@
assert_response :success
end

it "should render self page" do
it "should render other's page" do
get :show, :id => Factory(:user).to_param

assert_response :success
end

it "should render other's page with activity" do
tie = Factory(:friend, :receiver => @user.actor)
friend = tie.sender
Factory(:post, :_activity_tie_id => @user.activity_ties_to(friend).first)

get :show, :id => friend.to_param

response.should be_success
end

it "should render edit page" do
pending "Account section"
get :edit, :id => @user.to_param
Expand Down

0 comments on commit 05770b7

Please sign in to comment.