make jasmine view tests work, load templates, party

This commit is contained in:
Dennis Collinson 2011-12-11 14:28:43 -08:00
parent 4883c70ae2
commit 8e3db3aebe
10 changed files with 57 additions and 43 deletions

View file

@ -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

View file

@ -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>
<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>
<% } %>
<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>
<div class="comments"> </div>
</div>
</div>

View file

@ -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

View file

@ -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

View file

@ -2,14 +2,18 @@ describe("App.views.Stream", function(){
describe("#render", function(){
beforeEach(function(){
//hella hax
spec.loadFixture("multi_stream_json")
var fixtureStream = $.parseJSON($("#jasmine_content").html())
// should be jasmine helper
window.current_user = App.user({name: "alice", avatar : {small : "http://avatar.com"}});
this.statusMessage = new App.Models.Post(fixtureStream["posts"][0] );
//hella hax
spec.loadFixture("multi_stream_json");
var posts = $.parseJSON($("#jasmine_content").html())["posts"]
spec.loadFixture("underscore_templates");
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!")
})
})

View file

@ -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