From 34e3403e2e08ed9e9467d856f0a63e2c87dc852e Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Sun, 11 Dec 2011 17:33:17 -0800 Subject: [PATCH] jasmine green again; template switching in place, defaulting to displaying post text --- app/models/post.rb | 1 + app/views/templates/_templates.haml | 6 +++++ app/views/templates/reshare.ujs | 4 ++++ app/views/templates/status_message.ujs | 3 +++ app/views/templates/stream_element.ujs | 4 ++++ public/javascripts/app/views/comment_view.js | 2 +- .../app/views/commment_stream_view.js | 2 +- .../app/views/post_content_view.js | 24 +++++++++++++++++++ public/javascripts/app/views/post_view.js | 11 ++++++++- spec/controllers/multis_controller_spec.rb | 4 +++- .../javascripts/app/views/stream_view_spec.js | 24 +++++++++---------- 11 files changed, 68 insertions(+), 17 deletions(-) create mode 100644 app/views/templates/reshare.ujs create mode 100644 app/views/templates/status_message.ujs create mode 100644 public/javascripts/app/views/post_content_view.js diff --git a/app/models/post.rb b/app/models/post.rb index 8b2f19285..aa07c888f 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -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 diff --git a/app/views/templates/_templates.haml b/app/views/templates/_templates.haml index 568f74159..dc4ce6110 100644 --- a/app/views/templates/_templates.haml +++ b/app/views/templates/_templates.haml @@ -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") diff --git a/app/views/templates/reshare.ujs b/app/views/templates/reshare.ujs new file mode 100644 index 000000000..a17216e06 --- /dev/null +++ b/app/views/templates/reshare.ujs @@ -0,0 +1,4 @@ +

+

this is a reshare

+ <%= root.text %> +

diff --git a/app/views/templates/status_message.ujs b/app/views/templates/status_message.ujs new file mode 100644 index 000000000..a36daca39 --- /dev/null +++ b/app/views/templates/status_message.ujs @@ -0,0 +1,3 @@ +

+ <%= text %> +

diff --git a/app/views/templates/stream_element.ujs b/app/views/templates/stream_element.ujs index 9b0c203db..491f30586 100644 --- a/app/views/templates/stream_element.ujs +++ b/app/views/templates/stream_element.ujs @@ -36,9 +36,13 @@ +
+ +
<% if(provider_display_name != null) { %> diff --git a/public/javascripts/app/views/comment_view.js b/public/javascripts/app/views/comment_view.js index a5685cf4e..1e91da727 100644 --- a/public/javascripts/app/views/comment_view.js +++ b/public/javascripts/app/views/comment_view.js @@ -10,6 +10,6 @@ App.Views.Comment = Backbone.View.extend({ App.user() ))); - return this.el; + return this; } }); diff --git a/public/javascripts/app/views/commment_stream_view.js b/public/javascripts/app/views/commment_stream_view.js index 7c9931912..1a9d2225b 100644 --- a/public/javascripts/app/views/commment_stream_view.js +++ b/public/javascripts/app/views/commment_stream_view.js @@ -21,7 +21,7 @@ App.Views.CommentStream = Backbone.View.extend({ this.model.comments.each(this.appendComment); - return this.el; + return this; }, createComment: function(evt) { diff --git a/public/javascripts/app/views/post_content_view.js b/public/javascripts/app/views/post_content_view.js new file mode 100644 index 000000000..6a1ded2e1 --- /dev/null +++ b/public/javascripts/app/views/post_content_view.js @@ -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" +}); diff --git a/public/javascripts/app/views/post_view.js b/public/javascripts/app/views/post_view.js index 1a1de904f..1d9a9005c 100644 --- a/public/javascripts/app/views/post_view.js +++ b/public/javascripts/app/views/post_view.js @@ -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; } diff --git a/spec/controllers/multis_controller_spec.rb b/spec/controllers/multis_controller_spec.rb index 8bbe9738b..bed9c7343 100644 --- a/spec/controllers/multis_controller_spec.rb +++ b/spec/controllers/multis_controller_spec.rb @@ -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 diff --git a/spec/javascripts/app/views/stream_view_spec.js b/spec/javascripts/app/views/stream_view_spec.js index 42b5304c8..7715a7aa7 100644 --- a/spec/javascripts/app/views/stream_view_spec.js +++ b/spec/javascripts/app/views/stream_view_spec.js @@ -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"); + }) + }) }) })