only load photos for a post if photos_count > 0; display 'limited' or 'public' in stream elements; fix small like bug in stream
This commit is contained in:
parent
71bae10317
commit
64a90a30ef
4 changed files with 69 additions and 46 deletions
|
|
@ -31,7 +31,13 @@ class Post < ActiveRecord::Base
|
||||||
t.add :root
|
t.add :root
|
||||||
t.add :o_embed_cache
|
t.add :o_embed_cache
|
||||||
t.add :user_like
|
t.add :user_like
|
||||||
t.add :photos
|
t.add lambda { |post|
|
||||||
|
if post.photos_count > 0
|
||||||
|
post.photos
|
||||||
|
else
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
}, :as => :photos
|
||||||
end
|
end
|
||||||
|
|
||||||
xml_attr :provider_display_name
|
xml_attr :provider_display_name
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,9 @@
|
||||||
<div class="info">
|
<div class="info">
|
||||||
|
<span class="post_scope">
|
||||||
|
<%= public ? "Public" : "Limited" %>
|
||||||
|
</span>
|
||||||
|
–
|
||||||
|
|
||||||
<a href="#" class="like_action" rel='nofollow'>
|
<a href="#" class="like_action" rel='nofollow'>
|
||||||
<%= user_like ? "Unlike" : "Like" %>
|
<%= user_like ? "Unlike" : "Like" %>
|
||||||
</a>
|
</a>
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,9 @@ class Stream::Base
|
||||||
protected
|
protected
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def like_posts_for_stream!(posts)
|
def like_posts_for_stream!(posts)
|
||||||
likes = Like.where(:target_id => posts.map(&:id), :target_type => "Post")
|
return posts unless @user
|
||||||
|
|
||||||
|
likes = Like.where(:author_id => @user.person.id, :target_id => posts.map(&:id), :target_type => "Post")
|
||||||
|
|
||||||
like_hash = likes.inject({}) do |hash, like|
|
like_hash = likes.inject({}) do |hash, like|
|
||||||
hash[like.target_id] = like
|
hash[like.target_id] = like
|
||||||
|
|
|
||||||
|
|
@ -13,61 +13,63 @@ describe("app.views.Feedback", function(){
|
||||||
this.link = function(){ return this.view.$(".like_action"); }
|
this.link = function(){ return this.view.$(".like_action"); }
|
||||||
})
|
})
|
||||||
|
|
||||||
context("when the user likes the post", function(){
|
context("likes", function(){
|
||||||
beforeEach(function(){
|
context("when the user likes the post", function(){
|
||||||
this.view.render();
|
beforeEach(function(){
|
||||||
|
this.view.render();
|
||||||
|
})
|
||||||
|
|
||||||
|
it("the like action should be 'Unlike'", function(){
|
||||||
|
expect(this.link().text()).toContain('Unlike');
|
||||||
|
})
|
||||||
|
|
||||||
|
it("removes like when Unlike is clicked", function() {
|
||||||
|
var likeModel = new app.models.Like(this.view.model.get("user_like"));
|
||||||
|
spyOn(this.view.model.likes, "get").andReturn(likeModel);
|
||||||
|
spyOn(likeModel, "destroy");
|
||||||
|
|
||||||
|
this.link().click();
|
||||||
|
expect(likeModel.destroy).toHaveBeenCalled();
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it("the like action should be 'Unlike'", function(){
|
context("when the user doesn't yet like the post", function(){
|
||||||
expect(this.link().text()).toContain('Unlike');
|
beforeEach(function(){
|
||||||
})
|
this.view.model.set({user_like : null});
|
||||||
|
this.view.render();
|
||||||
|
})
|
||||||
|
|
||||||
it("removes like when Unlike is clicked", function() {
|
it("contains a .like_action", function(){
|
||||||
var likeModel = new app.models.Like(this.view.model.get("user_like"));
|
expect($(this.view.el).html()).toContain("like_action");
|
||||||
spyOn(this.view.model.likes, "get").andReturn(likeModel);
|
})
|
||||||
spyOn(likeModel, "destroy");
|
|
||||||
|
|
||||||
this.link().click();
|
it("the like action should be 'Like'", function(){
|
||||||
expect(likeModel.destroy).toHaveBeenCalled();
|
expect(this.link().text()).toContain('Like');
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
context("when the user doesn't yet like the post", function(){
|
it("allows for unliking a just-liked post", function(){
|
||||||
beforeEach(function(){
|
var like = new app.models.Like({id : 2});
|
||||||
this.view.model.set({user_like : null});
|
|
||||||
this.view.render();
|
|
||||||
})
|
|
||||||
|
|
||||||
it("contains a .like_action", function(){
|
spyOn(this.post.likes, "create").andReturn(like);
|
||||||
expect($(this.view.el).html()).toContain("like_action");
|
|
||||||
})
|
|
||||||
|
|
||||||
it("the like action should be 'Like'", function(){
|
expect(this.link().text()).toContain('Like');
|
||||||
expect(this.link().text()).toContain('Like');
|
this.link().click();
|
||||||
})
|
|
||||||
|
|
||||||
it("allows for unliking a just-liked post", function(){
|
this.view.render();
|
||||||
var like = new app.models.Like({id : 2});
|
expect(this.link().text()).toContain('Unlike');
|
||||||
|
|
||||||
spyOn(this.post.likes, "create").andReturn(like);
|
// spying + stubbing for destroy
|
||||||
|
var likeModel = new app.models.Like(this.view.model.get("user_like"));
|
||||||
|
spyOn(this.view.model.likes, "get").andReturn(likeModel);
|
||||||
|
spyOn(likeModel, "destroy").andReturn(function(){
|
||||||
|
this.view.model.set({user_like : null})
|
||||||
|
});
|
||||||
|
|
||||||
expect(this.link().text()).toContain('Like');
|
this.link().click();
|
||||||
this.link().click();
|
|
||||||
|
|
||||||
this.view.render();
|
this.view.render();
|
||||||
expect(this.link().text()).toContain('Unlike');
|
expect(this.link().text()).toContain('Like');
|
||||||
|
})
|
||||||
// spying + stubbing for destroy
|
|
||||||
var likeModel = new app.models.Like(this.view.model.get("user_like"));
|
|
||||||
spyOn(this.view.model.likes, "get").andReturn(likeModel);
|
|
||||||
spyOn(likeModel, "destroy").andReturn(function(){
|
|
||||||
this.view.model.set({user_like : null})
|
|
||||||
});
|
|
||||||
|
|
||||||
this.link().click();
|
|
||||||
|
|
||||||
this.view.render();
|
|
||||||
expect(this.link().text()).toContain('Like');
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -77,6 +79,10 @@ describe("app.views.Feedback", function(){
|
||||||
this.view.render();
|
this.view.render();
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("shows 'Public'", function(){
|
||||||
|
expect($(this.view.el).html()).toContain('Public')
|
||||||
|
})
|
||||||
|
|
||||||
it("shows a reshare_action link", function(){
|
it("shows a reshare_action link", function(){
|
||||||
expect($(this.view.el).html()).toContain('reshare_action')
|
expect($(this.view.el).html()).toContain('reshare_action')
|
||||||
});
|
});
|
||||||
|
|
@ -96,6 +102,10 @@ describe("app.views.Feedback", function(){
|
||||||
this.view.render();
|
this.view.render();
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("shows 'Limited'", function(){
|
||||||
|
expect($(this.view.el).html()).toContain('Limited')
|
||||||
|
})
|
||||||
|
|
||||||
it("does not show a reshare_action link", function(){
|
it("does not show a reshare_action link", function(){
|
||||||
expect($(this.view.el).html()).not.toContain('reshare_action');
|
expect($(this.view.el).html()).not.toContain('reshare_action');
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue