From 11cd3aba0c073a5cf9c65a4aa6acd9082a521246 Mon Sep 17 00:00:00 2001 From: mo Date: Sun, 3 Sep 2017 19:36:11 -0600 Subject: change autoview to lookup by path rather than key. --- .../backbone/models/cake_spec.js.coffee | 40 ---------------------- .../backbone/views/cake_view_spec.js.coffee | 16 --------- .../initializers/auto_view_setup_spec.js.coffee | 26 ++++++++++++++ spec/javascripts/models/cake_spec.js.coffee | 40 ++++++++++++++++++++++ spec/javascripts/views/cake_view_spec.js.coffee | 16 +++++++++ 5 files changed, 82 insertions(+), 56 deletions(-) delete mode 100644 spec/javascripts/backbone/models/cake_spec.js.coffee delete mode 100644 spec/javascripts/backbone/views/cake_view_spec.js.coffee create mode 100644 spec/javascripts/initializers/auto_view_setup_spec.js.coffee create mode 100644 spec/javascripts/models/cake_spec.js.coffee create mode 100644 spec/javascripts/views/cake_view_spec.js.coffee (limited to 'spec/javascripts') diff --git a/spec/javascripts/backbone/models/cake_spec.js.coffee b/spec/javascripts/backbone/models/cake_spec.js.coffee deleted file mode 100644 index 4223a255..00000000 --- a/spec/javascripts/backbone/models/cake_spec.js.coffee +++ /dev/null @@ -1,40 +0,0 @@ -describe "CakeSide.Models.Cake", -> - subject = (attributes) -> - new CakeSide.Models.Cake(attributes) - - describe "#validate", -> - it "returns an error when the name is null", -> - attributes = - name: null - cake = subject(attributes) - expect(cake.validate(attributes, {})).not.toBe(null) - expect(cake.isValid()).toBeFalsy() - - it "returns an error when the name is blank", -> - attributes = - name: ' ' - cake = subject(attributes) - expect(cake.validate(attributes, {})).not.toBe(null) - expect(cake.isValid()).toBeFalsy() - - - it 'returns an error when the category is blank', -> - attributes = - name: 'hi' - category_id: null - cake = subject(attributes) - expect(cake.validate(attributes)).not.toBe(null) - expect(cake.isValid()).toBeFalsy() - - it 'is valid when a name and category is specified', -> - attributes = - name: 'hi' - category_id: 1 - cake = subject(attributes) - expect(cake.validate(attributes)).toBeUndefined() - expect(cake.isValid()).toBeTruthy() - - describe "#public_url", -> - it "returns the correct url", -> - result = subject(slug: '123-cake').public_url() - expect(result).toMatch(/^http:\/\/.+\/creations\/123-cake$/) diff --git a/spec/javascripts/backbone/views/cake_view_spec.js.coffee b/spec/javascripts/backbone/views/cake_view_spec.js.coffee deleted file mode 100644 index f84d70a4..00000000 --- a/spec/javascripts/backbone/views/cake_view_spec.js.coffee +++ /dev/null @@ -1,16 +0,0 @@ -describe "CakeSide.Views.My.Cakes.CakeView", -> - cake = new CakeSide.Models.Cake - id: '1' - name: 'chocolate' - subject = new CakeSide.Views.My.Cakes.CakeView - model: cake - - describe "when there are no photos", -> - beforeEach -> - subject.render() - - it 'renders the cake', -> - expect(subject.$el.html()).toMatch(/chocolate/) - - it 'does not display any photos', -> - expect(subject.$el.html()).not.toMatch(/img/) diff --git a/spec/javascripts/initializers/auto_view_setup_spec.js.coffee b/spec/javascripts/initializers/auto_view_setup_spec.js.coffee new file mode 100644 index 00000000..3eb49971 --- /dev/null +++ b/spec/javascripts/initializers/auto_view_setup_spec.js.coffee @@ -0,0 +1,26 @@ +describe "CakeSide.AutoViewSetup", -> + subject = null + logger = null + + beforeEach -> + logger = + error: () -> {} + spyOn(logger, 'error') + subject = new CakeSide.AutoViewSetup(logger) + + describe "#execute", -> + beforeEach -> + CakeSide.AutoViewSetup.views = {} + + it 'attaches the autoview to the DOM element', -> + fixture.set '
' + subject.execute() + result = CakeSide.AutoViewSetup.views['MyChangePassword'] + expect(result instanceof CakeSide.Views.My.ChangePassword).toEqual(true) + + it "returns nil if the autoview cannot be discovered", -> + fixture.set '
' + subject.execute() + + expect(_.isEmpty(CakeSide.AutoViewSetup.views)).toEqual(true) + expect(logger.error).toHaveBeenCalled() diff --git a/spec/javascripts/models/cake_spec.js.coffee b/spec/javascripts/models/cake_spec.js.coffee new file mode 100644 index 00000000..4223a255 --- /dev/null +++ b/spec/javascripts/models/cake_spec.js.coffee @@ -0,0 +1,40 @@ +describe "CakeSide.Models.Cake", -> + subject = (attributes) -> + new CakeSide.Models.Cake(attributes) + + describe "#validate", -> + it "returns an error when the name is null", -> + attributes = + name: null + cake = subject(attributes) + expect(cake.validate(attributes, {})).not.toBe(null) + expect(cake.isValid()).toBeFalsy() + + it "returns an error when the name is blank", -> + attributes = + name: ' ' + cake = subject(attributes) + expect(cake.validate(attributes, {})).not.toBe(null) + expect(cake.isValid()).toBeFalsy() + + + it 'returns an error when the category is blank', -> + attributes = + name: 'hi' + category_id: null + cake = subject(attributes) + expect(cake.validate(attributes)).not.toBe(null) + expect(cake.isValid()).toBeFalsy() + + it 'is valid when a name and category is specified', -> + attributes = + name: 'hi' + category_id: 1 + cake = subject(attributes) + expect(cake.validate(attributes)).toBeUndefined() + expect(cake.isValid()).toBeTruthy() + + describe "#public_url", -> + it "returns the correct url", -> + result = subject(slug: '123-cake').public_url() + expect(result).toMatch(/^http:\/\/.+\/creations\/123-cake$/) diff --git a/spec/javascripts/views/cake_view_spec.js.coffee b/spec/javascripts/views/cake_view_spec.js.coffee new file mode 100644 index 00000000..f84d70a4 --- /dev/null +++ b/spec/javascripts/views/cake_view_spec.js.coffee @@ -0,0 +1,16 @@ +describe "CakeSide.Views.My.Cakes.CakeView", -> + cake = new CakeSide.Models.Cake + id: '1' + name: 'chocolate' + subject = new CakeSide.Views.My.Cakes.CakeView + model: cake + + describe "when there are no photos", -> + beforeEach -> + subject.render() + + it 'renders the cake', -> + expect(subject.$el.html()).toMatch(/chocolate/) + + it 'does not display any photos', -> + expect(subject.$el.html()).not.toMatch(/img/) -- cgit v1.2.3