From 631163ec028b339ba32b12f6204c1c6e54a9c228 Mon Sep 17 00:00:00 2001 From: Sarah Mei Date: Tue, 22 Mar 2011 13:16:58 -0700 Subject: [PATCH] "Add contact" buttons on tag page are smaller and don't appear on top of names. Moved some logic from view into user model. --- app/models/user.rb | 6 ++++++ app/views/people/_add_contact_small.haml | 9 ++++++++ app/views/tags/show.html.haml | 5 ++--- features/step_definitions/custom_web_steps.rb | 9 ++++++++ features/tags.feature | 8 +++---- public/stylesheets/sass/tags.sass | 5 ++++- spec/models/user_spec.rb | 21 +++++++++++++++++++ 7 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 app/views/people/_add_contact_small.haml diff --git a/app/models/user.rb b/app/models/user.rb index f5a16d92c..dbc94e017 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/views/people/_add_contact_small.haml b/app/views/people/_add_contact_small.haml new file mode 100644 index 000000000..72967d0ac --- /dev/null +++ b/app/views/people/_add_contact_small.haml @@ -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' diff --git a/app/views/tags/show.html.haml b/app/views/tags/show.html.haml index 50970b15b..52af3add6 100644 --- a/app/views/tags/show.html.haml +++ b/app/views/tags/show.html.haml @@ -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) diff --git a/features/step_definitions/custom_web_steps.rb b/features/step_definitions/custom_web_steps.rb index 613351df0..210f9e834 100644 --- a/features/step_definitions/custom_web_steps.rb +++ b/features/step_definitions/custom_web_steps.rb @@ -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 \ No newline at end of file diff --git a/features/tags.feature b/features/tags.feature index 93b118134..ba9bebf27 100644 --- a/features/tags.feature +++ b/features/tags.feature @@ -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" \ No newline at end of file + Then I should not see an add contact button diff --git a/public/stylesheets/sass/tags.sass b/public/stylesheets/sass/tags.sass index b755f2a08..23fadf9dd 100644 --- a/public/stylesheets/sass/tags.sass +++ b/public/stylesheets/sass/tags.sass @@ -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 diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 95fd1d6bf..cb40ff534 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -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