Commit c1f2bbac authored by Dennis Collinson's avatar Dennis Collinson

Wallpaper frame selected when post has one photo

parent d20af894
......@@ -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
},
setFrameName : function(){
this.set({frame_name : findTheme(this)})
function findTheme(model) {
return model.get("photos").length == 1 ? "Wallpaper" : "Day"
}
},
createdAt : function() {
return this.timeOf("created_at");
},
......
......@@ -6,7 +6,7 @@ app.views.TemplatePicker = app.views.Base.extend({
},
initialize : function(){
this.model.set({frame_name : 'Day'})
this.model.setFrameName()
},
postRenderTemplate : function(){
......
describe("app.views.TemplatePicker", function(){
beforeEach(function(){
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(){
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(){
expect(this.view.model.get("frame_name")).toBe("Day")
createView(this.model)
expect(this.model.get("frame_name")).toBe("Day")
})
})
......
......@@ -75,11 +75,12 @@ factory = {
},
photoAttrs : function(overrides){
var id = this.id.next();
return _.extend({
author: factory.userAttrs(),
created_at: "2012-03-27T20:11:52Z",
guid: "8b0db16a4c4307b2",
id: 117,
guid: "8b0db16a4c4307b2" + id,
id: id,
sizes: {
large: "http://localhost:3000/uploads/images/scaled_full_d85410bd19db1016894c.jpg",
medium: "http://localhost:3000/uploads/images/thumb_medium_d85410bd19db1016894c.jpg",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment