display reshare counts; test inf scroll & reshare counter in jasmine instead of cucumber

This commit is contained in:
danielgrippi 2012-01-01 14:20:46 -05:00 committed by Dennis Collinson
parent dd85521701
commit dbfb18e249
10 changed files with 98 additions and 78 deletions

View file

@ -21,6 +21,7 @@ class Post < ActiveRecord::Base
t.add :created_at
t.add :comments_count
t.add :likes_count
t.add :reshares_count
t.add :last_three_comments
t.add :provider_display_name
t.add :author

View file

@ -19,6 +19,11 @@
<time class="timeago" datetime="<%= root.created_at %>"/>
</a>
</span>
<% if(root.reshares_count) { %>
-
<%= root.reshares_count %> reshares
<% } %>
</div>
<!-- duplicate from statusmessage partial -->

View file

@ -26,6 +26,11 @@
<a href="/posts/<%= id %>">
<time class="timeago" datetime="<%= created_at %>"/>
</a>
<% if(reshares_count) { %>
-
<%= reshares_count %> reshares
<% } %>
</span>
</div>

View file

@ -1,40 +0,0 @@
@javascript
Feature: infinite scroll
In order to browse without disruption
As medium-sized internet grazing animal
I want the stream to infinite scroll
Background:
Given many posts from alice for bob
And I resize my window to 800x600
And I sign in as "bob@bob.bob"
And I follow "Your Aspects"
And I wait for the ajax to finish
Scenario: on the main stream
When I go to the home page
And I wait for the ajax to finish
Then I should see 15 posts
And I should see "alice - 15 - #seeded"
When I scroll down
Then I should see 30 posts
And I should see "alice - 30 - #seeded"
Scenario: On a tag page
When I go to the tag page for "seeded"
Then I should see 15 posts
And I should see "alice - 15 - #seeded"
When I scroll down
Then I should see 30 posts
And I should see "alice - 30 - #seeded"
Scenario: On a profile page
And I am on "alice@alice.alice"'s page
Then I should see 15 posts
And I should see "alice - 15 - #seeded"
When I scroll down
Then I should see 30 posts
And I should see "alice - 30 - #seeded"

View file

@ -24,16 +24,3 @@ Feature: public repost
Then I should see "reshare this!"
Then I should see a ".reshare"
And I should see "Bob"
# (NOTE) this should be a jasmine spec
Scenario: I can see the number of reshares
Given "bob@bob.bob" has a public post with text "reshare this!"
And I sign in as "alice@alice.alice"
And I wait for the ajax to finish
And I preemptively confirm the alert
And I follow "Reshare"
And I wait for 2 seconds
When I go to the home page
And I wait for the ajax to finish
Then I should see "1 reshare"

View file

