doodle 0.1.7 → 0.1.8

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.
@@ -2,7 +2,7 @@ class Doodle #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 7
5
+ TINY = 8
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -33,7 +33,7 @@ describe Doodle::DoodleAttribute, 'basics' do
33
33
  end
34
34
 
35
35
  it 'should have attribute :ivar1 with default defined' do
36
- @foo.doodle_attributes[:ivar1].default.should == 'Hello'
36
+ @foo.doodle.attributes[:ivar1].default.should == 'Hello'
37
37
  end
38
38
 
39
39
  it 'should have default name' do
@@ -45,68 +45,69 @@ describe Doodle::DoodleAttribute, 'basics' do
45
45
  end
46
46
 
47
47
  it 'should have name required == false (because has default)' do
48
- @foo.doodle_attributes[:ivar1].required?.should == false
48
+ @foo.doodle.attributes[:ivar1].required?.should == false
49
49
  end
50
50
 
51
51
  it 'should have ivar2 required == true' do
52
- @bar.doodle_attributes[:ivar2].required?.should == true
52
+ @bar.doodle.attributes[:ivar2].required?.should == true
53
53
  end
54
54
 
55
55
  it 'should have name.optional? == true (because has default)' do
56
- @foo.doodle_attributes[:ivar1].optional?.should == true
56
+ @foo.doodle.attributes[:ivar1].optional?.should == true
57
57
  end
58
58
 
59
59
  it 'should inherit attribute from parent' do
60
- @bar.doodle_attributes[:ivar1].should == @foo.doodle_attributes[:ivar1]
60
+ @bar.doodle.attributes[:ivar1].should == @foo.doodle.attributes[:ivar1]
61
61
  end
62
62
 
63
63
  it 'should have ivar2.optional? == false' do
64
- @bar.doodle_attributes[:ivar2].optional?.should == false
64
+ @bar.doodle.attributes[:ivar2].optional?.should == false
65
65
  end
66
66
 
67
- # it "should have doodle_parents in correct order" do
68
- # expected_doodle_parents = RUBY_VERSION <= "1.8.6" ? [Foo, Object] : [Foo, Object, BasicObject]
69
- # Bar.doodle_parents.should == expected_doodle_parents
67
+ # it "should have doodle.parents in correct order" do
68
+ # expected_doodle.parents = RUBY_VERSION <= "1.8.6" ? [Foo, Object] : [Foo, Object, BasicObject]
69
+ # Bar.doodle.parents.should == expected_doodle.parents
70
70
  # end
71
71
 
72
- it "should have Bar's singleton doodle_parents in reverse order of definition" do
73
- @bar.singleton_class.doodle_parents.should == []
72
+ it "should have Bar's singleton doodle.parents in reverse order of definition" do
73
+ @bar.singleton_class.doodle.parents.should == []
74
74
  end
75
75
 
76
76
  it 'should have singleton_class attributes in order of definition' do
77
- Bar.singleton_class.doodle_attributes.keys.should == [:cvar2]
77
+ Bar.singleton_class.doodle.attributes.keys.should == [:cvar2]
78
78
  end
79
79
 
80
80
  it 'should have inherited class_attributes in order of definition' do
81
- Bar.class_attributes.keys.should == [:cvar1, :cvar2]
81
+ Bar.doodle.class_attributes.keys.should == [:cvar1, :cvar2]
82
82
  end
83
83
 
84
84
  it 'should have inherited class_attributes in order of definition' do
85
- @bar.class_attributes.keys.should == [:cvar1, :cvar2]
85
+ @bar.doodle.class_attributes.keys.should == [:cvar1, :cvar2]
86
86
  end
87
87
 
88
88
  it 'should have local class attributes in order of definition' do
89
- Bar.singleton_class.doodle_attributes(false).keys.should == [:cvar2]
89
+ Bar.singleton_class.doodle.attributes(false).keys.should == [:cvar2]
90
90
  end
91
91
 
92
- it 'should not inherit singleton doodle_local_attributes' do
93
- @bar.singleton_class.class_eval { doodle_collect_inherited(:doodle_local_attributes).map { |x| x[0]} }.should == []
92
+ # bit iffy this test - testing implementation, not interface
93
+ it 'should not inherit singleton doodle.local_attributes' do
94
+ @bar.singleton_class.class_eval { doodle.collect_inherited(:local_attributes).map { |x| x[0]} }.should == []
94
95
  end
95
96
 
96
97
  it 'should not inherit singleton attributes#1' do
97
- @bar.singleton_class.doodle_attributes.map { |x| x[0]} .should == [:svar2]
98
+ @bar.singleton_class.doodle.attributes.map { |x| x[0]} .should == [:svar2]
98
99
  end
99
100
 
100
101
  it 'should not inherit singleton attributes#2' do
101
- @bar.singleton_class.doodle_attributes.keys.should == [:svar2]
102
+ @bar.singleton_class.doodle.attributes.keys.should == [:svar2]
102
103
  end
103
104
 
104
105
  it 'should not inherit singleton attributes#3' do
105
- @bar.singleton_class.doodle_attributes(false).keys.should == [:svar2]
106
+ @bar.singleton_class.doodle.attributes(false).keys.should == [:svar2]
106
107
  end
107
108
 
108
109
  it 'should show singleton attributes in attributes' do
109
- @bar.doodle_attributes.keys.should == [:ivar1, :ivar2, :svar2]
110
+ @bar.doodle.attributes.keys.should == [:ivar1, :ivar2, :svar2]
110
111
  end
111
112
 
112
113
  end
@@ -129,12 +130,12 @@ describe Doodle::DoodleAttribute, 'attribute order' do
129
130
  end
130
131
 
131
132
  # it 'should keep order of inherited attributes' do
132
- # expected_doodle_parents = RUBY_VERSION <= "1.8.6" ? [B, A, Doodle, Object] : [B, A, Doodle, Object, BasicObject]
133
- # C.doodle_parents.should == expected_doodle_parents
133
+ # expected_doodle.parents = RUBY_VERSION <= "1.8.6" ? [B, A, Doodle, Object] : [B, A, Doodle, Object, BasicObject]
134
+ # C.doodle.parents.should == expected_doodle.parents
134
135
  # end
135
136
 
136
137
  it 'should keep order of inherited attributes' do
137
- C.doodle_attributes.keys.should == [:a, :b, :c]
138
+ C.doodle.attributes.keys.should == [:a, :b, :c]
138
139
  end
139
140
  end
140
141
  end
@@ -15,8 +15,8 @@ describe 'Doodle', 'inheriting validations' do
15
15
 
16
16
  it 'should not duplicate validations when accessing them!' do
17
17
  foo = Foo 2
18
- foo.doodle_validations.size.should_be 1
19
- foo.doodle_validations.size.should_be 1
18
+ foo.doodle.validations.size.should_be 1
19
+ foo.doodle.validations.size.should_be 1
20
20
  end
21
21
  end
22
22
  end
@@ -36,11 +36,11 @@ describe Doodle, 'class attributes' do
36
36
  end
37
37
 
38
38
  it "should list all class's own attributes" do
39
- Foo.singleton_class.doodle_attributes(false).keys.should_be [:metadata]
39
+ Foo.singleton_class.doodle.attributes(false).keys.should_be [:metadata]
40
40
  end
41
41
 
42
42
  it "should list all class's own attributes" do
43
- Foo.singleton_class.doodle_attributes.keys.should_be [:metadata]
43
+ Foo.singleton_class.doodle.attributes.keys.should_be [:metadata]
44
44
  end
45
45
 
46
46
  it 'should create Bar class attribute' do
@@ -73,14 +73,14 @@ describe Doodle, 'class attributes' do
73
73
  end
74
74
 
75
75
  it "should list all class's own attributes" do
76
- Bar.singleton_class.doodle_attributes(false).keys.should_be [:doc]
76
+ Bar.singleton_class.doodle.attributes(false).keys.should_be [:doc]
77
77
  end
78
78
 
79
79
  it "should list all class's singleton attributes" do
80
- Bar.singleton_class.doodle_attributes.keys.should_be [:doc]
80
+ Bar.singleton_class.doodle.attributes.keys.should_be [:doc]
81
81
  end
