diff --git a/app/models/post.rb b/app/models/post.rb index e5d68b9d4..8b2f19285 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -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 diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 20ae83bbd..9b437ff8d 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -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 diff --git a/app/views/shared/_comment.html.underscore b/app/views/templates/_comment.html.underscore similarity index 100% rename from app/views/shared/_comment.html.underscore rename to app/views/templates/_comment.html.underscore diff --git a/app/views/shared/_comment_stream.html.underscore b/app/views/templates/_comment_stream.html.underscore similarity index 100% rename from app/views/shared/_comment_stream.html.underscore rename to app/views/templates/_comment_stream.html.underscore diff --git a/app/views/shared/_stream_element.html.underscore b/app/views/templates/_stream_element.html.underscore similarity index 100% rename from app/views/shared/_stream_element.html.underscore rename to app/views/templates/_stream_element.html.underscore diff --git a/public/javascripts/app/views/post.js b/public/javascripts/app/views/post.js index 12a325b62..1a1de904f 100644 --- a/public/javascripts/app/views/post.js +++ b/public/javascripts/app/views/post.js @@ -21,6 +21,6 @@ App.Views.Post = Backbone.View.extend({ Diaspora.BaseWidget.instantiate("StreamElement", $(this.el)); - return this.el; + return this; } }); diff --git a/public/javascripts/app/views/stream.js b/public/javascripts/app/views/stream.js index 79c2af518..16189f1f8 100644 --- a/public/javascripts/app/views/stream.js +++ b/public/javascripts/app/views/stream.js @@ -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() { diff --git a/spec/controllers/multis_controller_spec.rb b/spec/controllers/multis_controller_spec.rb index 35311af75..7afb5ea57 100644 --- a/spec/controllers/multis_controller_spec.rb +++ b/spec/controllers/multis_controller_spec.rb @@ -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 diff --git a/spec/javascripts/app/views/stream_view_spec.js b/spec/javascripts/app/views/stream_view_spec.js new file mode 100644 index 000000000..23380f679 --- /dev/null +++ b/spec/javascripts/app/views/stream_view_spec.js @@ -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") + // }) + // }) + }) +}) diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index aaf881e1d..4d6a2fdcc 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -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)