@ -22,7 +22,7 @@ app.views.Stream = Backbone.View.extend({
return this;
},
infScroll : function(options) {
infScroll : function() {
if(this.isLoading()) { return }
var $window = $(window);
@ -33,10 +33,12 @@ app.views.Stream = Backbone.View.extend({
if(distFromBottom < bufferPx) {
this.render();
}
return this;
},
isLoading : function(){
return !this._loading.isResolved();
return this._loading && !this._loading.isResolved();
},
addPost : function(post) {

View file

@ -13,10 +13,12 @@ describe MultisController do
it 'generates the multi_stream_json fixture', :fixture => true do
posts = []
posts << alice.post(:status_message, :text => "hella infos yo!", :to => alice.aspects.first.id)
posts << alice.post(:reshare, :root_guid => Factory(:status_message, :public => true).guid, :to => 'all')
posts << alice.post(:status_message, :text => "you're gonna love this.'", :to => alice.aspects.first.id)
alice.like(1, :target => posts.last)
10.times do
posts << alice.post(:status_message, :text => "hella infos yo!", :to => alice.aspects.first.id)
posts << alice.post(:reshare, :root_guid => Factory(:status_message, :public => true).guid, :to => 'all')
posts << alice.post(:status_message, :text => "you're gonna love this.'", :to => alice.aspects.first.id)
alice.like(1, :target => posts.last)
end
time = Time.now
posts.each do |p|
@ -26,9 +28,6 @@ describe MultisController do
get :index, :format => :json
response.should be_success
pp response.body
save_fixture(response.body, "multi_stream_json")
end
end

View file

@ -11,6 +11,22 @@ describe("app.views.Post", function(){
this.statusMessage = this.collection.models[0];
})
it("displays a reshare count", function(){
this.statusMessage.set({reshares_count : 2})
var view = new app.views.Post({model : this.statusMessage}).render();
var statusElement = $(view.el)
expect(statusElement.html()).toContain("2 reshares")
})
it("does not display a reshare count for 'zero'", function(){
this.statusMessage.set({reshares_count : 0})
var view = new app.views.Post({model : this.statusMessage}).render();
var statusElement = $(view.el)
expect(statusElement.html()).not.toContain("0 reshares")
})
context("user not signed in", function(){
it("does not provide a Feedback view", function(){
window.current_user = app.user(null);

View file

@ -1,24 +1,31 @@
describe("app.views.Stream", function(){
beforeEach(function(){
// should be jasmine helper
window.current_user = app.user({name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}});
var posts = $.parseJSON(spec.readFixture("multi_stream_json"))["posts"];
this.collection = new app.collections.Stream(posts);
this.view = new app.views.Stream({collection : this.collection});
// do this manually because we've moved loadMore into render??
this.view.render();
_.each(this.view.collection.models, function(post){
this.view.addPost(post);
}, this);
})
describe("initialize", function(){
it("binds an infinite scroll listener", function(){
})
})
describe("#render", function(){
beforeEach(function(){
// should be jasmine helper
window.current_user = app.user({name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}});
var posts = $.parseJSON(spec.readFixture("multi_stream_json"))["posts"];
this.collection = new app.collections.Stream(posts);
this.statusMessage = this.collection.models[0];
this.reshare = this.collection.models[1];
this.view = new app.views.Stream({collection : this.collection});
// do this manually because we've moved loadMore into render??
this.view.render();
_.each(this.view.collection.models, function(post){
this.view.addPost(post);
}, this);
this.statusElement = $(this.view.$("#" + this.statusMessage.get("guid")));
this.reshareElement = $(this.view.$("#" + this.reshare.get("guid")));
})
@ -29,4 +36,43 @@ describe("app.views.Stream", function(){
})
})
})
describe("infScroll", function(){
// NOTE: inf scroll happens at 300px
beforeEach(function(){
spyOn(this.view.collection, "fetch")
})
context("when the user is at the bottom of the page", function(){
beforeEach(function(){
spyOn($.fn, "height").andReturn(0)
spyOn($.fn, "scrollTop").andReturn(100)
})
it("calls fetch", function(){
spyOn(this.view, "isLoading").andReturn(false)
this.view.infScroll();
expect(this.view.collection.fetch).toHaveBeenCalled();
})
it("does not call fetch", function(){
spyOn(this.view, "isLoading").andReturn(true)
this.view.infScroll();
expect(this.view.collection.fetch).not.toHaveBeenCalled();
})
})
it("does not fetch new content when the user is not at the bottom of the page", function(){
spyOn(this.view, "isLoading").andReturn(false)
spyOn($.fn, "height").andReturn(0);
spyOn($.fn, "scrollTop").andReturn(-400);
this.view.infScroll();
expect(this.view.collection.fetch).not.toHaveBeenCalled();
})
})
})

View file

@ -49,7 +49,6 @@ describe("app.views.Base", function(){
postRenderTemplate : function(){
$(this.el).append("<div class=subview1/>")
$(this.el).append("<div class=subview2/>")
console.log($(this.el).html())
},
createSubview2 : function(){