diff --git a/app/assets/javascripts/app/pages/profile.js b/app/assets/javascripts/app/pages/profile.js index 5f97e329f..93afc54f4 100644 --- a/app/assets/javascripts/app/pages/profile.js +++ b/app/assets/javascripts/app/pages/profile.js @@ -37,9 +37,7 @@ app.pages.Profile = app.views.Base.extend({ this.canvasView = new app.views.Canvas({ model : this.stream }) this.wallpaperForm = new app.forms.Wallpaper() - - // send in isOwnProfile data - this.profileInfo = new app.views.ProfileInfo({ model : this.model.set({isOwnProfile : this.isOwnProfile()}) }) + this.profileInfo = new app.views.ProfileInfo({ model : this.model }) }, presenter : function(){ @@ -47,7 +45,6 @@ app.pages.Profile = app.views.Base.extend({ return _.extend(this.defaultPresenter(), {text : this.model && app.helpers.textFormatter(bio, this.model), - isOwnProfile : this.isOwnProfile(), showFollowButton : this.showFollowButton() }) }, @@ -84,10 +81,6 @@ app.pages.Profile = app.views.Base.extend({ }, showFollowButton : function() { - return this.followingEnabled() && !this.isOwnProfile() - }, - - isOwnProfile : function() { - return(app.currentUser.get("guid") == this.personGUID) + return this.followingEnabled() && !this.model.get("is_own_profile") } }); diff --git a/app/assets/javascripts/app/views/canvas_view.js b/app/assets/javascripts/app/views/canvas_view.js index b3f28af45..ad2681227 100644 --- a/app/assets/javascripts/app/views/canvas_view.js +++ b/app/assets/javascripts/app/views/canvas_view.js @@ -17,7 +17,7 @@ app.views.Canvas = app.views.Base.extend(_.extend({}, app.views.infiniteScrollMi if(person.get("is_own_profile")){ message = "Make something to start the magic." } else { - var name = person.get("full_name") || "" + var name = person.get("name") || "" message = name + " hasn't posted anything yet." } diff --git a/app/assets/javascripts/app/views/small_frame.js b/app/assets/javascripts/app/views/small_frame.js index 0061621e5..64f69a0c2 100644 --- a/app/assets/javascripts/app/views/small_frame.js +++ b/app/assets/javascripts/app/views/small_frame.js @@ -71,7 +71,7 @@ app.views.SmallFrame = app.views.Post.extend({ }, adjustedImageHeight : function() { - if(!this.model.get("photos")[0]) { return } + if(!(this.model.get("photos") || [])[0]) { return } var modifiers = [this.dimensionsClass(), this.colorClass()].join(' ') diff --git a/app/assets/templates/profile-info.jst.hbs b/app/assets/templates/profile-info.jst.hbs index 305bdba72..4b137f1a2 100644 --- a/app/assets/templates/profile-info.jst.hbs +++ b/app/assets/templates/profile-info.jst.hbs @@ -35,7 +35,7 @@ - {{#if isOwnProfile}} + {{#if is_own_profile}} diff --git a/app/assets/templates/profile.jst.hbs b/app/assets/templates/profile.jst.hbs index 75efb74f5..33dbe1490 100644 --- a/app/assets/templates/profile.jst.hbs +++ b/app/assets/templates/profile.jst.hbs @@ -1,4 +1,4 @@ -{{#if isOwnProfile}} +{{#if is_own_profile}}
{{/if}} @@ -34,7 +34,7 @@
{{/if}} - {{#if isOwnProfile}} + {{#if is_own_profile}} @@ -46,7 +46,7 @@
- {{#if isOwnProfile}} + {{#if is_own_profile}} diff --git a/app/models/person.rb b/app/models/person.rb index 015e7f45f..da551adae 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -309,6 +309,11 @@ class Person < ActiveRecord::Base end end + #gross method pulled out from controller, not exactly sure how it should be used. + def shares_with(user) + user.contacts.receiving.where(:person_id => self.id).first if user + end + # @param person [Person] # @param url [String] def update_url(url) @@ -339,6 +344,7 @@ class Person < ActiveRecord::Base end private + def fix_profile Webfinger.new(self.diaspora_handle).fetch self.reload diff --git a/app/presenters/person_presenter.rb b/app/presenters/person_presenter.rb index 0e3045818..df36bcad1 100644 --- a/app/presenters/person_presenter.rb +++ b/app/presenters/person_presenter.rb @@ -29,6 +29,6 @@ class PersonPresenter protected def person_is_following_current_user - @current_user.contacts.receiving.where(:person_id => @person.id).first + @person.shares_with(@current_user) end end \ No newline at end of file diff --git a/spec/controllers/profiles_controller_spec.rb b/spec/controllers/profiles_controller_spec.rb index 9916df70d..94cc429fa 100644 --- a/spec/controllers/profiles_controller_spec.rb +++ b/spec/controllers/profiles_controller_spec.rb @@ -10,33 +10,15 @@ describe ProfilesController do end describe '#show' do - it "returns the user as json" do - get :show, :id => eve.person.guid, :format => :json - JSON.parse(response.body).should include(JSON.parse(eve.person.as_api_response(:backbone).to_json)) - end + let(:mock_person) {mock_model(User)} + let(:mock_presenter) { mock(:as_json => {:rock_star => "Jamie Cai"})} - it "returns the user's public information if a user is not logged in" do - sign_out :user - get :show, :id => eve.person.guid, :format => :json - JSON.parse(response.body).should include(JSON.parse(eve.person.as_api_response(:backbone).to_json)) - end + it "returns a post Presenter" do + Person.should_receive(:find_by_guid!).with("12345").and_return(mock_person) + PersonPresenter.should_receive(:new).with(mock_person, eve).and_return(mock_presenter) - it "returns the user's public information if a user is logged in and the visiting user is not receiving" do - sign_in :user, alice - get :show, :id => eve.person.guid, :format => :json - response.body.should_not match(/.location./) - end - - it "returns the user's private information if a user is logged in and the visiting user is receiving" do - sign_in :user, bob - get :show, :id => eve.person.guid, :format => :json - response.body.should match(/.location./) - end - - it "returns the user's private information if a user is logged in as herself" do - sign_in :user, eve - get :show, :id => eve.person.guid, :format => :json - response.body.should match(/.location./) + get :show, :id => 12345, :format => :json + response.body.should == {:rock_star => "Jamie Cai"}.to_json end end diff --git a/spec/javascripts/app/pages/profile_spec.js b/spec/javascripts/app/pages/profile_spec.js index dc8b88a7e..1f723543f 100644 --- a/spec/javascripts/app/pages/profile_spec.js +++ b/spec/javascripts/app/pages/profile_spec.js @@ -33,7 +33,7 @@ describe("app.pages.Profile", function(){ describe("rendering", function(){ context("with no posts", function(){ beforeEach(function(){ - this.profile.set({"full_name" : "Alice Waters", person_id : "889"}) + this.profile.set({"name" : "Alice Waters", person_id : "889"}) }) it("has a message that there are no posts", function(){ @@ -59,7 +59,7 @@ describe("app.pages.Profile", function(){ context("profile control pane", function(){ it("shows the edit and create buttons if it's your profile", function() { - spyOn(this.page, "isOwnProfile").andReturn(true) + this.page.model.set({is_own_profile : true}) this.page.render() expect(this.page.$("#profile-controls .control").length).toBe(2) }) @@ -132,23 +132,6 @@ describe("app.pages.Profile", function(){ }) }) - describe("isOwnProfile", function(){ - beforeEach(function(){ - this.user = new app.models.User(factory.author()) - this.page.personGUID = this.user.get("guid") - }) - - it("returns true if app.currentUser matches the current profile's user", function(){ - app.currentUser = this.user - expect(this.page.isOwnProfile()).toBeTruthy() - }) - - it("returns false if app.currentUser does not match the current profile's user", function(){ - app.currentUser = new app.models.User(factory.author({guid : "nope!"})) - expect(this.page.isOwnProfile()).toBeFalsy() - }) - }) - describe("followingEnabled", function(){ /* for legacy beta testers */ it("returns false if following_count is zero", function(){ diff --git a/spec/presenters/person_presenter_spec.rb b/spec/presenters/person_presenter_spec.rb new file mode 100644 index 000000000..521291520 --- /dev/null +++ b/spec/presenters/person_presenter_spec.rb @@ -0,0 +1,32 @@ +require "spec_helper" + +describe PersonPresenter do + let(:profile_user) { Factory(:user_with_aspect) } + let(:person) { profile_user.person } + + describe "#as_json" do + context "with no current_user" do + it "returns the user's public information if a user is not logged in" do + PersonPresenter.new(person, nil).as_json.should include(person.as_api_response(:backbone)) + end + end + + context "with a current_user" do + let(:current_user) { Factory(:user)} + let(:presenter){ PersonPresenter.new(person, current_user) } + + it "doesn't share private information when the users aren't connected" do + presenter.as_json.should_not have_key(:location) + end + + it "has private information when the person is sharing with the current user" do + person.should_receive(:shares_with).with(current_user).and_return(true) + presenter.as_json.should have_key(:location) + end + + it "returns the user's private information if a user is logged in as herself" do + PersonPresenter.new(current_user.person, current_user).as_json.should have_key(:location) + end + end + end +end \ No newline at end of file