Moved to it's own file, added specs
This commit is contained in:
parent
9e7d7f420f
commit
5cd0a60073
5 changed files with 57 additions and 31 deletions
|
|
@ -1,18 +1,5 @@
|
||||||
:javascript
|
%script{:type => "text/javascript",
|
||||||
$(function() {
|
:src => "/javascripts/validation.js"}
|
||||||
var Validation = {
|
|
||||||
username: {
|
|
||||||
characters: /^(|[A-Za-z0-9_]{0,32})$/,
|
|
||||||
length: [6, 32]
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
$("#user_username").keypress(function(evt) {
|
|
||||||
if(!Validation.username.characters.test(this.value + String.fromCharCode(evt.charCode)) {
|
|
||||||
evt.preventDefault();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
= form_for(resource, :as => resource_name, :url => invitation_path(resource_name), :html => {:method => :put }) do |f|
|
= form_for(resource, :as => resource_name, :url => invitation_path(resource_name), :html => {:method => :put }) do |f|
|
||||||
%p
|
%p
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,5 @@
|
||||||
:javascript
|
%script {:type => "text/javascript"
|
||||||
$(function() {
|
:src "/javascripts/validation.js"}
|
||||||
var Validation = {
|
|
||||||
username: {
|
|
||||||
characters: /^(|[A-Za-z0-9_]{0,32})$/,
|
|
||||||
length: [6, 32]
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
$("#user_username").keypress(function(evt) {
|
|
||||||
if(!Validation.username.characters.test(this.value + String.fromCharCode(evt.charCode)) {
|
|
||||||
evt.preventDefault();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
.span-12.prepend-6.last
|
.span-12.prepend-6.last
|
||||||
.floating
|
.floating
|
||||||
%h3
|
%h3
|
||||||
|
|
|
||||||
19
public/javascripts/validation.js
Normal file
19
public/javascripts/validation.js
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
var Validation = {
|
||||||
|
rules: {
|
||||||
|
username: {
|
||||||
|
characters: /^(|[A-Za-z0-9_]{0,32})$/,
|
||||||
|
length: [6, 32]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
events: {
|
||||||
|
usernameKeypress: function(evt) {
|
||||||
|
if(!Validation.rules.username.characters.test(this.value + String.fromCharCode(evt.charCode))) {
|
||||||
|
evt.preventDefault();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
$(function() {
|
||||||
|
$("#user_username").keypress(Validation.events.usernameKeypress);
|
||||||
|
});
|
||||||
|
|
@ -14,6 +14,7 @@ src_files:
|
||||||
- public/javascripts/vendor/jquery144.js
|
- public/javascripts/vendor/jquery144.js
|
||||||
- public/javascripts/vendor/jquery-ui-1.8.6.custom.min.js
|
- public/javascripts/vendor/jquery-ui-1.8.6.custom.min.js
|
||||||
- public/javascripts/vendor/jquery.tipsy.js
|
- public/javascripts/vendor/jquery.tipsy.js
|
||||||
|
- public/javascripts/validation.js
|
||||||
- public/javascripts/diaspora.js
|
- public/javascripts/diaspora.js
|
||||||
- public/javascripts/mobile.js
|
- public/javascripts/mobile.js
|
||||||
- public/javascripts/aspect-edit.js
|
- public/javascripts/aspect-edit.js
|
||||||
|
|
|
||||||
33
spec/javascripts/validation-spec.js
Normal file
33
spec/javascripts/validation-spec.js
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
describe("Validation", function() {
|
||||||
|
describe("rules", function() {
|
||||||
|
it("contains all the rules for validation");
|
||||||
|
|
||||||
|
describe("username", function() {
|
||||||
|
describe("characters", function() {
|
||||||
|
it("is the regex for checking if we allow what the user typed");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe("events", function() {
|
||||||
|
it("contains all the events that use validation methods");
|
||||||
|
describe("usernameKeypress", function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
$("#jasmine_content").html(
|
||||||
|
' <input id="user_username" name="user[username]" size="30" type="text">'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("doesn't allow the user to type anything but letters, numbers and underscores", function() {
|
||||||
|
expect(Validation.rules.username.characters.test("*")).toBeFalsy();
|
||||||
|
expect(Validation.rules.username.characters.test("Aa_")).toBeTruthy();
|
||||||
|
expect(Validation.rules.username.characters.test("ffffffffffffffffffffffffffffffffff")).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("is called when the user presses a key on #user_username") {
|
||||||
|
spyOn(Validation.events, "usernameKeypress");
|
||||||
|
$("#user_username").keypress();
|
||||||
|
expect(Validation.events.usernameKeypress).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Reference in a new issue