added tests for photos page
This commit is contained in:
parent
082d5c9fd4
commit
cab953848f
4 changed files with 84 additions and 0 deletions
|
|
@ -62,4 +62,8 @@ app.models.Photos = Backbone.Model.extend({
|
||||||
return "createdAt";
|
return "createdAt";
|
||||||
},
|
},
|
||||||
|
|
||||||
|
add : function(models){
|
||||||
|
this.photos.add(models)
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
27
spec/javascripts/app/models/photo_spec.js
Normal file
27
spec/javascripts/app/models/photo_spec.js
Normal 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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
45
spec/javascripts/app/views/photos_view_spec.js
Normal file
45
spec/javascripts/app/views/photos_view_spec.js
Normal 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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
Loading…
Reference in a new issue