forked from mxriverlynn/backbone.modelbinding
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
spec to show that you can add your own conventions. documentation on …
…how to add / change conventions
- Loading branch information
Derick Bailey
committed
Jul 26, 2011
1 parent
649d286
commit c3433dd
Showing
3 changed files
with
82 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,53 @@ | ||
describe("custom conventions", function(){ | ||
describe("replace the text input handler with a convention that sets the #name field value", function(){ | ||
beforeEach(function(){ | ||
this.model = new AModel({}); | ||
this.view = new AView({model: this.model}); | ||
this.oldHandler = Backbone.ModelBinding.Conventions.text.handler; | ||
beforeEach(function(){ | ||
this.model = new AModel({}); | ||
this.view = new AView({model: this.model}); | ||
this.oldHandler = Backbone.ModelBinding.Conventions.text.handler; | ||
|
||
}); | ||
|
||
afterEach(function(){ | ||
Backbone.ModelBinding.Conventions.text.handler = this.oldHandler; | ||
}); | ||
|
||
describe("replace the text input handler", function(){ | ||
beforeEach(function(){ | ||
var nameSettingsHandler = { | ||
bind: function(selector, view, model){ | ||
view.$("#name").val("a custom convention supplied this name"); | ||
} | ||
}; | ||
Backbone.ModelBinding.Conventions.text.handler = nameSettingsHandler; | ||
|
||
Backbone.ModelBinding.Conventions.text.handler = nameSettingsHandler; | ||
this.view.render(); | ||
}); | ||
|
||
afterEach(function(){ | ||
Backbone.ModelBinding.Conventions.text.handler = this.oldHandler; | ||
}); | ||
|
||
it("should set the custom field value when rendered", function(){ | ||
expect(this.view.$("#name").val()).toBe("a custom convention supplied this name"); | ||
}); | ||
}); | ||
|
||
describe("add a brand new convention for paragraph tags", function(){ | ||
beforeEach(function(){ | ||
var PConvention = { | ||
selector: "p", | ||
handler: { | ||
bind: function(selector, view, model){ | ||
view.$(selector).each(function(index){ | ||
var name = model.get("name"); | ||
$(this).html(name); | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
Backbone.ModelBinding.Conventions.paragraphs = PConvention; | ||
}); | ||
|
||
it("should display the model name in the paragraph", function(){ | ||
this.model.set({name: "Gandalf Wizard"}); | ||
this.view.render(); | ||
expect(this.view.$("#aParagraph").html()).toBe("Gandalf Wizard"); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters