acts_as_human 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 [name of plugin creator]
1
+ Copyright (c) 2009 [Brent Greeff]
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -15,13 +15,21 @@ module ActsAs
15
15
  self.first_name = names_array.first
16
16
  return if names_array.size < 2
17
17
 
18
- self.last_name = names_array.last
18
+ self.last_name = get_last_name(names_array)
19
19
 
20
20
  assign_middle_names(names_array)
21
21
  end
22
22
 
23
23
  private
24
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
+
25
33
  def assign_middle_names(names_array)
26
34
  if names_array.size > 2
27
35
  self.middle_names = get_middle_names(names_array)
@@ -10,7 +10,7 @@ class ActsAsHumanTest < ActiveSupport::TestCase
10
10
  acts_as_human :require_last_name => false
11
11
  end
12
12
 
13
- def test_should_require_a_first_name
13
+ test "should require a first name" do
14
14
  user = create_user
15
15
  user.first_name = ''
16
16
 
@@ -18,26 +18,26 @@ class ActsAsHumanTest < ActiveSupport::TestCase
18
18
  assert_equal 'first name is required', user.errors[:first_name]
19
19
  end
20
20
 
21
- def test_should_have_first_name_that_is_less_than_40_characters
21
+ test "should have a first name that is less than 40 characters" do
22
22
  user = User.new(:first_name => 'aaaaabbbbbcccccdddddeeeeefffffggggghhhhhi')
23
23
 
24
24
  deny user.valid?
25
25
  assert_equal 'first name is too long (max 40 characters)', user.errors[:first_name]
26
26
  end
27
27
 
28
- def test_should_require_a_last_name
28
+ test "should require a last name" do
29
29
  user = User.new(:first_name => 'Brent')
30
30
 
31
31
  deny user.valid?
32
32
  assert_equal 'last name is required', user.errors[:last_name]
33
33
  end
34
34
 
35
- def test_should_not_require_a_last_name_if_not_required
35
+ test "should not require a last name if it is not required" do
36
36
  someone_else = Customer.new(:first_name => 'Brent')
37
37
  assert someone_else.valid?
38
38
  end
39
39
 
40
- def test_should_have_last_name_that_is_less_than_40_characters
40
+ test "should have a last name that is less than 40 characters" do
41
41
  user = create_user
42
42
  user.last_name = 'aaaaabbbbbcccccdddddeeeeefffffggggghhhhhi'
43
43
 
@@ -45,31 +45,35 @@ class ActsAsHumanTest < ActiveSupport::TestCase
45
45
  assert_equal 'last name is too long (max 40 characters)', user.errors[:last_name]
46
46
  end
47
47
 
48
- def test_should_have_a_last_name_when_assigned_through_full_name
48
+ test "should have a last name when assigned through full name" do
49
49
  user = User.new(:full_name => 'Brent')
50
50
 
51
51
  deny user.valid?
52
52
  assert_equal 'last name is required', user.errors[:last_name]
53
53
  end
54
54
 
55
- def test_should_have_full_name_composed_of_first_and_last_name
55
+ test "should have a full name composed of first and last names" do
56
56
  user = User.new(:first_name => 'Brent', :last_name => 'Greeff')
57
57
  assert_equal 'Brent Greeff', user.full_name
58
58
  end
59
59
 
60
- def test_should_have_full_name_composed_of_first_middle_and_last_name
61
- user = User.new(:first_name => 'Brent', :middle_names => 'Middle Names', :last_name => 'Greeff')
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
+ )
62
66
  assert_equal 'Brent Middle Names Greeff', user.full_name
63
67
  end
64
68
 
65
- def test_should_assign_first_and_last_name_when_assigning_to_full_name
69
+ test "should assign first and last name when assigning to full name" do
66
70
  user = User.new(:full_name => 'Brent Greeff')
67
71
 
68
72
  assert_equal 'Brent', user.first_name
69
73
  assert_equal 'Greeff', user.last_name
70
74
  end
71
75
 
72
- def test_should_assign_first_last_and_middle_names_when_assigning_to_full_name
76
+ test "should assign first last and middle names when assigning to full name" do
73
77
  user = User.new(:full_name => 'Brent Middle Names Greeff')
74
78
 
75
79
  assert_equal 'Brent', user.first_name
@@ -77,7 +81,7 @@ class ActsAsHumanTest < ActiveSupport::TestCase
77
81
  assert_equal 'Greeff', user.last_name
78
82
  end
79
83
 
80
- def test_should_have_middle_names_that_are_less_than_40_characters
84
+ test "should have middle names that are less than 40 characters" do
81
85
  user = create_user
82
86
  user.middle_names = 'aaaaabbbbbcccccdddddeeeeefffffggggghhhhhi'
83
87
 
@@ -85,12 +89,12 @@ class ActsAsHumanTest < ActiveSupport::TestCase
85
89
  assert_equal 'middle names are too long (max 40 characters)', user.errors[:middle_names]
86
90
  end
87
91
 
88
- def test_should_have_a_empty_full_name_when_user_is_new
92
+ test "should have an empty full name when user is new" do
89
93
  user = User.new
90
94
  assert_equal '', user.full_name
91
95
  end
92
96
 
93
- def test_should_not_allow_non_name_like_characters
97
+ test "should not allow non name like characters" do
94
98
  user = User.new(:full_name => "<Brent> Middle >< Names Gre&eff")
95
99
 
96
100
  deny user.valid?
@@ -99,6 +103,22 @@ class ActsAsHumanTest < ActiveSupport::TestCase
99
103
  assert_equal 'some characters in your name are not allowed', user.errors[:middle_names]
100
104
  end
101
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
+
102
122
  private
103
123
 
104
124
  def create_user(options={})
@@ -122,5 +142,4 @@ class ActsAsHumanTest < ActiveSupport::TestCase
122
142
  def deny(expected_to_be_false, message = '')
123
143
  assert ! expected_to_be_false, message
124
144
  end
125
-
126
145
  end
data/test/schema.rb CHANGED
@@ -11,5 +11,4 @@ ActiveRecord::Schema.define(:version => 20090628014113) do
11
11
  t.string "middle_names"
12
12
  t.string "last_name"
13
13
  end
14
-
15
14
  end
data/test/test_helper.rb CHANGED
@@ -3,15 +3,27 @@ require 'active_support'
3
3
  require 'active_support/test_case'
4
4
  require 'test/unit'
5
5
 
6
- ENV['RAILS_ENV'] = 'test'
7
- ENV['RAILS_ROOT'] ||= File.dirname(__FILE__) + '/../../../..'
6
+ require 'active_record'
8
7
 
9
- require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config/environment.rb'))
8
+ CurrentDir = File.expand_path(File.dirname(__FILE__))
10
9
 
11
- ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
12
- config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
13
- ActiveRecord::Base.establish_connection(config['test'])
10
+ # log_path = File.join(CurrentDir, "debug.log")
11
+ # ActiveRecord::Base.logger = Logger.new(log_path)
14
12
 
15
- load(File.dirname(__FILE__) + "/schema.rb")
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
16
18
 
17
- require File.dirname(__FILE__) + '/../rails/init.rb'
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'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_human
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
- - 2
10
- version: 2.0.2
9
+ - 3
10
+ version: 2.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brent Greeff
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-29 00:00:00 +01:00
18
+ date: 2010-11-15 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies: []
21
21