82
82
  it "should list all class's class_attributes" do
83
- Bar.class_attributes.keys.should_be [:metadata, :doc]
83
+ Bar.doodle.class_attributes.keys.should_be [:metadata, :doc]
84
84
  end
85
85
  end
86
86
  end
@@ -47,7 +47,7 @@ describe Doodle, 'conversions' do
47
47
  end
48
48
 
49
49
  it 'should return class_conversions' do
50
- Foo.doodle_conversions.keys.should == [String]
50
+ Foo.doodle.conversions.keys.should == [String]
51
51
  end
52
52
 
53
53
  end
@@ -17,22 +17,22 @@ describe Doodle, 'attributes with defaults' do
17
17
  end
18
18
 
19
19
  it 'should have instance attribute default via class' do
20
- Foo.doodle_attributes[:name].default.should_be 'D1'
20
+ Foo.doodle.attributes[:name].default.should_be 'D1'
21
21
  end
22
22
  it 'should have instance attribute default via instance' do
23
- @foo.doodle_attributes[:name].default.should_be 'D1'
23
+ @foo.doodle.attributes[:name].default.should_be 'D1'
24
24
  end
25
25
  it 'should have class attribute default via class.meta' do
26
- Foo.singleton_class.doodle_attributes(false)[:metadata].default.should_be 'D2'
26
+ Foo.singleton_class.doodle.attributes(false)[:metadata].default.should_be 'D2'
27
27
  end
28
28
  it 'should have class attribute default via class.meta' do
29
- Foo.singleton_class.doodle_attributes[:metadata].default.should_be 'D2'
29
+ Foo.singleton_class.doodle.attributes[:metadata].default.should_be 'D2'
30
30
  end
31
- it 'should have singleton attribute default via instance.singleton_class.doodle_attributes(false)' do
32
- @foo.singleton_class.doodle_attributes(false)[:special].default.should_be 'D3'
31
+ it 'should have singleton attribute default via instance.singleton_class.doodle.attributes(false)' do
32
+ @foo.singleton_class.doodle.attributes(false)[:special].default.should_be 'D3'
33
33
  end
34
- it 'should have singleton attribute default via instance.singleton_class.doodle_attributes' do
35
- @foo.singleton_class.doodle_attributes[:special].default.should_be 'D3'
34
+ it 'should have singleton attribute default via instance.singleton_class.doodle.attributes' do
35
+ @foo.singleton_class.doodle.attributes[:special].default.should_be 'D3'
36
36
  end
37
37
  it 'should have singleton attribute name by default' do
38
38
  @foo.name.should_be 'D1'
@@ -20,7 +20,7 @@ describe Doodle, "doodle_context" do
20
20
  # during initialization - this is a way to capture that
21
21
  # value for ues later
22
22
 
23
- init { doodle_parent }
23
+ init { doodle.parent }
24
24
  end
25
25
  end
26
26
 
@@ -38,7 +38,7 @@ describe Doodle, "doodle_context" do
38
38
 
39
39
  sean = dad.children[0]
40
40
  sean.dad.name.should_be 'Conn'
41
- sean.doodle_parent.name.should_be 'Conn'
41
+ sean.doodle.parent.name.should_be 'Conn'
42
42
  end
43
43
  end
44
44
  end
@@ -24,15 +24,15 @@ describe Doodle, 'instance attributes' do
24
24
  end
25
25
 
26
26
  it 'should list instance attributes(false)' do
27
- @foo.doodle_attributes(false).keys.should_be []
27
+ @foo.doodle.attributes(false).keys.should_be []
28
28
  end
29
29
 
30
30
  it 'should list instance attributes' do
31
- @foo.doodle_attributes.keys.should_be [:name]
31
+ @foo.doodle.attributes.keys.should_be [:name]
32
32
  end
33
33
 
34
34
  it 'should list all instance attributes(false) at class level' do
35
- Foo.doodle_attributes(false).keys.should_be [:name]
35
+ Foo.doodle.attributes(false).keys.should_be [:name]
36
36
  end
37
37
  end
38
38
  end
