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,7 +74,6 @@
%header{:class=>('landing' unless current_user)} %header{:class=>('landing' unless current_user)}
= render 'layouts/header' = render 'layouts/header'
- if @backbone
= render 'templates/templates' = render 'templates/templates'
.container{:style=> "#{yield(:break_the_mold)}"} .container{:style=> "#{yield(:break_the_mold)}"}

View file

@ -34,8 +34,9 @@
<time class="timeago" datetime="<%= created_at %>"/> <time class="timeago" datetime="<%= created_at %>"/>
</a> </a>
</span> </span>
</div>
<p> <p class="post-text">
<%= text %> <%= text %>
</p> </p>
@ -71,4 +72,3 @@
</div> </div>
</div> </div>
</div>

View file

@ -17,7 +17,7 @@ describe MultisController do
describe 'jasmine fixtures' do describe 'jasmine fixtures' do
it 'generate' 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 get :index, :format => :json
save_fixture(response.body, "multi_stream_json") save_fixture(response.body, "multi_stream_json")
end 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(){ describe("#render", function(){
beforeEach(function(){ beforeEach(function(){
//hella hax // should be jasmine helper
spec.loadFixture("multi_stream_json") window.current_user = App.user({name: "alice", avatar : {small : "http://avatar.com"}});
var fixtureStream = $.parseJSON($("#jasmine_content").html())
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.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 = 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")));
@ -18,8 +22,7 @@ describe("App.views.Stream", function(){
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(){
// we need to load the underscore templates here, otherwise our views won't render! expect($.trim(this.statusElement.find(".content p.post-text").text())).toBe("hella infos yo!")
expect(this.statusElement.find(".post-content p")).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 # Saves the markup to a fixture file using the given name
def save_fixture(markup, name, fixture_path=nil ) def save_fixture(markup, name, fixture_path=nil )
fixture_path = File.join(Rails.root, 'tmp', 'js_dom_fixtures') unless fixture_path 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
end end
RSpec::Rails::ControllerExampleGroup.class_eval do
include JasmineFixtureGeneration
end