From 8e3db3aebee171a558009801139a9227ffc1d86a Mon Sep 17 00:00:00 2001
From: Dennis Collinson <dennis.collective@gmail.com>
Date: Sun, 11 Dec 2011 14:28:43 -0800
Subject: [PATCH] make jasmine view tests work, load templates, party

---
 app/views/layouts/application.html.haml       |  3 +-
 app/views/templates/stream_element.ujs        | 56 +++++++++----------
 .../app/views/{comment.js => comment_view.js} |  0
 ...ment-stream.js => commment_stream_view.js} |  0
 .../app/views/{post.js => post_view.js}       |  0
 .../app/views/{stream.js => stream_view.js}   |  0
 spec/controllers/multis_controller_spec.rb    |  2 +-
 spec/jasmine_fixtures/template_spec.rb        |  9 +++
 .../javascripts/app/views/stream_view_spec.js | 15 +++--
 spec/support/fixture_generation.rb            |  7 ++-
 10 files changed, 53 insertions(+), 39 deletions(-)
 rename public/javascripts/app/views/{comment.js => comment_view.js} (100%)
 rename public/javascripts/app/views/{comment-stream.js => commment_stream_view.js} (100%)
 rename public/javascripts/app/views/{post.js => post_view.js} (100%)
 rename public/javascripts/app/views/{stream.js => stream_view.js} (100%)
 create mode 100644 spec/jasmine_fixtures/template_spec.rb

diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml
index 52bf259fee..2c4d516205 100644
--- a/app/views/layouts/application.html.haml
+++ b/app/views/layouts/application.html.haml
@@ -74,8 +74,7 @@
     %header{:class=>('landing' unless current_user)}
       = render 'layouts/header'
 
-    - if @backbone
-      = render 'templates/templates'
+    = render 'templates/templates'
 
     .container{:style=> "#{yield(:break_the_mold)}"}
       - if @aspsect == :getting_started || @page == :logged_out
diff --git a/app/views/templates/stream_element.ujs b/app/views/templates/stream_element.ujs
index 6b7ea2f6e5..9b0c203db7 100644
--- a/app/views/templates/stream_element.ujs
+++ b/app/views/templates/stream_element.ujs
@@ -34,41 +34,41 @@
             <time class="timeago" datetime="<%= created_at %>"/>
           </a>
         </span>
+      </div>
 
-        <p>
-          <%= text %>
-        </p>
+      <p class="post-text">
+        <%= text %>
+      </p>
 
-        <div class="info">
-          <% if(provider_display_name != null) { %>
-            <span class="via">
-              via <%= provider_display_name %>
-              -
-            </span>
-          <% } %>
-          <span class="post_scope">
-            <%= public === true ? "Public" : "Limited" %>
+      <div class="info">
+        <% if(provider_display_name != null) { %>
+          <span class="via">
+            via <%= provider_display_name %>
             -
           </span>
-          <a href="#" class="focus_comment_textarea">
-            Comment
-          </a>
-        </div>
+        <% } %>
+        <span class="post_scope">
+          <%= public === true ? "Public" : "Limited" %>
+          -
+        </span>
+        <a href="#" class="focus_comment_textarea">
+          Comment
+        </a>
+      </div>
 
-        <div class="likes on_post">
-          <div class="likes_container">
-            <% if(likes_count > 0){ %>
-              <img alt="Heart" src="/images/icons/heart.png?1322618579"> 
-              <a href="/posts/<%= id %>/likes" class="expand_likes">
-                <%= likes_count %> like
-              </a>
-              <span class="hidden likes_list"></span>
-            <% } %>
-          </div>
+      <div class="likes on_post">
+        <div class="likes_container">
+          <% if(likes_count > 0){ %>
+            <img alt="Heart" src="/images/icons/heart.png?1322618579"> 
+            <a href="/posts/<%= id %>/likes" class="expand_likes">
+              <%= likes_count %> like
+            </a>
+            <span class="hidden likes_list"></span>
+          <% } %>
         </div>
+      </div>
 
-        <div class="comments"> </div>
+      <div class="comments"> </div>
 
-      </div>
     </div>
 </div>