@@ -68,11 +68,11 @@ describe Doodle, 'class attributes(false)' do
68
68
  end
69
69
 
70
70
  it "should list all class's own attributes" do
71
- Foo.singleton_class.doodle_attributes(false).keys.should_be [:metadata]
71
+ Foo.singleton_class.doodle.attributes(false).keys.should_be [:metadata]
72
72
  end
73
73
 
74
74
  it "should list all class's own attributes" do
75
- Foo.singleton_class.doodle_attributes.keys.should_be [:metadata]
75
+ Foo.singleton_class.doodle.attributes.keys.should_be [:metadata]
76
76
  end
77
77
  end
78
78
  end
@@ -137,27 +137,27 @@ describe Doodle, 'inherited class attributes(false)' do
137
137
  end
138
138
 
139
139
  it "should list class's own attributes" do
140
- Foo.singleton_class.doodle_attributes(false).keys.should_be [:metadata]
140
+ Foo.singleton_class.doodle.attributes(false).keys.should_be [:metadata]
141
141
  end
142
142
 
143
143
  it "should list all class's own attributes" do
144
- Foo.singleton_class.doodle_attributes.keys.should_be [:metadata]
144
+ Foo.singleton_class.doodle.attributes.keys.should_be [:metadata]
145
145
  end
146
146
 
147
147
  it "should list class's own attributes(false)" do
148
- Bar.singleton_class.doodle_attributes(false).keys.should_be [:doc]
148
+ Bar.singleton_class.doodle.attributes(false).keys.should_be [:doc]
149
149
  end
150
150
 
151
151
  it "should list all singleton class attributes" do
152
- Bar.singleton_class.doodle_attributes.keys.should_be [:doc]
152
+ Bar.singleton_class.doodle.attributes.keys.should_be [:doc]
153
153
  end
154
154
 
155
155
  it "should list all inherited meta class attributes" do
156
- Bar.class_attributes.keys.should_be [:metadata, :doc]
156
+ Bar.doodle.class_attributes.keys.should_be [:metadata, :doc]
157
157
  end
158
158
 
159
159
  it "should list all inherited class's attributes" do
160
- Bar.doodle_attributes.keys.should_be [:name, :location]
160
+ Bar.doodle.attributes.keys.should_be [:name, :location]
161
161
  end
162
162
  end
163
163
  end
@@ -188,15 +188,15 @@ describe Doodle, 'singleton class attributes' do
188
188
  end
189
189
 
190
190
  it 'should list singleton instance attributes(false)' do
191
- @foo.singleton_class.doodle_attributes(false).keys.should_be [:special]
191
+ @foo.singleton_class.doodle.attributes(false).keys.should_be [:special]
192
192
  end
193
193
 
194
194
  it 'should list singleton instance attributes' do
195
- @foo.singleton_class.doodle_attributes.keys.should_be [:special]
195
+ @foo.singleton_class.doodle.attributes.keys.should_be [:special]
196
196
  end
197
197
 
198
198
  it 'should list instance attributes' do
199
- @foo.doodle_attributes.keys.should_be [:name, :special]
199
+ @foo.doodle.attributes.keys.should_be [:name, :special]
200
200
  end
201
201
 
202
202
  end
@@ -245,19 +245,19 @@ describe Doodle, 'inherited singleton class attributes' do
245
245
  end
246
246
 
247
247
  it 'should list instance attributes' do
248
- @foo.class.doodle_attributes(false).keys.should_be [:name]
249
- @bar.class.doodle_attributes(false).keys.should_be [:info]
250
- @bar2.class.doodle_attributes(false).keys.should_be [:info]
248
+ @foo.class.doodle.attributes(false).keys.should_be [:name]
249
+ @bar.class.doodle.attributes(false).keys.should_be [:info]
250
+ @bar2.class.doodle.attributes(false).keys.should_be [:info]
251
251
  end
252
252
 
253
253
  it 'should list instance meta attributes' do
254
- @foo.singleton_class.doodle_attributes(false).keys.should_be [:special]
255
- @bar.singleton_class.doodle_attributes(false).keys.should_be [:extra]
254
+ @foo.singleton_class.doodle.attributes(false).keys.should_be [:special]
255
+ @bar.singleton_class.doodle.attributes(false).keys.should_be [:extra]
256
256
  end
