Jamie Cai DC refactor isOwnProfile, fix tests
This commit is contained in:
parent
cb2c972cee
commit
d1d99d5dd4
10 changed files with 56 additions and 60 deletions
|
|
@ -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")
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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."
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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(' ')
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@
|
|||
</a>
|
||||
</span>
|
||||
|
||||
{{#if isOwnProfile}}
|
||||
{{#if is_own_profile}}
|
||||
<span class="divider">•</span>
|
||||
<a href="/profile/edit" title="Edit Profile" rel="tooltip" style="margin-left:2px;">
|
||||
<i class="icon-cog icon-white"></i>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
{{#if isOwnProfile}}
|
||||
{{#if is_own_profile}}
|
||||
<div id="wallpaper-upload"></div>
|
||||
{{/if}}
|
||||
|
||||
|
|
@ -34,7 +34,7 @@
|
|||
</a>
|
||||
{{/if}}
|
||||
|
||||
{{#if isOwnProfile}}
|
||||
{{#if is_own_profile}}
|
||||
<a href="/users/sign_out" title="Log out" id="logout-button">
|
||||
<span class="label label-inverse">
|
||||
<i class="icon-off icon-white"></i>
|
||||
|
|
@ -46,7 +46,7 @@
|
|||
<section id="profile-info"/>
|
||||
|
||||
<section id="profile-controls">
|
||||
{{#if isOwnProfile}}
|
||||
{{#if is_own_profile}}
|
||||
<a href="#composer" id="composer-button" class="control small" rel="facebox">
|
||||
<img src='{{imageUrl "buttons/pub@2x.png"}}' title="New Post" rel="tooltip"/>
|
||||
</a>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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(){
|
||||
|
|
|
|||
32
spec/presenters/person_presenter_spec.rb
Normal file
32
spec/presenters/person_presenter_spec.rb
Normal file
|
|
@ -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
|
||||
Loading…
Reference in a new issue