doodle 0.1.9 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +29 -10
- data/Manifest.txt +12 -0
- data/README.txt +5 -4
- data/lib/doodle.rb +227 -112
- data/lib/doodle/app.rb +25 -21
- data/lib/doodle/version.rb +2 -2
- data/lib/doodle/xml.rb +175 -0
- data/spec/arg_order_spec.rb +1 -1
- data/spec/block_init_spec.rb +1 -1
- data/spec/bugs_spec.rb +61 -29
- data/spec/collector_spec.rb +92 -25
- data/spec/defaults_spec.rb +13 -0
- data/spec/doodle_context_spec.rb +1 -1
- data/spec/doodle_spec.rb +4 -14
- data/spec/equality_spec.rb +118 -0
- data/spec/modules_spec.rb +67 -0
- data/spec/serialization_spec.rb +3 -3
- data/spec/spec.template +16 -0
- data/spec/spec_helper.rb +5 -1
- data/spec/to_hash_spec.rb +12 -2
- data/spec/validation2_spec.rb +10 -10
- data/spec/validation_spec.rb +1 -1
- data/spec/xml_spec.rb +219 -0
- metadata +17 -2
data/spec/serialization_spec.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
2
|
require 'yaml'
|
3
3
|
|
4
|
+
# TODO: add more complex (e.g. nested doodles) scenarios here
|
4
5
|
describe Doodle, "Serialization" do
|
5
6
|
temporary_constant :Foo do
|
6
7
|
before :each do
|
7
|
-
class Foo < Doodle
|
8
|
+
class ::Foo < Doodle
|
8
9
|
has :var, :kind => Integer
|
9
10
|
end
|
10
11
|
@foo = Foo 42
|
@@ -14,9 +15,8 @@ describe Doodle, "Serialization" do
|
|
14
15
|
end
|
15
16
|
|
16
17
|
it "should be serializable to yaml" do
|
17
|
-
# is this a bug in the MRI yaml implementation? why the space after Foo?
|
18
18
|
# (note: all on one line to pass coverage)
|
19
|
-
|
19
|
+
@foo.to_yaml.should == "--- !ruby/object:Foo \nvar: 42\n"
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should be loadable from yaml" do
|
data/spec/spec.template
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
describe 'Doodle', '' do
|
5
|
+
temporary_constant :Foo do
|
6
|
+
before :each do
|
7
|
+
class Foo < Doodle
|
8
|
+
has :ivar1, :kind => String
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should behave' do
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
data/spec/spec_helper.rb
CHANGED
data/spec/to_hash_spec.rb
CHANGED
@@ -4,7 +4,7 @@ require 'yaml'
|
|
4
4
|
describe 'Doodle', 'block initialization of scalar attributes' do
|
5
5
|
temporary_constant :Foo, :Bar, :Farm, :Barn, :Animal do
|
6
6
|
before :each do
|
7
|
-
class Animal < Doodle
|
7
|
+
class ::Animal < Doodle
|
8
8
|
has :species
|
9
9
|
end
|
10
10
|
class Barn < Doodle
|
@@ -20,7 +20,7 @@ describe 'Doodle', 'block initialization of scalar attributes' do
|
|
20
20
|
has :block, :kind => Proc
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
it 'should initialize an scalar attribute from a block' do
|
25
25
|
farm = Farm do
|
26
26
|
barn do
|
@@ -30,6 +30,16 @@ describe 'Doodle', 'block initialization of scalar attributes' do
|
|
30
30
|
farm.to_hash.should_be( {:barn=>{:animals=>[{:species=>"pig"}]}} )
|
31
31
|
farm.to_string_hash.should_be( {"barn"=>{"animals"=>[{"species"=>"pig"}]}} )
|
32
32
|
end
|
33
|
+
|
34
|
+
it 'should do something sensible with Proc-valued attributes' do
|
35
|
+
pending
|
36
|
+
source_block = proc { puts "hello" }
|
37
|
+
b = Bar do
|
38
|
+
block(&source_block)
|
39
|
+
end
|
40
|
+
b.to_hash.should_be( { :block => source_block } )
|
41
|
+
end
|
42
|
+
|
33
43
|
end
|
34
44
|
end
|
35
45
|
|
data/spec/validation2_spec.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
require File.dirname(__FILE__) + '/spec_helper.rb'
|
5
5
|
|
6
6
|
shared_code = proc do
|
7
|
-
class DateRange < Doodle
|
7
|
+
class ::DateRange < Doodle
|
8
8
|
has :start_date, :kind => Date do
|
9
9
|
from String do |s|
|
10
10
|
Date.parse(s)
|
@@ -63,13 +63,13 @@ end
|
|
63
63
|
before :each, &shared_code
|
64
64
|
before :each do
|
65
65
|
|
66
|
-
class DerivedDateRange < DateRange
|
66
|
+
class ::DerivedDateRange < DateRange
|
67
67
|
end
|
68
68
|
|
69
|
-
class SecondLevelDerivedDateRange < DateRange
|
69
|
+
class ::SecondLevelDerivedDateRange < DateRange
|
70
70
|
end
|
71
71
|
|
72
|
-
@klass =
|
72
|
+
@klass = Object.const_get(klass)
|
73
73
|
@meth = @klass.method(:new)
|
74
74
|
|
75
75
|
end
|
@@ -155,13 +155,13 @@ end
|
|
155
155
|
temporary_constants :AttributeDate, :Base, :DateRange, :DerivedDateRange, :SecondLevelDerivedDateRange do
|
156
156
|
before :each, &shared_code
|
157
157
|
before :each do
|
158
|
-
class DerivedDateRange < DateRange
|
158
|
+
class ::DerivedDateRange < DateRange
|
159
159
|
end
|
160
160
|
|
161
|
-
class SecondLevelDerivedDateRange < DateRange
|
161
|
+
class ::SecondLevelDerivedDateRange < DateRange
|
162
162
|
end
|
163
163
|
|
164
|
-
@klass =
|
164
|
+
@klass = Object.const_get(klass)
|
165
165
|
@dr = @klass.new
|
166
166
|
end
|
167
167
|
|
@@ -179,13 +179,13 @@ end
|
|
179
179
|
temporary_constants :AttributeDate, :Base, :DateRange, :DerivedDateRange, :SecondLevelDerivedDateRange do
|
180
180
|
before :each, &shared_code
|
181
181
|
before :each do
|
182
|
-
class DerivedDateRange < DateRange
|
182
|
+
class ::DerivedDateRange < DateRange
|
183
183
|
end
|
184
184
|
|
185
|
-
class SecondLevelDerivedDateRange < DateRange
|
185
|
+
class ::SecondLevelDerivedDateRange < DateRange
|
186
186
|
end
|
187
187
|
|
188
|
-
@klass =
|
188
|
+
@klass = Object.const_get(klass)
|
189
189
|
@dr = @klass.new
|
190
190
|
end
|
191
191
|
|
data/spec/validation_spec.rb
CHANGED
data/spec/xml_spec.rb
ADDED
@@ -0,0 +1,219 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
require 'doodle/xml'
|
3
|
+
|
4
|
+
describe Doodle, 'xml serialization within a module' do
|
5
|
+
temporary_constants :Container, :Base, :Slideshow, :Layout do
|
6
|
+
before(:each) do
|
7
|
+
@xml_source = '<Slideshow id="1" name="test"><Layout template="generic" /></Slideshow>'
|
8
|
+
module ::Container
|
9
|
+
class Base < Doodle
|
10
|
+
include Doodle::XML
|
11
|
+
end
|
12
|
+
class Layout < Base
|
13
|
+
has :template
|
14
|
+
end
|
15
|
+
class Slideshow < Base
|
16
|
+
has :id, :kind => Integer do
|
17
|
+
from String do |s|
|
18
|
+
s.to_i
|
19
|
+
end
|
20
|
+
end
|
21
|
+
has :name, :kind => String
|
22
|
+
has Layout
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
it 'should serialize to xml' do
|
27
|
+
slideshow = Container::Slideshow.new do
|
28
|
+
id 1
|
29
|
+
name "test"
|
30
|
+
layout "generic"
|
31
|
+
end
|
32
|
+
slideshow.to_xml.should_be @xml_source
|
33
|
+
end
|
34
|
+
it 'should serialize from xml' do
|
35
|
+
slideshow = Container::Slideshow.new do
|
36
|
+
id 1
|
37
|
+
name "test"
|
38
|
+
layout "generic"
|
39
|
+
end
|
40
|
+
ss2 = Doodle::XML.from_xml(Container, @xml_source)
|
41
|
+
ss2.should_be slideshow
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe Doodle, 'xml serialization at top level' do
|
47
|
+
temporary_constants :Base, :Slideshow, :Layout do
|
48
|
+
before(:each) do
|
49
|
+
@xml_source = '<Slideshow id="1" name="test"><Layout template="generic" /></Slideshow>'
|
50
|
+
class ::Base < Doodle
|
51
|
+
include Doodle::XML
|
52
|
+
end
|
53
|
+
class ::Layout < Base
|
54
|
+
has :template
|
55
|
+
end
|
56
|
+
class ::Slideshow < Base
|
57
|
+
has :id, :kind => Integer do
|
58
|
+
from String do |s|
|
59
|
+
s.to_i
|
60
|
+
end
|
61
|
+
end
|
62
|
+
has :name, :kind => String
|
63
|
+
has Layout
|
64
|
+
end
|
65
|
+
end
|
66
|
+
it 'should serialize to xml' do
|
67
|
+
slideshow = ::Slideshow.new do
|
68
|
+
id 1
|
69
|
+
name "test"
|
70
|
+
layout "generic"
|
71
|
+
end
|
72
|
+
slideshow.to_xml.should_be @xml_source
|
73
|
+
end
|
74
|
+
it 'should serialize from xml' do
|
75
|
+
slideshow = ::Slideshow.new do
|
76
|
+
id 1
|
77
|
+
name "test"
|
78
|
+
layout "generic"
|
79
|
+
end
|
80
|
+
ss2 = Doodle::XML.from_xml(Object, @xml_source)
|
81
|
+
ss2.should_be slideshow
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe Doodle, 'if default specified before required attributes, they are ignored if defined in block' do
|
87
|
+
temporary_constant :Address do
|
88
|
+
before :each do
|
89
|
+
class Address < Doodle
|
90
|
+
include Doodle::XML
|
91
|
+
has :where, :default => "home"
|
92
|
+
has :city
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'should raise an error that required attributes have not been set' do
|
97
|
+
proc {
|
98
|
+
Address do
|
99
|
+
city "London"
|
100
|
+
end
|
101
|
+
}.should_not raise_error
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should define required attributes' do
|
105
|
+
a = Address do
|
106
|
+
city "London"
|
107
|
+
end
|
108
|
+
a.city.should_be "London"
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'should output required attributes in XML' do
|
112
|
+
a = Address do
|
113
|
+
city "London"
|
114
|
+
end
|
115
|
+
a.to_xml.should_be '<Address city="London" />'
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe Doodle, 'if default specified before required attributes, they are ignored if defined in block #2' do
|
121
|
+
temporary_constant :Base, :City, :Address do
|
122
|
+
before :each do
|
123
|
+
class Base < Doodle
|
124
|
+
include Doodle::XML
|
125
|
+
end
|
126
|
+
class City < Base
|
127
|
+
has :_text_
|
128
|
+
has :country, :default => "UK"
|
129
|
+
end
|
130
|
+
class Address < Base
|
131
|
+
has :where, :default => "home"
|
132
|
+
has City
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'should output required tags in XML' do
|
137
|
+
a = Address do
|
138
|
+
city "London"
|
139
|
+
end
|
140
|
+
a.to_xml.should_be '<Address><City>London</City></Address>'
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'should output specified optional attributes as xml attributes if kind not a doodle class' do
|
144
|
+
a = Address :where => 'home' do
|
145
|
+
city "London"
|
146
|
+
end
|
147
|
+
a.to_xml.should_be %[<Address where="home"><City>London</City></Address>]
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'should output specified optional attributes' do
|
151
|
+
a = Address :where => 'home' do
|
152
|
+
city "London", :country => "England" do
|
153
|
+
country "UK"
|
154
|
+
end
|
155
|
+
end
|
156
|
+
a.to_xml.should_be %[<Address where="home"><City country="UK">London</City></Address>]
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
describe Doodle, 'if default specified before required attributes, they are ignored if defined in block #2' do
|
164
|
+
temporary_constant :Base, :City, :Address, :Country do
|
165
|
+
before :each do
|
166
|
+
|
167
|
+
@country_example = %[<Address where="home"><City>London<Country>UK</Country></City></Address>]
|
168
|
+
|
169
|
+
class ::Base < Doodle
|
170
|
+
include Doodle::XML
|
171
|
+
end
|
172
|
+
class ::Country < Base
|
173
|
+
has :_text_
|
174
|
+
end
|
175
|
+
class ::City < Base
|
176
|
+
has :_text_
|
177
|
+
has Country, :default => "UK"
|
178
|
+
end
|
179
|
+
class ::Address < Base
|
180
|
+
has :where, :default => "home"
|
181
|
+
has City
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'should output required tags in XML' do
|
186
|
+
a = Address do
|
187
|
+
city "London"
|
188
|
+
end
|
189
|
+
a.to_xml.should_be '<Address><City>London</City></Address>'
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'should output specified optional attributes' do
|
193
|
+
a = Address :where => 'home' do
|
194
|
+
city "London"
|
195
|
+
end
|
196
|
+
a.to_xml.should_be %[<Address where="home"><City>London</City></Address>]
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'should output specified optional attributes as tags if kind is a Doodle class' do
|
200
|
+
a = Address :where => 'home' do
|
201
|
+
city "London", :country => "England" do
|
202
|
+
country "UK"
|
203
|
+
end
|
204
|
+
end
|
205
|
+
a.to_xml.should_be @country_example
|
206
|
+
end
|
207
|
+
|
208
|
+
it 'should reconstruct object graph from xml source' do
|
209
|
+
a = Address :where => 'home' do
|
210
|
+
city "London", :country => "England" do
|
211
|
+
country "UK"
|
212
|
+
end
|
213
|
+
end
|
214
|
+
a.to_xml.should_be @country_example
|
215
|
+
b = Doodle::XML.from_xml(Base, a.to_xml)
|
216
|
+
b.should_be a
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean O'Halpin
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-03-02 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -68,6 +68,7 @@ files:
|
|
68
68
|
- lib/doodle/rfc822.rb
|
69
69
|
- lib/doodle/utils.rb
|
70
70
|
- lib/doodle/version.rb
|
71
|
+
- lib/doodle/xml.rb
|
71
72
|
- lib/molic_orderedhash.rb
|
72
73
|
- log/debug.log
|
73
74
|
- script/console
|
@@ -77,6 +78,7 @@ files:
|
|
77
78
|
- setup.rb
|
78
79
|
- spec/arg_order_spec.rb
|
79
80
|
- spec/attributes_spec.rb
|
81
|
+
- spec/block_init_spec.rb
|
80
82
|
- spec/bugs_spec.rb
|
81
83
|
- spec/class_spec.rb
|
82
84
|
- spec/class_validation_spec.rb
|
@@ -86,21 +88,31 @@ files:
|
|
86
88
|
- spec/defaults_spec.rb
|
87
89
|
- spec/doodle_context_spec.rb
|
88
90
|
- spec/doodle_spec.rb
|
91
|
+
- spec/equality_spec.rb
|
89
92
|
- spec/extra_args_spec.rb
|
90
93
|
- spec/factory_spec.rb
|
91
94
|
- spec/flatten_first_level_spec.rb
|
95
|
+
- spec/from_spec.rb
|
96
|
+
- spec/has_spec.rb
|
92
97
|
- spec/inheritance_spec.rb
|
93
98
|
- spec/init_spec.rb
|
99
|
+
- spec/kind_spec.rb
|
100
|
+
- spec/member_init_spec.rb
|
94
101
|
- spec/new_doodle_spec.rb
|
102
|
+
- spec/readonly_spec.rb
|
95
103
|
- spec/required_spec.rb
|
96
104
|
- spec/serialization_spec.rb
|
97
105
|
- spec/singleton_spec.rb
|
98
106
|
- spec/spec.opts
|
107
|
+
- spec/spec.template
|
99
108
|
- spec/spec_helper.rb
|
100
109
|
- spec/specialized_attribute_class_spec.rb
|
101
110
|
- spec/superclass_spec.rb
|
111
|
+
- spec/symbolize_keys_spec.rb
|
112
|
+
- spec/to_hash_spec.rb
|
102
113
|
- spec/validation2_spec.rb
|
103
114
|
- spec/validation_spec.rb
|
115
|
+
- spec/xml_spec.rb
|
104
116
|
- tasks/deployment.rake
|
105
117
|
- tasks/environment.rake
|
106
118
|
- tasks/rspec.rake
|
@@ -146,6 +158,7 @@ test_files:
|
|
146
158
|
- spec/defaults_spec.rb
|
147
159
|
- spec/doodle_context_spec.rb
|
148
160
|
- spec/doodle_spec.rb
|
161
|
+
- spec/equality_spec.rb
|
149
162
|
- spec/extra_args_spec.rb
|
150
163
|
- spec/factory_spec.rb
|
151
164
|
- spec/flatten_first_level_spec.rb
|
@@ -155,6 +168,7 @@ test_files:
|
|
155
168
|
- spec/init_spec.rb
|
156
169
|
- spec/kind_spec.rb
|
157
170
|
- spec/member_init_spec.rb
|
171
|
+
- spec/modules_spec.rb
|
158
172
|
- spec/new_doodle_spec.rb
|
159
173
|
- spec/readonly_spec.rb
|
160
174
|
- spec/required_spec.rb
|
@@ -166,3 +180,4 @@ test_files:
|
|
166
180
|
- spec/to_hash_spec.rb
|
167
181
|
- spec/validation2_spec.rb
|
168
182
|
- spec/validation_spec.rb
|
183
|
+
- spec/xml_spec.rb
|