257
257
 
258
258
  it 'should list singleton attributes only' do
259
- @foo.singleton_class.doodle_attributes.keys.should_be [:special]
260
- @bar.singleton_class.doodle_attributes.keys.should_be [:extra]
259
+ @foo.singleton_class.doodle.attributes.keys.should_be [:special]
260
+ @bar.singleton_class.doodle.attributes.keys.should_be [:extra]
261
261
  end
262
262
 
263
263
  it 'should keep meta attributes separate' do
@@ -287,7 +287,7 @@ describe Doodle, 'inherited singleton class attributes' do
287
287
 
288
288
  it 'should inherit singleton methods from class' do
289
289
  @foo.singleton_class.respond_to?(:metadata).should_be true
290
- @foo.singleton_class.doodle_attributes[:metadata].should_be nil
290
+ @foo.singleton_class.doodle.attributes[:metadata].should_be nil
291
291
  @foo.singleton_class.metadata = 'foo meta'
292
292
  @foo.singleton_class.instance_eval { @metadata }.should_be 'foo meta'
293
293
  if RUBY_VERSION < '1.9.0'
@@ -0,0 +1,43 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe 'Doodle', 'applying Doodle type conversions' do
4
+ temporary_constant :Foo, :Name do
5
+ before :each do
6
+ class Name < String
7
+ include Doodle::Core
8
+ from String do |s|
9
+ Name.new(s)
10
+ end
11
+ must "be > 3 chars long" do
12
+ size > 3
13
+ end
14
+ end
15
+
16
+ class Foo < Doodle
17
+ has Name do
18
+ must "start with A" do |s|
19
+ s =~ /^A/
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ it 'should convert a value based on conversions in doodle class' do
26
+ proc { foo = Foo 'Arthur' }.should_not raise_error
27
+ end
28
+
29
+ it 'should convert a value based on conversions in doodle class to the correct class' do
30
+ foo = Foo 'Arthur'
31
+ foo.name.class.should_be Name
32
+ end
33
+
34
+ it 'should apply validations from attribute' do
35
+ proc { Foo 'Zaphod' }.should raise_error(Doodle::ValidationError)
36
+ end
37
+
38
+ it 'should apply validations from doodle type' do
39
+ proc { Foo 'Art' }.should raise_error(Doodle::ConversionError)
40
+ end
41
+
42
+ end
43
+ end
@@ -8,9 +8,9 @@ describe Doodle, 'has Class' do
8
8
  class Foo < Doodle
9
9
  has Bar
10
10
  end
11
- att = Foo.doodle_attributes.values.first
11
+ att = Foo.doodle.attributes.values.first
12
12
  att.name.should_be :bar
13
- att.kind.should_be Bar
13
+ att.kind.should_be [Bar]
14
14
  end
15
15
  it "should allow overriding name of attribute when using 'has Bar'" do
16
16
  class Bar
@@ -18,9 +18,9 @@ describe Doodle, 'has Class' do
18
18
  class Foo < Doodle
19
19
  has Bar, :name => :baz
20
20
  end
21
- att = Foo.doodle_attributes.values.first
21
+ att = Foo.doodle.attributes.values.first
22
22
  att.name.should_be :baz
23
- att.kind.should_be Bar
23
+ att.kind.should_be [Bar]
24
24
  end
25
25
  it "should convert class name to snakecase when using CamelCase class constant" do
26
26
  class AudioClip
@@ -28,9 +28,18 @@ describe Doodle, 'has Class' do
28
28
  class Foo < Doodle
29
29
  has AudioClip
30
30
  end
31
- att = Foo.doodle_attributes.values.first
31
+ att = Foo.doodle.attributes.values.first
32
32
  att.name.should_be :audio_clip
