doodle 0.0.8 → 0.0.9

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.
@@ -0,0 +1,8 @@
1
+ ;; Object lib/
2
+ ;; SEMANTICDB Tags save file
3
+ (semanticdb-project-database-file "lib/"
4
+ :tables 'nil
5
+ :file "semantic.cache"
6
+ :semantic-tag-version "2.0pre4"
7
+ :semanticdb-version "2.0pre4"
8
+ )
@@ -77,4 +77,4 @@ describe 'Doodle', ' loading bad data from yaml' do
77
77
  proc { foo = YAML::load(@str).validate! }.should raise_error(Doodle::ConversionError)
78
78
  end
79
79
  end
80
- end
80
+ end
@@ -25,7 +25,7 @@ describe Doodle, 'class attributes' do
25
25
  Foo.metadata.should == 'Foo metadata'
26
26
  end
27
27
 
28
- it 'should access class attribute via self.class' do
28
+ it 'should access @foo class attribute via self.class' do
29
29
  @foo.class.metadata = '@foo metadata'
30
30
  @foo.class.metadata.should == '@foo metadata'
31
31
  Foo.metadata.should == '@foo metadata'
@@ -48,7 +48,7 @@ describe Doodle, 'class attributes' do
48
48
  Bar.metadata.should == 'Bar metadata'
49
49
  end
50
50
 
51
- it 'should access class attribute via self.class' do
51
+ it 'should access @bar class attribute via self.class' do
52
52
  @bar.class.metadata = '@bar metadata'
53
53
  @bar.class.metadata.should == '@bar metadata'
54
54
  Bar.metadata.should == '@bar metadata'
@@ -71,7 +71,7 @@ describe Doodle, "Typed collector with specified collector name" do
71
71
  end
72
72
  end
73
73
 
74
- describe Doodle, "Typed collector with specified collector name" do
74
+ describe Doodle, "typed collector with specified collector name" do
75
75
  temporary_constant :Location, :Event do
76
76
  before :each do
77
77
  class Location < Doodle::Base
@@ -95,3 +95,51 @@ describe Doodle, "Typed collector with specified collector name" do
95
95
  end
96
96
  end
97
97
 
98
+ describe Doodle, "typed collector with specified collector name initialized from hash (with default :init param)" do
99
+ temporary_constant :Location, :Event do
100
+ before :each do
101
+ class Location < Doodle::Base
102
+ has :name, :kind => String
103
+ has :events, :collect => :Event
104
+ end
105
+ class Event < Doodle::Base
106
+ has :name, :kind => String
107
+ has :locations, :collect => :Location
108
+ end
109
+ end
110
+ it "should collect items from hash" do
111
+ event = nil
112
+ data = {
113
+ :name => 'RAR',
114
+ :locations =>
115
+ [
116
+ {
117
+ :name => "Stage 1",
118
+ :events =>
119
+ [
120
+ {
121
+ :name => 'Foobars',
122
+ :locations =>
123
+ [
124
+ {
125
+ :name => 'Backstage'
126
+ }
127
+ ]
128
+ }
129
+ ]
130
+ },
131
+ {
132
+ :name => "Stage 2"
133
+ }
134
+ ]
135
+ }
136
+ proc {
137
+ event = Event(data)
138
+ }.should_not raise_error
139
+ event.locations.map{|loc| loc.name}.should == ["Stage 1", "Stage 2"]
140
+ event.locations.map{|loc| loc.class}.should == [Location, Location]
141
+ event.locations[0].events[0].kind_of?(Event).should == true
142
+ end
143
+ end
144
+ end
145
+
@@ -45,13 +45,5 @@ describe Doodle, 'defaults which have not been set' do
45
45
  foo = Foo.from("2007-12-31")
46
46
  foo.start.should == Date.new(2007, 12, 31)
47
47
  end
48
-
49
- it 'should allow factory function' do
50
- # class Foo
51
- # include Doodle::Factory
52
- # end
53
- foo = Foo("2007-12-31")
54
- foo.start.should == Date.new(2007, 12, 31)
55
- end
56
48
  end
57
49
 
@@ -0,0 +1,46 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe Doodle, "doodle_context" do
4
+ temporary_constants :Foo, :Bar do
5
+ before :each do
6
+ class Child < Doodle::Base
7
+ has :name
8
+ has :dad do
9
+ # there is an important difference between a block argument
10
+ # and a Proc object (proc/lambda) argument
11
+ # - a proc/lamba is treated as a literal argument, i.e. the
12
+ # - value is set to a Proc
13
+ # - a block argument, on the other hand, is instance
14
+ # - evaluated during initialization
15
+ # - consequences
16
+ # - can only be done in init block
17
+ # - somewhat subtle difference (from programmer's point of
18
+ # - view) between a proc and a block
19
+ # Also note re: Doodle.parent - its value is only valid
20
+ # during initialization - this is a way to capture that
21
+ # value for ues later
22
+
23
+ init {
24
+ Doodle.parent
25
+ }
26
+ end
27
+ end
28
+
29
+ class Parent < Child
30
+ has :children, :collect => Child
31
+ end
32
+
33
+ end
34
+
35
+ it 'should provide a means to find out the current parent of an item in initialization block' do
36
+ dad = Parent 'Conn' do
37
+ child 'Sean'
38
+ child 'Paul'
39
+ end
40
+
41
+ sean = dad.children[0]
42
+ sean.dad.name.should == 'Conn'
43
+ end
44
+ end
45
+ end
46
+
@@ -57,7 +57,7 @@ describe Doodle, 'class attributes(false)' do
57
57
  Foo.metadata.should == 'Foo metadata'
58
58
  end
59
59
 
60
- it 'should access class attribute via self.class' do
60
+ it 'should access @foo.class attribute via self.class' do
61
61
  @foo.class.metadata = '@foo metadata'
62
62
  @foo.class.metadata.should == '@foo metadata'
63
63
  Foo.metadata.should == '@foo metadata'
@@ -108,7 +108,7 @@ describe Doodle, 'inherited class attributes(false)' do
108
108
  Foo.metadata.should == 'Foo metadata'
109
109
  end
110
110
 
111
- it 'should access class attribute via self.class' do
111
+ it 'should access @foo.class attribute via self.class' do
112
112
  @foo.class.metadata = '@foo metadata'
113
113
  @foo.class.metadata.should == '@foo metadata'
114
114
  Foo.metadata.should == '@foo metadata'
@@ -122,7 +122,7 @@ describe Doodle, 'inherited class attributes(false)' do
122
122
  @bar.class.metadata.should == 'Bar metadata'
123
123
  end
124
124
 
125
- it 'should access inherited class attribute via self.class' do
125
+ it 'should access inherited @foo.class attribute via self.class' do
126
126
  @foo.class.metadata = '@foo metadata'
127
127
  @foo.class.metadata.should == '@foo metadata'
