Wallpaper frame selected when post has one photo

This commit is contained in:
Dennis Collinson 2012-04-12 11:56:11 -07:00
parent d20af894a4
commit c1f2bbac88
4 changed files with 44 additions and 5 deletions

View file

@ -12,6 +12,15 @@ app.models.Post = Backbone.Model.extend({
this.participations = this.participations || new app.collections.Participations([], {post : this}); // load in the user like initially this.participations = this.participations || new app.collections.Participations([], {post : this}); // load in the user like initially
}, },
setFrameName : function(){
this.set({frame_name : findTheme(this)})
function findTheme(model) {
return model.get("photos").length == 1 ? "Wallpaper" : "Day"
}
},
createdAt : function() { createdAt : function() {
return this.timeOf("created_at"); return this.timeOf("created_at");
}, },

View file

@ -6,7 +6,7 @@ app.views.TemplatePicker = app.views.Base.extend({
}, },
initialize : function(){ initialize : function(){
this.model.set({frame_name : 'Day'}) this.model.setFrameName()
}, },
postRenderTemplate : function(){ postRenderTemplate : function(){

View file

@ -1,12 +1,41 @@
describe("app.views.TemplatePicker", function(){ describe("app.views.TemplatePicker", function(){
beforeEach(function(){ beforeEach(function(){
this.model = factory.statusMessage({frame_name: undefined}) this.model = factory.statusMessage({frame_name: undefined})
this.view = new app.views.TemplatePicker({model : this.model }) this.view = createView(this.model)
}) })
function createView(model){
return new app.views.TemplatePicker({model : model })
}
describe("initialization", function(){ describe("initialization", function(){
context("when the model has photos:", function(){
context("one photo", function(){
beforeEach(function(){
this.model.set({photos : [factory.photoAttrs()]})
})
it("sets the frame name to Wallpaper", function(){
createView(this.model)
expect(this.model.get("frame_name")).toBe("Wallpaper")
})
})
context("two photos", function(){
beforeEach(function(){
this.model.set({photos : [factory.photoAttrs(), factory.photoAttrs()]})
})
it("sets the frame name to Wallpaper", function(){
createView(this.model)
expect(this.model.get("frame_name")).toBe("Day")
})
})
})
it("sets the frame_name of the model to 'Day' by default", function(){ it("sets the frame_name of the model to 'Day' by default", function(){
expect(this.view.model.get("frame_name")).toBe("Day") createView(this.model)
expect(this.model.get("frame_name")).toBe("Day")
}) })
}) })

View file

@ -75,11 +75,12 @@ factory = {
}, },
photoAttrs : function(overrides){ photoAttrs : function(overrides){
var id = this.id.next();
return _.extend({ return _.extend({
author: factory.userAttrs(), author: factory.userAttrs(),
created_at: "2012-03-27T20:11:52Z", created_at: "2012-03-27T20:11:52Z",
guid: "8b0db16a4c4307b2", guid: "8b0db16a4c4307b2" + id,
id: 117, id: id,
sizes: { sizes: {
large: "http://localhost:3000/uploads/images/scaled_full_d85410bd19db1016894c.jpg", large: "http://localhost:3000/uploads/images/scaled_full_d85410bd19db1016894c.jpg",
medium: "http://localhost:3000/uploads/images/thumb_medium_d85410bd19db1016894c.jpg", medium: "http://localhost:3000/uploads/images/thumb_medium_d85410bd19db1016894c.jpg",