33
- att.kind.should_be AudioClip
33
+ att.kind.should_be [AudioClip]
34
+ end
35
+ it "should apply validations for 'has Bar' as if 'has :bar, :kind => Bar' was used" do
36
+ class Bar
37
+ end
38
+ class Foo < Doodle
39
+ has Bar
40
+ end
41
+ proc { Foo.new(:bar => Bar.new) }.should_not raise_error
42
+ proc { Foo.new(:bar => "Hello") }.should raise_error(Doodle::ValidationError)
34
43
  end
35
44
  end
36
45
  end
@@ -19,8 +19,7 @@ describe Doodle, "inheritance" do
19
19
 
20
20
  it "should collect_inherited for instance" do
21
21
  foo = Foo.new(:ivar => "foo")
22
- foo.send(:doodle_collect_inherited, :doodle_attributes).map{ |key, value| key}.should_be [:ivar]
23
- foo.doodle_attributes.map{ |key, value| key}.should_be [:ivar]
22
+ foo.doodle.attributes.map{ |key, value| key}.should_be [:ivar]
24
23
  end
25
24
 
26
25
  it "should collect inherited for singleton" do
@@ -28,8 +27,8 @@ describe Doodle, "inheritance" do
28
27
  class << foo
29
28
  has :svar
30
29
  end
31
- foo.doodle_attributes.map{ |key, value| key}.should_be [:ivar, :svar]
32
- foo.singleton_class.doodle_attributes.map{ |key, value| key}.should_be [:svar]
30
+ foo.doodle.attributes.map{ |key, value| key}.should_be [:ivar, :svar]
31
+ foo.singleton_class.doodle.attributes.map{ |key, value| key}.should_be [:svar]
33
32
  end
34
33
 
35
34
  it "should collect singleton class attributes for singleton" do
@@ -38,7 +37,7 @@ describe Doodle, "inheritance" do
38
37
  has :svar
39
38
  end
40
39
  foo.singleton_class.respond_to?(:cvar).should_be true
41
- foo.doodle_attributes.map{ |key, value| key}.should_be [:ivar, :svar]
40
+ foo.doodle.attributes.map{ |key, value| key}.should_be [:ivar, :svar]
42
41
  # is this what I want? not sure
43
42
  # foo.class.singleton_class.should_be foo.singleton_class.superclass
44
43
  # foo.singleton_class.singleton_class # => #<Class:#<Class:#<Foo:0xb7bc8dd0>>>
@@ -53,22 +52,22 @@ describe Doodle, "inheritance" do
53
52
  class << bar
54
53
  has :svar2
55
54
  end
56
- bar.doodle_attributes.map{ |key, value| key}.should_be [:ivar, :ivar2, :svar2]
57
- bar.singleton_class.doodle_attributes.map{ |key, value| key}.should_be [:svar2]
55
+ bar.doodle.attributes.map{ |key, value| key}.should_be [:ivar, :ivar2, :svar2]
56
+ bar.singleton_class.doodle.attributes.map{ |key, value| key}.should_be [:svar2]
58
57
  end
59
58
 
60
59
  it "should show instance attributes for class" do
61
- Foo.doodle_attributes.map{ |key, value| key}.should_be [:ivar]
62
- Bar.doodle_attributes.map{ |key, value| key}.should_be [:ivar, :ivar2]
60
+ Foo.doodle.attributes.map{ |key, value| key}.should_be [:ivar]
61
+ Bar.doodle.attributes.map{ |key, value| key}.should_be [:ivar, :ivar2]
63
62
  end
64
63
 
65
64
  it "should inherite class attributes for class" do
66
- Foo.class_attributes.map{ |key, value| key}.should_be [:cvar]
67
- Bar.class_attributes.map{ |key, value| key}.should_be [:cvar, :cvar2]
65
+ Foo.doodle.class_attributes.map{ |key, value| key}.should_be [:cvar]
66
+ Bar.doodle.class_attributes.map{ |key, value| key}.should_be [:cvar, :cvar2]
68
67
  end
69
68
 
70
69
  it "should not inherit class attributes via singleton_class" do
71
- Bar.singleton_class.doodle_attributes.map{ |key, value| key}.should_be [:cvar2]
70
+ Bar.singleton_class.doodle.attributes.map{ |key, value| key}.should_be [:cvar2]
72
71
  end
73
72
  end
74
73
  end