diff --git a/public/javascripts/app/views/comment.js b/public/javascripts/app/views/comment_view.js
similarity index 100%
rename from public/javascripts/app/views/comment.js
rename to public/javascripts/app/views/comment_view.js
diff --git a/public/javascripts/app/views/comment-stream.js b/public/javascripts/app/views/commment_stream_view.js
similarity index 100%
rename from public/javascripts/app/views/comment-stream.js
rename to public/javascripts/app/views/commment_stream_view.js
diff --git a/public/javascripts/app/views/post.js b/public/javascripts/app/views/post_view.js
similarity index 100%
rename from public/javascripts/app/views/post.js
rename to public/javascripts/app/views/post_view.js
diff --git a/public/javascripts/app/views/stream.js b/public/javascripts/app/views/stream_view.js
similarity index 100%
rename from public/javascripts/app/views/stream.js
rename to public/javascripts/app/views/stream_view.js
diff --git a/spec/controllers/multis_controller_spec.rb b/spec/controllers/multis_controller_spec.rb
index 7afb5ea57c..8bbe9738b3 100644
--- a/spec/controllers/multis_controller_spec.rb
+++ b/spec/controllers/multis_controller_spec.rb
@@ -17,7 +17,7 @@ describe MultisController do
 
     describe 'jasmine fixtures' do
       it 'generate' do
-        status_message = alice.post(:status_message, :text => "hey", :to => alice.aspects.first.id)
+        status_message = alice.post(:status_message, :text => "hella infos yo!", :to => alice.aspects.first.id)
         get :index, :format => :json
         save_fixture(response.body, "multi_stream_json")
       end
diff --git a/spec/jasmine_fixtures/template_spec.rb b/spec/jasmine_fixtures/template_spec.rb
new file mode 100644
index 0000000000..3be7d6b705
--- /dev/null
+++ b/spec/jasmine_fixtures/template_spec.rb
@@ -0,0 +1,9 @@
+require "spec_helper"
+
+describe "template generation" do
+  it "generates templates" do
+    extend JasmineFixtureGeneration
+    templates = Haml::Engine.new(Rails.root.join("app", "views", "templates", "_templates.haml").read).render
+    save_fixture(templates, "underscore_templates")
+  end
+end
diff --git a/spec/javascripts/app/views/stream_view_spec.js b/spec/javascripts/app/views/stream_view_spec.js
index 23380f6798..42b5304c8c 100644
--- a/spec/javascripts/app/views/stream_view_spec.js
+++ b/spec/javascripts/app/views/stream_view_spec.js
@@ -2,14 +2,18 @@ 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"}});
+
       //hella hax
-      spec.loadFixture("multi_stream_json") 
-      var fixtureStream = $.parseJSON($("#jasmine_content").html())
+      spec.loadFixture("multi_stream_json");
+      var posts = $.parseJSON($("#jasmine_content").html())["posts"]
+      spec.loadFixture("underscore_templates");
 
-      this.statusMessage = new App.Models.Post(fixtureStream["posts"][0] );
+      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.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")));
@@ -18,8 +22,7 @@ describe("App.views.Stream", function(){
 
     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!")
+        expect($.trim(this.statusElement.find(".content p.post-text").text())).toBe("hella infos yo!")
       })
     })
 
diff --git a/spec/support/fixture_generation.rb b/spec/support/fixture_generation.rb
index d0961589e6..3d8293f00c 100644
--- a/spec/support/fixture_generation.rb
+++ b/spec/support/fixture_generation.rb
@@ -1,5 +1,4 @@
-RSpec::Rails::ControllerExampleGroup.class_eval do
-
+module JasmineFixtureGeneration
   # Saves the markup to a fixture file using the given name
   def save_fixture(markup, name, fixture_path=nil )
     fixture_path = File.join(Rails.root, 'tmp', 'js_dom_fixtures') unless fixture_path
@@ -41,3 +40,7 @@ RSpec::Rails::ControllerExampleGroup.class_eval do
   end
 end
 
+RSpec::Rails::ControllerExampleGroup.class_eval do
+  include JasmineFixtureGeneration
+end
+
-- 
GitLab