From 52efb3710c84dcc1eab08ab87c2e7be7fb5a9fb5 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Sat, 28 Apr 2012 14:13:43 -0700 Subject: [PATCH] show a follow button for users with pre-existing contacts (legacy beta testers) --- app/assets/javascripts/app/pages/profile.js | 13 +++++-- app/assets/templates/profile.jst.hbs | 8 ++-- app/presenters/user_presenter.rb | 3 +- spec/javascripts/app/pages/profile_spec.js | 41 ++++++++++++++++++--- 4 files changed, 51 insertions(+), 14 deletions(-) diff --git a/app/assets/javascripts/app/pages/profile.js b/app/assets/javascripts/app/pages/profile.js index 8c789f382..13fa88566 100644 --- a/app/assets/javascripts/app/pages/profile.js +++ b/app/assets/javascripts/app/pages/profile.js @@ -24,11 +24,10 @@ app.pages.Profile = app.views.Base.extend({ presenter : function(){ var bio = this.model.get("bio") || '' - console.log(this.isOwnProfile()) - return _.extend(this.defaultPresenter(), {text : this.model && app.helpers.textFormatter(bio, this.model), - isOwnProfile : this.isOwnProfile() }) + isOwnProfile : this.isOwnProfile(), + showFollowButton : this.showFollowButton() }) }, initialize : function(options) { @@ -55,6 +54,14 @@ app.pages.Profile = app.views.Base.extend({ evt.preventDefault(); }, + followingEnabled : function() { + return app.currentUser.get("following_count") != 0 + }, + + showFollowButton : function() { + return this.followingEnabled() && !this.isOwnProfile() + }, + isOwnProfile : function() { return(app.currentUser.get("guid") == this.personGUID) } diff --git a/app/assets/templates/profile.jst.hbs b/app/assets/templates/profile.jst.hbs index 1636383c1..b6173ac81 100644 --- a/app/assets/templates/profile.jst.hbs +++ b/app/assets/templates/profile.jst.hbs @@ -1,6 +1,5 @@
- - {{#unless isOwnProfile}} + {{#if showFollowButton}} @@ -9,7 +8,7 @@ - {{/unless}} + {{/if}} @@ -29,7 +28,6 @@ {{/if}}
-
-
+
\ No newline at end of file diff --git a/app/presenters/user_presenter.rb b/app/presenters/user_presenter.rb index 8fd5af0a1..8b0b7f0c9 100644 --- a/app/presenters/user_presenter.rb +++ b/app/presenters/user_presenter.rb @@ -11,7 +11,8 @@ class UserPresenter :unread_messages_count => unread_messages_count, :admin => admin, :aspects => aspects, - :services => services + :services => services, + :following_count => self.user.contacts.receiving.count } ).to_json(options) end diff --git a/spec/javascripts/app/pages/profile_spec.js b/spec/javascripts/app/pages/profile_spec.js index 162dfa26b..d37cf584d 100644 --- a/spec/javascripts/app/pages/profile_spec.js +++ b/spec/javascripts/app/pages/profile_spec.js @@ -40,11 +40,16 @@ describe("app.pages.Profile", function(){ expect(this.page.$("#profile-controls .control").length).toBe(2) }) - it("shows a follow button if not", function() { -// will fix this in the next commit. -// spyOn(this.page, "isOwnProfile").andReturn(false) -// this.page.render() -// expect(this.page.$("#follow .control").length).toBe(1) + it("shows a follow button if showFollowButton returns true", function() { + spyOn(this.page, "showFollowButton").andReturn(true) + this.page.render() + expect(this.page.$("#follow-button").length).toBe(1) + }) + + it("doesn't show a follow button if showFollowButton returns false", function() { + spyOn(this.page, "showFollowButton").andReturn(false) + this.page.render() + expect(this.page.$("#follow-button").length).toBe(0) }) }) @@ -118,4 +123,30 @@ describe("app.pages.Profile", function(){ expect(this.page.isOwnProfile()).toBeFalsy() }) }) + + describe("followingEnabled", function(){ + /* for legacy beta testers */ + it("returns false if following_count is zero", function(){ + app.currentUser.set({following_count : 0}) + expect(this.page.followingEnabled()).toBeFalsy() + }) + + it("returns false if following_count is zero", function(){ + app.currentUser.set({following_count : 1}) + expect(this.page.followingEnabled()).toBeTruthy() + }) + }) + + describe("followingEnabled", function(){ + /* for legacy beta testers */ + it("returns false if following_count is zero", function(){ + app.currentUser.set({following_count : 0}) + expect(this.page.followingEnabled()).toBeFalsy() + }) + + it("returns false if following_count is zero", function(){ + app.currentUser.set({following_count : 1}) + expect(this.page.followingEnabled()).toBeTruthy() + }) + }) });