diff --git a/app/assets/javascripts/app/pages/profile.js b/app/assets/javascripts/app/pages/profile.js index 8c789f382b53990d1dd84cd60cc852bcad966db9..13fa8856643303af77ffec384e9c7a5c5cf22508 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 1636383c1f0bab8a3b471d30384bf80481c44cc4..b6173ac8123678c83773ae8e3a15229cd4f48383 100644 --- a/app/assets/templates/profile.jst.hbs +++ b/app/assets/templates/profile.jst.hbs @@ -1,6 +1,5 @@ <div id="top-right-nav"> - - {{#unless isOwnProfile}} + {{#if showFollowButton}} <a href="#" onClick="alert('Not yet implemented!')" id="follow-button"> <span class="label label-inverse"> <i class="icon-plus icon-white"></i> @@ -9,7 +8,7 @@ </span> </span> </a> - {{/unless}} + {{/if}} <a href="/" id="home-button"> <span class="label label-inverse"> @@ -29,7 +28,6 @@ {{/if}} </div> - <section id="profile-info"/> <div id="composer" style="display:none;"> @@ -47,6 +45,6 @@ {{/if}} </section> -<section id="canvas"/> +<section id="canvas"></section> <div id="paginate"><span class="loader hidden"/></div> \ No newline at end of file diff --git a/app/presenters/user_presenter.rb b/app/presenters/user_presenter.rb index 8fd5af0a191862645f9862506c5f7c401d17c4cb..8b0b7f0c920b68296ea8c757b853b6a3ef5cf731 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 162dfa26b29a66ecd7213292a3e9cd0ab5e9c227..d37cf584d41342f5aed0b0e0cec3e71114189d9c 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() + }) + }) });