128
128
  Foo.metadata.should == '@foo metadata'
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe Doodle, ' unspecified attributes' do
4
+ temporary_constants :Foo do
5
+ before :each do
6
+ class Foo < Doodle::Base
7
+ end
8
+ end
9
+
10
+ it 'should raise Doodle::UnknownAttributeError for unspecified attributes' do
11
+ proc { foo = Foo(:name => 'foo') }.should raise_error(Doodle::UnknownAttributeError)
12
+ end
13
+ end
14
+ end
15
+
16
+ describe Doodle::Attribute, ' unspecified attributes' do
17
+ it 'should raise Doodle::UnknownAttributeError for unspecified attributes' do
18
+ proc { foo = Doodle::Attribute(:name => 'foo', :extra => 'unwanted') }.should raise_error(Doodle::UnknownAttributeError)
19
+ end
20
+ end
@@ -0,0 +1,80 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe Doodle::Factory, " as part of Doodle::Base" do
4
+ temporary_constant :Foo, :Bar do
5
+ before(:each) do
6
+ class Foo < Doodle::Base
7
+ has :var1
8
+ end
9
+ class Bar < Foo
10
+ has :var2
11
+ end
12
+ end
13
+
14
+ it 'should provide factory function' do
15
+ proc {
16
+ foo = Foo("abcd")
17
+ foo.var1.should == "abcd"
18
+ }.should_not raise_error
19
+ end
20
+
21
+ it 'should inherit factory function' do
22
+ proc {
23
+ bar = Bar("abcd", 1234)
24
+ bar.var1.should == "abcd"
25
+ bar.var2.should == 1234
26
+ }.should_not raise_error
27
+ end
28
+ end
29
+ end
30
+
31
+ describe Doodle::Factory, " included as module" do
32
+ temporary_constant :Baz, :Qux, :MyDate, :AnotherDate do
33
+ before(:each) do
34
+ class Baz
35
+ include Doodle::Helper
36
+ has :var1
37
+ end
38
+ class Qux < Baz
39
+ has :var2
40
+ end
41
+ class MyDate < Date
42
+ include Doodle::Factory
43
+ end
44
+ class AnotherDate < MyDate
45
+ end
46
+ end
47
+
48
+ it 'should provide factory function' do
49
+ proc {
50
+ foo = Baz("abcd")
51
+ foo.var1.should == "abcd"
52
+ }.should_not raise_error
53
+ end
54
+
55
+ it 'should inherit factory function' do
56
+ proc {
57
+ qux = Qux("abcd", 1234)
58
+ qux.var1.should == "abcd"
59
+ qux.var2.should == 1234
60
+ }.should_not raise_error
61
+ end
62
+
63
+ it 'should be includeable in non-doodle classes' do
64
+ proc {
65
+ qux = MyDate(2008, 01, 01)
66
+ qux.to_s.should == "2008-01-01"
67
+ }.should_not raise_error
68
+ end
69
+
70
+ # do I actually want this? should it be opt-in at each level?
71
+ # it 'should be inheritable by non-doodle classes' do
72
+ # proc {
73
+ # qux = AnotherDate(2008, 01, 01)
74
+ # qux.to_s.should == "2008-01-01"
75
+ # }.should_not raise_error
76
+ # end
77
+
78
+ end
79
+ end
80
+
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
3
  describe Doodle, 'init' do
4
4
  temporary_constant :Foo do
5
-
5
+
6
6
  before(:each) do
7
7
  class Foo
8
8
  include Doodle::Helper
@@ -16,7 +16,7 @@ describe Doodle, 'init' do
16
16
  has :special, :init => 'D3'
17
17
  end
18
18
  end
19
-
19
+
20
20
  it 'should have instance attribute init via class' do
21
21
  Foo.attributes[:name].init.should == 'D1'
22
22
  end
@@ -42,12 +42,66 @@ describe Doodle, 'init' do
42
42
  @foo.instance_variables.include?('@name').should == true
43
43
  end
44
44
  it 'should have an initialized class attribute :metadata' do
45
- pending 'deciding how this should work'
46
- #Foo.metadata.should == 'D2'
45
+ pending 'deciding how this should work' do
46
+ Foo.metadata.should == 'D2'
47
+ end
47
48
  end
48
49
  it 'should have an initialized singleton attribute :special' do
49
- pending 'deciding how this should work'
50
- #@foo.special.should == 'D3'
50
+ pending 'deciding how this should work' do
51
+ @foo.special.should == 'D3'
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ describe Doodle, 'init' do
58
+ temporary_constant :Foo do
59
+ it 'should accept nil as :init' do
60
+ class Foo < Doodle::Base
61
+ has :value, :init => nil
62
+ end
63
+ foo = Foo.new
64
+ foo.value.should == nil
65
+ end
66
+ end
67
+ temporary_constant :Foo do
68
+ it 'should accept true as :init' do
69
+ class Foo < Doodle::Base
70
+ has :value, :init => true
71
+ end
72
+ foo = Foo.new
73
+ foo.value.should == true
74
+ end
75
+ end
76
+ temporary_constant :Foo do
77
+ it 'should accept Fixnum as :init' do
78
+ class Foo < Doodle::Base
79
+ has :value, :init => 42
80
+ end
81
+ foo = Foo.new
82
+ foo.value.should == 42
83
+ end
84
+ end
85
+ temporary_constant :Foo do
86
+ it 'should not evaluate value when proc given as :init' do
87
+ class Foo < Doodle::Base
88
+ has :value, :init => proc { 42 }
89
+ end
90
+ foo = Foo.new
91
+ foo.value.call.should == 42
92
+ end
93
+ end
94
+ temporary_constant :Foo do
95
+ it 'should evaluate value when block given as :init' do
96
+ class Foo < Doodle::Base
97
+ has :value do
98
+ init do
99
+ 42
100
+ end
101
+ end
102
+ end
103
+ foo = Foo.new
104
+ foo.value.should == 42
51
105
  end
