username_not_reserved_validator 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/README.md +22 -11
- data/lib/username_not_reserved_validator/reserved_names.rb +3 -0
- data/spec/username_not_reserved_validator_spec.rb +109 -95
- data/username_not_reserved_validator.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ec6488df3ec58634c942eb9151ffa4cfb83a199
|
4
|
+
data.tar.gz: 9db69886edf7e099ca98bdbbf2cbb0efc71a6e40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 336f8f94107f9523cb353e5a86b7657e66f798914feb57259d5d76db3a5d74d63bcaa9917336620116300f3ad87e1283835783c8734fa9ad06c5727c3e7bb440
|
7
|
+
data.tar.gz: c1d9ef08e67ce4aedbb3d5007073d9ed7abb718a029ff65813986b1d3e8a4c8ab27ee44ce1787b4ba2a68a210b9aec45c5d34b81c00f02c5187366fb3fdafa5b
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
# UsernameNotReservedValidator
|
2
2
|
|
3
3
|
[](https://travis-ci.org/kwappa/username_not_reserved_validator)
|
4
|
-
|
5
4
|
[](https://coveralls.io/r/kwappa/username_not_reserved_validator?branch=master)
|
6
|
-
|
7
5
|
[](https://codeclimate.com/github/kwappa/username_not_reserved_validator)
|
8
6
|
|
9
|
-
|
7
|
+
Custom validator for ActiveModel.
|
10
8
|
|
11
|
-
|
9
|
+
Validates that username is not included in the list of reserved names.
|
12
10
|
|
13
11
|
e.g:
|
14
12
|
|
@@ -37,13 +35,12 @@ Or install it yourself as:
|
|
37
35
|
|
38
36
|
### validation settings
|
39
37
|
|
40
|
-
|
41
|
-
|
38
|
+
Add validation setting on your ActiveModel.
|
42
39
|
|
43
|
-
```
|
40
|
+
```ruby
|
44
41
|
class User < ActiveRecord::Base
|
45
42
|
validates(:name, username_not_reserved: true)
|
46
|
-
|
43
|
+
end
|
47
44
|
```
|
48
45
|
|
49
46
|
### options
|
@@ -51,9 +48,23 @@ class User < ActiveRecord::Base
|
|
51
48
|
* `additional_reserved_names` (Array of String / default: `[]`)
|
52
49
|
* specify additional reserved names
|
53
50
|
* `case_insencitve` (Boolean / default: `true`)
|
54
|
-
* if set to `false`, comparison is case
|
51
|
+
* if set to `false`, comparison is case sencitive
|
55
52
|
* `message` (Symbol / default: `:invalid`)
|
56
|
-
* specify key of error message
|
53
|
+
* specify custom key of error message
|
54
|
+
|
55
|
+
e.g.)
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
class User < ActiveRecord::Base
|
59
|
+
validates(:name,
|
60
|
+
username_not_reserved: {
|
61
|
+
additional_reserved_names: %w[foo bar],
|
62
|
+
case_insencitve: true,
|
63
|
+
message: :reserved_username
|
64
|
+
}
|
65
|
+
)
|
66
|
+
end
|
67
|
+
```
|
57
68
|
|
58
69
|
## Referenced resources
|
59
70
|
|
@@ -61,4 +72,4 @@ class User < ActiveRecord::Base
|
|
61
72
|
* http://bitarts.jp/blog/archives/004363.html
|
62
73
|
* https://github.com/balexand/email_validator
|
63
74
|
|
64
|
-
|
75
|
+
With tons of thanks :sushi:
|
@@ -152,6 +152,8 @@ module UsernameNotReservedValidator::ReservedNames
|
|
152
152
|
activity
|
153
153
|
password
|
154
154
|
auth
|
155
|
+
oauth
|
156
|
+
oauth2
|
155
157
|
session
|
156
158
|
register
|
157
159
|
login
|
@@ -215,6 +217,7 @@ module UsernameNotReservedValidator::ReservedNames
|
|
215
217
|
code
|
216
218
|
guest
|
217
219
|
app
|
220
|
+
application
|
218
221
|
maintenance
|
219
222
|
roc
|
220
223
|
id
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe UsernameNotReservedValidator do
|
4
|
-
|
5
4
|
let(:reserved_usernames) { UsernameNotReservedValidator::ReservedNames.list }
|
6
5
|
let(:valid_username) { 'valid_username' }
|
7
6
|
let(:invalid_username) { reserved_usernames.first(30).sample }
|
@@ -9,134 +8,149 @@ describe UsernameNotReservedValidator do
|
|
9
8
|
let(:invalid_pluralized_username) { reserved_usernames.first(30).sample.pluralize }
|
10
9
|
let(:invalid_additional_username) { 'additional_reserved_username' }
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
describe '#validate_each' do
|
12
|
+
describe 'sample user name' do
|
13
|
+
context 'when valid' do
|
14
|
+
it 'does not included in reserved list' do
|
15
|
+
expect(reserved_usernames.map(&:downcase)).to_not include(valid_username)
|
16
|
+
expect(reserved_usernames.map(&:downcase).map(&:pluralize)).to_not include(valid_username)
|
17
|
+
end
|
18
18
|
end
|
19
|
-
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
context 'when invalid' do
|
21
|
+
it 'included in reserved list' do
|
22
|
+
expect(reserved_usernames).to include(invalid_username)
|
23
|
+
end
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
context 'when camelized invalid name' do
|
26
|
+
it 'included only downcase list' do
|
27
|
+
expect(reserved_usernames).to_not include(invalid_camelized_username)
|
28
|
+
expect(reserved_usernames.map(&:downcase)).to include(invalid_camelized_username.downcase)
|
29
|
+
end
|
30
30
|
end
|
31
|
-
end
|
32
31
|
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
context 'when pluarized invalid name' do
|
33
|
+
it 'included in pluralized list' do
|
34
|
+
expect(reserved_usernames).to include(invalid_pluralized_username.singularize)
|
35
|
+
end
|
36
36
|
end
|
37
|
-
end
|
38
37
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
context 'when additional invalid name' do
|
39
|
+
it 'does not included in reserved list' do
|
40
|
+
expect(reserved_usernames.map(&:downcase)).to_not include(invalid_additional_username)
|
41
|
+
expect(reserved_usernames.map(&:downcase).map(&:pluralize)).to_not include(invalid_additional_username)
|
42
|
+
end
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
46
|
-
end
|
47
46
|
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
shared_examples_for 'accepts username' do
|
48
|
+
it { expect(user).to be_valid }
|
49
|
+
end
|
51
50
|
|
52
|
-
|
53
|
-
|
54
|
-
|
51
|
+
shared_examples_for 'rejects username' do
|
52
|
+
it { expect(user).to_not be_valid }
|
53
|
+
end
|
55
54
|
|
55
|
+
describe 'model without validation' do
|
56
|
+
subject(:user) { WithoutValidationUser.new(name: username) }
|
56
57
|
|
57
|
-
|
58
|
-
|
58
|
+
context 'with valid username' do
|
59
|
+
let(:username) { valid_username }
|
60
|
+
include_examples 'accepts username'
|
61
|
+
end
|
59
62
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
63
|
+
context 'with invalid username' do
|
64
|
+
let(:username) { invalid_username }
|
65
|
+
include_examples 'accepts username'
|
66
|
+
end
|
64
67
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
68
|
+
context 'with invalid camelized username' do
|
69
|
+
let(:username) { invalid_camelized_username }
|
70
|
+
include_examples 'accepts username'
|
71
|
+
end
|
69
72
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
73
|
+
context 'with invalid pluralized username' do
|
74
|
+
let(:username) { invalid_pluralized_username }
|
75
|
+
include_examples 'accepts username'
|
76
|
+
end
|
74
77
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
+
context 'with additionals invalid username' do
|
79
|
+
let(:username) { invalid_additional_username }
|
80
|
+
include_examples 'accepts username'
|
81
|
+
end
|
78
82
|
end
|
79
83
|
|
80
|
-
|
81
|
-
|
82
|
-
include_examples 'accepts username'
|
83
|
-
end
|
84
|
-
end
|
84
|
+
describe 'model with validation' do
|
85
|
+
subject(:user) { WithValidationUser.new(name: username) }
|
85
86
|
|
86
|
-
|
87
|
-
|
87
|
+
context 'with valid username' do
|
88
|
+
let(:username) { valid_username }
|
89
|
+
include_examples 'accepts username'
|
90
|
+
end
|
88
91
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
92
|
+
context 'with invalid username' do
|
93
|
+
let(:username) { invalid_username }
|
94
|
+
include_examples 'rejects username'
|
95
|
+
end
|
93
96
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
97
|
+
context 'with invalid camelized username' do
|
98
|
+
let(:username) { invalid_camelized_username }
|
99
|
+
include_examples 'rejects username'
|
100
|
+
end
|
98
101
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
102
|
+
context 'with invalid pluralized username' do
|
103
|
+
let(:username) { invalid_pluralized_username }
|
104
|
+
include_examples 'rejects username'
|
105
|
+
end
|
103
106
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
+
describe 'name "user" and "users"' do
|
108
|
+
context 'when "user"' do
|
109
|
+
let(:username) { 'user' }
|
110
|
+
include_examples 'rejects username'
|
111
|
+
end
|
112
|
+
context 'when "users"' do
|
113
|
+
let(:username) { 'users' }
|
114
|
+
include_examples 'rejects username'
|
115
|
+
end
|
116
|
+
end
|
107
117
|
end
|
108
|
-
end
|
109
118
|
|
110
|
-
|
111
|
-
|
119
|
+
describe 'model with case insencitive validation' do
|
120
|
+
subject(:user) { WithCaseInsencitiveValidationUser.new(name: username) }
|
112
121
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
122
|
+
context 'with valid username' do
|
123
|
+
let(:username) { valid_username }
|
124
|
+
include_examples 'accepts username'
|
125
|
+
end
|
117
126
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
127
|
+
context 'with invalid username' do
|
128
|
+
let(:username) { invalid_username }
|
129
|
+
include_examples 'rejects username'
|
130
|
+
end
|
122
131
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
132
|
+
context 'with invalid camelized username' do
|
133
|
+
let(:username) { invalid_camelized_username }
|
134
|
+
include_examples 'accepts username'
|
135
|
+
end
|
127
136
|
|
128
|
-
|
129
|
-
|
130
|
-
|
137
|
+
context 'with invalid pluralized username' do
|
138
|
+
let(:username) { invalid_pluralized_username }
|
139
|
+
include_examples 'rejects username'
|
140
|
+
end
|
131
141
|
end
|
132
|
-
end
|
133
142
|
|
134
|
-
|
135
|
-
|
143
|
+
describe 'model with validation and additional reserved username' do
|
144
|
+
subject(:user) { WithAdditionalReservedNamesValidationUser.new(name: username) }
|
136
145
|
|
137
|
-
|
138
|
-
|
139
|
-
|
146
|
+
context 'with additionals invalid username' do
|
147
|
+
let(:username) { invalid_additional_username }
|
148
|
+
include_examples 'rejects username'
|
149
|
+
end
|
140
150
|
end
|
141
151
|
end
|
152
|
+
|
153
|
+
describe '.default_options' do
|
154
|
+
it { expect(described_class.default_options).to eq( { case_insencitive: true } ) }
|
155
|
+
end
|
142
156
|
end
|
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "username_not_reserved_validator"
|
7
|
-
spec.version = "1.0.
|
7
|
+
spec.version = "1.0.1"
|
8
8
|
spec.authors = ["SHIOYA, Hiromu"]
|
9
9
|
spec.email = ["kwappa.856@gmail.com"]
|
10
10
|
spec.summary = "validates that username is not included in reserved list."
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: username_not_reserved_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SHIOYA, Hiromu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -119,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
119
|
version: '0'
|
120
120
|
requirements: []
|
121
121
|
rubyforge_project:
|
122
|
-
rubygems_version: 2.
|
122
|
+
rubygems_version: 2.4.5
|
123
123
|
signing_key:
|
124
124
|
specification_version: 4
|
125
125
|
summary: validates that username is not included in reserved list.
|