From bed07872f2e0cd8fca98d9d304436fe5e9cfbe06 Mon Sep 17 00:00:00 2001 From: Maxwell Salzberg Date: Thu, 24 May 2012 11:36:16 -0700 Subject: [PATCH] composer now prevents you from submitting an empty frame. --- app/assets/javascripts/app/pages/framer.js | 9 ++++++++- .../app/views/framer_controls_view_spec.js | 20 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/app/pages/framer.js b/app/assets/javascripts/app/pages/framer.js index bd3c44baf..73ed8247f 100644 --- a/app/assets/javascripts/app/pages/framer.js +++ b/app/assets/javascripts/app/pages/framer.js @@ -123,11 +123,18 @@ app.views.framerControls = app.views.Base.extend({ }, saveFrame : function(){ - this.$('input').prop('disabled', 'disabled') this.setFormAttrs() + if(this.inValidFrame()) { + return false; + } + this.$('input').prop('disabled', 'disabled') this.model.save() }, + inValidFrame : function(){ + return (this.model.get('text').trim().length == 0) && (this.model.get('photos').length == 0) + }, + editFrame : function(){ app.router.renderPage(function(){return new app.pages.Composer({model : app.frame})}) app.router.navigate("/posts/new") diff --git a/spec/javascripts/app/views/framer_controls_view_spec.js b/spec/javascripts/app/views/framer_controls_view_spec.js index 2b288b381..713500662 100644 --- a/spec/javascripts/app/views/framer_controls_view_spec.js +++ b/spec/javascripts/app/views/framer_controls_view_spec.js @@ -14,5 +14,25 @@ describe("rendering", function(){ this.view.$("input.done").click(); expect(this.view.$('input').prop('disabled')).toBeTruthy(); }); + + it("does not disable the frame if it is invaild", function(){ + spyOn(this.view, 'inValidFrame').andReturn(true) + this.view.$("input.done").click(); + expect(this.view.$('input').prop('disabled')).toBeFalsy(); + }); + + it("does not disable the frame if it is invaild", function(){ + spyOn(this.view.model, 'save') + spyOn(this.view, 'inValidFrame').andReturn(true) + this.view.$("input.done").click(); + expect(this.view.model.save).not.toHaveBeenCalled() + }); }) + +describe("inValidFrame", function(){ + it("is invalid if the frame has no text or photos", function(){ + this.view.model = new factory.statusMessage({text: '', photos : []}) + expect(this.view.inValidFrame).toBeTruthy(); + }) + }); });