Permalink
Browse files

Allow both vertical and horizontal forms to be used

  • Loading branch information...
1 parent 39ec281 commit fab4e3606adaee3e4ae366493489ca5d5f7b7761 @mhuggins committed Jul 5, 2012
View
3 Makefile
@@ -1,6 +1,7 @@
NODE = node
TEST = ./node_modules/.bin/vows
-TESTS ?= test/*-test.js
+TESTS ?= ./test/*-test.js ./test/**/*-test.js
+TEST_FLAGS = -spec
test:
@NODE_ENV=test NODE_PATH=lib $(TEST) $(TEST_FLAGS) $(TESTS)
View
39 lib/railway-bootstrap/forms/form-util.js
@@ -0,0 +1,39 @@
+module.exports = {
+ humanize: humanize,
+ divTag: divTag,
+ spanTag: spanTag,
+ genericTag: genericTag
+};
+
+function humanize(name) {
+ return railway.utils.humanize(railway.utils.underscore(name));
+}
+
+function divTag(params, block) {
+ return genericTag('div', params, block);
+}
+
+function spanTag(params, block) {
+ return genericTag('span', params, block);
+}
+
+function genericTag(name, params, block) {
+ var html = [];
+
+ if (typeof(params) === 'function') {
+ block = params;
+ params = {};
+ }
+ params = params || {};
+
+ html.push("<" + name + railway.utils.html_tag_params(params) + ">");
+
+ if (typeof(block) === 'function') {
+ html.push(block());
+ } else if (block) {
+ html.push(block);
+ }
+
+ html.push("</" + name + ">");
+ return html.join("\n");
+}
View
94 lib/railway-bootstrap/forms/horizontal.js
@@ -0,0 +1,94 @@
+module.exports = HorizontalForm;
+
+function HorizontalForm(context, resource, params) {
+ var self = this;
+
+ this.buf = arguments.callee.caller.buf;
+ this.context = context;
+ this.resource = resource;
+ this.params = railway.utils.safe_merge({ class: 'form-horizontal' }, params);
+}
+
+HorizontalForm.prototype.fieldsFor = function (block) {
+ var context = this.context;
+ var resource = this.resource;
+ var util = require('./form-util');
+
+ arguments.callee.buf = this.buf;
+
+ context.formTag(this.params, function () {
+ if (block) {
+ block({
+ input: input('input'),
+ file: input('file'),
+ textarea: input('textarea'),
+ submit: submit
+ });
+ }
+ });
+
+ function input(inputType) {
+ return function (name, params) {
+ var output;
+ params = params || {};
+
+ context.fields_for(resource, function (form) {
+ output = controlGroup(name, function () {
+ var label = params.label;
+ var html = [];
+
+ delete params.label;
+
+ if (label !== false) {
+ label = label || util.humanize(name);
+ html.push(form.label(name, label, { class: 'control-label' }));
+ }
+
+ html.push(controls(name, function () {
+ return form[inputType](name, params);
+ }));
+
+ return html.join("\n");
+ });
+ });
+
+ return output;
+ };
+ }
+
+ function submit(name, params) {
+ var output;
+ params = params || {};
+
+ context.fields_for(resource, function (form) {
+ output = actions(function () {
+ params = railway.utils.safe_merge({ class: 'btn btn-primary' }, params);
+ return form.submit(name, params);
+ });
+ });
+
+ return output;
+ }
+
+ function controlGroup(name, block) {
+ var css = 'control-group' + ((resource.errors && resource.errors[name]) ? ' error' : '');
+ return util.divTag({ class: css }, block);
+ }
+
+ function controls(name, block) {
+ return util.divTag({ class: 'controls' }, function () {
+ var html = [];
+ var errors = resource.errors && resource.errors[name];
+
+ html.push(block());
+ if (errors) {
+ html.push(util.spanTag({ class: 'help-inline' }, errors ? errors.join(', ') : null));
+ }
+ return html.join("\n");
+ });
+ }
+
+ function actions(block) {
+ return util.divTag({ class: 'form-actions' }, block);
+ }
+};
View
64 lib/railway-bootstrap/forms/vertical.js
@@ -0,0 +1,64 @@
+module.exports = VerticalForm;
+
+function VerticalForm(context, resource, params) {
+ var self = this;
+
+ this.buf = arguments.callee.caller.buf;
+ this.context = context;
+ this.resource = resource;
+ this.params = railway.utils.safe_merge({ class: 'form-vertical' }, params);
+}
+
+VerticalForm.prototype.fieldsFor = function (block) {
+ var context = this.context;
+ var resource = this.resource;
+ var util = require('./form-util');
+
+ arguments.callee.buf = this.buf;
+
+ context.formTag(this.params, function () {
+ if (block) {
+ block({
+ input: input('input'),
+ file: input('file'),
+ textarea: input('textarea'),
+ submit: submit
+ });
+ }
+ });
+
+ function input(inputType) {
+ return function (name, params) {
+ var output = [];
+ params = params || {};
+
+ context.fields_for(resource, function (form) {
+ var label = params.label;
+ delete params.label;
+
+ if (label !== false) {
+ label = label || util.humanize(name);
+ output.push(form.label(name, label));
+ }
+
+ output.push(form[inputType](name, params));
+ });
+
+ return output.join("\n");
+ };
+ }
+
+ function submit(name, params) {
+ var output;
+ params = params || {};
+
+ context.fields_for(resource, function (form) {
+ params = railway.utils.safe_merge({ class: 'btn btn-primary' }, params);
+ output = util.divTag(function () {
+ return form.submit(name, params);
+ });
+ });
+
+ return output;
+ }
+};
View
147 lib/railway-bootstrap/helpers.js
@@ -1,140 +1,39 @@
+var util = require('util');
+
/**
- * Form tag helper.
+ * Twitter Bootstrap form tag helper.
*
* bootstrapFieldsFor(user, function (form) { ... });
*/
-module.exports.bootstrapFormFor = function (resource, params, block) {
+exports.bootstrapFormFor = exports.bootstrap_form_for = function (resource, params, block) {
var self = this;
var buf = arguments.callee.buf = arguments.callee.caller.buf;
- if (resource && resource.modelName) {
- if (typeof params !== 'object') {
- params = {};
- }
- if (!params.method) {
- params.method = 'PUT';
- }
- if (!params.action) {
- params.action = railway.routeMapper.pathTo[railway.utils.underscore(resource.modelName)](resource);
- }
- }
-
- params = railway.utils.safe_merge({ class: 'form-horizontal' }, params);
-
- this.formTag(params, function () {
- if (block) {
- module.exports.bootstrapFieldsFor.call(self, resource, block);
- }
- });
-};
-module.exports.bootstrap_form_for = module.exports.bootstrapFormFor;
-
-/**
- * Form fields for resource helper.
- *
- * bootstrapFieldsFor(user, function (form) {
- * form.input('email', { label: 'E-mail Address' });
- * form.input('password', { type: 'password' });
- * form.submit('Login');
- * });
- */
-module.exports.bootstrapFieldsFor = function (resource, block) {
- var self = this;
-
- var inputs = {
- submit: function (name, params) {
- var output;
- params = params || {};
-
- self.fields_for(resource, function (form) {
- output = actions(function () {
- params = railway.utils.safe_merge({ class: 'btn btn-primary' }, params);
- return form.submit(name, params);
- });
- });
- return output;
- }
- };
-
- ['input', 'file', 'textarea'].forEach(function (inputType) {
- inputs[inputType] = function (name, params) {
- var output;
- params = params || {};
-
- self.fields_for(resource, function (form) {
- output = controlGroup(name, function () {
- var label = params.label;
- var html = [];
-
- if (label !== false) {
- label = label || humanize(name);
- html.push(form.label(name, label, { class: 'control-label' }));
- }
-
- html.push(controls(name, function () {
- return form[inputType](name, params);
- }));
-
- return html.join("\n");
- });
- });
- return output;
- };
- });
-
- block(inputs);
-
- function humanize(name) {
- var u = railway.utils;
- return u.humanize(u.underscore(name));
+ if (typeof(params) == 'function') {
+ block = params;
+ params = {};
}
+ params = params || {};
- function controlGroup(name, block) {
- var css = 'control-group' + ((resource.errors && resource.errors[name]) ? ' error' : '');
- return divTag({ class: css }, block);
- }
+ var format = params.format || 'vertical';
+ delete params.format;
- function controls(name, block) {
- return divTag({ class: 'controls' }, function () {
- var html = [];
- var errors = resource.errors && resource.errors[name];
-
- html.push(block());
- if (errors) {
- html.push(spanTag({ class: 'help-inline' }, errors ? errors.join(', ') : null));
- }
- return html.join("\n");
- });
+ if (resource && resource.modelName) {
+ params.method = params.method || 'PUT';
+ params.action = params.action || railway.routeMapper.pathTo[railway.utils.underscore(resource.modelName)](resource);
}
- function actions(block) {
- return divTag({ class: 'form-actions' }, block);
- }
+ var Form = require('./forms/' + format);
+ var form = new Form(this, resource, params);
+ form.fieldsFor(block);
};
-module.exports.bootstrap_fields_for = module.exports.bootstrapFieldsFor;
/**
- * Private helper methods.
+ * Twitter Bootstrap form tag helpers for specific form types.
*/
-function divTag(params, block) {
- return genericTag('div', params, block);
-}
-
-function spanTag(params, block) {
- return genericTag('span', params, block);
-}
-
-function genericTag(name, params, block) {
- var html = [];
-
- html.push("<" + name + railway.utils.html_tag_params(params) + ">");
-
- if (typeof(block) === 'function') {
- html.push(block());
- } else if (block) {
- html.push(block);
- }
-
- html.push("</" + name + ">");
- return html.join("\n");
-}
+['basic', 'horizontal'].forEach(function (format) {
+ exports[format + 'FormFor'] = exports[format + '_form_for'] = function (resource, params, block) {
+ params = railway.utils.safe_merge({ format: format }, params);
+ exports.bootstrapFormFor(resource, params, block);
+ };
+});
View
18 lib/railway-bootstrap/index.js
@@ -6,3 +6,21 @@ exports.init = function () {
HelperSet.prototype[name] = helpers[name];
}
};
+
+exports.bootstrapFormFor = function (resource, params, block) {
+ var self = this;
+ var buf = arguments.callee.buf = arguments.callee.caller.buf;
+
+ params = params || {};
+ params.format = params.format || 'horizontal';
+
+ if (resource && resource.modelName) {
+ params.method = params.method || 'PUT';
+ params.action = params.action || railway.routeMapper.pathTo[railway.utils.underscore(resource.modelName)](resource);
+ }
+
+ var Form = require('./forms/' + params.format);
+ new Form(this, resource, params, block);
+};
+
+exports.bootstrap_form_for = exports.bootstrapFormFor;
View
2 package.json
@@ -13,7 +13,7 @@
"railway": ">= 0.2.6"
},
"scripts": {
- "test": "NODE_PATH=lib node_modules/.bin/vows test/*-test.js"
+ "test": "NODE_PATH=lib node_modules/.bin/vows test/*-test.js test/**/*-test.js -spec"
},
"engines": { "node": ">= 0.4.0" },
"licenses": [ {
View
26 readme.md
@@ -54,19 +54,29 @@ key/value pairs included in the object will be converted to HTML attributes on t
This will produce the following HTML:
- <form class="form-horizontal" action="/users/new" method="post">
+ <form class="well" action="/users/new" method="post">
<input type="hidden" name="authenticity_token" value="f46d9de27e45fef8dce10a36dcdc7be7fa8612af" />
<input type="hidden" name="_method" value="PUT" />
<!-- any other calls made on the form object will render here -->
</form>
-For either format of `bootstrapFormFor` that is used, the `callback` parameter
-will be provided with `form` object. This object provides several methods used
-for rendering form fields. By default, each field is wrapped according to
-Twitter Bootstrap's [horizontal form](http://twitter.github.com/bootstrap/base-css.html#forms)
-format with an accompanying label
+The type of the Bootstrap form that you want to use can be provided in the
+`options` parameter as well. Currently, only "vertical" and "horizontal" are
+provided, with "vertical" being the default. The available types map to the
+following CSS classes. (See the [Forms section of the Twitter Bootstrap docs](http://twitter.github.com/bootstrap/base-css.html#forms)
+for more details on form types.)
-The following methods are provided:
+* `vertical` = `form-vertical`
+* `horizontal` = `form-horizontal`
+
+Finally, for either format of `bootstrapFormFor` that is used, the `callback`
+parameter will be provided with `form` object. This object provides several
+methods used for rendering form fields. By default, each field is wrapped
+according to Twitter Bootstrap's [horizontal form](http://twitter.github.com/bootstrap/base-css.html#forms)
+format with an accompanying label.
+
+The `form` object that is provided to your callback has the following methods
+available:
* `input (name, options)`: Creates an `<input>` element, where `name` is the name of
the resource's property to render. If no `options` are provided, the input type
@@ -84,4 +94,4 @@ Created By:
License:
--------
-Railway-Bootstrap is released under the [MIT license](http://www.opensource.org/licenses/MIT).
+Railway Bootstrap is released under the [MIT license](http://www.opensource.org/licenses/MIT).
View
167 test/forms/horizontal-test.js
@@ -0,0 +1,167 @@
+require('railway').createServer();
+require('railway-bootstrap').init();
+
+var vows = require('vows');
+var assert = require('assert');
+var HorizontalForm = require('railway-bootstrap/forms/horizontal');
+
+function User() {
+ this.id = 1;
+ this.username = 'AzureDiamond';
+ this.email = 'hunter2@example.com';
+ this.description = 'doesnt look like stars to me';
+ this.avatar = null;
+}
+
+var user = new User();
+
+vows.describe('HorizontalForm').addBatch({
+ before: function () {
+ railway.helpers.controller = {
+ request: { csrfParam: 'csrf_name', csrfToken: 'csrf_value' }
+ }
+ },
+
+ 'constructor': {
+ topic: function () {
+ arguments.callee.buf = [];
+ return new HorizontalForm(railway.helpers, user);
+ },
+
+ 'includes class in form tag': function (form) {
+ form.fieldsFor();
+ var output = form.buf.join('');
+ var expected = /<form[^>]*class="form-horizontal"[^>]*>/;
+ assert.match(output, expected);
+ }
+ },
+
+ 'fieldsFor': {
+ topic: function () {
+ arguments.callee.buf = [];
+ return new HorizontalForm(railway.helpers, user)
+ },
+
+ 'with type input': {
+ 'creates control group': function (form) {
+ form.fieldsFor(function (form) {
+ var output = form.input('username');
+ assert.match(output, /^<div class="control-group">/ );
+ assert.match(output, /<\/div>$/ );
+ });
+ },
+
+ 'creates label': function (form) {
+ form.fieldsFor(function (form) {
+ var output = form.input('username');
+ var expected = '<label for="username" class="control-label">Username</label>';
+ assert.include(output, expected);
+ });
+ },
+
+ 'creates text input': function (form) {
+ form.fieldsFor(function (form) {
+ var output = form.input('username');
+ var expected = '<input name="username" id="username" value="' + user.username + '" />';
+ assert.include(output, expected);
+ });
+ },
+
+ 'creates control container around input': function (form) {
+ form.fieldsFor(function (form) {
+ var output = form.input('username');
+ var expected = /<div class="controls">\s*<input\b[^>]*\/>\s*<\/div>/;
+ assert.match(output, expected);
+ });
+ }
+ },
+
+ 'with type textarea': {
+ 'creates control group': function (form) {
+ form.fieldsFor(function (form) {
+ var output = form.textarea('description');
+ assert.match(output, /^<div class="control-group">/ );
+ assert.match(output, /<\/div>$/ );
+ });
+ },
+
+ 'creates label': function (form) {
+ form.fieldsFor(function (form) {
+ var output = form.textarea('description');
+ var expected = '<label for="description" class="control-label">Description</label>';
+ assert.include(output, expected);
+ });
+ },
+
+ 'creates textarea': function (form) {
+ form.fieldsFor(function (form) {
+ var output = form.textarea('description');
+ var expected = '<textarea name="description" id="description">' + user.description + '</textarea>';
+ assert.include(output, expected);
+ });
+ },
+
+ 'creates control container around textarea': function (form) {
+ form.fieldsFor(function (form) {
+ var output = form.textarea('description');
+ var expected = /<div class="controls">\s*<textarea\b[^>]*>.*<\/textarea>\s*<\/div>/;
+ assert.match(output, expected);
+ });
+ }
+ },
+
+ 'with type file': {
+ 'creates control group': function (form) {
+ form.fieldsFor(function (form) {
+ var output = form.file('avatar');
+ var expectedStart = /^<div class="control-group">/;
+ var expectedEnd = /<\/div>$/;
+ assert.match(output, expectedStart);
+ assert.match(output, expectedEnd);
+ });
+ },
+
+ 'creates label': function (form) {
+ form.fieldsFor(function (form) {
+ var output = form.file('avatar');
+ var expected = '<label for="avatar" class="control-label">Avatar</label>';
+ assert.include(output, expected);
+ });
+ },
+
+ 'creates file input': function (form) {
+ form.fieldsFor(function (form) {
+ var output = form.file('avatar');
+ var expected = '<input name="avatar" id="avatar" type="file" />';
+ assert.include(output, expected);
+ });
+ },
+
+ 'creates control container around input': function (form) {
+ form.fieldsFor(function (form) {
+ var output = form.file('avatar');
+ var expected = /<div class="controls">\s*<input\b[^>]*\/>\s*<\/div>/;
+ assert.match(output, expected);
+ });
+ }
+ },
+
+ 'with type submit': {
+ 'creates form actions container': function (form) {
+ form.fieldsFor(function (form) {
+ var output = form.submit();
+ assert.match(output, /^<div class="form-actions">/ );
+ assert.match(output, /<\/div>$/ );
+ });
+ },
+
+ 'creates submit button': function (form) {
+ form.fieldsFor(function (form) {
+ var output = form.submit('Register');
+ var expected = '<button type="submit" class="btn btn-primary">Register</button>';
+ assert.include(output, expected);
+ });
+ }
+ }
+ }
+}).export(module);
View
109 test/forms/vertical-test.js
@@ -0,0 +1,109 @@
+require('railway').createServer();
+require('railway-bootstrap').init();
+
+var vows = require('vows');
+var assert = require('assert');
+var VerticalForm = require('railway-bootstrap/forms/vertical');
+
+function User() {
+ this.id = 1;
+ this.username = 'AzureDiamond';
+ this.email = 'hunter2@example.com';
+ this.description = 'doesnt look like stars to me';
+ this.avatar = null;
+}
+
+var user = new User();
+
+vows.describe('VerticalForm').addBatch({
+ before: function () {
+ railway.helpers.controller = {
+ request: { csrfParam: 'csrf_name', csrfToken: 'csrf_value' }
+ }
+ },
+
+ 'constructor': {
+ topic: function () {
+ arguments.callee.buf = [];
+ return new VerticalForm(railway.helpers, user);
+ },
+
+ 'includes class in form tag': function (form) {
+ form.fieldsFor();
+ var output = form.buf.join('');
+ var expected = /<form[^>]*class="form-vertical"[^>]*>/;
+ assert.match(output, expected);
+ }
+ },
+
+ 'fieldsFor': {
+ topic: function () {
+ arguments.callee.buf = [];
+ return new VerticalForm(railway.helpers, user)
+ },
+
+ 'with type input': {
+ 'creates label': function (form) {
+ form.fieldsFor(function (form) {
+ var output = form.input('username');
+ var expected = '<label for="username">Username</label>';
+ assert.include(output, expected);
+ });
+ },
+
+ 'creates text input': function (form) {
+ form.fieldsFor(function (form) {
+ var output = form.input('username');
+ var expected = '<input name="username" id="username" value="' + user.username + '" />';
+ assert.include(output, expected);
+ });
+ }
+ },
+
+ 'with type textarea': {
+ 'creates label': function (form) {
+ form.fieldsFor(function (form) {
+ var output = form.textarea('description');
+ var expected = '<label for="description">Description</label>';
+ assert.include(output, expected);
+ });
+ },
+
+ 'creates textarea': function (form) {
+ form.fieldsFor(function (form) {
+ var output = form.textarea('description');
+ var expected = '<textarea name="description" id="description">' + user.description + '</textarea>';
+ assert.include(output, expected);
+ });
+ }
+ },
+
+ 'with type file': {
+ 'creates label': function (form) {
+ form.fieldsFor(function (form) {
+ var output = form.file('avatar');
+ var expected = '<label for="avatar">Avatar</label>';
+ assert.include(output, expected);
+ });
+ },
+
+ 'creates file input': function (form) {
+ form.fieldsFor(function (form) {
+ var output = form.file('avatar');
+ var expected = '<input name="avatar" id="avatar" type="file" />';
+ assert.include(output, expected);
+ });
+ }
+ },
+
+ 'with type submit': {
+ 'creates submit button': function (form) {
+ form.fieldsFor(function (form) {
+ var output = form.submit('Register');
+ var expected = '<button type="submit" class="btn btn-primary">Register</button>';
+ assert.include(output, expected);
+ });
+ }
+ }
+ }
+}).export(module);
View
138 test/helpers-test.js
@@ -1,17 +1,9 @@
require('railway').createServer();
-require('../lib/railway-bootstrap').init();
+require('railway-bootstrap').init();
var vows = require('vows');
var assert = require('assert');
-function User() {
- this.id = 1;
- this.username = 'AzureDiamond';
- this.email = 'hunter2@example.com';
- this.description = 'doesnt look like stars to me';
- this.avatar = null;
-}
-
vows.describe('Helpers').addBatch({
before: function () {
railway.helpers.controller = {
@@ -25,7 +17,7 @@ vows.describe('Helpers').addBatch({
railway.helpers.bootstrapFormFor(null, function () {});
var output = buf.join("\n");
- var expectedStart = /^<form class="form-horizontal" method="POST">/;
+ var expectedStart = /^<form[^>]*method="POST"[^>]*>/;
var expectedEnd = /<\/form>$/;
assert.match(output, expectedStart);
@@ -40,131 +32,5 @@ vows.describe('Helpers').addBatch({
var expected = '<input type="hidden" name="csrf_name" value="csrf_value" />';
assert.include(output, expected);
}
- },
-
- 'bootstrapFieldsFor': {
- topic: new User(),
-
- 'with type input': {
- 'creates control group': function (user) {
- railway.helpers.bootstrapFieldsFor(user, function (form) {
- var output = form.input('username');
- assert.match(output, /^<div class="control-group">/ );
- assert.match(output, /<\/div>$/ );
- });
- },
-
- 'creates label': function (user) {
- railway.helpers.bootstrapFieldsFor(user, function (form) {
- var output = form.input('username');
- var expected = '<label for="username" class="control-label">Username</label>';
- assert.include(output, expected);
- });
- },
-
- 'creates text input': function (user) {
- railway.helpers.bootstrapFieldsFor(user, function (form) {
- var output = form.input('username');
- var expected = '<input name="username" id="username" value="' + user.username + '" />';
- assert.include(output, expected);
- });
- },
-
- 'creates control container around input': function (user) {
- railway.helpers.bootstrapFieldsFor(user, function (form) {
- var output = form.input('username');
- var expected = /<div class="controls">\s*<input\b[^>]*\/>\s*<\/div>/;
- assert.match(output, expected);
- });
- }
- },
-
- 'with type textarea': {
- 'creates control group': function (user) {
- railway.helpers.bootstrapFieldsFor(user, function (form) {
- var output = form.textarea('description');
- assert.match(output, /^<div class="control-group">/ );
- assert.match(output, /<\/div>$/ );
- });
- },
-
- 'creates label': function (user) {
- railway.helpers.bootstrapFieldsFor(user, function (form) {
- var output = form.textarea('description');
- var expected = '<label for="description" class="control-label">Description</label>';
- assert.include(output, expected);
- });
- },
-
- 'creates textarea': function (user) {
- railway.helpers.bootstrapFieldsFor(user, function (form) {
- var output = form.textarea('description');
- var expected = '<textarea name="description" id="description">' + user.description + '</textarea>';
- assert.include(output, expected);
- });
- },
-
- 'creates control container around textarea': function (user) {
- railway.helpers.bootstrapFieldsFor(user, function (form) {
- var output = form.textarea('description');
- var expected = /<div class="controls">\s*<textarea\b[^>]*>.*<\/textarea>\s*<\/div>/;
- assert.match(output, expected);
- });
- }
- },
-
- 'with type file': {
- 'creates control group': function (user) {
- railway.helpers.bootstrapFieldsFor(user, function (form) {
- var output = form.file('avatar');
- var expectedStart = /^<div class="control-group">/;
- var expectedEnd = /<\/div>$/;
- assert.match(output, expectedStart);
- assert.match(output, expectedEnd);
- });
- },
-
- 'creates label': function (user) {
- railway.helpers.bootstrapFieldsFor(user, function (form) {
- var output = form.file('avatar');
- var expected = '<label for="avatar" class="control-label">Avatar</label>';
- assert.include(output, expected);
- });
- },
-
- 'creates file input': function (user) {
- railway.helpers.bootstrapFieldsFor(user, function (form) {
- var output = form.file('avatar');
- var expected = '<input name="avatar" id="avatar" type="file" />';
- assert.include(output, expected);
- });
- },
-
- 'creates control container around input': function (user) {
- railway.helpers.bootstrapFieldsFor(user, function (form) {
- var output = form.file('avatar');
- var expected = /<div class="controls">\s*<input\b[^>]*\/>\s*<\/div>/;
- assert.match(output, expected);
- });
- }
- },
-
- 'with type submit': {
- 'creates form actions container': function (user) {
- railway.helpers.bootstrapFieldsFor(user, function (form) {
- var output = form.submit();
- assert.match(output, /^<div class="form-actions">/ );
- assert.match(output, /<\/div>$/ );
- });
- },
-
- 'creates submit button': function (user) {
- railway.helpers.bootstrapFieldsFor(user, function (form) {
- var output = form.submit('Register');
- var expected = '<button type="submit" class="btn btn-primary">Register</button>';
- assert.include(output, expected);
- });
- }
- }
}
}).export(module);

0 comments on commit fab4e36

Please sign in to comment.