52
106
  end
53
107
  end
@@ -14,7 +14,12 @@ describe Doodle, "Serialization" do
14
14
  end
15
15
 
16
16
  it "should be serializable to yaml" do
17
- @foo.to_yaml.should == "--- !ruby/object:Foo \nvar: 42\n"
17
+ # is this a bug in the MRI yaml implementation? why the space after Foo?
18
+ if RUBY_PLATFORM == 'java'
19
+ @foo.to_yaml.should == "--- !ruby/object:Foo\nvar: 42\n"
20
+ else
21
+ @foo.to_yaml.should == "--- !ruby/object:Foo \nvar: 42\n"
22
+ end
18
23
  end
19
24
 
20
25
  it "should be loadable from yaml" do
@@ -24,7 +29,7 @@ describe Doodle, "Serialization" do
24
29
  end
25
30
 
26
31
  it "should make it possible to validate already set instance variables" do
27
- new_foo = YAML::load("--- !ruby/object:Foo \nvar: Hello World!\n")
32
+ new_foo = YAML::load("--- !ruby/object:Foo\nvar: Hello World!\n")
28
33
  proc { new_foo.validate!(true) }.should raise_error(Doodle::ValidationError)
29
34
  end
30
35
 
@@ -0,0 +1,63 @@
1
+ require File.dirname(__FILE__) + "/spec_helper.rb"
2
+
3
+ describe Doodle, "singletons" do
4
+ temporary_constant :Foo do
5
+ it "should allow creating attributes on classes via inheritance" do
6
+ class Foo < Doodle::Base
7
+ class << self
8
+ has :c1
9
+ end
10
+ end
11
+ Foo.attributes.should == OrderedHash.new
12
+ Foo.singleton_class.attributes.should_not == OrderedHash.new
13
+ Foo.singleton_class.attributes.map{ |name, attr| name }.should == [:c1]
14
+ Foo.c1 = 1
15
+ Foo.c1.should == 1
16
+ end
17
+
18
+ it "should allow creating attributes on classes via module inclusion" do
19
+ class Foo
20
+ include Doodle::Helper
21
+ class << self
22
+ has :c2
23
+ end
24
+ end
25
+ Foo.attributes.should == OrderedHash.new
26
+ Foo.singleton_class.attributes.should_not == OrderedHash.new
27
+ Foo.singleton_class.attributes.map{ |name, attr| name }.should == [:c2]
28
+ Foo.c2 = 1
29
+ Foo.c2.should == 1
30
+ end
31
+
32
+ it "should allow creating attributes on singletons via inheritance" do
33
+ class Foo < Doodle::Base
34
+ end
35
+ foo = Foo.new
36
+ class << foo
37
+ has :i1
38
+ end
39
+ foo.attributes.should == OrderedHash.new
40
+ foo.singleton_class.attributes.should_not == OrderedHash.new
41
+ foo.singleton_class.attributes.map{ |name, attr| name }.should == [:i1]
42
+ foo.i1 = 1
43
+ foo.i1.should == 1
44
+ end
45
+
46
+ it "should allow creating attributes on a singleton's singleton via module inclusion" do
47
+ class Foo
48
+ include Doodle::Helper
49
+ end
50
+ foo = Foo.new
51
+ class << foo
52
+ class << self
53
+ has :i2
54
+ end
55
+ end
56
+ foo.attributes.should == OrderedHash.new
57
+ foo.singleton_class.singleton_class.attributes.should_not == OrderedHash.new
58
+ foo.singleton_class.singleton_class.attributes.map{ |name, attr| name }.should == [:i2]
59
+ foo.singleton_class.i2 = 1
60
+ foo.singleton_class.i2.should == 1
61
+ end
62
+ end
63
+ end