added tests for photos page

This commit is contained in:
Florian Staudacher 2012-02-09 23:12:39 +01:00
parent 082d5c9fd4
commit cab953848f
4 changed files with 84 additions and 0 deletions

View file

@ -62,4 +62,8 @@ app.models.Photos = Backbone.Model.extend({
return "createdAt"; return "createdAt";
}, },
add : function(models){
this.photos.add(models)
}
}); });

View file

@ -80,6 +80,14 @@ describe PhotosController do
assigns[:person].should == bob.person assigns[:person].should == bob.person
assigns[:posts].should == [@bobs_photo] assigns[:posts].should == [@bobs_photo]
end end
it "returns json when requested" do
request.env['HTTP_ACCEPT'] = 'application/json'
get :index, :person_id => alice.person.guid.to_s
response.headers['Content-Type'].should match 'application/json.*'
save_fixture(response.body, "photos_json")
end
end end
describe '#show' do describe '#show' do

View file

@ -0,0 +1,27 @@
describe("app.models.Photo", function() {
beforeEach(function(){
this.photo = new app.models.Photo();
});
describe("url", function(){
it("should be /photos when it doesn't have an id", function(){
expect(new app.models.Photo().url()).toBe("/photos");
});
it("should be /photos/id when it doesn't have an id", function(){
expect(new app.models.Photo({id: 5}).url()).toBe("/photos/5");
});
});
describe("createdAt", function() {
it("returns the photo's created_at as an integer", function() {
var date = new Date;
this.photo.set({ created_at: +date * 1000 });
expect(typeof this.photo.createdAt()).toEqual("number");
expect(this.photo.createdAt()).toEqual(+date);
});
});
});

View file

@ -0,0 +1,45 @@
describe("app.views.Photos", function() {
beforeEach(function() {
loginAs({name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}});
this._photos = $.parseJSON(spec.readFixture("photos_json"))["photos"];
this.photos = new app.models.Photos();
this.photos.add(this._photos);
this.view = new app.views.Photos({model : this.photos});
// do this manually because we've moved loadMore into render??
this.view.render();
_.each(this.view.collection.models, function(photo) {
this.view.addPhoto(photo);
}, this);
});
describe("initialize", function() {
// nothing there yet
});
describe("#render", function() {
beforeEach(function() {
this.photo = this.photos.photos.models[0];
this.photoElement = $(this.view.$("#" + this.photo.get("guid")));
});
context("when rendering a photo message", function() {
it("shows the photo in the content area", function() {
expect(this.photoElement.length).toBeGreaterThan(0); //markdown'ed
});
});
});
describe("removeLoader", function() {
it("emptys the pagination div when the stream is fetched", function() {
$("#jasmine_content").append($('<div id="paginate">OMG</div>'));
expect($("#paginate").text()).toBe("OMG");
this.view.photos.trigger("fetched");
expect($("#paginate")).toBeEmpty();
});
});
});