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 :o_embed_cache
|
||||
t.add :user_like
|
||||
t.add :photos
|
||||
t.add lambda { |post|
|
||||
if post.photos_count > 0
|
||||
post.photos
|
||||
else
|
||||
[]
|
||||
end
|
||||
}, :as => :photos
|
||||
end
|
||||
|
||||
xml_attr :provider_display_name
|
||||
|
|
|
|||
|
|
@ -1,4 +1,9 @@
|
|||
<div class="info">
|
||||
<span class="post_scope">
|
||||
<%= public ? "Public" : "Limited" %>
|
||||
</span>
|
||||
–
|
||||
|
||||
<a href="#" class="like_action" rel='nofollow'>
|
||||
<%= user_like ? "Unlike" : "Like" %>
|
||||
</a>
|
||||
|
|
|
|||
|
|
@ -114,7 +114,9 @@ class Stream::Base
|
|||
protected
|
||||
# @return [void]
|
||||
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|
|
||||
hash[like.target_id] = like
|
||||
|
|
|
|||
|
|
@ -13,61 +13,63 @@ describe("app.views.Feedback", function(){
|
|||
this.link = function(){ return this.view.$(".like_action"); }
|
||||
})
|
||||
|
||||
context("when the user likes the post", function(){
|
||||
beforeEach(function(){
|
||||
this.view.render();
|
||||
context("likes", function(){
|
||||
context("when the user likes the post", function(){
|
||||
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(){
|
||||
expect(this.link().text()).toContain('Unlike');
|
||||
})
|
||||
context("when the user doesn't yet like the post", function(){
|
||||
beforeEach(function(){
|
||||
this.view.model.set({user_like : null});
|
||||
this.view.render();
|
||||
})
|
||||
|
||||
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");
|
||||
it("contains a .like_action", function(){
|
||||
expect($(this.view.el).html()).toContain("like_action");
|
||||
})
|
||||
|
||||
this.link().click();
|
||||
expect(likeModel.destroy).toHaveBeenCalled();
|
||||
})
|
||||
})
|
||||
it("the like action should be 'Like'", function(){
|
||||
expect(this.link().text()).toContain('Like');
|
||||
})
|
||||
|
||||
context("when the user doesn't yet like the post", function(){
|
||||
beforeEach(function(){
|
||||
this.view.model.set({user_like : null});
|
||||
this.view.render();
|
||||
})
|
||||
it("allows for unliking a just-liked post", function(){
|
||||
var like = new app.models.Like({id : 2});
|
||||
|
||||
it("contains a .like_action", function(){
|
||||
expect($(this.view.el).html()).toContain("like_action");
|
||||
})
|
||||
spyOn(this.post.likes, "create").andReturn(like);
|
||||
|
||||
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(){
|
||||
var like = new app.models.Like({id : 2});
|
||||
this.view.render();
|
||||
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();
|
||||
expect(this.link().text()).toContain('Unlike');
|
||||
|
||||
// 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');
|
||||
this.view.render();
|
||||
expect(this.link().text()).toContain('Like');
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
|
@ -77,6 +79,10 @@ describe("app.views.Feedback", function(){
|
|||
this.view.render();
|
||||
})
|
||||
|
||||
it("shows 'Public'", function(){
|
||||
expect($(this.view.el).html()).toContain('Public')
|
||||
})
|
||||
|
||||
it("shows a reshare_action link", function(){
|
||||
expect($(this.view.el).html()).toContain('reshare_action')
|
||||
});
|
||||
|
|
@ -96,6 +102,10 @@ describe("app.views.Feedback", function(){
|
|||
this.view.render();
|
||||
})
|
||||
|
||||
it("shows 'Limited'", function(){
|
||||
expect($(this.view.el).html()).toContain('Limited')
|
||||
})
|
||||
|
||||
it("does not show a reshare_action link", function(){
|
||||
expect($(this.view.el).html()).not.toContain('reshare_action');
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue