doodle 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +21 -0
- data/examples/profile-options.rb +2 -1
- data/lib/doodle.rb +251 -200
- data/lib/doodle/version.rb +1 -1
- data/spec/attributes_spec.rb +24 -24
- data/spec/bugs_spec.rb +3 -3
- data/spec/class_spec.rb +4 -4
- data/spec/collector_spec.rb +36 -0
- data/spec/conversion_spec.rb +1 -1
- data/spec/defaults_spec.rb +8 -8
- data/spec/doodle_spec.rb +21 -21
- data/spec/extra_args_spec.rb +3 -3
- data/spec/inheritance_spec.rb +11 -11
- data/spec/init_spec.rb +6 -6
- data/spec/singleton_spec.rb +12 -12
- data/spec/specialized_attribute_class_spec.rb +5 -5
- data/spec/superclass_spec.rb +6 -6
- data/spec/validation_spec.rb +5 -5
- metadata +2 -2
data/lib/doodle/version.rb
CHANGED
data/spec/attributes_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
2
|
|
3
|
-
describe Doodle::
|
3
|
+
describe Doodle::DoodleAttribute, 'basics' do
|
4
4
|
temporary_constants :Foo, :Bar do
|
5
5
|
before(:each) do
|
6
6
|
class Foo
|
@@ -33,7 +33,7 @@ describe Doodle::Attribute, 'basics' do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'should have attribute :ivar1 with default defined' do
|
36
|
-
@foo.
|
36
|
+
@foo.doodle_attributes[:ivar1].default.should == 'Hello'
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'should have default name' do
|
@@ -45,36 +45,36 @@ describe Doodle::Attribute, 'basics' do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'should have name required == false (because has default)' do
|
48
|
-
@foo.
|
48
|
+
@foo.doodle_attributes[:ivar1].required?.should == false
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'should have ivar2 required == true' do
|
52
|
-
@bar.
|
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.
|
56
|
+
@foo.doodle_attributes[:ivar1].optional?.should == true
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'should inherit attribute from parent' do
|
60
|
-
@bar.
|
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.
|
64
|
+
@bar.doodle_attributes[:ivar2].optional?.should == false
|
65
65
|
end
|
66
66
|
|
67
|
-
# it "should have
|
68
|
-
#
|
69
|
-
# Bar.
|
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
|
73
|
-
@bar.singleton_class.
|
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.
|
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
|
@@ -86,33 +86,33 @@ describe Doodle::Attribute, 'basics' do
|
|
86
86
|
end
|
87
87
|
|
88
88
|
it 'should have local class attributes in order of definition' do
|
89
|
-
Bar.singleton_class.
|
89
|
+
Bar.singleton_class.doodle_attributes(false).keys.should == [:cvar2]
|
90
90
|
end
|
91
91
|
|
92
|
-
it 'should not inherit singleton
|
93
|
-
@bar.singleton_class.class_eval {
|
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 == []
|
94
94
|
end
|
95
95
|
|
96
96
|
it 'should not inherit singleton attributes#1' do
|
97
|
-
@bar.singleton_class.
|
97
|
+
@bar.singleton_class.doodle_attributes.map { |x| x[0]} .should == [:svar2]
|
98
98
|
end
|
99
99
|
|
100
100
|
it 'should not inherit singleton attributes#2' do
|
101
|
-
@bar.singleton_class.
|
101
|
+
@bar.singleton_class.doodle_attributes.keys.should == [:svar2]
|
102
102
|
end
|
103
103
|
|
104
104
|
it 'should not inherit singleton attributes#3' do
|
105
|
-
@bar.singleton_class.
|
105
|
+
@bar.singleton_class.doodle_attributes(false).keys.should == [:svar2]
|
106
106
|
end
|
107
107
|
|
108
108
|
it 'should show singleton attributes in attributes' do
|
109
|
-
@bar.
|
109
|
+
@bar.doodle_attributes.keys.should == [:ivar1, :ivar2, :svar2]
|
110
110
|
end
|
111
111
|
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
-
describe Doodle::
|
115
|
+
describe Doodle::DoodleAttribute, 'attribute order' do
|
116
116
|
temporary_constants :A, :B, :C do
|
117
117
|
before :each do
|
118
118
|
class A < Doodle
|
@@ -129,12 +129,12 @@ describe Doodle::Attribute, 'attribute order' do
|
|
129
129
|
end
|
130
130
|
|
131
131
|
# it 'should keep order of inherited attributes' do
|
132
|
-
#
|
133
|
-
# C.
|
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
|
134
134
|
# end
|
135
135
|
|
136
136
|
it 'should keep order of inherited attributes' do
|
137
|
-
C.
|
137
|
+
C.doodle_attributes.keys.should == [:a, :b, :c]
|
138
138
|
end
|
139
139
|
end
|
140
140
|
end
|
data/spec/bugs_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
2
|
require 'yaml'
|
3
3
|
|
4
|
-
describe 'Doodle', '
|
4
|
+
describe 'Doodle', 'inheriting validations' do
|
5
5
|
temporary_constant :Foo do
|
6
6
|
before :each do
|
7
7
|
class Foo < Doodle
|
@@ -15,8 +15,8 @@ describe 'Doodle', 'parents' do
|
|
15
15
|
|
16
16
|
it 'should not duplicate validations when accessing them!' do
|
17
17
|
foo = Foo 2
|
18
|
-
foo.
|
19
|
-
foo.
|
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
|
data/spec/class_spec.rb
CHANGED
@@ -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.
|
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.
|
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,11 +73,11 @@ 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.
|
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.
|
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
83
|
Bar.class_attributes.keys.should_be [:metadata, :doc]
|
data/spec/collector_spec.rb
CHANGED
@@ -1,5 +1,31 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
2
|
|
3
|
+
describe Doodle, "Default collector" do
|
4
|
+
temporary_constant :Foo do
|
5
|
+
before :each do
|
6
|
+
class Foo < Doodle
|
7
|
+
has :list, :collect => :item
|
8
|
+
end
|
9
|
+
@foo = Foo do
|
10
|
+
item "Hello"
|
11
|
+
item "World"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
after :each do
|
15
|
+
remove_ivars :foo
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should define a collector method :item" do
|
19
|
+
@foo.methods.map{ |x| x.to_sym }.include?(:item).should_be true
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should collect items into attribute :list" do
|
23
|
+
@foo.list.should_be ["Hello", "World"]
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
3
29
|
describe Doodle, "Simple collector" do
|
4
30
|
temporary_constant :Foo do
|
5
31
|
before :each do
|
@@ -100,6 +126,7 @@ describe Doodle, "typed collector with specified collector name" do
|
|
100
126
|
end
|
101
127
|
|
102
128
|
describe Doodle, "typed collector with specified collector name initialized from hash (with default :init param)" do
|
129
|
+
# note: this spec also checks for resolving collector class
|
103
130
|
temporary_constant :Location, :Event do
|
104
131
|
before :each do
|
105
132
|
class Location < Doodle
|
@@ -202,6 +229,15 @@ describe Doodle, "Simple keyed collector #2" do
|
|
202
229
|
)
|
203
230
|
foo.list.to_a.map{ |k, v| [k, v.class, v.name] }.should_be( [["Hello", Item, "Hello"], ["World", Item, "World"]] )
|
204
231
|
end
|
232
|
+
|
233
|
+
it "should collect named argument hash into attribute :list" do
|
234
|
+
foo = Foo(:list => {
|
235
|
+
"Hello" => { :name => "Hello" },
|
236
|
+
"World" => { :name => "World" }
|
237
|
+
}
|
238
|
+
)
|
239
|
+
foo.list.to_a.map{ |k, v| [k, v.class, v.name] }.should_be( [["Hello", Item, "Hello"], ["World", Item, "World"]] )
|
240
|
+
end
|
205
241
|
|
206
242
|
end
|
207
243
|
end
|
data/spec/conversion_spec.rb
CHANGED
data/spec/defaults_spec.rb
CHANGED
@@ -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.
|
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.
|
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.
|
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.
|
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.
|
32
|
-
@foo.singleton_class.
|
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.
|
35
|
-
@foo.singleton_class.
|
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'
|
data/spec/doodle_spec.rb
CHANGED
@@ -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.
|
27
|
+
@foo.doodle_attributes(false).keys.should_be []
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'should list instance attributes' do
|
31
|
-
@foo.
|
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.
|
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.
|
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.
|
75
|
+
Foo.singleton_class.doodle_attributes.keys.should_be [:metadata]
|
76
76
|
end
|
77
77
|
end
|
78
78
|
end
|
@@ -137,19 +137,19 @@ 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.
|
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.
|
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.
|
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.
|
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
|
@@ -157,7 +157,7 @@ describe Doodle, 'inherited class attributes(false)' do
|
|
157
157
|
end
|
158
158
|
|
159
159
|
it "should list all inherited class's attributes" do
|
160
|
-
Bar.
|
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.
|
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.
|
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.
|
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.
|
249
|
-
@bar.class.
|
250
|
-
@bar2.class.
|
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.
|
255
|
-
@bar.singleton_class.
|
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.
|
260
|
-
@bar.singleton_class.
|
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.
|
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'
|
data/spec/extra_args_spec.rb
CHANGED
@@ -13,8 +13,8 @@ describe Doodle, ' unspecified attributes' do
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
describe Doodle::
|
16
|
+
describe Doodle::DoodleAttribute, ' unspecified attributes' do
|
17
17
|
it 'should raise Doodle::UnknownAttributeError for unspecified attributes' do
|
18
|
-
proc { foo = Doodle::
|
18
|
+
proc { foo = Doodle::DoodleAttribute(:name => 'foo', :extra => 'unwanted') }.should raise_error(Doodle::UnknownAttributeError)
|
19
19
|
end
|
20
|
-
end
|
20
|
+
end
|
data/spec/inheritance_spec.rb
CHANGED
@@ -19,8 +19,8 @@ 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(:
|
23
|
-
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]
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should collect inherited for singleton" do
|
@@ -28,8 +28,8 @@ describe Doodle, "inheritance" do
|
|
28
28
|
class << foo
|
29
29
|
has :svar
|
30
30
|
end
|
31
|
-
foo.
|
32
|
-
foo.singleton_class.
|
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]
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should collect singleton class attributes for singleton" do
|
@@ -38,7 +38,7 @@ describe Doodle, "inheritance" do
|
|
38
38
|
has :svar
|
39
39
|
end
|
40
40
|
foo.singleton_class.respond_to?(:cvar).should_be true
|
41
|
-
foo.
|
41
|
+
foo.doodle_attributes.map{ |key, value| key}.should_be [:ivar, :svar]
|
42
42
|
# is this what I want? not sure
|
43
43
|
# foo.class.singleton_class.should_be foo.singleton_class.superclass
|
44
44
|
# foo.singleton_class.singleton_class # => #<Class:#<Class:#<Foo:0xb7bc8dd0>>>
|
@@ -53,22 +53,22 @@ describe Doodle, "inheritance" do
|
|
53
53
|
class << bar
|
54
54
|
has :svar2
|
55
55
|
end
|
56
|
-
bar.
|
57
|
-
bar.singleton_class.
|
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]
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should show instance attributes for class" do
|
61
|
-
Foo.
|
62
|
-
Bar.
|
61
|
+
Foo.doodle_attributes.map{ |key, value| key}.should_be [:ivar]
|
62
|
+
Bar.doodle_attributes.map{ |key, value| key}.should_be [:ivar, :ivar2]
|
63
63
|
end
|
64
64
|
|
65
|
-
it "should
|
65
|
+
it "should inherite class attributes for class" do
|
66
66
|
Foo.class_attributes.map{ |key, value| key}.should_be [:cvar]
|
67
67
|
Bar.class_attributes.map{ |key, value| key}.should_be [:cvar, :cvar2]
|
68
68
|
end
|
69
69
|
|
70
70
|
it "should not inherit class attributes via singleton_class" do
|
71
|
-
Bar.singleton_class.
|
71
|
+
Bar.singleton_class.doodle_attributes.map{ |key, value| key}.should_be [:cvar2]
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|