doodle 0.1.4 → 0.1.5
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/History.txt +5 -0
- data/examples/example-01.rb +2 -2
- data/lib/doodle.rb +4 -5
- data/lib/doodle/version.rb +1 -1
- data/spec/bugs_spec.rb +27 -0
- metadata +1 -1
data/History.txt
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
== 0.1.5 / 2008-05-06
|
2
|
+
- Bug fixes:
|
3
|
+
- fixed bug where defaults were preventing validation working when loading from
|
4
|
+
YAML and added spec
|
5
|
+
|
1
6
|
== 0.1.4 / 2008-05-06
|
2
7
|
- Features:
|
3
8
|
- keyed collections - see http://doodle.rubyforge.org/#keyed_collections for details
|
data/examples/example-01.rb
CHANGED
data/lib/doodle.rb
CHANGED
@@ -774,11 +774,6 @@ class Doodle
|
|
774
774
|
##DBG: Doodle::Debug.d { [:validate!, "using instance_attributes", attributes] }
|
775
775
|
end
|
776
776
|
attribs.each do |name, att|
|
777
|
-
# treat default as special case
|
778
|
-
if att.default_defined?
|
779
|
-
##DBG: Doodle::Debug.d { [:validate!, "default_defined - breaking" ]}
|
780
|
-
break
|
781
|
-
end
|
782
777
|
ivar_name = "@#{att.name}"
|
783
778
|
if instance_variable_defined?(ivar_name)
|
784
779
|
# if all == true, reset values so conversions and
|
@@ -788,10 +783,14 @@ class Doodle
|
|
788
783
|
##DBG: Doodle::Debug.d { [:validate!, :sending, att.name, instance_variable_get(ivar_name) ] }
|
789
784
|
__send__("#{att.name}=", instance_variable_get(ivar_name))
|
790
785
|
end
|
786
|
+
elsif att.optional? # treat default/init as special case
|
787
|
+
##DBG: Doodle::Debug.d { [:validate!, :optional, name ]}
|
788
|
+
break
|
791
789
|
elsif self.class != Class
|
792
790
|
handle_error name, Doodle::ValidationError, "#{self} missing required attribute '#{name}'", [caller[-1]]
|
793
791
|
end
|
794
792
|
end
|
793
|
+
|
795
794
|
# now apply instance level validations
|
796
795
|
|
797
796
|
##DBG: Doodle::Debug.d { [:validate!, "validations", validations ]}
|
data/lib/doodle/version.rb
CHANGED
data/spec/bugs_spec.rb
CHANGED
@@ -80,6 +80,33 @@ describe 'Doodle', ' loading bad data from yaml' do
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
+
describe 'Doodle', 'loading bad data from yaml with default defined' do
|
84
|
+
temporary_constant :Foo do
|
85
|
+
before :each do
|
86
|
+
class Foo < Doodle
|
87
|
+
has :date, :kind => Date do
|
88
|
+
default Date.today
|
89
|
+
from String do |s|
|
90
|
+
Date.parse(s)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
@str = %[
|
95
|
+
--- !ruby/object:Foo
|
96
|
+
date: "2000"
|
97
|
+
]
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'should succeed without validation' do
|
101
|
+
proc { foo = YAML::load(@str)}.should_not raise_error
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should fail with ConversionError when it cannot convert' do
|
105
|
+
proc { foo = YAML::load(@str).validate! }.should raise_error(Doodle::ConversionError)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
83
110
|
describe Doodle, 'class attributes:' do
|
84
111
|
temporary_constant :Foo do
|
85
112
|
before :each do
|