jasmine green again; template switching in place, defaulting to displaying post text
This commit is contained in:
parent
8e3db3aebe
commit
34e3403e2e
11 changed files with 68 additions and 17 deletions
|
|
@ -24,6 +24,7 @@ class Post < ActiveRecord::Base
|
||||||
t.add :author
|
t.add :author
|
||||||
t.add :post_type
|
t.add :post_type
|
||||||
t.add :image_url
|
t.add :image_url
|
||||||
|
t.add :root
|
||||||
end
|
end
|
||||||
|
|
||||||
xml_attr :provider_display_name
|
xml_attr :provider_display_name
|
||||||
|
|
|
||||||
|
|
@ -10,3 +10,9 @@
|
||||||
|
|
||||||
%script{:id => "comment-stream-template", :type => 'text/template'}
|
%script{:id => "comment-stream-template", :type => 'text/template'}
|
||||||
!= File.read("#{Rails.root}/app/views/templates/comment_stream.ujs")
|
!= 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")
|
||||||
|
|
|
||||||
4
app/views/templates/reshare.ujs
Normal file
4
app/views/templates/reshare.ujs
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
<p>
|
||||||
|
<h2>this is a reshare</h2>
|
||||||
|
<%= root.text %>
|
||||||
|
</p>
|
||||||
3
app/views/templates/status_message.ujs
Normal file
3
app/views/templates/status_message.ujs
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
<p>
|
||||||
|
<%= text %>
|
||||||
|
</p>
|
||||||
|
|
@ -36,9 +36,13 @@
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="post-content"> </div>
|
||||||
|
|
||||||
|
<!--
|
||||||
<p class="post-text">
|
<p class="post-text">
|
||||||
<%= text %>
|
<%= text %>
|
||||||
</p>
|
</p>
|
||||||
|
-->
|
||||||
|
|
||||||
<div class="info">
|
<div class="info">
|
||||||
<% if(provider_display_name != null) { %>
|
<% if(provider_display_name != null) { %>
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,6 @@ App.Views.Comment = Backbone.View.extend({
|
||||||
App.user()
|
App.user()
|
||||||
)));
|
)));
|
||||||
|
|
||||||
return this.el;
|
return this;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ App.Views.CommentStream = Backbone.View.extend({
|
||||||
|
|
||||||
this.model.comments.each(this.appendComment);
|
this.model.comments.each(this.appendComment);
|
||||||
|
|
||||||
return this.el;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
createComment: function(evt) {
|
createComment: function(evt) {
|
||||||
|
|
|
||||||
24
public/javascripts/app/views/post_content_view.js
Normal file
24
public/javascripts/app/views/post_content_view.js
Normal 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"
|
||||||
|
});
|
||||||
|
|
@ -16,10 +16,19 @@ App.Views.Post = Backbone.View.extend({
|
||||||
model: this.model
|
model: this.model
|
||||||
}).render());
|
}).render());
|
||||||
|
|
||||||
|
this.renderPostContent();
|
||||||
|
|
||||||
this.$(".details time").timeago();
|
this.$(".details time").timeago();
|
||||||
this.$("label").inFieldLabels();
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,9 @@ describe MultisController do
|
||||||
|
|
||||||
describe 'jasmine fixtures' do
|
describe 'jasmine fixtures' do
|
||||||
it 'generate' 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
|
get :index, :format => :json
|
||||||
save_fixture(response.body, "multi_stream_json")
|
save_fixture(response.body, "multi_stream_json")
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,33 +3,31 @@ describe("App.views.Stream", function(){
|
||||||
describe("#render", function(){
|
describe("#render", function(){
|
||||||
beforeEach(function(){
|
beforeEach(function(){
|
||||||
// should be jasmine helper
|
// 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
|
var posts = $.parseJSON(spec.readFixture("multi_stream_json"))["posts"];
|
||||||
spec.loadFixture("multi_stream_json");
|
|
||||||
var posts = $.parseJSON($("#jasmine_content").html())["posts"]
|
|
||||||
spec.loadFixture("underscore_templates");
|
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.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 = new App.Views.Stream({collection : this.collection});
|
||||||
this.view.render();
|
this.view.render();
|
||||||
this.statusElement = $(this.view.$("#" + this.statusMessage.get("guid")));
|
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(){
|
context("when rendering a Status Mesasage", function(){
|
||||||
it("shows the status message in the content area", 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(){
|
context("when rendering a Reshare", function(){
|
||||||
// it("shows the picture in the content area", function(){
|
it("shows the reshare in the content area", function(){
|
||||||
// expect(this.streamElement.find(".post-content img").attr("src")).toBe("http://amazonks.com/pretty_picture_lol.gif")
|
expect($.trim(this.reshareElement.find(".content h2").text())).toBe("this is a reshare");
|
||||||
// })
|
})
|
||||||
// })
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue