From b22398951eab4576b95e616e737854c82839c004 Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 15 Dec 2010 14:47:55 -0800 Subject: [PATCH] Send requests from the aspect list on the person show page --- app/controllers/aspects_controller.rb | 6 +++- app/helpers/aspects_helper.rb | 16 ++++++++-- app/models/person.rb | 18 +++++++---- app/views/people/_aspect_list.haml | 16 +++++++--- app/views/people/_profile_sidebar.html.haml | 2 +- app/views/people/show.html.haml | 17 ---------- config/locales/diaspora/en.yml | 4 +-- features/connects_users.feature | 9 ++++-- features/step_definitions/custom_web_steps.rb | 10 ++++++ spec/controllers/aspects_controller_spec.rb | 31 +++++++++++++------ spec/models/person_spec.rb | 13 +++----- 11 files changed, 88 insertions(+), 54 deletions(-) diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index 5d1f66058..9f4ace667 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -112,7 +112,11 @@ class AspectsController < ApplicationController @aspect = current_user.aspects.find(params[:aspect_id]) @contact = current_user.contact_for(@person) - current_user.add_contact_to_aspect(@contact, @aspect) + if @contact + current_user.add_contact_to_aspect(@contact, @aspect) + else + current_user.send_contact_request_to(@person, @aspect) + end flash.now[:notice] = I18n.t 'aspects.add_to_aspect.success' respond_to do |format| diff --git a/app/helpers/aspects_helper.rb b/app/helpers/aspects_helper.rb index 2536132da..8a9f08da8 100644 --- a/app/helpers/aspects_helper.rb +++ b/app/helpers/aspects_helper.rb @@ -16,11 +16,23 @@ module AspectsHelper end def add_to_aspect_button(aspect_id, person_id) - link_to image_tag('icons/monotone_plus_add_round.png'), {:controller => "aspects", :action => 'add_to_aspect', :aspect_id => aspect_id, :person_id => person_id}, :remote => true, :class => 'add button' + link_to image_tag('icons/monotone_plus_add_round.png'), + {:controller => "aspects", + :action => 'add_to_aspect', + :aspect_id => aspect_id, + :person_id => person_id}, + :remote => true, + :class => 'add button' end def remove_from_aspect_button(aspect_id, person_id) - link_to image_tag('icons/monotone_check_yes.png'), {:controller => "aspects", :action => 'remove_from_aspect', :aspect_id => aspect_id, :person_id => person_id}, :remote => true, :class => 'added button' + link_to image_tag('icons/monotone_check_yes.png'), + {:controller => "aspects", + :action => 'remove_from_aspect', + :aspect_id => aspect_id, + :person_id => person_id}, + :remote => true, + :class => 'added button' end def aspect_membership_button(aspect_id, contact, person) diff --git a/app/models/person.rb b/app/models/person.rb index 0898cce6c..db0a4fa4c 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -25,9 +25,9 @@ class Person one :profile, :class_name => 'Profile' validates_associated :profile - delegate :first_name, :last_name, :to => :profile - before_save :downcase_diaspora_handle - + delegate :last_name, :to => :profile + before_save :downcase_diaspora_handle + def downcase_diaspora_handle diaspora_handle.downcase! end @@ -35,7 +35,7 @@ class Person belongs_to :owner, :class_name => 'User' timestamps! - + before_destroy :remove_all_traces before_validation :clean_url validates_presence_of :url, :profile, :serialized_public_key @@ -63,7 +63,7 @@ class Person | Person.searchable.all('diaspora_handle' => /^#{q}/i, 'limit' => 30) \ | p end - + return p end @@ -74,7 +74,13 @@ class Person "#{profile.first_name.to_s} #{profile.last_name.to_s}" end end - + def first_name + @first_name ||= if profile.first_name.nil? || profile.first_name.blank? + self.diaspora_handle.split('@').first + else + profile.first_name.to_s + end + end def owns?(post) self.id == post.person.id end diff --git a/app/views/people/_aspect_list.haml b/app/views/people/_aspect_list.haml index 47605869d..795ee47eb 100644 --- a/app/views/people/_aspect_list.haml +++ b/app/views/people/_aspect_list.haml @@ -23,6 +23,13 @@ }); .aspects + - if !contact + %h4 + = t('people.show.not_connected', :name => person.first_name) + - elsif contact.pending + %h4 + = t('people.person.pending_request') + .badges{:class => ("hidden" if !contact)} - for aspect in aspects_with_person = render :partial => 'aspects/aspect_badge', :locals => {:aspect => aspect} @@ -30,17 +37,17 @@ = link_to "edit aspect membership", "#", :id=> "edit_contact_aspects" .edit{:class => ("hidden" if contact)} - .contact_list + .contact_list#aspects_list %ul - for aspect in aspects_with_person - %li + %li{:data=>{:guid=>aspect.id}} %span.name = link_to aspect.name, aspect .right = aspect_membership_button(aspect.id, contact, person) - for aspect in aspects_without_person - %li + %li{:data=>{:guid=>aspect.id}} %span.name = link_to aspect.name, aspect .right @@ -48,4 +55,5 @@ .right = link_to "done editing", "#", :id => "done_contact_aspects" - = link_to t('people.profile_sidebar.remove_contact'), person, :confirm => t('are_you_sure'), :method => :delete + - if contact + = link_to t('people.profile_sidebar.remove_contact'), person, :confirm => t('are_you_sure'), :method => :delete diff --git a/app/views/people/_profile_sidebar.html.haml b/app/views/people/_profile_sidebar.html.haml index 2f9e0ed6c..f2cc51f57 100644 --- a/app/views/people/_profile_sidebar.html.haml +++ b/app/views/people/_profile_sidebar.html.haml @@ -25,7 +25,7 @@ %hr{:style=>"width:300px;"} %ul - - if contact + - unless person == current_user.person %li = render :partial => 'people/aspect_list', :locals => {:person => person, diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index ec32a4fdf..f0c417485 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -31,23 +31,6 @@ = link_to t('.return_to_aspects'), aspects_manage_path = t('.to_accept_or_ignore') - - else - .floating - %h3 - = t('.not_connected', :name => @person.name) - - - unless @outgoing_request - %h3 - .description - = t('.request_people') - - = render :partial =>'requests/new_request_to_person', :locals => {:aspects => @aspects, :destination_handle => @person.diaspora_handle} - - - else - %h3 - .description - = t('.already_requested', :name => @person.name) - - if @posts.count > 0 -if @post_type == :photos %h4 diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 6b1897714..ef1c50da2 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -334,10 +334,8 @@ en: incoming_request: "You have an incoming request from this person." return_to_aspects: "Return to your aspects page" to_accept_or_ignore: "to accept or ignore it." - request_people: "If you'd like, you can request to place him/her in one of your aspects." - already_requested: "You have already sent a request to %{name}." does_not_exist: "Person does not exist!" - not_connected: "You are not connected with this person" + not_connected: "You are not sharing with %{name}" recent_posts: "Recent Posts" recent_public_posts: "Recent Public Posts" edit: diff --git a/features/connects_users.feature b/features/connects_users.feature index 122834502..261ddb382 100644 --- a/features/connects_users.feature +++ b/features/connects_users.feature @@ -8,9 +8,9 @@ Feature: sending and receiving requests Scenario: initiating and accepting a contact request When I sign in as "bob@bob.bob" And I am on "alice@alice.alice"'s page - And I press "add contact" + And I press the first ".add.button" within "#aspects_list ul > li:first-child" And I wait for the ajax to finish - Then I should see "sent!" + Then I should see a ".added.button" within "#aspects_list ul > li:first-child" Then I go to the destroy user session page When I sign in as "alice@alice.alice" @@ -23,4 +23,9 @@ Feature: sending and receiving requests When I go to the home page Then I go to the aspects manage page Then I should see 1 contact in "Besties" + Then I go to the destroy user session page + + When I sign in as "bob@bob.bob" + And I am on the aspects manage page + Then I should see 1 contact in "Besties" diff --git a/features/step_definitions/custom_web_steps.rb b/features/step_definitions/custom_web_steps.rb index bd1f617d9..88a82d4e4 100644 --- a/features/step_definitions/custom_web_steps.rb +++ b/features/step_definitions/custom_web_steps.rb @@ -16,6 +16,16 @@ When /^(.*) in the aspect list$/ do |action| end end +When /^I press the first "([^"]*)"(?: within "([^"]*)")?$/ do |link_selector, within_selector| + with_scope(within_selector) do + find(:css, link_selector).click + end +end +Then /^(?:|I )should see a "([^"]*)"(?: within "([^"]*)")?$/ do |selector, scope_selector| + with_scope(scope_selector) do + page.has_css?(selector).should be_true + end +end Then /^I should see "([^\"]*)" in the main content area$/ do |stuff| within("#main_stream") do Then "I should see #{stuff}" diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index 2f73c17ce..4a23fabc0 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -21,6 +21,7 @@ describe AspectsController do @user.getting_started = false @user.save sign_in :user, @user + @controller.stub(:current_user).and_return(@user) request.env["HTTP_REFERER"] = 'http://' + request.host end @@ -231,25 +232,37 @@ describe AspectsController do @person = Factory(:person) end it 'calls send_contact_request_to' do - + @user.should_receive(:send_contact_request_to).with(@person, @aspect1) + post 'add_to_aspect', + :format => 'js', + :person_id => @person.id, + :aspect_id => @aspect1.id + end + it 'does not call add_contact_to_aspect' do + @user.should_not_receive(:add_contact_to_aspect) + post 'add_to_aspect', + :format => 'js', + :person_id => @person.id, + :aspect_id => @aspect1.id end end it 'adds the users to the aspect' do - @aspect1.reload - @aspect1.contacts.include?(@contact).should be_false - post 'add_to_aspect', :format => 'js', :person_id => @user2.person.id, :aspect_id => @aspect1.id + @user.should_receive(:add_contact_to_aspect) + post 'add_to_aspect', + :format => 'js', + :person_id => @user2.person.id, + :aspect_id => @aspect1.id response.should be_success - @aspect1.reload - @aspect1.contacts.include?(@contact).should be_true end end describe "#remove_from_aspect" do it 'removes contacts from an aspect' do @user.add_contact_to_aspect(@contact, @aspect1) - @aspect.reload - @aspect.contacts.include?(@contact).should be true - post 'remove_from_aspect', :format => 'js', :person_id => @user2.person.id, :aspect_id => @aspect.id + post 'remove_from_aspect', + :format => 'js', + :person_id => @user2.person.id, + :aspect_id => @aspect.id response.should be_success @aspect.reload @aspect.contacts.include?(@contact).should be false diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index 9f422055a..dc71dfca3 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -14,11 +14,6 @@ describe Person do end describe "delegating" do - it "delegates first_name to the profile" do - @person.first_name.should == @person.profile.first_name - @person.profile.update_attributes(:first_name => "Jane") - @person.reload.first_name.should == "Jane" - end it "delegates last_name to the profile" do @person.last_name.should == @person.profile.last_name @person.profile.update_attributes(:last_name => "Heathers") @@ -121,7 +116,7 @@ describe Person do Factory.create(:comment, :person_id => person.id, :diaspora_handle => person.diaspora_handle, :text => "i love you", :post => status_message) Factory.create(:comment, :person_id => @person.id,:diaspora_handle => @person.diaspora_handle, :text => "you are creepy", :post => status_message) - + lambda {person.destroy}.should_not change(Comment, :count) end @@ -245,14 +240,14 @@ describe Person do Person.by_account_identifier("tom@tom.joindiaspora.com").diaspora_handle.should == "tom@tom.joindiaspora.com" end - it 'should only find people who are exact matches (2/2)' do + it 'should only find people who are exact matches (2/2)' do person = Factory(:person, :diaspora_handle => "tomtom@tom.joindiaspora.com") person1 = Factory(:person, :diaspora_handle => "tom@tom.joindiaspora.comm") - f = Person.by_account_identifier("tom@tom.joindiaspora.com") + f = Person.by_account_identifier("tom@tom.joindiaspora.com") f.should be nil end - + end describe '.local_by_account_identifier' do