doodle 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +18 -0
- data/History.txt +9 -0
- data/Manifest.txt +16 -12
- data/PostInstall.txt +1 -0
- data/lib/doodle.rb +166 -86
- data/lib/doodle/datatypes.rb +19 -6
- data/lib/doodle/rfc822.rb +22 -15
- data/lib/doodle/version.rb +1 -1
- data/spec/arg_order_spec.rb +11 -11
- data/spec/attributes_spec.rb +8 -8
- data/spec/bugs_spec.rb +12 -12
- data/spec/class_spec.rb +21 -21
- data/spec/collector_spec.rb +87 -11
- data/spec/defaults_spec.rb +21 -21
- data/spec/doodle_context_spec.rb +2 -2
- data/spec/doodle_spec.rb +86 -70
- data/spec/factory_spec.rb +8 -8
- data/spec/inheritance_spec.rb +74 -0
- data/spec/new_doodle_spec.rb +3 -3
- data/spec/singleton_spec.rb +16 -16
- data/spec/spec_helper.rb +10 -0
- data/spec/specialized_attribute_class_spec.rb +111 -0
- data/spec/superclass_spec.rb +4 -4
- data/spec/validation_spec.rb +8 -8
- data/tasks/deployment.rake +5 -5
- metadata +21 -14
- data/tasks/website.rake +0 -17
data/spec/defaults_spec.rb
CHANGED
@@ -17,44 +17,44 @@ describe Doodle, 'attributes with defaults' do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'should have instance attribute default via class' do
|
20
|
-
Foo.attributes[:name].default.
|
20
|
+
Foo.attributes[:name].default.should_be 'D1'
|
21
21
|
end
|
22
22
|
it 'should have instance attribute default via instance' do
|
23
|
-
@foo.attributes[:name].default.
|
23
|
+
@foo.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.attributes(false)[:metadata].default.
|
26
|
+
Foo.singleton_class.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.attributes[:metadata].default.
|
29
|
+
Foo.singleton_class.attributes[:metadata].default.should_be 'D2'
|
30
30
|
end
|
31
31
|
it 'should have singleton attribute default via instance.singleton_class.attributes(false)' do
|
32
|
-
@foo.singleton_class.attributes(false)[:special].default.
|
32
|
+
@foo.singleton_class.attributes(false)[:special].default.should_be 'D3'
|
33
33
|
end
|
34
34
|
it 'should have singleton attribute default via instance.singleton_class.attributes' do
|
35
|
-
@foo.singleton_class.attributes[:special].default.
|
35
|
+
@foo.singleton_class.attributes[:special].default.should_be 'D3'
|
36
36
|
end
|
37
37
|
it 'should have singleton attribute name by default' do
|
38
|
-
@foo.name.
|
38
|
+
@foo.name.should_be 'D1'
|
39
39
|
end
|
40
40
|
it 'should have singleton attribute name by default' do
|
41
|
-
Foo.metadata.
|
41
|
+
Foo.metadata.should_be 'D2'
|
42
42
|
end
|
43
43
|
it 'should have singleton attribute special by default' do
|
44
|
-
@foo.special.
|
44
|
+
@foo.special.should_be 'D3'
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'should not have a @name instance variable' do
|
48
|
-
@foo.instance_variables.include?("@name").
|
49
|
-
@foo.instance_variables.sort.
|
48
|
+
@foo.instance_variables.include?("@name").should_be false
|
49
|
+
@foo.instance_variables.sort.should_be []
|
50
50
|
end
|
51
51
|
it 'should not have a @metadata class instance variable' do
|
52
|
-
Foo.instance_variables.include?("@metadata").
|
53
|
-
Foo.instance_variables.sort.
|
52
|
+
Foo.instance_variables.include?("@metadata").should_be false
|
53
|
+
Foo.instance_variables.sort.should_be []
|
54
54
|
end
|
55
55
|
it 'should not have @special singleton instance variable' do
|
56
|
-
@foo.singleton_class.instance_variables.include?("@special").
|
57
|
-
@foo.singleton_class.instance_variables.sort.
|
56
|
+
@foo.singleton_class.instance_variables.include?("@special").should_be false
|
57
|
+
@foo.singleton_class.instance_variables.sort.should_be []
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
@@ -90,11 +90,11 @@ describe Doodle, 'defaults which have been set' do
|
|
90
90
|
end
|
91
91
|
|
92
92
|
it 'should have default value set from hash arg' do
|
93
|
-
@foo.baz.
|
93
|
+
@foo.baz.should_be 'Hi!'
|
94
94
|
end
|
95
95
|
|
96
96
|
it 'should have default value set from block' do
|
97
|
-
@foo.start.
|
97
|
+
@foo.start.should_be Date.today
|
98
98
|
end
|
99
99
|
end
|
100
100
|
end
|
@@ -120,8 +120,8 @@ describe Doodle, "overriding inherited defaults" do
|
|
120
120
|
|
121
121
|
it 'should allow initialization using defaults' do
|
122
122
|
text = Text.new(:value => 'any')
|
123
|
-
text.name.
|
124
|
-
text.value.
|
123
|
+
text.name.should_be 'text'
|
124
|
+
text.value.should_be 'any'
|
125
125
|
end
|
126
126
|
|
127
127
|
it 'should raise Doodle::ValidationError if initialized without all required values' do
|
@@ -130,8 +130,8 @@ describe Doodle, "overriding inherited defaults" do
|
|
130
130
|
|
131
131
|
it 'should allow initialization using inherited defaults' do
|
132
132
|
text = Text2.new
|
133
|
-
text.name.
|
134
|
-
text.value.
|
133
|
+
text.name.should_be 'text'
|
134
|
+
text.value.should_be 'any2'
|
135
135
|
end
|
136
136
|
end
|
137
137
|
end
|
data/spec/doodle_context_spec.rb
CHANGED
data/spec/doodle_spec.rb
CHANGED
@@ -15,24 +15,24 @@ describe Doodle, 'instance attributes' do
|
|
15
15
|
|
16
16
|
it 'should create attribute' do
|
17
17
|
@foo.name = 'Smee'
|
18
|
-
@foo.name.
|
18
|
+
@foo.name.should_be 'Smee'
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'should create attribute using getter_setter' do
|
22
22
|
@foo.name 'Smee'
|
23
|
-
@foo.name.
|
23
|
+
@foo.name.should_be 'Smee'
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'should list instance attributes(false)' do
|
27
|
-
@foo.attributes(false).keys.
|
27
|
+
@foo.attributes(false).keys.should_be []
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'should list instance attributes' do
|
31
|
-
@foo.attributes.keys.
|
31
|
+
@foo.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.attributes(false).keys.
|
35
|
+
Foo.attributes(false).keys.should_be [:name]
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
@@ -54,25 +54,25 @@ describe Doodle, 'class attributes(false)' do
|
|
54
54
|
|
55
55
|
it 'should create class attribute' do
|
56
56
|
Foo.metadata = 'Foo metadata'
|
57
|
-
Foo.metadata.
|
57
|
+
Foo.metadata.should_be 'Foo metadata'
|
58
58
|
end
|
59
59
|
|
60
60
|
it 'should access @foo.class attribute via self.class' do
|
61
61
|
@foo.class.metadata = '@foo metadata'
|
62
|
-
@foo.class.metadata.
|
63
|
-
Foo.metadata.
|
62
|
+
@foo.class.metadata.should_be '@foo metadata'
|
63
|
+
Foo.metadata.should_be '@foo metadata'
|
64
64
|
|
65
65
|
Foo.metadata = 'Foo metadata'
|
66
|
-
Foo.metadata.
|
67
|
-
@foo.class.metadata.
|
66
|
+
Foo.metadata.should_be 'Foo metadata'
|
67
|
+
@foo.class.metadata.should_be 'Foo metadata'
|
68
68
|
end
|
69
69
|
|
70
70
|
it "should list all class's own attributes" do
|
71
|
-
Foo.singleton_class.attributes(false).keys.
|
71
|
+
Foo.singleton_class.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.attributes.keys.
|
75
|
+
Foo.singleton_class.attributes.keys.should_be [:metadata]
|
76
76
|
end
|
77
77
|
end
|
78
78
|
end
|
@@ -103,61 +103,61 @@ describe Doodle, 'inherited class attributes(false)' do
|
|
103
103
|
it 'should create inherited class attribute' do
|
104
104
|
Foo.metadata = 'Foo metadata'
|
105
105
|
Bar.metadata = 'Bar metadata'
|
106
|
-
Foo.metadata.
|
107
|
-
Bar.metadata.
|
108
|
-
Foo.metadata.
|
106
|
+
Foo.metadata.should_be 'Foo metadata'
|
107
|
+
Bar.metadata.should_be 'Bar metadata'
|
108
|
+
Foo.metadata.should_be 'Foo metadata'
|
109
109
|
end
|
110
110
|
|
111
111
|
it 'should access @foo.class attribute via self.class' do
|
112
112
|
@foo.class.metadata = '@foo metadata'
|
113
|
-
@foo.class.metadata.
|
114
|
-
Foo.metadata.
|
113
|
+
@foo.class.metadata.should_be '@foo metadata'
|
114
|
+
Foo.metadata.should_be '@foo metadata'
|
115
115
|
|
116
116
|
Foo.metadata = 'Foo metadata'
|
117
117
|
Bar.metadata = 'Bar metadata'
|
118
|
-
Foo.metadata.
|
119
|
-
Bar.metadata.
|
120
|
-
Foo.metadata.
|
121
|
-
@foo.class.metadata.
|
122
|
-
@bar.class.metadata.
|
118
|
+
Foo.metadata.should_be 'Foo metadata'
|
119
|
+
Bar.metadata.should_be 'Bar metadata'
|
120
|
+
Foo.metadata.should_be 'Foo metadata'
|
121
|
+
@foo.class.metadata.should_be 'Foo metadata'
|
122
|
+
@bar.class.metadata.should_be 'Bar metadata'
|
123
123
|
end
|
124
124
|
|
125
125
|
it 'should access inherited @foo.class attribute via self.class' do
|
126
126
|
@foo.class.metadata = '@foo metadata'
|
127
|
-
@foo.class.metadata.
|
128
|
-
Foo.metadata.
|
127
|
+
@foo.class.metadata.should_be '@foo metadata'
|
128
|
+
Foo.metadata.should_be '@foo metadata'
|
129
129
|
Foo.metadata = 'Foo metadata'
|
130
130
|
|
131
131
|
Bar.metadata = 'Bar metadata'
|
132
|
-
Bar.metadata.
|
133
|
-
@bar.class.metadata.
|
132
|
+
Bar.metadata.should_be 'Bar metadata'
|
133
|
+
@bar.class.metadata.should_be 'Bar metadata'
|
134
134
|
|
135
|
-
Foo.metadata.
|
136
|
-
@foo.class.metadata.
|
135
|
+
Foo.metadata.should_be 'Foo metadata'
|
136
|
+
@foo.class.metadata.should_be 'Foo metadata'
|
137
137
|
end
|
138
138
|
|
139
139
|
it "should list class's own attributes" do
|
140
|
-
Foo.singleton_class.attributes(false).keys.
|
140
|
+
Foo.singleton_class.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.attributes.keys.
|
144
|
+
Foo.singleton_class.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.attributes(false).keys.
|
148
|
+
Bar.singleton_class.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.attributes.keys.
|
152
|
+
Bar.singleton_class.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.
|
156
|
+
Bar.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.attributes.keys.
|
160
|
+
Bar.attributes.keys.should_be [:name, :location]
|
161
161
|
end
|
162
162
|
end
|
163
163
|
end
|
@@ -184,19 +184,19 @@ describe Doodle, 'singleton class attributes' do
|
|
184
184
|
|
185
185
|
it 'should allow creation of singleton class attributes' do
|
186
186
|
@foo.special = 42
|
187
|
-
@foo.special.
|
187
|
+
@foo.special.should_be 42
|
188
188
|
end
|
189
189
|
|
190
190
|
it 'should list singleton instance attributes(false)' do
|
191
|
-
@foo.singleton_class.attributes(false).keys.
|
191
|
+
@foo.singleton_class.attributes(false).keys.should_be [:special]
|
192
192
|
end
|
193
193
|
|
194
194
|
it 'should list singleton instance attributes' do
|
195
|
-
@foo.singleton_class.attributes.keys.
|
195
|
+
@foo.singleton_class.attributes.keys.should_be [:special]
|
196
196
|
end
|
197
197
|
|
198
198
|
it 'should list instance attributes' do
|
199
|
-
@foo.attributes.keys.
|
199
|
+
@foo.attributes.keys.should_be [:name, :special]
|
200
200
|
end
|
201
201
|
|
202
202
|
end
|
@@ -236,65 +236,81 @@ describe Doodle, 'inherited singleton class attributes' do
|
|
236
236
|
|
237
237
|
it 'should allow creation of singleton class attributes' do
|
238
238
|
@foo.special = 42
|
239
|
-
@foo.special.
|
239
|
+
@foo.special.should_be 42
|
240
240
|
@bar.extra = 84
|
241
|
-
@bar.extra.
|
241
|
+
@bar.extra.should_be 84
|
242
242
|
proc { @foo.extra = 1 }.should raise_error(NoMethodError)
|
243
243
|
proc { @bar2.extra = 1 }.should raise_error(NoMethodError)
|
244
244
|
proc { @bar.special = 1 }.should raise_error(NoMethodError)
|
245
245
|
end
|
246
246
|
|
247
247
|
it 'should list instance attributes' do
|
248
|
-
@foo.class.attributes(false).keys.
|
249
|
-
@bar.class.attributes(false).keys.
|
250
|
-
@bar2.class.attributes(false).keys.
|
248
|
+
@foo.class.attributes(false).keys.should_be [:name]
|
249
|
+
@bar.class.attributes(false).keys.should_be [:info]
|
250
|
+
@bar2.class.attributes(false).keys.should_be [:info]
|
251
251
|
end
|
252
252
|
|
253
253
|
it 'should list instance meta attributes' do
|
254
|
-
@foo.singleton_class.attributes(false).keys.
|
255
|
-
@bar.singleton_class.attributes(false).keys.
|
254
|
+
@foo.singleton_class.attributes(false).keys.should_be [:special]
|
255
|
+
@bar.singleton_class.attributes(false).keys.should_be [:extra]
|
256
256
|
end
|
257
257
|
|
258
258
|
it 'should list singleton attributes only' do
|
259
|
-
@foo.singleton_class.attributes.keys.
|
260
|
-
@bar.singleton_class.attributes.keys.
|
259
|
+
@foo.singleton_class.attributes.keys.should_be [:special]
|
260
|
+
@bar.singleton_class.attributes.keys.should_be [:extra]
|
261
261
|
end
|
262
262
|
|
263
263
|
it 'should keep meta attributes separate' do
|
264
264
|
@foo.special = 'foo special'
|
265
|
-
@foo.special.
|
266
|
-
|
267
|
-
#
|
268
|
-
|
265
|
+
@foo.special.should_be 'foo special'
|
266
|
+
|
267
|
+
# CHECK
|
268
|
+
|
269
269
|
# note: you cannot set any other values on @bar until you have set @bar.extra because it's defined as required
|
270
270
|
@bar.extra = 'bar extra'
|
271
|
-
@bar.extra.
|
271
|
+
@bar.extra.should_be 'bar extra'
|
272
272
|
Foo.metadata = 'Foo meta'
|
273
|
-
Foo.metadata.
|
273
|
+
Foo.metadata.should_be 'Foo meta'
|
274
274
|
Bar.metadata = 'Bar meta'
|
275
|
-
Bar.metadata.
|
275
|
+
Bar.metadata.should_be 'Bar meta'
|
276
276
|
Bar.doc = 'Bar doc'
|
277
|
-
Bar.doc.
|
277
|
+
Bar.doc.should_be 'Bar doc'
|
278
278
|
|
279
279
|
# now make sure they haven't bumped each other off
|
280
|
-
@foo.special.
|
281
|
-
|
282
|
-
@bar.extra.
|
283
|
-
Foo.metadata.
|
284
|
-
Bar.metadata.
|
285
|
-
Bar.doc.
|
280
|
+
@foo.special.should_be 'foo special'
|
281
|
+
|
282
|
+
@bar.extra.should_be 'bar extra'
|
283
|
+
Foo.metadata.should_be 'Foo meta'
|
284
|
+
Bar.metadata.should_be 'Bar meta'
|
285
|
+
Bar.doc.should_be 'Bar doc'
|
286
|
+
end
|
287
|
+
|
288
|
+
it 'should inherit singleton methods from class' do
|
289
|
+
@foo.singleton_class.respond_to?(:metadata).should_be true
|
290
|
+
@foo.singleton_class.attributes[:metadata].should_be nil
|
291
|
+
@foo.singleton_class.metadata = 'foo meta'
|
292
|
+
@foo.singleton_class.instance_eval { @metadata }.should_be 'foo meta'
|
293
|
+
if RUBY_VERSION < '1.9.0'
|
294
|
+
@foo.singleton_class.metadata.should_be 'foo meta'
|
295
|
+
else
|
296
|
+
pending 'figuring out why this fails in 1.9' do
|
297
|
+
@foo.singleton_class.metadata.should_be 'foo meta'
|
298
|
+
end
|
299
|
+
end
|
286
300
|
end
|
287
|
-
|
301
|
+
|
288
302
|
it 'should behave predictably when setting singleton attributes' do
|
289
303
|
@bar.extra = 'bar extra'
|
290
|
-
@bar.extra.
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
304
|
+
@bar.extra.should_be 'bar extra'
|
305
|
+
@bar.singleton_class.metadata = 'bar meta metadata'
|
306
|
+
if RUBY_VERSION < '1.9.0'
|
307
|
+
@bar.singleton_class.metadata.should_be 'bar meta metadata'
|
308
|
+
@bar.singleton_class.doc = 'bar doc'
|
309
|
+
@bar.singleton_class.doc.should_be 'bar doc'
|
310
|
+
else
|
311
|
+
pending 'figuring out why this fails in 1.9'
|
312
|
+
end
|
313
|
+
proc { @foo.singleton_class.doc = 1 }.should raise_error(NoMethodError)
|
298
314
|
end
|
299
315
|
end
|
300
316
|
end
|
data/spec/factory_spec.rb
CHANGED
@@ -14,15 +14,15 @@ describe Doodle::Factory, " as part of Doodle" do
|
|
14
14
|
it 'should provide factory function' do
|
15
15
|
proc {
|
16
16
|
foo = Foo("abcd")
|
17
|
-
foo.var1.
|
17
|
+
foo.var1.should_be "abcd"
|
18
18
|
}.should_not raise_error
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'should inherit factory function' do
|
22
22
|
proc {
|
23
23
|
bar = Bar("abcd", 1234)
|
24
|
-
bar.var1.
|
25
|
-
bar.var2.
|
24
|
+
bar.var1.should_be "abcd"
|
25
|
+
bar.var2.should_be 1234
|
26
26
|
}.should_not raise_error
|
27
27
|
end
|
28
28
|
end
|
@@ -48,22 +48,22 @@ describe Doodle::Factory, " included as module" do
|
|
48
48
|
it 'should provide factory function' do
|
49
49
|
proc {
|
50
50
|
foo = Baz("abcd")
|
51
|
-
foo.var1.
|
51
|
+
foo.var1.should_be "abcd"
|
52
52
|
}.should_not raise_error
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'should inherit factory function' do
|
56
56
|
proc {
|
57
57
|
qux = Qux("abcd", 1234)
|
58
|
-
qux.var1.
|
59
|
-
qux.var2.
|
58
|
+
qux.var1.should_be "abcd"
|
59
|
+
qux.var2.should_be 1234
|
60
60
|
}.should_not raise_error
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'should be includeable in non-doodle classes' do
|
64
64
|
proc {
|
65
65
|
qux = MyDate(2008, 01, 01)
|
66
|
-
qux.to_s.
|
66
|
+
qux.to_s.should_be "2008-01-01"
|
67
67
|
}.should_not raise_error
|
68
68
|
end
|
69
69
|
|
@@ -71,7 +71,7 @@ describe Doodle::Factory, " included as module" do
|
|
71
71
|
# it 'should be inheritable by non-doodle classes' do
|
72
72
|
# proc {
|
73
73
|
# qux = AnotherDate(2008, 01, 01)
|
74
|
-
# qux.to_s.
|
74
|
+
# qux.to_s.should_be "2008-01-01"
|
75
75
|
# }.should_not raise_error
|
76
76
|
# end
|
77
77
|
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe Doodle, "inheritance" do
|
4
|
+
temporary_constants :Foo, :Bar do
|
5
|
+
before :each do
|
6
|
+
class Foo < Doodle
|
7
|
+
class << self
|
8
|
+
has :cvar
|
9
|
+
end
|
10
|
+
has :ivar
|
11
|
+
end
|
12
|
+
class Bar < Foo
|
13
|
+
class << self
|
14
|
+
has :cvar2
|
15
|
+
end
|
16
|
+
has :ivar2
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should collect_inherited for instance" do
|
21
|
+
foo = Foo.new(:ivar => "foo")
|
22
|
+
foo.send(:collect_inherited, :attributes).map{ |key, value| key}.should_be [:ivar]
|
23
|
+
foo.attributes.map{ |key, value| key}.should_be [:ivar]
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should collect inherited for singleton" do
|
27
|
+
foo = Foo.new(:ivar => "foo")
|
28
|
+
class << foo
|
29
|
+
has :svar
|
30
|
+
end
|
31
|
+
foo.attributes.map{ |key, value| key}.should_be [:ivar, :svar]
|
32
|
+
foo.singleton_class.attributes.map{ |key, value| key}.should_be [:svar]
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should collect singleton class attributes for singleton" do
|
36
|
+
foo = Foo.new(:ivar => "foo")
|
37
|
+
class << foo
|
38
|
+
has :svar
|
39
|
+
end
|
40
|
+
foo.singleton_class.respond_to?(:cvar).should_be true
|
41
|
+
foo.attributes.map{ |key, value| key}.should_be [:ivar, :svar]
|
42
|
+
# is this what I want? not sure
|
43
|
+
# foo.class.singleton_class.should_be foo.singleton_class.superclass
|
44
|
+
# foo.singleton_class.singleton_class # => #<Class:#<Class:#<Foo:0xb7bc8dd0>>>
|
45
|
+
# and now it's false
|
46
|
+
# all different in 1.9
|
47
|
+
# foo.class.singleton_class.should_not == foo.singleton_class.superclass # => false
|
48
|
+
# foo.singleton_class.respond_to?(:cvar).should_be true
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should collect inherited for subclass singleton" do
|
52
|
+
bar = Bar.new(:ivar => "foo", :ivar2 => "bar")
|
53
|
+
class << bar
|
54
|
+
has :svar2
|
55
|
+
end
|
56
|
+
bar.attributes.map{ |key, value| key}.should_be [:ivar, :ivar2, :svar2]
|
57
|
+
bar.singleton_class.attributes.map{ |key, value| key}.should_be [:svar2]
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should show instance attributes for class" do
|
61
|
+
Foo.attributes.map{ |key, value| key}.should_be [:ivar]
|
62
|
+
Bar.attributes.map{ |key, value| key}.should_be [:ivar, :ivar2]
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should collect_inherited 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]
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should not inherit class attributes via singleton_class" do
|
71
|
+
Bar.singleton_class.attributes.map{ |key, value| key}.should_be [:cvar2]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|