jasmine green again; template switching in place, defaulting to displaying post text

This commit is contained in:
danielgrippi 2011-12-11 17:33:17 -08:00 committed by Dennis Collinson
parent 8e3db3aebe
commit 34e3403e2e
11 changed files with 68 additions and 17 deletions

View file

@ -24,6 +24,7 @@ class Post < ActiveRecord::Base
t.add :author
t.add :post_type
t.add :image_url
t.add :root
end
xml_attr :provider_display_name

View file

@ -10,3 +10,9 @@
%script{:id => "comment-stream-template", :type => 'text/template'}
!= File.read("#{Rails.root}/app/views/templates/comment_stream.ujs")
%script{:id => "status-message-template", :type => 'text/template'}
!= File.read("#{Rails.root}/app/views/templates/status_message.ujs")
%script{:id => "reshare-template", :type => 'text/template'}
!= File.read("#{Rails.root}/app/views/templates/reshare.ujs")

View file

@ -0,0 +1,4 @@
<p>
<h2>this is a reshare</h2>
<%= root.text %>
</p>

View file

@ -0,0 +1,3 @@
<p>
<%= text %>
</p>

View file

@ -36,9 +36,13 @@
</span>
</div>
<div class="post-content"> </div>
<!--
<p class="post-text">
<%= text %>
</p>
-->
<div class="info">
<% if(provider_display_name != null) { %>

View file

@ -10,6 +10,6 @@ App.Views.Comment = Backbone.View.extend({
App.user()
)));
return this.el;
return this;
}
});

View file

@ -21,7 +21,7 @@ App.Views.CommentStream = Backbone.View.extend({
this.model.comments.each(this.appendComment);
return this.el;
return this;
},
createComment: function(evt) {

View file

@ -0,0 +1,24 @@
App.Views.PostContent = Backbone.View.extend({
initialize: function(options) {
this.model = options.model;
this.template = _.template($(this.template_name).html());
},
render: function() {
this.el = $(this.template($.extend(
this.model.toJSON(),
App.user()
)));
return this;
}
});
App.Views.StatusMessage = App.Views.PostContent.extend({
template_name : "#status-message-template"
});
App.Views.Reshare = App.Views.PostContent.extend({
template_name : "#reshare-template"
});

View file

@ -16,10 +16,19 @@ App.Views.Post = Backbone.View.extend({
model: this.model
}).render());
this.renderPostContent();
this.$(".details time").timeago();
this.$("label").inFieldLabels();
Diaspora.BaseWidget.instantiate("StreamElement", $(this.el));
return this;
},
renderPostContent: function(){
var postClass = App.Views[this.model.get("post_type")] || App.Views.StatusMessage;
var postView = new postClass({ model : this.model });
this.$(".post-content").html(postView.render().el);
return this;
}

View file

@ -17,7 +17,9 @@ describe MultisController do
describe 'jasmine fixtures' do
it 'generate' do
status_message = alice.post(:status_message, :text => "hella infos yo!", :to => alice.aspects.first.id)
alice.post(:status_message, :text => "hella infos yo!", :to => alice.aspects.first.id)
alice.post(:reshare, :root_guid => Factory(:status_message, :public => true).guid, :to => 'all')
get :index, :format => :json
save_fixture(response.body, "multi_stream_json")
end

View file

@ -3,33 +3,31 @@ describe("App.views.Stream", function(){
describe("#render", function(){
beforeEach(function(){
// should be jasmine helper
window.current_user = App.user({name: "alice", avatar : {small : "http://avatar.com"}});
window.current_user = App.user({name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}});
//hella hax
spec.loadFixture("multi_stream_json");
var posts = $.parseJSON($("#jasmine_content").html())["posts"]
var posts = $.parseJSON(spec.readFixture("multi_stream_json"))["posts"];
spec.loadFixture("underscore_templates");
this.collection = new App.Collections.Stream(posts)
this.collection = new App.Collections.Stream(posts);
this.statusMessage = this.collection.models[0];
// this.picture = new App.Models.Post({post_type : "ActivityStreams::Photo", image_url : "http://amazonks.com/pretty_picture_lol.gif"});
this.reshare = this.collection.models[1];
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")));
this.reshareElement = $(this.view.$("#" + this.reshare.get("guid")));
})
context("when rendering a Status Mesasage", function(){
it("shows the status message in the content area", function(){
expect($.trim(this.statusElement.find(".content p.post-text").text())).toBe("hella infos yo!")
expect($.trim(this.statusElement.find(".post-content p").text())).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")
// })
// })
context("when rendering a Reshare", function(){
it("shows the reshare in the content area", function(){
expect($.trim(this.reshareElement.find(".content h2").text())).toBe("this is a reshare");
})
})
})
})