parent
98b345305e
commit
e3b3da404f
11 changed files with 71 additions and 27 deletions
|
|
@ -3,6 +3,7 @@
|
|||
## Refactor
|
||||
|
||||
## Bug fixes
|
||||
* Fix fetching comments after fetching likes [#7167](https://github.com/diaspora/diaspora/pull/7167)
|
||||
|
||||
## Features
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
app.collections.Reshares = Backbone.Collection.extend({
|
||||
model: app.models.Reshare,
|
||||
url : "/reshares"
|
||||
|
||||
initialize: function(models, options) {
|
||||
this.url = "/posts/" + options.post.id + "/reshares";
|
||||
}
|
||||
});
|
||||
// @license-end
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ app.models.Post.Interactions = Backbone.Model.extend({
|
|||
self.post.set({participation: true});
|
||||
self.trigger("change");
|
||||
self.set({"likes_count" : self.get("likes_count") + 1});
|
||||
self.likes.trigger("change");
|
||||
},
|
||||
error: function() {
|
||||
app.flashMessages.error(Diaspora.I18n.t("failed_to_like"));
|
||||
|
|
@ -84,6 +85,7 @@ app.models.Post.Interactions = Backbone.Model.extend({
|
|||
this.userLike().destroy({success : function() {
|
||||
self.trigger('change');
|
||||
self.set({"likes_count" : self.get("likes_count") - 1});
|
||||
self.likes.trigger("change");
|
||||
}});
|
||||
|
||||
app.instrument("track", "Unlike");
|
||||
|
|
@ -116,6 +118,8 @@ app.models.Post.Interactions = Backbone.Model.extend({
|
|||
app.stream.addNow(reshare);
|
||||
}
|
||||
interactions.trigger("change");
|
||||
interactions.set({"reshares_count": interactions.get("reshares_count") + 1});
|
||||
interactions.reshares.trigger("change");
|
||||
})
|
||||
.fail(function(){
|
||||
app.flashMessages.error(Diaspora.I18n.t("reshares.duplicate"));
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ app.views.LikesInfo = app.views.Base.extend({
|
|||
tooltipSelector : ".avatar",
|
||||
|
||||
initialize : function() {
|
||||
this.model.interactions.bind('change', this.render, this);
|
||||
this.model.interactions.likes.on("change", this.render, this);
|
||||
this.displayAvatars = false;
|
||||
},
|
||||
|
||||
|
|
@ -19,18 +19,16 @@ app.views.LikesInfo = app.views.Base.extend({
|
|||
return _.extend(this.defaultPresenter(), {
|
||||
likes : this.model.interactions.likes.toJSON(),
|
||||
likesCount : this.model.interactions.likesCount(),
|
||||
displayAvatars : this.model.interactions.get("fetched") && this.displayAvatars
|
||||
displayAvatars: this.displayAvatars
|
||||
});
|
||||
},
|
||||
|
||||
showAvatars : function(evt){
|
||||
if(evt) { evt.preventDefault() }
|
||||
this.displayAvatars = true;
|
||||
if(!this.model.interactions.get("fetched")){
|
||||
this.model.interactions.fetch();
|
||||
} else {
|
||||
this.model.interactions.trigger("change");
|
||||
}
|
||||
this.model.interactions.likes.fetch({success: function() {
|
||||
this.model.interactions.likes.trigger("change");
|
||||
}.bind(this)});
|
||||
}
|
||||
});
|
||||
// @license-end
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ app.views.ResharesInfo = app.views.Base.extend({
|
|||
tooltipSelector : ".avatar",
|
||||
|
||||
initialize : function() {
|
||||
this.model.interactions.bind("change", this.render, this);
|
||||
this.model.interactions.reshares.bind("change", this.render, this);
|
||||
this.displayAvatars = false;
|
||||
},
|
||||
|
||||
|
|
@ -19,18 +19,16 @@ app.views.ResharesInfo = app.views.Base.extend({
|
|||
return _.extend(this.defaultPresenter(), {
|
||||
reshares : this.model.interactions.reshares.toJSON(),
|
||||
resharesCount : this.model.interactions.resharesCount(),
|
||||
displayAvatars : this.model.interactions.get("fetched") && this.displayAvatars
|
||||
displayAvatars: this.displayAvatars
|
||||
});
|
||||
},
|
||||
|
||||
showAvatars : function(evt){
|
||||
if(evt) { evt.preventDefault() }
|
||||
this.displayAvatars = true;
|
||||
if(!this.model.interactions.get("fetched")){
|
||||
this.model.interactions.fetch();
|
||||
} else {
|
||||
this.model.interactions.trigger("change");
|
||||
}
|
||||
this.model.interactions.reshares.fetch({success: function() {
|
||||
this.model.interactions.reshares.trigger("change");
|
||||
}.bind(this)});
|
||||
}
|
||||
});
|
||||
// @license-end
|
||||
|
|
|
|||
|
|
@ -73,3 +73,16 @@ Feature: commenting
|
|||
When I follow "less than a minute ago" within ".comments .comment:last-child"
|
||||
Then I should see "I think that’s a cat" within ".comments .comment .highlighted"
|
||||
And I should have scrolled down
|
||||
|
||||
Scenario: Show more comments after loading likes
|
||||
When "alice@alice.alice" has commented a lot on "Look at this dog"
|
||||
And "alice@alice.alice" has liked the post "Look at this dog"
|
||||
And I am on "alice@alice.alice"'s page
|
||||
Then I should see "Look at this dog"
|
||||
And I should not see "Comment 2"
|
||||
|
||||
When I follow "1 Like"
|
||||
Then I should not see "1 Like"
|
||||
|
||||
When I click on selector ".toggle_post_comments"
|
||||
Then I should see "Comment 2"
|
||||
|
|
|
|||
5
features/step_definitions/like_steps.rb
Normal file
5
features/step_definitions/like_steps.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
Given /^"([^"]*)" has liked the post "([^"]*)"$/ do |email, post_text|
|
||||
user = User.find_by(email: email)
|
||||
post = StatusMessage.find_by(text: post_text)
|
||||
user.like!(post)
|
||||
end
|
||||
|
|
@ -98,7 +98,7 @@ describe ResharesController, :type => :controller do
|
|||
expect(JSON.parse(response.body).map {|h| h["id"] }).to eq(@post.reshares.map(&:id))
|
||||
end
|
||||
|
||||
it "returns an empty array for a post with no likes" do
|
||||
it "returns an empty array for a post with no reshares" do
|
||||
get :index, post_id: @post.id, format: :json
|
||||
expect(JSON.parse(response.body)).to eq([])
|
||||
end
|
||||
|
|
|
|||
|
|
@ -40,6 +40,13 @@ describe("app.models.Post.Interactions", function(){
|
|||
jasmine.Ajax.requests.mostRecent().respondWith(ajaxSuccess);
|
||||
expect(this.post.get("participation")).toBeTruthy();
|
||||
});
|
||||
|
||||
it("triggers a change on the likes collection", function() {
|
||||
spyOn(this.interactions.likes, "trigger");
|
||||
this.interactions.like();
|
||||
jasmine.Ajax.requests.mostRecent().respondWith(ajaxSuccess);
|
||||
expect(this.interactions.likes.trigger).toHaveBeenCalledWith("change");
|
||||
});
|
||||
});
|
||||
|
||||
describe("unlike", function(){
|
||||
|
|
@ -56,7 +63,7 @@ describe("app.models.Post.Interactions", function(){
|
|||
this.reshare = this.interactions.post.reshare();
|
||||
});
|
||||
|
||||
it("triggers a change on the model", function() {
|
||||
it("triggers a change on the interactions model", function() {
|
||||
spyOn(this.interactions, "trigger");
|
||||
|
||||
this.interactions.reshare();
|
||||
|
|
@ -65,6 +72,13 @@ describe("app.models.Post.Interactions", function(){
|
|||
expect(this.interactions.trigger).toHaveBeenCalledWith("change");
|
||||
});
|
||||
|
||||
it("triggers a change on the reshares collection", function() {
|
||||
spyOn(this.interactions.reshares, "trigger");
|
||||
this.interactions.reshare();
|
||||
jasmine.Ajax.requests.mostRecent().respondWith(ajaxSuccess);
|
||||
expect(this.interactions.reshares.trigger).toHaveBeenCalledWith("change");
|
||||
});
|
||||
|
||||
it("adds the reshare to the default, activity and aspects stream", function() {
|
||||
app.stream = { addNow: $.noop };
|
||||
spyOn(app.stream, "addNow");
|
||||
|
|
|
|||
|
|
@ -21,19 +21,23 @@ describe("app.views.LikesInfo", function(){
|
|||
|
||||
it("fires on a model change", function(){
|
||||
spyOn(this.view, "postRenderTemplate");
|
||||
this.view.model.interactions.trigger('change');
|
||||
this.view.model.interactions.likes.trigger("change");
|
||||
expect(this.view.postRenderTemplate).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("showAvatars", function(){
|
||||
beforeEach(function(){
|
||||
spyOn(this.post.interactions, "fetch").and.callThrough();
|
||||
it("calls fetch on the model's like collection", function() {
|
||||
spyOn(this.post.interactions.likes, "fetch").and.callThrough();
|
||||
this.view.showAvatars();
|
||||
expect(this.post.interactions.likes.fetch).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("calls fetch on the model's like collection", function(){
|
||||
it("triggers 'change' on the likes collection", function() {
|
||||
spyOn(this.post.interactions.likes, "trigger");
|
||||
this.view.showAvatars();
|
||||
expect(this.post.interactions.fetch).toHaveBeenCalled();
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({status: 200, responseText: "{\"id\": 1}"});
|
||||
expect(this.post.interactions.likes.trigger).toHaveBeenCalledWith("change");
|
||||
});
|
||||
|
||||
it("sets 'displayAvatars' to true", function(){
|
||||
|
|
|
|||
|
|
@ -22,19 +22,23 @@ describe("app.views.ResharesInfo", function(){
|
|||
|
||||
it("fires on a model change", function(){
|
||||
spyOn(this.view, "postRenderTemplate");
|
||||
this.view.model.interactions.trigger("change");
|
||||
this.view.model.interactions.reshares.trigger("change");
|
||||
expect(this.view.postRenderTemplate).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("showAvatars", function(){
|
||||
beforeEach(function(){
|
||||
spyOn(this.post.interactions, "fetch").and.callThrough();
|
||||
it("calls fetch on the model's reshare collection", function() {
|
||||
spyOn(this.post.interactions.reshares, "fetch").and.callThrough();
|
||||
this.view.showAvatars();
|
||||
expect(this.post.interactions.reshares.fetch).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("calls fetch on the model's reshare collection", function(){
|
||||
it("triggers 'change' on the reshares collection", function() {
|
||||
spyOn(this.post.interactions.reshares, "trigger");
|
||||
this.view.showAvatars();
|
||||
expect(this.post.interactions.fetch).toHaveBeenCalled();
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({status: 200, responseText: "{\"id\": 1}"});
|
||||
expect(this.post.interactions.reshares.trigger).toHaveBeenCalledWith("change");
|
||||
});
|
||||
|
||||
it("sets 'displayAvatars' to true", function(){
|
||||
|
|
|
|||
Loading…
Reference in a new issue