person-name 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/person_name/has_person_name.rb +13 -0
- data/spec/models.rb +2 -0
- data/spec/person_name/has_person_name_spec.rb +10 -4
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.7
|
@@ -40,6 +40,8 @@ module PersonName
|
|
40
40
|
base.send :include, PersonName::ActiveRecord::Core::InstanceMethods
|
41
41
|
base.extend PersonName::ActiveRecord::Core::ClassMethods
|
42
42
|
base.initialize_person_names
|
43
|
+
base.before_validation :start_name_validation
|
44
|
+
base.after_validation :stop_name_validation
|
43
45
|
#base.define_scopes
|
44
46
|
end
|
45
47
|
|
@@ -87,6 +89,7 @@ module PersonName
|
|
87
89
|
def person_name_for field
|
88
90
|
@person_names ||= {}
|
89
91
|
@person_names[field] ||= PersonName::ActiveRecordPersonName.new(field, self)
|
92
|
+
@name_validation ? @person_names[field].full_name : @person_names[field]
|
90
93
|
end
|
91
94
|
|
92
95
|
def set_person_name_for field, new_name
|
@@ -94,6 +97,16 @@ module PersonName
|
|
94
97
|
person_name_for(field).full_name = new_name
|
95
98
|
end
|
96
99
|
|
100
|
+
private
|
101
|
+
|
102
|
+
def start_name_validation
|
103
|
+
@name_validation = true
|
104
|
+
end
|
105
|
+
|
106
|
+
def stop_name_validation
|
107
|
+
@name_validation = false
|
108
|
+
end
|
109
|
+
|
97
110
|
end
|
98
111
|
|
99
112
|
end
|
data/spec/models.rb
CHANGED
@@ -107,17 +107,23 @@ describe "Has Person Name" do
|
|
107
107
|
|
108
108
|
end
|
109
109
|
|
110
|
-
describe "
|
111
|
-
|
110
|
+
describe "active record specifics" do
|
111
|
+
|
112
|
+
it "should have a working with_name scope" do
|
112
113
|
clean_database!
|
113
114
|
@person = Person.new :name => "Matthijs Jacobus Groen"
|
114
115
|
@person.save
|
115
|
-
end
|
116
116
|
|
117
|
-
it "should have a working with_name scope" do
|
118
117
|
Person.find_by_name("Matthijs Jacobus Groen").should == @person
|
119
118
|
end
|
120
119
|
|
120
|
+
it "should validate names" do
|
121
|
+
@person = NamePerson.new :name => "Matthijs Groen"
|
122
|
+
@person.should_not be_valid
|
123
|
+
@person.birth_name = "Matthijs Jacobus Groen"
|
124
|
+
@person.should be_valid
|
125
|
+
end
|
126
|
+
|
121
127
|
end
|
122
128
|
|
123
129
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: person-name
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 7
|
10
|
+
version: 0.2.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Matthijs Groen
|