"Add contact" buttons on tag page are smaller and don't appear on top of names.

Moved some logic from view into user model.
This commit is contained in:
Sarah Mei 2011-03-22 13:16:58 -07:00
parent cc01beb3d0
commit 631163ec02
7 changed files with 54 additions and 9 deletions

View file

@ -84,6 +84,12 @@ class User < ActiveRecord::Base
super(conditions)
end
def can_add?(person)
return false if self.person == person
return false if self.contact_for(person).present?
true
end
######### Aspects ######################
def drop_aspect(aspect)
aspect.destroy

View file

@ -0,0 +1,9 @@
- if current_user.can_add?(person)
.add_contact
= link_to image_tag("icons/monotone_plus_add_round.png"),
{:controller => "contacts",
:action => "new",
:person_id => person.id},
:alt => 'add contact from tag',
:class => 'button',
:rel => 'facebox'

View file

@ -37,9 +37,8 @@
.stream_element{:id => person.id}
= person_image_link(person)
- if current_user
.right
= render :partial => 'people/relationship_action',
:locals => { :person => person, :contact => current_user.contact_for(person), :request => nil}
= render :partial => 'people/add_contact_small',
:locals => { :person => person }
.content
%span.from
=person_link(person)

View file

@ -156,4 +156,13 @@ When /^I add the person to my first aspect$/ do
And I wait for the ajax to finish
Then I should see a ".added.button" within "#facebox #aspects_list ul > li:first-child"
}
end
Then /^I should( not)? see an add contact button$/ do |not_see|
expected_length = not_see ? 0 : 1
evaluate_script("$('.add_contact a').length == #{expected_length};")
end
When /^I click on the add contact button$/ do
page.execute_script("$('.add_contact a').click();")
end

View file

@ -13,15 +13,13 @@ Feature: Interacting with tags
Scenario: adding a contact from a tag page
When I search for "#rockstar"
Then I should see "start sharing"
But I should not see "Pending request"
Then I should see an add contact button
When I follow "start sharing"
When I click on the add contact button
Then I should see the contact dialog
When I add the person to my first aspect
And I follow "done editing"
Then I should not see the contact dialog
When I search for "#rockstar"
Then I should not see "start sharing"
But I should see "Pending request"
Then I should not see an add contact button

View file

@ -5,8 +5,11 @@
.tags_show
.side_stream
.stream_element
.right
.add_contact
:display inline
:float right
:font-size 10px
.button
:padding 5px 1px 4px 1px
:margin-right 3px
:font-size 10px

View file

@ -216,6 +216,27 @@ describe User do
end
end
describe "#can_add?" do
it "returns true if there is no existing connection" do
alice.can_add?(eve.person).should be_true
end
it "returns false if the user and the person are the same" do
alice.can_add?(alice.person).should be_false
end
it "returns false if the users are already connected" do
alice.can_add?(bob.person).should be_false
end
it "returns false if the user has already sent a request to that person" do
alice.send_contact_request_to(eve.person, alice.aspects.first)
alice.reload
eve.reload
alice.can_add?(eve.person).should be_false
end
end
describe 'update_user_preferences' do
it 'unsets disable mail and makes the right amount of prefs' do
alice.disable_mail = true