vizjerai-validatable 1.8.0 → 1.9.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.
- data/VERSION.yml +1 -1
- data/lib/validatable_instance_methods.rb +18 -0
- data/test/functional/test_validatable.rb +10 -0
- data/test/unit/test_validatable.rb +18 -0
- metadata +2 -2
data/VERSION.yml
CHANGED
@@ -3,6 +3,24 @@ module Validatable
|
|
3
3
|
klass.extend Validatable::ClassMethods
|
4
4
|
klass.extend Validatable::Macros
|
5
5
|
end
|
6
|
+
|
7
|
+
def initialize(attributes = nil)
|
8
|
+
# Mass Assignment implementation
|
9
|
+
if attributes
|
10
|
+
attributes.each do |key, value|
|
11
|
+
self[key] = value
|
12
|
+
end
|
13
|
+
end
|
14
|
+
yield self if block_given?
|
15
|
+
end
|
16
|
+
|
17
|
+
def [](key)
|
18
|
+
instance_variable_get("@#{key}")
|
19
|
+
end
|
20
|
+
|
21
|
+
def []=(key, value)
|
22
|
+
instance_variable_set("@#{key}", value)
|
23
|
+
end
|
6
24
|
|
7
25
|
# call-seq: valid?
|
8
26
|
#
|
@@ -159,6 +159,16 @@ functional_tests do
|
|
159
159
|
end
|
160
160
|
|
161
161
|
|
162
|
+
test 'initialize' do
|
163
|
+
klass = Class.new do
|
164
|
+
include Validatable
|
165
|
+
attr_accessor :first_name, :last_name
|
166
|
+
end
|
167
|
+
instance = klass.new({:first_name => 'First Name', :last_name => 'Last Name'})
|
168
|
+
assert_equal 'First Name', instance.first_name
|
169
|
+
assert_equal 'Last Name', instance.last_name
|
170
|
+
end
|
171
|
+
|
162
172
|
test "when child validations have errors, level 2 and higher parent validations are not performed" do
|
163
173
|
child_class = Class.new do
|
164
174
|
include Validatable
|
@@ -10,6 +10,24 @@ Expectations do
|
|
10
10
|
klass.new.valid?
|
11
11
|
end
|
12
12
|
|
13
|
+
expect 'First Name' do
|
14
|
+
klass = Class.new do
|
15
|
+
include Validatable
|
16
|
+
attr_accessor :first_name, :last_name
|
17
|
+
end
|
18
|
+
instance = klass.new({:first_name => 'First Name', :last_name => 'Last Name'})
|
19
|
+
instance.first_name
|
20
|
+
end
|
21
|
+
|
22
|
+
expect 'Last Name' do
|
23
|
+
klass = Class.new do
|
24
|
+
include Validatable
|
25
|
+
attr_accessor :first_name, :last_name
|
26
|
+
end
|
27
|
+
instance = klass.new({:first_name => 'First Name', :last_name => 'Last Name'})
|
28
|
+
instance.last_name
|
29
|
+
end
|
30
|
+
|
13
31
|
expect true do
|
14
32
|
klass = Class.new do
|
15
33
|
include Validatable
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vizjerai-validatable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jay Fields
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-06-
|
13
|
+
date: 2009-06-15 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|