acts_as_human 2.0.3 → 4.0.0
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 +7 -0
- data/.github/workflows/ci.yml +51 -0
- data/.github/workflows/release.yml +18 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +31 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +69 -0
- data/Rakefile +5 -20
- data/acts_as_human.gemspec +35 -0
- data/bin/console +15 -0
- data/bin/rspec +27 -0
- data/bin/rubocop +27 -0
- data/bin/setup +8 -0
- data/lefthook.yml +9 -0
- data/lib/acts_as_human/class_methods.rb +28 -40
- data/lib/acts_as_human/instance_methods.rb +11 -37
- data/lib/acts_as_human/name_parser.rb +35 -0
- data/lib/acts_as_human/person_name_validator.rb +11 -0
- data/lib/acts_as_human/version.rb +5 -0
- data/lib/acts_as_human.rb +9 -1
- data/lib/generators/acts_as_human/migration/migration_generator.rb +16 -0
- data/lib/generators/acts_as_human/migration/templates/migration.rb +7 -0
- metadata +163 -64
- data/MIT-LICENSE +0 -20
- data/README.rdoc +0 -46
- data/VERSION +0 -1
- data/lib/acts_as_human/validations.rb +0 -22
- data/test/acts_as_human_test.rb +0 -145
- data/test/database.yml +0 -3
- data/test/schema.rb +0 -14
- data/test/test_helper.rb +0 -29
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 2e1b8f04bef566dbf85b27a41a55c22a6bbebf2d8ba6cc6c89926cb22861ef5c
|
|
4
|
+
data.tar.gz: fc902452ab63bca268f8ffd4aa07d09eedfa97619d360e4f6f0bb0498221f121
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 7fa2a3766bb4ddbb7d3a11774ae3fa790a5e1c35a7b55761562466f01bbe8c5c9bf3631a7fbe438137439f336e6f68b34be5f379b3f206531dbf74e16204e316
|
|
7
|
+
data.tar.gz: 7b4baae82d36987e518e3fb2707c5b2cfb69837017af6d9caa45f6e9d321546883d5e51f86b4f400acc106c591b950bbb6f934d7f3000cb3c1a2a2d3297fe866
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main, master]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
ruby: ["3.3", "3.4"]
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- uses: ruby/setup-ruby@v1
|
|
20
|
+
with:
|
|
21
|
+
ruby-version: ${{ matrix.ruby }}
|
|
22
|
+
bundler-cache: true
|
|
23
|
+
|
|
24
|
+
- run: bundle exec rspec
|
|
25
|
+
|
|
26
|
+
audit:
|
|
27
|
+
runs-on: ubuntu-latest
|
|
28
|
+
|
|
29
|
+
steps:
|
|
30
|
+
- uses: actions/checkout@v4
|
|
31
|
+
|
|
32
|
+
- uses: ruby/setup-ruby@v1
|
|
33
|
+
with:
|
|
34
|
+
ruby-version: "3.4"
|
|
35
|
+
bundler-cache: true
|
|
36
|
+
|
|
37
|
+
- run: gem install bundler-audit
|
|
38
|
+
- run: bundle-audit check --update
|
|
39
|
+
|
|
40
|
+
lint:
|
|
41
|
+
runs-on: ubuntu-latest
|
|
42
|
+
|
|
43
|
+
steps:
|
|
44
|
+
- uses: actions/checkout@v4
|
|
45
|
+
|
|
46
|
+
- uses: ruby/setup-ruby@v1
|
|
47
|
+
with:
|
|
48
|
+
ruby-version: "3.4"
|
|
49
|
+
bundler-cache: true
|
|
50
|
+
|
|
51
|
+
- run: bundle exec rubocop
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags: ['v*']
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
release:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
permissions:
|
|
11
|
+
id-token: write
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
- uses: ruby/setup-ruby@v1
|
|
15
|
+
with:
|
|
16
|
+
ruby-version: "3.4"
|
|
17
|
+
bundler-cache: true
|
|
18
|
+
- uses: rubygems/release-gem@v1
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
plugins:
|
|
2
|
+
- rubocop-rspec
|
|
3
|
+
|
|
4
|
+
AllCops:
|
|
5
|
+
TargetRubyVersion: 3.3
|
|
6
|
+
NewCops: enable
|
|
7
|
+
SuggestExtensions: false
|
|
8
|
+
Exclude:
|
|
9
|
+
- "bin/**/*"
|
|
10
|
+
- "vendor/**/*"
|
|
11
|
+
- "lib/generators/**/*.rb"
|
|
12
|
+
|
|
13
|
+
Style/Documentation:
|
|
14
|
+
Enabled: false
|
|
15
|
+
|
|
16
|
+
Gemspec/DevelopmentDependencies:
|
|
17
|
+
Enabled: false
|
|
18
|
+
|
|
19
|
+
Metrics/BlockLength:
|
|
20
|
+
Exclude:
|
|
21
|
+
- "spec/**/*"
|
|
22
|
+
|
|
23
|
+
RSpec/SpecFilePathFormat:
|
|
24
|
+
Exclude:
|
|
25
|
+
- "spec/generators/**/*"
|
|
26
|
+
|
|
27
|
+
RSpec/MultipleExpectations:
|
|
28
|
+
Enabled: false
|
|
29
|
+
|
|
30
|
+
RSpec/ExampleLength:
|
|
31
|
+
Enabled: false
|
data/.ruby-gemset
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
acts_as_human
|
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ruby-3.4.8
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Brent
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
[](https://github.com/brentgreeff/acts_as_human/actions/workflows/ci.yml)
|
|
2
|
+
|
|
3
|
+
# acts_as_human
|
|
4
|
+
|
|
5
|
+
Adds `full_name` / `full_name=` to an ActiveRecord model, splitting a single input into `first_name`, `middle_names`, and `last_name` with validations.
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
class User < ActiveRecord::Base
|
|
9
|
+
acts_as_human
|
|
10
|
+
end
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```ruby
|
|
16
|
+
# Gemfile
|
|
17
|
+
gem 'acts_as_human'
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
bundle install
|
|
22
|
+
rails generate acts_as_human:migration users
|
|
23
|
+
rake db:migrate
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Change `users` to the name of your table.
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
Assign names individually:
|
|
31
|
+
|
|
32
|
+
```ruby
|
|
33
|
+
user = User.new(first_name: 'Brent', last_name: 'Greeff')
|
|
34
|
+
user.full_name # => "Brent Greeff"
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Or assign via a single input:
|
|
38
|
+
|
|
39
|
+
```ruby
|
|
40
|
+
user = User.new(full_name: 'Brent Wicked Middle Names Greeff')
|
|
41
|
+
user.first_name # => "Brent"
|
|
42
|
+
user.middle_names # => "Wicked Middle Names"
|
|
43
|
+
user.last_name # => "Greeff"
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Options
|
|
47
|
+
|
|
48
|
+
```ruby
|
|
49
|
+
acts_as_human require_last_name: false
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Validations
|
|
53
|
+
|
|
54
|
+
- `first_name` is required
|
|
55
|
+
- `last_name` is required (unless `require_last_name: false`)
|
|
56
|
+
- Each field is limited to 40 characters
|
|
57
|
+
- Non-name characters (`< > & /`) are rejected
|
|
58
|
+
|
|
59
|
+
## Development
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
bundle install
|
|
63
|
+
bundle exec lefthook install
|
|
64
|
+
bundle exec rspec
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## License
|
|
68
|
+
|
|
69
|
+
MIT
|
data/Rakefile
CHANGED
|
@@ -1,23 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
require 'rake/testtask'
|
|
3
|
-
require 'rake/rdoctask'
|
|
1
|
+
# frozen_string_literal: true
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
require 'bundler/gem_tasks'
|
|
4
|
+
require 'rspec/core/rake_task'
|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
Rake::TestTask.new(:test) do |t|
|
|
10
|
-
t.libs << 'lib'
|
|
11
|
-
t.libs << 'test'
|
|
12
|
-
t.pattern = 'test/**/*_test.rb'
|
|
13
|
-
t.verbose = true
|
|
14
|
-
end
|
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
15
7
|
|
|
16
|
-
|
|
17
|
-
Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
18
|
-
rdoc.rdoc_dir = 'rdoc'
|
|
19
|
-
rdoc.title = 'ActsAsHuman'
|
|
20
|
-
rdoc.options << '--line-numbers' << '--inline-source'
|
|
21
|
-
rdoc.rdoc_files.include('README')
|
|
22
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
23
|
-
end
|
|
8
|
+
task default: :spec
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lib/acts_as_human/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'acts_as_human'
|
|
7
|
+
spec.version = ActsAsHuman::VERSION
|
|
8
|
+
spec.authors = ['Brent Greeff']
|
|
9
|
+
spec.email = ['brentgreeff@gmail.com']
|
|
10
|
+
spec.summary = 'Rails plugin to handle first_name, middle_names and last_name combinations.'
|
|
11
|
+
spec.homepage = 'https://github.com/brentgreeff/acts_as_human'
|
|
12
|
+
spec.license = 'MIT'
|
|
13
|
+
|
|
14
|
+
spec.required_ruby_version = '>= 3.3'
|
|
15
|
+
|
|
16
|
+
spec.metadata = {
|
|
17
|
+
'source_code_uri' => 'https://github.com/brentgreeff/acts_as_human',
|
|
18
|
+
'rubygems_mfa_required' => 'true'
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:spec|test|features)/}) }
|
|
22
|
+
spec.bindir = 'exe'
|
|
23
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
24
|
+
spec.require_paths = ['lib']
|
|
25
|
+
|
|
26
|
+
spec.add_dependency 'activerecord', '>= 7.0'
|
|
27
|
+
spec.add_dependency 'railties', '>= 7.0'
|
|
28
|
+
|
|
29
|
+
spec.add_development_dependency 'bundler-audit'
|
|
30
|
+
spec.add_development_dependency 'lefthook'
|
|
31
|
+
spec.add_development_dependency 'rspec-rails'
|
|
32
|
+
spec.add_development_dependency 'rubocop'
|
|
33
|
+
spec.add_development_dependency 'rubocop-rspec'
|
|
34
|
+
spec.add_development_dependency 'sqlite3'
|
|
35
|
+
end
|
data/bin/console
ADDED
data/bin/rspec
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
#
|
|
5
|
+
# This file was generated by Bundler.
|
|
6
|
+
#
|
|
7
|
+
# The application 'rspec' is installed as part of a gem, and
|
|
8
|
+
# this file is here to facilitate running it.
|
|
9
|
+
#
|
|
10
|
+
|
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
|
|
12
|
+
|
|
13
|
+
bundle_binstub = File.expand_path("bundle", __dir__)
|
|
14
|
+
|
|
15
|
+
if File.file?(bundle_binstub)
|
|
16
|
+
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
|
|
17
|
+
load(bundle_binstub)
|
|
18
|
+
else
|
|
19
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
|
20
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
require "rubygems"
|
|
25
|
+
require "bundler/setup"
|
|
26
|
+
|
|
27
|
+
load Gem.bin_path("rspec-core", "rspec")
|
data/bin/rubocop
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
#
|
|
5
|
+
# This file was generated by Bundler.
|
|
6
|
+
#
|
|
7
|
+
# The application 'rubocop' is installed as part of a gem, and
|
|
8
|
+
# this file is here to facilitate running it.
|
|
9
|
+
#
|
|
10
|
+
|
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
|
|
12
|
+
|
|
13
|
+
bundle_binstub = File.expand_path("bundle", __dir__)
|
|
14
|
+
|
|
15
|
+
if File.file?(bundle_binstub)
|
|
16
|
+
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
|
|
17
|
+
load(bundle_binstub)
|
|
18
|
+
else
|
|
19
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
|
20
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
require "rubygems"
|
|
25
|
+
require "bundler/setup"
|
|
26
|
+
|
|
27
|
+
load Gem.bin_path("rubocop", "rubocop")
|
data/bin/setup
ADDED
data/lefthook.yml
ADDED
|
@@ -1,48 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ActsAs
|
|
2
4
|
module Human
|
|
3
|
-
mattr_accessor :acceptable_name, :bad_name_message
|
|
4
|
-
|
|
5
|
-
self.acceptable_name = /\A[^[:cntrl:]\\<>\/&]*\z/
|
|
6
|
-
self.bad_name_message = "some characters in your name are not allowed".freeze
|
|
7
|
-
|
|
8
|
-
def self.included(base)
|
|
9
|
-
base.send :extend, ClassMethods
|
|
10
|
-
end
|
|
11
|
-
|
|
12
5
|
module ClassMethods
|
|
13
|
-
|
|
14
|
-
def acts_as_human(options={})
|
|
6
|
+
def acts_as_human(options = {})
|
|
15
7
|
cattr_accessor :require_last_name
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
end
|
|
8
|
+
self.require_last_name = options.fetch(:require_last_name, true)
|
|
9
|
+
|
|
10
|
+
validate_first_name
|
|
11
|
+
validate_middle_names
|
|
12
|
+
validate_last_name
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def validate_first_name
|
|
18
|
+
validates :first_name, presence: { message: 'first name is required' },
|
|
19
|
+
length: { maximum: 40, message: 'first name is too long (max 40 characters)' },
|
|
20
|
+
person_name: true
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def validate_middle_names
|
|
24
|
+
validates :middle_names, length: { maximum: 40, message: 'middle names are too long (max 40 characters)' },
|
|
25
|
+
person_name: true,
|
|
26
|
+
allow_nil: true
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def validate_last_name
|
|
30
|
+
validates :last_name, presence: { message: 'last name is required', if: -> { require_last_name } },
|
|
31
|
+
length: { maximum: 40, message: 'last name is too long (max 40 characters)' },
|
|
32
|
+
person_name: true
|
|
42
33
|
end
|
|
43
34
|
end
|
|
44
35
|
end
|
|
45
36
|
end
|
|
46
|
-
|
|
47
|
-
ActiveRecord::Base.send(:include, ActsAs::Human)
|
|
48
|
-
|
|
@@ -1,47 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ActsAs
|
|
2
4
|
module Human
|
|
3
|
-
|
|
4
5
|
module InstanceMethods
|
|
5
6
|
def full_name
|
|
6
|
-
return '' if first_name.blank?
|
|
7
|
-
|
|
7
|
+
return '' if first_name.blank? && last_name.blank?
|
|
8
8
|
return "#{first_name} #{last_name}" if middle_names.blank?
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def full_name=(names)
|
|
13
|
-
names_array = names.titlecase.split
|
|
14
|
-
|
|
15
|
-
self.first_name = names_array.first
|
|
16
|
-
return if names_array.size < 2
|
|
17
|
-
|
|
18
|
-
self.last_name = get_last_name(names_array)
|
|
19
|
-
|
|
20
|
-
assign_middle_names(names_array)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
private
|
|
24
|
-
|
|
25
|
-
def get_last_name(names_array)
|
|
26
|
-
if names_array.size > 2 and names_array[-2].eql? 'Mc'
|
|
27
|
-
surname = names_array.pop
|
|
28
|
-
names_array << "#{names_array.pop} #{surname}"
|
|
29
|
-
end
|
|
30
|
-
names_array.last
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def assign_middle_names(names_array)
|
|
34
|
-
if names_array.size > 2
|
|
35
|
-
self.middle_names = get_middle_names(names_array)
|
|
36
|
-
else
|
|
37
|
-
self.middle_names = nil
|
|
38
|
-
end
|
|
9
|
+
|
|
10
|
+
"#{first_name} #{middle_names} #{last_name}"
|
|
39
11
|
end
|
|
40
|
-
|
|
41
|
-
def
|
|
42
|
-
|
|
12
|
+
|
|
13
|
+
def full_name=(value)
|
|
14
|
+
parsed = NameParser.new(value)
|
|
15
|
+
self.first_name = parsed.first_name
|
|
16
|
+
self.last_name = parsed.last_name
|
|
17
|
+
self.middle_names = parsed.middle_names
|
|
43
18
|
end
|
|
44
19
|
end
|
|
45
20
|
end
|
|
46
21
|
end
|
|
47
|
-
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ActsAs
|
|
4
|
+
module Human
|
|
5
|
+
class NameParser
|
|
6
|
+
attr_reader :first_name, :middle_names, :last_name
|
|
7
|
+
|
|
8
|
+
def initialize(full_name)
|
|
9
|
+
parts = full_name.titlecase.split
|
|
10
|
+
@first_name = parts.first
|
|
11
|
+
@last_name = extract_last_name(parts)
|
|
12
|
+
@middle_names = extract_middle_names(parts)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def extract_last_name(parts)
|
|
18
|
+
return nil if parts.size < 2
|
|
19
|
+
|
|
20
|
+
if parts.size > 2 && parts[-2] == 'Mc'
|
|
21
|
+
"#{parts[-2]} #{parts[-1]}"
|
|
22
|
+
else
|
|
23
|
+
parts.last
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def extract_middle_names(parts)
|
|
28
|
+
return nil if parts.size < 3
|
|
29
|
+
|
|
30
|
+
upper = parts[-2] == 'Mc' ? -3 : -2
|
|
31
|
+
parts[1..upper].join(' ')
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class PersonNameValidator < ActiveModel::EachValidator
|
|
4
|
+
ACCEPTABLE = %r{\A[^[:cntrl:]\\<>/&]*\z}
|
|
5
|
+
|
|
6
|
+
def validate_each(record, attribute, value)
|
|
7
|
+
return if value.nil?
|
|
8
|
+
|
|
9
|
+
record.errors.add(attribute, 'some characters in your name are not allowed') unless value.match?(ACCEPTABLE)
|
|
10
|
+
end
|
|
11
|
+
end
|
data/lib/acts_as_human.rb
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'acts_as_human/person_name_validator'
|
|
4
|
+
require 'acts_as_human/name_parser'
|
|
2
5
|
require 'acts_as_human/instance_methods'
|
|
3
6
|
require 'acts_as_human/class_methods'
|
|
7
|
+
|
|
8
|
+
ActiveSupport.on_load(:active_record) do
|
|
9
|
+
include ActsAs::Human::InstanceMethods
|
|
10
|
+
extend ActsAs::Human::ClassMethods
|
|
11
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ActsAsHuman
|
|
4
|
+
module Generators
|
|
5
|
+
class MigrationGenerator < Rails::Generators::NamedBase
|
|
6
|
+
source_root File.expand_path('templates', __dir__)
|
|
7
|
+
|
|
8
|
+
desc 'Generates a migration to add first_name, middle_names, and last_name to a table.'
|
|
9
|
+
|
|
10
|
+
def create_migration
|
|
11
|
+
timestamp = Time.now.utc.strftime('%Y%m%d%H%M%S')
|
|
12
|
+
template 'migration.rb', "db/migrate/#{timestamp}_add_names_to_#{file_name}.rb"
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
class AddNamesTo<%= class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
|
|
2
|
+
def change
|
|
3
|
+
add_column :<%= table_name %>, :first_name, :string
|
|
4
|
+
add_column :<%= table_name %>, :middle_names, :string
|
|
5
|
+
add_column :<%= table_name %>, :last_name, :string
|
|
6
|
+
end
|
|
7
|
+
end
|
metadata
CHANGED
|
@@ -1,79 +1,178 @@
|
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: acts_as_human
|
|
3
|
-
version: !ruby/object:Gem::Version
|
|
4
|
-
|
|
5
|
-
prerelease: false
|
|
6
|
-
segments:
|
|
7
|
-
- 2
|
|
8
|
-
- 0
|
|
9
|
-
- 3
|
|
10
|
-
version: 2.0.3
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 4.0.0
|
|
11
5
|
platform: ruby
|
|
12
|
-
authors:
|
|
6
|
+
authors:
|
|
13
7
|
- Brent Greeff
|
|
14
|
-
|
|
15
|
-
bindir: bin
|
|
8
|
+
bindir: exe
|
|
16
9
|
cert_chain: []
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: activerecord
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '7.0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '7.0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: railties
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '7.0'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '7.0'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: bundler-audit
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
47
|
+
type: :development
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: lefthook
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '0'
|
|
61
|
+
type: :development
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '0'
|
|
68
|
+
- !ruby/object:Gem::Dependency
|
|
69
|
+
name: rspec-rails
|
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - ">="
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '0'
|
|
75
|
+
type: :development
|
|
76
|
+
prerelease: false
|
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - ">="
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '0'
|
|
82
|
+
- !ruby/object:Gem::Dependency
|
|
83
|
+
name: rubocop
|
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - ">="
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '0'
|
|
89
|
+
type: :development
|
|
90
|
+
prerelease: false
|
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - ">="
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '0'
|
|
96
|
+
- !ruby/object:Gem::Dependency
|
|
97
|
+
name: rubocop-rspec
|
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
|
99
|
+
requirements:
|
|
100
|
+
- - ">="
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: '0'
|
|
103
|
+
type: :development
|
|
104
|
+
prerelease: false
|
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
106
|
+
requirements:
|
|
107
|
+
- - ">="
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: '0'
|
|
110
|
+
- !ruby/object:Gem::Dependency
|
|
111
|
+
name: sqlite3
|
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
|
113
|
+
requirements:
|
|
114
|
+
- - ">="
|
|
115
|
+
- !ruby/object:Gem::Version
|
|
116
|
+
version: '0'
|
|
117
|
+
type: :development
|
|
118
|
+
prerelease: false
|
|
119
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
120
|
+
requirements:
|
|
121
|
+
- - ">="
|
|
122
|
+
- !ruby/object:Gem::Version
|
|
123
|
+
version: '0'
|
|
124
|
+
email:
|
|
125
|
+
- brentgreeff@gmail.com
|
|
24
126
|
executables: []
|
|
25
|
-
|
|
26
127
|
extensions: []
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
-
|
|
30
|
-
-
|
|
31
|
-
|
|
32
|
-
-
|
|
33
|
-
-
|
|
128
|
+
extra_rdoc_files: []
|
|
129
|
+
files:
|
|
130
|
+
- ".github/workflows/ci.yml"
|
|
131
|
+
- ".github/workflows/release.yml"
|
|
132
|
+
- ".gitignore"
|
|
133
|
+
- ".rspec"
|
|
134
|
+
- ".rubocop.yml"
|
|
135
|
+
- ".ruby-gemset"
|
|
136
|
+
- ".ruby-version"
|
|
137
|
+
- Gemfile
|
|
138
|
+
- LICENSE.txt
|
|
139
|
+
- README.md
|
|
34
140
|
- Rakefile
|
|
35
|
-
-
|
|
141
|
+
- acts_as_human.gemspec
|
|
142
|
+
- bin/console
|
|
143
|
+
- bin/rspec
|
|
144
|
+
- bin/rubocop
|
|
145
|
+
- bin/setup
|
|
146
|
+
- lefthook.yml
|
|
36
147
|
- lib/acts_as_human.rb
|
|
37
|
-
- lib/acts_as_human/validations.rb
|
|
38
|
-
- lib/acts_as_human/instance_methods.rb
|
|
39
148
|
- lib/acts_as_human/class_methods.rb
|
|
40
|
-
-
|
|
41
|
-
-
|
|
42
|
-
-
|
|
43
|
-
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
149
|
+
- lib/acts_as_human/instance_methods.rb
|
|
150
|
+
- lib/acts_as_human/name_parser.rb
|
|
151
|
+
- lib/acts_as_human/person_name_validator.rb
|
|
152
|
+
- lib/acts_as_human/version.rb
|
|
153
|
+
- lib/generators/acts_as_human/migration/migration_generator.rb
|
|
154
|
+
- lib/generators/acts_as_human/migration/templates/migration.rb
|
|
155
|
+
homepage: https://github.com/brentgreeff/acts_as_human
|
|
156
|
+
licenses:
|
|
157
|
+
- MIT
|
|
158
|
+
metadata:
|
|
159
|
+
source_code_uri: https://github.com/brentgreeff/acts_as_human
|
|
160
|
+
rubygems_mfa_required: 'true'
|
|
161
|
+
rdoc_options: []
|
|
162
|
+
require_paths:
|
|
52
163
|
- lib
|
|
53
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
|
54
|
-
|
|
55
|
-
requirements:
|
|
164
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
165
|
+
requirements:
|
|
56
166
|
- - ">="
|
|
57
|
-
- !ruby/object:Gem::Version
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
version: "0"
|
|
62
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
|
-
none: false
|
|
64
|
-
requirements:
|
|
167
|
+
- !ruby/object:Gem::Version
|
|
168
|
+
version: '3.3'
|
|
169
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
170
|
+
requirements:
|
|
65
171
|
- - ">="
|
|
66
|
-
- !ruby/object:Gem::Version
|
|
67
|
-
|
|
68
|
-
segments:
|
|
69
|
-
- 0
|
|
70
|
-
version: "0"
|
|
172
|
+
- !ruby/object:Gem::Version
|
|
173
|
+
version: '0'
|
|
71
174
|
requirements: []
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
rubygems_version: 1.3.7
|
|
75
|
-
signing_key:
|
|
76
|
-
specification_version: 3
|
|
175
|
+
rubygems_version: 3.6.9
|
|
176
|
+
specification_version: 4
|
|
77
177
|
summary: Rails plugin to handle first_name, middle_names and last_name combinations.
|
|
78
178
|
test_files: []
|
|
79
|
-
|
data/MIT-LICENSE
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
Copyright (c) 2009 [Brent Greeff]
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
-
a copy of this software and associated documentation files (the
|
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
-
the following conditions:
|
|
10
|
-
|
|
11
|
-
The above copyright notice and this permission notice shall be
|
|
12
|
-
included in all copies or substantial portions of the Software.
|
|
13
|
-
|
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
= ActsAsHuman
|
|
2
|
-
|
|
3
|
-
== Install
|
|
4
|
-
Use the Gem:
|
|
5
|
-
|
|
6
|
-
gem install acts_as_human
|
|
7
|
-
|
|
8
|
-
With braid:
|
|
9
|
-
|
|
10
|
-
braid add git://github.com/brentgreeff/acts_as_human.git -p
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* Adds:
|
|
14
|
-
full_name
|
|
15
|
-
* and
|
|
16
|
-
full_name=
|
|
17
|
-
instance methods to a model
|
|
18
|
-
|
|
19
|
-
Adds validations to ensure that the names are reasonable.
|
|
20
|
-
|
|
21
|
-
* Requires:
|
|
22
|
-
first_name, last_name and middle_names columns on the model
|
|
23
|
-
|
|
24
|
-
@todo Need to add rake task to add fields to model.
|
|
25
|
-
|
|
26
|
-
== Example
|
|
27
|
-
|
|
28
|
-
class User < ActiveRecord::Base
|
|
29
|
-
acts_as_human
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
* user = User.new(:first_name => 'Brent', :last_name => 'Greeff')
|
|
33
|
-
user.full_name
|
|
34
|
-
=> "Brent Greeff"
|
|
35
|
-
|
|
36
|
-
* user = User.new(:full_name => "Brent Wicked Middle Names Greeff")
|
|
37
|
-
user.first_name
|
|
38
|
-
=> "Brent"
|
|
39
|
-
|
|
40
|
-
user.last_name
|
|
41
|
-
=> "Greeff"
|
|
42
|
-
|
|
43
|
-
user.middle_names
|
|
44
|
-
=> "Wicked Middle Names"
|
|
45
|
-
|
|
46
|
-
Copyright (c) 2009 [Brent Greeff], released under the MIT license
|
data/VERSION
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
2.0.2
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
module ActiveRecord
|
|
2
|
-
module Validations
|
|
3
|
-
module ClassMethods
|
|
4
|
-
|
|
5
|
-
def validates_as_person_name(*attr_names)
|
|
6
|
-
config = {
|
|
7
|
-
:with => ActsAs::Human.acceptable_name,
|
|
8
|
-
:message => ActsAs::Human.bad_name_message
|
|
9
|
-
}
|
|
10
|
-
check_format(attr_names, config)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
private
|
|
14
|
-
|
|
15
|
-
def check_format(attr_names, config)
|
|
16
|
-
config.update(attr_names.pop) if attr_names.last.is_a?(Hash)
|
|
17
|
-
validates_format_of attr_names, config
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
data/test/acts_as_human_test.rb
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper.rb'
|
|
2
|
-
|
|
3
|
-
class ActsAsHumanTest < ActiveSupport::TestCase
|
|
4
|
-
|
|
5
|
-
class User < ActiveRecord::Base
|
|
6
|
-
acts_as_human
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
class Customer < ActiveRecord::Base
|
|
10
|
-
acts_as_human :require_last_name => false
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
test "should require a first name" do
|
|
14
|
-
user = create_user
|
|
15
|
-
user.first_name = ''
|
|
16
|
-
|
|
17
|
-
deny user.valid?, 'Should not be valid without a first name'
|
|
18
|
-
assert_equal 'first name is required', user.errors[:first_name]
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
test "should have a first name that is less than 40 characters" do
|
|
22
|
-
user = User.new(:first_name => 'aaaaabbbbbcccccdddddeeeeefffffggggghhhhhi')
|
|
23
|
-
|
|
24
|
-
deny user.valid?
|
|
25
|
-
assert_equal 'first name is too long (max 40 characters)', user.errors[:first_name]
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
test "should require a last name" do
|
|
29
|
-
user = User.new(:first_name => 'Brent')
|
|
30
|
-
|
|
31
|
-
deny user.valid?
|
|
32
|
-
assert_equal 'last name is required', user.errors[:last_name]
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
test "should not require a last name if it is not required" do
|
|
36
|
-
someone_else = Customer.new(:first_name => 'Brent')
|
|
37
|
-
assert someone_else.valid?
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
test "should have a last name that is less than 40 characters" do
|
|
41
|
-
user = create_user
|
|
42
|
-
user.last_name = 'aaaaabbbbbcccccdddddeeeeefffffggggghhhhhi'
|
|
43
|
-
|
|
44
|
-
deny user.valid?
|
|
45
|
-
assert_equal 'last name is too long (max 40 characters)', user.errors[:last_name]
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
test "should have a last name when assigned through full name" do
|
|
49
|
-
user = User.new(:full_name => 'Brent')
|
|
50
|
-
|
|
51
|
-
deny user.valid?
|
|
52
|
-
assert_equal 'last name is required', user.errors[:last_name]
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
test "should have a full name composed of first and last names" do
|
|
56
|
-
user = User.new(:first_name => 'Brent', :last_name => 'Greeff')
|
|
57
|
-
assert_equal 'Brent Greeff', user.full_name
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
test "should have a full name composed of first middle and last names" do
|
|
61
|
-
user = User.new(
|
|
62
|
-
:first_name => 'Brent',
|
|
63
|
-
:middle_names => 'Middle Names',
|
|
64
|
-
:last_name => 'Greeff'
|
|
65
|
-
)
|
|
66
|
-
assert_equal 'Brent Middle Names Greeff', user.full_name
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
test "should assign first and last name when assigning to full name" do
|
|
70
|
-
user = User.new(:full_name => 'Brent Greeff')
|
|
71
|
-
|
|
72
|
-
assert_equal 'Brent', user.first_name
|
|
73
|
-
assert_equal 'Greeff', user.last_name
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
test "should assign first last and middle names when assigning to full name" do
|
|
77
|
-
user = User.new(:full_name => 'Brent Middle Names Greeff')
|
|
78
|
-
|
|
79
|
-
assert_equal 'Brent', user.first_name
|
|
80
|
-
assert_equal 'Middle Names', user.middle_names
|
|
81
|
-
assert_equal 'Greeff', user.last_name
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
test "should have middle names that are less than 40 characters" do
|
|
85
|
-
user = create_user
|
|
86
|
-
user.middle_names = 'aaaaabbbbbcccccdddddeeeeefffffggggghhhhhi'
|
|
87
|
-
|
|
88
|
-
deny user.valid?
|
|
89
|
-
assert_equal 'middle names are too long (max 40 characters)', user.errors[:middle_names]
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
test "should have an empty full name when user is new" do
|
|
93
|
-
user = User.new
|
|
94
|
-
assert_equal '', user.full_name
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
test "should not allow non name like characters" do
|
|
98
|
-
user = User.new(:full_name => "<Brent> Middle >< Names Gre&eff")
|
|
99
|
-
|
|
100
|
-
deny user.valid?
|
|
101
|
-
assert_equal 'some characters in your name are not allowed', user.errors[:first_name]
|
|
102
|
-
assert_equal 'some characters in your name are not allowed', user.errors[:last_name]
|
|
103
|
-
assert_equal 'some characters in your name are not allowed', user.errors[:middle_names]
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
test "should split up scottish names correctly" do
|
|
107
|
-
user = User.new(:full_name => "Ewan Mc Greggor")
|
|
108
|
-
|
|
109
|
-
assert_equal 'Ewan', user.first_name
|
|
110
|
-
assert_equal 'Mc Greggor', user.last_name
|
|
111
|
-
assert_nil user.middle_names
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
test "should split up scottish names with middle names correctly" do
|
|
115
|
-
user = User.new(:full_name => "Jade Frances Roseanne Mc Cracken")
|
|
116
|
-
|
|
117
|
-
assert_equal 'Jade', user.first_name
|
|
118
|
-
assert_equal 'Mc Cracken', user.last_name
|
|
119
|
-
assert_equal 'Frances Roseanne', user.middle_names
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
private
|
|
123
|
-
|
|
124
|
-
def create_user(options={})
|
|
125
|
-
default_options = {
|
|
126
|
-
:first_name => "Brent",
|
|
127
|
-
:last_name => "Greeff"
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return User.create!(default_options.merge(options))
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
def create_customer(options={})
|
|
134
|
-
default_options = {
|
|
135
|
-
:first_name => "Brent",
|
|
136
|
-
:last_name => "Greeff"
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return Customer.create!(default_options.merge(options))
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
def deny(expected_to_be_false, message = '')
|
|
143
|
-
assert ! expected_to_be_false, message
|
|
144
|
-
end
|
|
145
|
-
end
|
data/test/database.yml
DELETED
data/test/schema.rb
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
ActiveRecord::Schema.define(:version => 20090628014113) do
|
|
2
|
-
|
|
3
|
-
create_table "users", :force => true do |t|
|
|
4
|
-
t.string "first_name"
|
|
5
|
-
t.string "middle_names"
|
|
6
|
-
t.string "last_name"
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
create_table "customers", :force => true do |t|
|
|
10
|
-
t.string "first_name"
|
|
11
|
-
t.string "middle_names"
|
|
12
|
-
t.string "last_name"
|
|
13
|
-
end
|
|
14
|
-
end
|
data/test/test_helper.rb
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
require 'rubygems'
|
|
2
|
-
require 'active_support'
|
|
3
|
-
require 'active_support/test_case'
|
|
4
|
-
require 'test/unit'
|
|
5
|
-
|
|
6
|
-
require 'active_record'
|
|
7
|
-
|
|
8
|
-
CurrentDir = File.expand_path(File.dirname(__FILE__))
|
|
9
|
-
|
|
10
|
-
# log_path = File.join(CurrentDir, "debug.log")
|
|
11
|
-
# ActiveRecord::Base.logger = Logger.new(log_path)
|
|
12
|
-
|
|
13
|
-
def load_db_config
|
|
14
|
-
database_yml = File.join(CurrentDir, 'database.yml')
|
|
15
|
-
config = YAML::load(IO.read(database_yml))
|
|
16
|
-
config['test']
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
ActiveRecord::Base.establish_connection(load_db_config)
|
|
20
|
-
load(File.join(CurrentDir, "schema.rb"))
|
|
21
|
-
|
|
22
|
-
$: << (File.join(CurrentDir, "..", "lib"))
|
|
23
|
-
|
|
24
|
-
begin
|
|
25
|
-
require 'redgreen' unless ENV['TM_MODE']
|
|
26
|
-
rescue LoadError
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
require 'acts_as_human.rb'
|