diff --git a/public/javascripts/app/models/photos.js b/public/javascripts/app/models/photos.js index d50680e67..cbffb3de2 100644 --- a/public/javascripts/app/models/photos.js +++ b/public/javascripts/app/models/photos.js @@ -62,4 +62,8 @@ app.models.Photos = Backbone.Model.extend({ return "createdAt"; }, + add : function(models){ + this.photos.add(models) + } + }); \ No newline at end of file diff --git a/spec/controllers/photos_controller_spec.rb b/spec/controllers/photos_controller_spec.rb index 1d9e5d491..6279723af 100644 --- a/spec/controllers/photos_controller_spec.rb +++ b/spec/controllers/photos_controller_spec.rb @@ -80,6 +80,14 @@ describe PhotosController do assigns[:person].should == bob.person assigns[:posts].should == [@bobs_photo] 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 describe '#show' do diff --git a/spec/javascripts/app/models/photo_spec.js b/spec/javascripts/app/models/photo_spec.js new file mode 100644 index 000000000..26a8fa661 --- /dev/null +++ b/spec/javascripts/app/models/photo_spec.js @@ -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); + }); + }); + +}); diff --git a/spec/javascripts/app/views/photos_view_spec.js b/spec/javascripts/app/views/photos_view_spec.js new file mode 100644 index 000000000..c96a39df8 --- /dev/null +++ b/spec/javascripts/app/views/photos_view_spec.js @@ -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($('
OMG
')); + expect($("#paginate").text()).toBe("OMG"); + this.view.photos.trigger("fetched"); + expect($("#paginate")).toBeEmpty(); + }); + }); + +});