doodle 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -12,6 +12,6 @@ class DateRange < Doodle
12
12
  end
13
13
 
14
14
  dr = DateRange.new
15
- dr.start_date # => #<Date: 4908855/2,0,2299161>
16
- dr.end_date # => #<Date: 4908855/2,0,2299161>
15
+ dr.start_date # => #<Date: 4909185/2,0,2299161>
16
+ dr.end_date # => #<Date: 4909185/2,0,2299161>
17
17
 
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 ]}
@@ -2,7 +2,7 @@ class Doodle #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 4
5
+ TINY = 5
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doodle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean O'Halpin