diff --git a/app/models/user.rb b/app/models/user.rb index 2f17715092331947123597b38358450e1b26194c..cba4022a532850398e4174d7a4dbe1005fb8a61f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -61,7 +61,7 @@ class User person.save if person end - attr_accessible :getting_started, :password, :password_confirmation, :language, + attr_accessible :getting_started, :password, :password_confirmation, :language, def strip_and_downcase_username if username.present? @@ -81,6 +81,12 @@ class User super end + def has_incoming_request_from(person) + self.pending_requests.select do |req| + req.to_id == self.person.id + end.any? { |req| req.from_id == person.id } + end + ######## Making things work ######## key :email, String @@ -350,7 +356,7 @@ class User self.person.save! self.save! invitations_to_me.each{|invitation| invitation.to_request!} - + self.reload # Because to_request adds a request and saves elsewhere self end @@ -366,7 +372,7 @@ class User def setup(opts) self.username = opts[:username] - + opts[:person] ||= {} opts[:person][:profile] ||= Profile.new diff --git a/app/views/aspects/manage.html.haml b/app/views/aspects/manage.html.haml index f6a0cdb6d39cba40a9ba9519b62674900699890f..c34ba95779b6d7a00510f17cdfca8f98a05014a2 100644 --- a/app/views/aspects/manage.html.haml +++ b/app/views/aspects/manage.html.haml @@ -27,7 +27,7 @@ .x X .circle - = person_image_tag(request.from) + = person_image_link(request.from) = render 'shared/invitations', :invites => @invites @@ -53,7 +53,7 @@ .x X .circle - = person_image_tag(contact.person) + = person_image_link(contact.person) .draggable_info =t('.drag_to_add') diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index bc53f5e367851589d71da92323c618d4c707d3dc..85b460ce0ec65cdd604b4d147e5f677beba01a8a 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -24,6 +24,14 @@ %li %h3= t('.no_posts') + - elsif current_user.has_incoming_request_from(@person) + .floating + %h3 + = t('.incoming_request') + %h4 + = link_to t('.return_to_aspects'), aspects_manage_path + = t('.to_accept_or_ignore') + - else .floating %h3 diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index b5d76b3325635a088d9ad4e3e9123d3331a4a16c..0585eec9150371bd09a406d416792ba3719bd1c3 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -292,6 +292,9 @@ en: results_for: "search results for" show: no_posts: "no posts to display!" + 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!" diff --git a/features/manages_contact_requests.feature b/features/manages_contact_requests.feature index 92a750a4bd3a9dbbf7d76de7019164159372839c..1a42063dfeecb95db4128f68186d7a16847896cb 100644 --- a/features/manages_contact_requests.feature +++ b/features/manages_contact_requests.feature @@ -5,20 +5,28 @@ Feature: managing contact requests And I have an aspect called "Family" And I have one contact request - Scenario: seeing contact requests + Scenario: seeing contact request notifications When I am on the home page Then I should see "Home (1)" in the header + When I follow "Home (1)" + Then I should see "1 new request!" + + @javascript + Scenario: viewing a request's profile + When I am on the aspects manage page + Then I should see 1 contact request + When I click on the contact request + And I wait for the request's profile page to load + Then I should be on the requestor's profile page + And I should see "You have an incoming request from this person" @javascript Scenario: accepting a contact request When I am on the home page - And I follow "Home (1)" - Then I should see "1 new request!" - And I should see 0 contacts in "Family" + And I follow "1 new request!" + Then I should see 0 contacts in "Family" - When I am on the home page - Then I follow "1 new request!" - And I drag the contact request to the "Family" aspect + When I drag the contact request to the "Family" aspect And I wait for the ajax to finish Then I should see 1 contact in "Family" diff --git a/features/step_definitions/custom_web_steps.rb b/features/step_definitions/custom_web_steps.rb index 4dc0222e93d3430213287c46355ebc9e5b9696f3..328bdac31d7db3abb10e43c9d94a480faed6d31e 100644 --- a/features/step_definitions/custom_web_steps.rb +++ b/features/step_definitions/custom_web_steps.rb @@ -26,6 +26,10 @@ When /^I wait for the aspects page to load$/ do wait_until { current_path == aspects_path } end +When /^I wait for the request's profile page to load$/ do + wait_until { current_path == person_path(@me.reload.pending_requests.first.from) } +end + When /^I wait for the ajax to finish$/ do wait_until { evaluate_script("$.active") == 0 } end diff --git a/features/step_definitions/user_steps.rb b/features/step_definitions/user_steps.rb index 8e0b990ea07d82da9a132bf39827b367a7c5d7ed..51a020617d99b068c29c515614fbcbfc7619e35f 100644 --- a/features/step_definitions/user_steps.rb +++ b/features/step_definitions/user_steps.rb @@ -47,4 +47,8 @@ When /^I click "X" on the contact request$/ do window.confirm = function() { return true; }; $(".person.request.ui-draggable .delete").hover().click(); JS -end \ No newline at end of file +end + +When /^I click on the contact request$/ do + find(".person.request.ui-draggable a").click +end diff --git a/features/support/paths.rb b/features/support/paths.rb index 2b0f8572d853746e348caa366d725da4eabae0f8..3ab712fac72302153839ccc8504beb4b0cdfee30 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -9,6 +9,8 @@ module NavigationHelpers send("#{$1.gsub(/\W+/, '_')}_path") when /^my edit profile page$/ edit_person_path(@me.person) + when /^the requestor's profile page$/ + person_path(@me.reload.pending_requests.first.from) when /^"(\/.*)"/ $1 else diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 2088f76b696dff7c4d5e1960eae51b629b18dfe4..c4fb6d472cb8f29228f92a3f544e70550ec4cb05 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -14,6 +14,28 @@ describe User do user.encryption_key.should_not be nil end + describe "#has_incoming_request_from" do + it "returns true if the user has an incoming request from the person" do + user2.send_contact_request_to(user.person, aspect2) + + user.reload + user2.reload + + user.has_incoming_request_from(user2.person).should be_true + end + it "returns false if the user does not have an incoming request from the person" do + user.has_incoming_request_from(user2.person).should be_false + end + it "returns false if the user has requested to be contacts with the person" do + user.send_contact_request_to(user2.person, aspect) + + user.reload + user2.reload + + user.has_incoming_request_from(user2.person).should be_false + end + end + describe 'overwriting people' do it 'does not overwrite old users with factory' do pending "Why do you want to set ids directly? MONGOMAPPERRRRR!!!" @@ -26,9 +48,9 @@ describe User do :email => "ohai@example.com", :password => "password", :password_confirmation => "password", - :person => - {:profile => - {:first_name => "O", + :person => + {:profile => + {:first_name => "O", :last_name => "Hai"} } } @@ -105,12 +127,12 @@ describe User do user = Factory.build(:user, :username => "kittens;") user.should_not be_valid end - + it "can be 32 characters long" do user = Factory.build(:user, :username => "hexagoooooooooooooooooooooooooon") user.should be_valid end - + it "cannot be 33 characters" do user = Factory.build(:user, :username => "hexagooooooooooooooooooooooooooon") user.should_not be_valid @@ -154,9 +176,9 @@ describe User do :email => "ohai@example.com", :password => "password", :password_confirmation => "password", - :person => - {:profile => - {:first_name => "O", + :person => + {:profile => + {:first_name => "O", :last_name => "Hai"} } } @@ -206,10 +228,10 @@ describe User do :email => "ohai@example.com", :password => "password", :password_confirmation => "password", - :person => + :person => {:_id => person.id, - :profile => - {:first_name => "O", + :profile => + {:first_name => "O", :last_name => "Hai"} } } @@ -257,7 +279,7 @@ describe User do it 'sends a notification to aspects' do user.should_receive(:push_to_aspects).twice photo = user.post(:photo, :user_file => uploaded_photo, :caption => "hello", :to => aspect.id) - + user.update_post(photo, :caption => 'hellp') end end