clean up mistakes

This commit is contained in:
John Bintz 2011-05-09 07:35:37 -04:00
parent a37de3c20c
commit 429549027f
5 changed files with 19 additions and 16 deletions

View File

@ -33,6 +33,10 @@ class BackboneGenerator < Thor
singularize(Thor::Util.snake_case(@name.gsub("::", "/")))
end
def css_class_name
underscore_name.gsub(%r{[^a-z0-9_]}, '-')
end
def plural_underscore_name
pluralize(underscore_name)
end

View File

@ -6,18 +6,18 @@ class window.<%= plural_object_name %>View extends Backbone.View
initialize: ->
@collection.bind('refresh', @addAll)
@render
this.render()
@collection.fetch
render: =>
$(this.el).html(@template())
$(this.el).html(this.template())
this
addOne: (model) =>
view = new <%= object_name %>View({model: model})
this.$('.list').append(view.render().el)
addAll: =>
@collection.each(@addOne)
@collection.each(this.addOne())
addNew: =>
facility = new <%= object_name %>()
@collection.add(facility)
@addOne(facility)
this.addOne(facility)

View File

@ -3,17 +3,16 @@ describe '<%= plural_object_name %>View', ->
beforeEach ->
collection = new <%= plural_object_name %>()
view = new <%= plural_object_name %>View({collection: collection})
view.render()
it 'should render', ->
view = new <%= plural_object_name %>View({collection: collectioon})
view.render
expect($(view.el)).toContain('.list')
expect($(view.el)).toContail('button.new')
expect($(view.el)).toContain('button.new')
it 'should add a new model when new is clicked', ->
view.$('button.new').trigger('click')
expect(view.$('.list').toContain('.<%= underscore_name %>')
expect(view.$('.list')).toContain('.<%= css_class_name %>')
expect(collection.length).toEqual(1)

View File

@ -5,17 +5,17 @@ class window.<%= object_name %>View extends Backbone.View
}
attributeFields: []
template: JST['<%= underscore_name %>s/view']
className: '<%= underscore_name %>'
className: '<%= css_class_name %>'
initialize: ->
@model.bind('change', @render)
@model.bind('remove', @remove)
@model.view = this
render: =>
$(@el).html(@template(@model.toJSON))
this.$('button.save').text(@model.isNew() ? 'Create' : 'Update')
$(@el).html(@template(@model.toJSON()))
this.$('button.save').text(if @model.isNew() then 'Create' else 'Update')
this
save: =>
@model.save(@attributes)
@model.save(@attributes())
destroy: =>
if confirm("Are you sure?")
@model.destroy

View File

@ -7,7 +7,7 @@ describe '<%= object_name %>View', ->
it 'should render with a create button', ->
view = new <%= object_name %>View({model: model})
view.render
view.render()
expect(view.$('button.save')).toHaveText('Create')
@ -19,13 +19,13 @@ describe '<%= object_name %>View', ->
view = new <%= object_name %>View({model: model})
it 'should render with an update button', ->
view.render
view.render()
expect(view.$('button.save')).toHaveText('Update')
it 'should destroy the model', ->
spyOn(window, 'confirm').andReturn(true)
spyOn(model, 'destory')
spyOn(model, 'destroy')
$('#container').append(view.el)
view.$('button.delete').trigger('click')