DC DG; test stream view WIP

This commit is contained in:
danielgrippi 2011-12-10 19:28:51 -08:00 committed by Dennis Collinson
parent 1d178116e9
commit 52e3f1b240
10 changed files with 70 additions and 13 deletions

View file

@ -22,6 +22,8 @@ class Post < ActiveRecord::Base
t.add :last_three_comments
t.add :provider_display_name
t.add :author
t.add :post_type
t.add :image_url
end
xml_attr :provider_display_name
@ -38,6 +40,10 @@ class Post < ActiveRecord::Base
#scopes
scope :includes_for_a_stream, includes(:o_embed_cache, {:author => :profile}, :mentions => {:person => :profile}) #note should include root and photos, but i think those are both on status_message
def post_type
self.class.name
end
# gives the last three comments on the post
def last_three_comments
return if self.comments_count == 0

View file

@ -74,14 +74,15 @@
%header{:class=>('landing' unless current_user)}
= render 'layouts/header'
%script{:id => "stream-element-template", :type => 'text/template'}
!= File.read("#{Rails.root}/app/views/shared/_stream_element.html.underscore")
- if @backbone
%script{:id => "stream-element-template", :type => 'text/template'}
!= File.read("#{Rails.root}/app/views/templates/_stream_element.html.underscore")
%script{:id => "comment-template", :type => 'text/template'}
!= File.read("#{Rails.root}/app/views/shared/_comment.html.underscore")
%script{:id => "comment-template", :type => 'text/template'}
!= File.read("#{Rails.root}/app/views/templates/_comment.html.underscore")
%script{:id => "comment-stream-template", :type => 'text/template'}
!= File.read("#{Rails.root}/app/views/shared/_comment_stream.html.underscore")
%script{:id => "comment-stream-template", :type => 'text/template'}
!= File.read("#{Rails.root}/app/views/templates/_comment_stream.html.underscore")
.container{:style=> "#{yield(:break_the_mold)}"}
- if @aspsect == :getting_started || @page == :logged_out

View file

@ -21,6 +21,6 @@ App.Views.Post = Backbone.View.extend({
Diaspora.BaseWidget.instantiate("StreamElement", $(this.el));
return this.el;
return this;
}
});

View file

@ -4,16 +4,20 @@ App.Views.Stream = Backbone.View.extend({
},
initialize: function() {
_.bindAll(this, "appendPost", "collectionFetched", "loadMore");
_.bindAll(this, "render", "appendPost", "collectionFetched", "loadMore");
this.collection = new App.Collections.Stream;
this.collection = this.collection || new App.Collections.Stream;
this.collection.bind("add", this.appendPost);
},
render : function(){
_.each(this.collection.models, this.appendPost)
return this
},
appendPost: function(post) {
$(this.el).append(new App.Views.Post({
model: post
}).render());
var postView = new App.Views.Post({ model: post }).render();
$(this.el).append(postView.el);
},
collectionFetched: function() {

View file

@ -15,6 +15,14 @@ describe MultisController do
AppConfig[:community_spotlight] = @old_spotlight_value
end
describe 'jasmine fixtures' do
it 'generate' do
status_message = alice.post(:status_message, :text => "hey", :to => alice.aspects.first.id)
get :index, :format => :json
save_fixture(response.body, "multi_stream_json")
end
end
it 'succeeds' do
AppConfig[:community_spotlight] = [bob.person.diaspora_handle]
get :index

View file

@ -0,0 +1,32 @@
describe("App.views.Stream", function(){
describe("#render", function(){
beforeEach(function(){
//hella hax
spec.loadFixture("multi_stream_json")
var fixtureStream = $.parseJSON($("#jasmine_content").html())
this.statusMessage = new App.Models.Post(fixtureStream["posts"][0] );
// this.picture = new App.Models.Post({post_type : "ActivityStreams::Photo", image_url : "http://amazonks.com/pretty_picture_lol.gif"});
this.collection = new App.Collections.Stream([this.statusMessage]);
this.view = new App.Views.Stream({collection : this.collection});
this.view.render();
this.statusElement = $(this.view.$("#" + this.statusMessage.get("guid")));
//this.pictureElement = $(this.view.$("#" + this.picture.get("guid")));
})
context("when rendering a Status Mesasage", function(){
it("shows the status message in the content area", function(){
// we need to load the underscore templates here, otherwise our views won't render!
expect(this.statusElement.find(".post-content p")).toBe("hella infos yo!")
})
})
// context("when rendering a Picture", function(){
// it("shows the picture in the content area", function(){
// expect(this.streamElement.find(".post-content img").attr("src")).toBe("http://amazonks.com/pretty_picture_lol.gif")
// })
// })
})
})

View file

@ -132,7 +132,6 @@ describe Post do
end
end
describe 'validations' do
it 'validates uniqueness of guid and does not throw a db error' do
message = Factory(:status_message)
@ -140,6 +139,13 @@ describe Post do
end
end
describe 'post_type' do
it 'returns the class constant' do
status_message = Factory(:status_message)
status_message.post_type.should == "StatusMessage"
end
end
describe 'deletion' do
it 'should delete a posts comments on delete' do
post = Factory.create(:status_message, :author => @user.person)