Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Semigradsky committed Apr 22, 2015
1 parent f64d244 commit b18b4e8
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 94 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
4 changes: 1 addition & 3 deletions Gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ var uglify = require('gulp-uglify');
var streamify = require('gulp-streamify');
var notify = require('gulp-notify');
var gutil = require('gulp-util');
var shell = require('gulp-shell');
var livereload = require('gulp-livereload');
var glob = require('glob');
var jasminePhantomJs = require('gulp-jasmine2-phantomjs');
var fs = require('fs');

var dependencies = ['react'];
Expand Down Expand Up @@ -63,7 +61,7 @@ var browserifyTask = function (options) {

// We create a separate bundle for our dependencies as they
// should not rebundle on file changes. This only happens when
// we develop. When deploying the dependencies will be included
// we develop. When deploying the dependencies will be included
// in the application bundle
if (options.development) {

Expand Down
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"main": "src/main.js",
"scripts": {
"test": "./node_modules/.bin/jasmine-node ./specs",
"test": "echo \"Error: no test specified\" && exit 1",
"examples": "webpack-dev-server --config examples/webpack.config.js --content-base examples"
},
"author": "Christian Alfoni",
Expand All @@ -25,15 +25,12 @@
"glob": "^4.0.6",
"gulp": "^3.8.9",
"gulp-if": "^1.2.4",
"gulp-jasmine2-phantomjs": "^0.1.1",
"gulp-livereload": "^3.4.0",
"gulp-notify": "^1.4.2",
"gulp-shell": "^0.2.10",
"gulp-streamify": "0.0.5",
"gulp-uglify": "^0.3.1",
"gulp-util": "^3.0.0",
"jsx-loader": "^0.12.2",
"phantomjs": "^1.9.12",
"reactify": "^1.1.0",
"vinyl-source-stream": "^0.1.1",
"watchify": "^2.1.1",
Expand Down
13 changes: 7 additions & 6 deletions release/formsy-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,26 +425,28 @@ var convertValidationsToObject = function (validations) {
return validations.split(/\,(?![^{\[]*[}\]])/g).reduce(function (validations, validation) {
var args = validation.split(':');
var validateMethod = args.shift();

args = args.map(function (arg) {
try {
return JSON.parse(arg);
} catch (e) {
return arg; // It is a string if it can not parse it
}
});

if (args.length > 1) {
throw new Error('Formsy does not support multiple args on string validations. Use object format of validations instead.');
}

validations[validateMethod] = args.length ? args[0] : true;
return validations;
}, {});

}

return validations || {};

};

module.exports = {
getInitialState: function () {
return {
Expand All @@ -463,8 +465,8 @@ module.exports = {
validationErrors: {}
};
},
componentWillMount: function () {

componentWillMount: function () {
var configure = function () {
this.setValidations(this.props.validations, this.props.required);
this.props._attachToForm(this);
Expand All @@ -484,7 +486,6 @@ module.exports = {
}.bind(this), 0);
}
configure();

},

// We have to make the validate method is kept when new props are added
Expand All @@ -495,13 +496,13 @@ module.exports = {
componentDidUpdate: function (prevProps, prevState) {

var isValueChanged = function () {

return this.props.value !== prevProps.value && this.state._value === prevProps.value;

}.bind(this);


// If validations has changed or something outside changes
// If validations has changed or something outside changes
// the value, set the value again running a validation
if (isValueChanged()) {
this.setValue(this.props.value);
Expand Down
44 changes: 22 additions & 22 deletions specs/Element-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var Formsy = require('./../src/main.js');
describe('Element', function() {

it('should return passed and setValue() value when using getValue()', function () {

var TestInput = React.createClass({
mixins: [Formsy.Mixin],
updateValue: function (event) {
Expand All @@ -27,7 +27,7 @@ describe('Element', function() {
});

it('should set back to pristine value when running reset', function () {

var reset = null;
var TestInput = React.createClass({
mixins: [Formsy.Mixin],
Expand Down Expand Up @@ -55,7 +55,7 @@ describe('Element', function() {
});

it('should return error message passed when calling getErrorMessage()', function () {

var getErrorMessage = null;
var TestInput = React.createClass({
mixins: [Formsy.Mixin],
Expand All @@ -80,7 +80,7 @@ describe('Element', function() {
});

it('should return true or false when calling isValid() depending on valid state', function () {

var isValid = null;
var TestInput = React.createClass({
mixins: [Formsy.Mixin],
Expand Down Expand Up @@ -108,7 +108,7 @@ describe('Element', function() {
});

it('should return true or false when calling isRequired() depending on passed required attribute', function () {

var isRequireds = [];
var TestInput = React.createClass({
mixins: [Formsy.Mixin],
Expand Down Expand Up @@ -137,7 +137,7 @@ describe('Element', function() {
});

it('should return true or false when calling showRequired() depending on input being empty and required is passed, or not', function () {

var showRequireds = [];
var TestInput = React.createClass({
mixins: [Formsy.Mixin],
Expand Down Expand Up @@ -166,7 +166,7 @@ describe('Element', function() {
});

it('should return true or false when calling isPristine() depending on input has been "touched" or not', function () {

var isPristine = null;
var TestInput = React.createClass({
mixins: [Formsy.Mixin],
Expand All @@ -190,7 +190,7 @@ describe('Element', function() {
var input = TestUtils.findRenderedDOMComponentWithTag(form, 'INPUT');
TestUtils.Simulate.change(input, {target: {value: 'foo'}});
expect(isPristine()).toBe(false);

});

it('should allow an undefined value to be updated to a value', function (done) {
Expand Down Expand Up @@ -227,7 +227,7 @@ it('should allow an undefined value to be updated to a value', function (done) {
expect(input.getDOMNode().value).toBe('foo');
done();
}, 0);
});
});

it('should be able to test a values validity', function () {

Expand Down Expand Up @@ -255,7 +255,7 @@ it('should allow an undefined value to be updated to a value', function (done) {
expect(input.isValidValue('[email protected]')).toBe(true);
expect(input.isValidValue('foo@bar')).toBe(false);

});
});

it('should be able to use an object as validations property', function () {

Expand All @@ -282,7 +282,7 @@ it('should allow an undefined value to be updated to a value', function (done) {

var input = TestUtils.findRenderedComponentWithType(form, TestInput);
expect(input.isValidValue('[email protected]')).toBe(true);
expect(input.isValidValue('foo@bar')).toBe(false);
expect(input.isValidValue('foo@bar')).toBe(false);
});

it('should be able to pass complex values to a validation rule', function () {
Expand Down Expand Up @@ -314,7 +314,7 @@ it('should allow an undefined value to be updated to a value', function (done) {
var inputComponent = TestUtils.findRenderedComponentWithType(form, TestInput);
expect(inputComponent.isValid()).toBe(true);
var input = TestUtils.findRenderedDOMComponentWithTag(form, 'INPUT');
TestUtils.Simulate.change(input, {target: {value: 'bar'}});
TestUtils.Simulate.change(input, {target: {value: 'bar'}});
expect(inputComponent.isValid()).toBe(false);
});

Expand Down Expand Up @@ -357,7 +357,7 @@ it('should allow an undefined value to be updated to a value', function (done) {
expect(inputComponent[0].isValid()).toBe(true);
expect(inputComponent[1].isValid()).toBe(true);
var input = TestUtils.scryRenderedDOMComponentsWithTag(form, 'INPUT');
TestUtils.Simulate.change(input[0], {target: {value: 'bar'}});
TestUtils.Simulate.change(input[0], {target: {value: 'bar'}});
expect(inputComponent[0].isValid()).toBe(false);
expect(inputComponent[1].isValid()).toBe(false);
});
Expand Down Expand Up @@ -399,12 +399,12 @@ it('should allow an undefined value to be updated to a value', function (done) {
render: function () {
return (
<Formsy.Form>
<TestInput name="A"
<TestInput name="A"
validations={{
isEmail: true
}}
validationError="bar"
validationErrors={{isEmail: 'bar2', isLength: 'bar3'}}
}}
validationError="bar"
validationErrors={{isEmail: 'bar2', isLength: 'bar3'}}
value="f"
required={{
isLength: 1
Expand Down Expand Up @@ -433,12 +433,12 @@ it('should allow an undefined value to be updated to a value', function (done) {
render: function () {
return (
<Formsy.Form>
<TestInput name="A"
<TestInput name="A"
validations={{
isEmail: true
}}
validationError="bar"
validationErrors={{foo: 'bar'}}
}}
validationError="bar"
validationErrors={{foo: 'bar'}}
value="foo"
/>
</Formsy.Form>
Expand All @@ -464,7 +464,7 @@ it('should allow an undefined value to be updated to a value', function (done) {
render: function () {
return (
<Formsy.Form>
<TestInput name="A"
<TestInput name="A"
required
/>
</Formsy.Form>
Expand Down
12 changes: 6 additions & 6 deletions specs/Rules-equals-spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
var Formsy = require('./../src/main.js');

describe('Rules: equals', function() {
var TestInput, isValid, form, input;
var TestInput, isValid, form, input;

beforeEach(function() {
isValid = jasmine.createSpy('valid');
TestInput = React.createClass({
isValid = jasmine.createSpy('valid');

TestInput = React.createClass({
mixins: [Formsy.Mixin],
updateValue: function (event) {
this.setValue(event.target.value);
Expand All @@ -30,7 +30,7 @@ describe('Rules: equals', function() {
});

afterEach(function() {
TestInput = isValid = isInvalid = form = null;
TestInput = isValid = isInvalid = form = null;
});

it('should fail with undefined', function () {
Expand All @@ -57,4 +57,4 @@ describe('Rules: equals', function() {
expect(isValid).toHaveBeenCalled();
});

});
});
12 changes: 6 additions & 6 deletions specs/Rules-hasValue-spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
var Formsy = require('./../src/main.js');

describe('Rules: hasValue', function() {
var TestInput, isValid, form, input;
var TestInput, isValid, form, input;

beforeEach(function() {
isValid = jasmine.createSpy('valid');
TestInput = React.createClass({
isValid = jasmine.createSpy('valid');

TestInput = React.createClass({
mixins: [Formsy.Mixin],
updateValue: function (event) {
this.setValue(event.target.value);
Expand All @@ -30,7 +30,7 @@ describe('Rules: hasValue', function() {
});

afterEach(function() {
TestInput = isValid = isInvalid = form = null;
TestInput = isValid = isInvalid = form = null;
});

it('should fail with undefined', function () {
Expand All @@ -51,4 +51,4 @@ describe('Rules: hasValue', function() {
expect(isValid).toHaveBeenCalled();
});

});
});
12 changes: 6 additions & 6 deletions specs/Rules-isAlpha-spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
var Formsy = require('./../src/main.js');

describe('Rules: isAlpha', function() {
var TestInput, isValid, form, input;
var TestInput, isValid, form, input;

beforeEach(function() {
isValid = jasmine.createSpy('valid');
TestInput = React.createClass({
isValid = jasmine.createSpy('valid');

TestInput = React.createClass({
mixins: [Formsy.Mixin],
updateValue: function (event) {
this.setValue(event.target.value);
Expand All @@ -30,7 +30,7 @@ describe('Rules: isAlpha', function() {
});

afterEach(function() {
TestInput = isValid = isInvalid = form = null;
TestInput = isValid = isInvalid = form = null;
});

it('should fail with undefined', function () {
Expand All @@ -57,4 +57,4 @@ describe('Rules: isAlpha', function() {
expect(isValid).toHaveBeenCalled();
});

});
});
Loading

0 comments on commit b18b4e8

Please sign in to comment.