atdis 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ module Atdis
2
+ VERSION = "0.1"
3
+ end
data/lib/atdis.rb ADDED
@@ -0,0 +1,12 @@
1
+ require "atdis/version"
2
+
3
+ require "atdis/validators"
4
+ require "atdis/model"
5
+ require "atdis/event"
6
+ require "atdis/document"
7
+ require "atdis/location"
8
+ require "atdis/person"
9
+ require "atdis/application"
10
+ require "atdis/feed"
11
+ require "atdis/page"
12
+ require "atdis/separated_url"
@@ -0,0 +1,406 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe ATDIS::Application do
4
+
5
+ context "extra parameter in json" do
6
+ it "should not be valid" do
7
+ ATDIS::Location.should_receive(:interpret).with(:foo => "Some location data").and_return(double(:valid? => true))
8
+ a = ATDIS::Application.interpret(:application => {
9
+ :info => {
10
+ :dat_id => "DA2013-0381",
11
+ :last_modified_date => "2013-04-20T02:01:07Z",
12
+ :description => "New pool plus deck",
13
+ :authority => "Example Council Shire Council",
14
+ :lodgement_date => "2013-04-20T02:01:07Z",
15
+ :determination_date => "2013-06-20",
16
+ :status => "OPEN"
17
+ },
18
+ :reference => {
19
+ # This is the extra parameter that shouldn't be here
20
+ :foo => "bar",
21
+ :more_info_url => "http://foo.com/bar"
22
+ },
23
+ :location => {:foo => "Some location data"}
24
+ })
25
+ a.should_not be_valid
26
+ a.errors.messages.should == {:json => ['Unexpected parameters in json data: {"application":{"reference":{"foo":"bar"}}}']}
27
+ end
28
+ end
29
+
30
+ describe ".interpret" do
31
+ it "should parse the json and create an application object" do
32
+ application = double
33
+
34
+ ATDIS::Application.should_receive(:new).with(
35
+ :dat_id => "DA2013-0381",
36
+ :last_modified_date => "2013-04-20T02:01:07Z",
37
+ :description => "New pool plus deck",
38
+ :authority => "Example Council Shire Council",
39
+ :lodgement_date => "2013-04-20T02:01:07Z",
40
+ :determination_date => "2013-06-20",
41
+ :notification_start_date => "2013-04-20T02:01:07Z",
42
+ :notification_end_date => "2013-05-20T02:01:07Z",
43
+ :officer => "Ms Smith",
44
+ :estimated_cost => "50,000",
45
+ :status => "OPEN",
46
+ :more_info_url => "http://foo.com/bar",
47
+ :comments_url => "http://foo.com/comment",
48
+ :location => { :address => "123 Fourfivesix Street" },
49
+ :events => [ { :id => "event1" }, { :id => "event2" } ],
50
+ :documents => [ { :ref => "27B/6/a" }, { :ref => "27B/6/b" } ],
51
+ :people => [ { :name => "Tuttle" }, { :name => "Buttle" } ],
52
+ :extended => {:another_parameter => "with some value", :anything => "can go here"},
53
+ :json_left_overs => {}
54
+ ).and_return(application)
55
+
56
+ ATDIS::Application.interpret(:application => {
57
+ :info => {
58
+ :dat_id => "DA2013-0381",
59
+ :last_modified_date => "2013-04-20T02:01:07Z",
60
+ :description => "New pool plus deck",
61
+ :authority => "Example Council Shire Council",
62
+ :lodgement_date => "2013-04-20T02:01:07Z",
63
+ :determination_date => "2013-06-20",
64
+ :notification_start_date => "2013-04-20T02:01:07Z",
65
+ :notification_end_date => "2013-05-20T02:01:07Z",
66
+ :officer => "Ms Smith",
67
+ # TODO: In ATDIS-1.0.3 it does not specify whether this is a float or a string
68
+ # and whether to include (or not) AUD or dollar sign. For the time being we'll
69
+ # just assume it's a free-form string
70
+ :estimated_cost => "50,000",
71
+ :status => "OPEN"
72
+ },
73
+ :reference => {
74
+ :more_info_url => "http://foo.com/bar",
75
+ :comments_url => "http://foo.com/comment"
76
+ },
77
+ :location => { :address => "123 Fourfivesix Street" },
78
+ :events => [ { :id => "event1" }, { :id => "event2" } ],
79
+ :documents => [ { :ref => "27B/6/a" }, { :ref => "27B/6/b" } ],
80
+ :people => [ { :name => "Tuttle" }, { :name => "Buttle" } ],
81
+ :extended => {:another_parameter => "with some value", :anything => "can go here"}
82
+ }).should == application
83
+ end
84
+
85
+ it "should create a nil valued application when there is no information in the json" do
86
+ application = double
87
+ ATDIS::Application.should_receive(:new).with({:json_left_overs => {}}).and_return(application)
88
+
89
+ ATDIS::Application.interpret(:application => {:info => {}, :reference => {}}).should == application
90
+ end
91
+ end
92
+
93
+ describe "#extended" do
94
+ it "should do no typecasting" do
95
+ a = ATDIS::Application.new(:extended => {:another_parameter => "with some value", :anything => "can go here"})
96
+ a.extended.should == {:another_parameter => "with some value", :anything => "can go here"}
97
+ end
98
+ end
99
+
100
+ describe "#location=" do
101
+ let(:a) { ATDIS::Application.new }
102
+ it "should type cast to a location" do
103
+ location = double
104
+ ATDIS::Location.should_receive(:interpret).with(:address => "123 Fourfivesix Street").and_return(location)
105
+ a.location = { :address => "123 Fourfivesix Street" }
106
+ a.location.should == location
107
+ end
108
+
109
+ it "should not cast when it's already a location" do
110
+ l = ATDIS::Location.new
111
+ a.location = l
112
+ a.location.should == l
113
+ end
114
+ end
115
+
116
+ describe "#events" do
117
+ let(:a) { ATDIS::Application.new }
118
+ it "should type cast to several events" do
119
+ event1, event2 = double, double
120
+ ATDIS::Event.should_receive(:interpret).with(:id => "event1").and_return(event1)
121
+ ATDIS::Event.should_receive(:interpret).with(:id => "event2").and_return(event2)
122
+ a.events = [ { :id => "event1" }, { :id => "event2" } ]
123
+ a.events.should == [event1, event2]
124
+ end
125
+ end
126
+
127
+ describe "#documents" do
128
+ let(:a) { ATDIS::Application.new }
129
+ it "should type cast to several documents" do
130
+ document1, document2 = double, double
131
+ ATDIS::Document.should_receive(:interpret).with(:ref => "27B/6/a").and_return(document1)
132
+ ATDIS::Document.should_receive(:interpret).with(:ref => "27B/6/b").and_return(document2)
133
+ a.documents = [ { :ref => "27B/6/a" }, { :ref => "27B/6/b" } ]
134
+ a.documents.should == [document1, document2]
135
+ end
136
+ end
137
+
138
+ describe "#people" do
139
+ let(:a) { ATDIS::Application.new }
140
+ it "should type cast to several people" do
141
+ tuttle, buttle = double, double
142
+ ATDIS::Person.should_receive(:interpret).with(:name => "Tuttle").and_return(tuttle)
143
+ ATDIS::Person.should_receive(:interpret).with(:name => "Buttle").and_return(buttle)
144
+ a.people = [ { :name => "Tuttle" }, { :name => "Buttle" } ]
145
+ a.people.should == [tuttle, buttle]
146
+ end
147
+ end
148
+
149
+ describe "#last_modified_date=" do
150
+ let(:a) { ATDIS::Application.new }
151
+ it "should do no type casting when it's already a date" do
152
+ a.last_modified_date = DateTime.new(2013,1,1)
153
+ a.last_modified_date.should == DateTime.new(2013,1,1)
154
+ end
155
+
156
+ it "should cast a string to a date when it's a valid date" do
157
+ a.last_modified_date = "2013-01-01"
158
+ a.last_modified_date.should == DateTime.new(2013,1,1)
159
+ end
160
+
161
+ context "not a valid date" do
162
+ before :each do
163
+ a.last_modified_date = "2013/01/01"
164
+ end
165
+ it "should be nil" do
166
+ a.last_modified_date.should be_nil
167
+ end
168
+ it "should keep the original string" do
169
+ a.last_modified_date_before_type_cast.should == "2013/01/01"
170
+ end
171
+ end
172
+ end
173
+
174
+ describe "#lodgement_date=" do
175
+ let(:a) { ATDIS::Application.new }
176
+ it "should do no type casting when it's already a date" do
177
+ a.lodgement_date = DateTime.new(2013,1,1)
178
+ a.lodgement_date.should == DateTime.new(2013,1,1)
179
+ end
180
+
181
+ it "should cast a string to a date when it's a valid date" do
182
+ a.lodgement_date = "2013-01-01"
183
+ a.lodgement_date.should == DateTime.new(2013,1,1)
184
+ end
185
+
186
+ context "not a valid date" do
187
+ before :each do
188
+ a.lodgement_date = "2013/01/01"
189
+ end
190
+ it "should be nil" do
191
+ a.lodgement_date.should be_nil
192
+ end
193
+ it "should keep the original string" do
194
+ a.lodgement_date_before_type_cast.should == "2013/01/01"
195
+ end
196
+ end
197
+ end
198
+
199
+ describe "#more_info_url=" do
200
+ let(:a) { ATDIS::Application.new }
201
+ it "should do no type casting when it's already a URI" do
202
+ a.more_info_url = URI.parse("http://foo.com/bar")
203
+ a.more_info_url.should == URI.parse("http://foo.com/bar")
204
+ end
205
+
206
+ it "should cast a string to a URI when it's a valid url" do
207
+ a.more_info_url = "http://foo.com/bar"
208
+ a.more_info_url.should == URI.parse("http://foo.com/bar")
209
+ end
210
+
211
+ context "not a valid url" do
212
+ before :each do
213
+ a.more_info_url = "This is not a url"
214
+ end
215
+ it "should be nil" do
216
+ a.more_info_url.should be_nil
217
+ end
218
+ it "should keep the original string" do
219
+ a.more_info_url_before_type_cast.should == "This is not a url"
220
+ end
221
+ end
222
+ end
223
+
224
+ describe "#description=" do
225
+ let(:a) { ATDIS::Application.new }
226
+ it "should do not type casting when it's already a String" do
227
+ a.description = "foo"
228
+ a.description.should == "foo"
229
+ end
230
+ context "not a string" do
231
+ before :each do
232
+ a.description = 123
233
+ end
234
+ it "should cast to a string when it's not a string" do
235
+ a.description.should == "123"
236
+ end
237
+ it "should keep the original value" do
238
+ a.description_before_type_cast.should == 123
239
+ end
240
+ end
241
+ end
242
+
243
+ # TODO This should really be a test on the Model base class
244
+ describe ".attributes" do
245
+ it do
246
+ a = ATDIS::Application.new(:dat_id => "DA2013-0381", :description => "New pool plus deck")
247
+ a.attributes.should == {"dat_id" => "DA2013-0381", "description" => "New pool plus deck"}
248
+ end
249
+ end
250
+
251
+ # TODO This should really be a test on the Model base class
252
+ describe "#attribute_names" do
253
+ it do
254
+ ATDIS::Application.attribute_names.sort.should == ["authority", "comments_url", "dat_id", "description",
255
+ "determination_date", "documents", "estimated_cost", "events", "extended", "last_modified_date",
256
+ "location", "lodgement_date", "more_info_url", "notification_end_date", "notification_start_date", "officer",
257
+ "people", "status"]
258
+ end
259
+ end
260
+
261
+ describe "validations" do
262
+ before :each do
263
+ l = double(:valid? => true)
264
+ ATDIS::Location.should_receive(:interpret).with(:address => "123 Fourfivesix Street Neutral Bay NSW 2089").and_return(l)
265
+ end
266
+
267
+ let(:a) { ATDIS::Application.new(
268
+ :dat_id => "DA2013-0381",
269
+ :last_modified_date => DateTime.new(2013,4,20,2,1,7),
270
+ :description => "New pool plus deck",
271
+ :authority => "Example Council Shire Council",
272
+ :lodgement_date => DateTime.new(2013,4,20,2,1,7),
273
+ :determination_date => DateTime.new(2013,6,20),
274
+ :status => "OPEN",
275
+ :more_info_url => URI.parse("http://foo.com/bar"),
276
+ :location => {:address => "123 Fourfivesix Street Neutral Bay NSW 2089"}
277
+ ) }
278
+
279
+ it { a.should be_valid }
280
+
281
+ describe ".location" do
282
+ it "should not be valid if the location is not valid" do
283
+ l = double(:valid? => false)
284
+ ATDIS::Location.should_receive(:interpret).with(:foo => "some location data").and_return(l)
285
+ a.location = {:foo => "some location data"}
286
+ a.should_not be_valid
287
+ end
288
+ end
289
+
290
+ it ".dat_id" do
291
+ a.dat_id = nil
292
+ a.should_not be_valid
293
+ a.errors.messages.should == {:dat_id => ["can't be blank"]}
294
+ end
295
+
296
+ describe ".last_modified_date" do
297
+ it do
298
+ a.last_modified_date = nil
299
+ a.should_not be_valid
300
+ a.errors.messages.should == {:last_modified_date => ["can't be blank"]}
301
+ end
302
+ it do
303
+ a.last_modified_date = "18 January 2013"
304
+ a.should_not be_valid
305
+ a.errors.messages.should == {:last_modified_date => ["is not a valid date"]}
306
+ end
307
+ end
308
+
309
+ describe ".description" do
310
+ it do
311
+ a.description = ""
312
+ a.should_not be_valid
313
+ a.errors.messages.should == {:description => ["can't be blank"]}
314
+ end
315
+ end
316
+
317
+ describe ".authority" do
318
+ it do
319
+ a.authority = nil
320
+ a.should_not be_valid
321
+ a.errors.messages.should == {:authority => ["can't be blank"]}
322
+ end
323
+ end
324
+
325
+ describe ".lodgement_date" do
326
+ it do
327
+ a.lodgement_date = nil
328
+ a.should_not be_valid
329
+ a.errors.messages.should == {:lodgement_date => ["can't be blank"]}
330
+ end
331
+ it do
332
+ a.lodgement_date = "18 January 2013"
333
+ a.should_not be_valid
334
+ a.errors.messages.should == {:lodgement_date => ["is not a valid date"]}
335
+ end
336
+ end
337
+
338
+ describe ".determination_date" do
339
+ it do
340
+ a.determination_date = nil
341
+ a.should_not be_valid
342
+ a.errors.messages.should == {:determination_date => ["can't be blank"]}
343
+ end
344
+ it do
345
+ a.determination_date = "18 January 2013"
346
+ a.should_not be_valid
347
+ a.errors.messages.should == {:determination_date => ["is not a valid date"]}
348
+ end
349
+ end
350
+
351
+ describe ".status" do
352
+ it do
353
+ a.status = nil
354
+ a.should_not be_valid
355
+ a.errors.messages.should == {:status => ["can't be blank"]}
356
+ end
357
+ end
358
+
359
+ describe ".notification_start_date" do
360
+ it do
361
+ a.notification_start_date = DateTime.new(2013,4,20,2,1,7)
362
+ a.should be_valid
363
+ end
364
+ it do
365
+ a.notification_start_date = "18 January 2013"
366
+ a.should_not be_valid
367
+ a.errors.messages.should == {:notification_start_date => ["is not a valid date"]}
368
+ end
369
+ end
370
+
371
+ describe ".notification_end_date" do
372
+ it do
373
+ a.notification_end_date = DateTime.new(2013,5,20,2,1,7)
374
+ a.should be_valid
375
+ end
376
+ it do
377
+ a.notification_end_date = "18 January 2013"
378
+ a.should_not be_valid
379
+ a.errors.messages.should == {:notification_end_date => ["is not a valid date"]}
380
+ end
381
+ end
382
+
383
+ describe ".more_info_url" do
384
+ it do
385
+ a.more_info_url = nil
386
+ a.should_not be_valid
387
+ a.errors.messages.should == {:more_info_url => ["can't be blank"]}
388
+ end
389
+ it do
390
+ a.more_info_url = "This is not a valid url"
391
+ a.should_not be_valid
392
+ a.errors.messages.should == {:more_info_url => ["is not a valid URL"]}
393
+ end
394
+ it do
395
+ a.more_info_url = "foo.com"
396
+ a.should_not be_valid
397
+ a.errors.messages.should == {:more_info_url => ["is not a valid URL"]}
398
+ end
399
+ it do
400
+ a.more_info_url = "httpss://foo.com"
401
+ a.should_not be_valid
402
+ a.errors.messages.should == {:more_info_url => ["is not a valid URL"]}
403
+ end
404
+ end
405
+ end
406
+ end
@@ -0,0 +1,15 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe ATDIS::Document do
4
+ it ".ref" do
5
+ ATDIS::Document.interpret(:ref => "27B/6").ref.should == "27B/6"
6
+ end
7
+
8
+ it ".title" do
9
+ ATDIS::Document.interpret(:title => "Authorisation for Repairs").title.should == "Authorisation for Repairs"
10
+ end
11
+
12
+ it ".document_url" do
13
+ ATDIS::Document.interpret(:document_url => "http://foo.com/bar").document_url.should == URI.parse("http://foo.com/bar")
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe ATDIS::Event do
4
+ it ".id" do
5
+ ATDIS::Event.interpret(:id => "27B/6").id.should == "27B/6"
6
+ end
7
+
8
+ it ".date" do
9
+ ATDIS::Event.interpret(:date => "2013-06-18").date.should == DateTime.new(2013,6,18)
10
+ end
11
+
12
+ it ".description" do
13
+ ATDIS::Event.interpret(:description => "A very fine event").description.should == "A very fine event"
14
+ end
15
+
16
+ it ".event_type" do
17
+ # TODO Is event_type always a string? ATDIS-1.0.3 doesn't say
18
+ ATDIS::Event.interpret(:event_type => "approval").event_type.should == "approval"
19
+ end
20
+
21
+ it ".status" do
22
+ # TODO Is status always a string? ATDIS-1.0.3 doesn't say
23
+ ATDIS::Event.interpret(:status => "approved").status.should == "approved"
24
+ end
25
+ end
@@ -0,0 +1,40 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe ATDIS::Feed do
4
+ let (:base_url_string) { "http://www.council.nsw.gov.au" }
5
+ let (:base_url) { URI.parse(base_url_string) }
6
+
7
+ context "base_url passed as string" do
8
+ let(:feed) { ATDIS::Feed.new(base_url_string) }
9
+
10
+ describe "#base_url" do
11
+ it { feed.base_url.should == base_url }
12
+ end
13
+
14
+ describe "#applications" do
15
+ it do
16
+ applications_results = double
17
+ ATDIS::Page.should_receive(:read_url).with(URI.parse("http://www.council.nsw.gov.au/atdis/1.0/applications.json")).and_return(applications_results)
18
+ feed.applications.should == applications_results
19
+ end
20
+ end
21
+ end
22
+
23
+ context "base_url passed as url" do
24
+ let(:feed) { ATDIS::Feed.new(base_url) }
25
+
26
+ describe "#base_url" do
27
+ it { feed.base_url.should == base_url }
28
+ end
29
+ end
30
+
31
+ context "request for page 2" do
32
+ let(:feed) { ATDIS::Feed.new(base_url_string)}
33
+
34
+ it "#applications" do
35
+ applications_results = double
36
+ ATDIS::Page.should_receive(:read_url).with(URI.parse("http://www.council.nsw.gov.au/atdis/1.0/applications.json?page=2")).and_return(applications_results)
37
+ feed.applications(2).should == applications_results
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,97 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe ATDIS::Location do
4
+ describe "validation" do
5
+ context "valid location" do
6
+ let(:l) { ATDIS::Location.new(
7
+ :address => "123 Fourfivesix Street Neutral Bay NSW 2089",
8
+ :lot => "10",
9
+ :section => "ABC",
10
+ :dpsp_id => "DP2013-0381",
11
+ :geometry => {
12
+ :type => "Point",
13
+ :coordinates => [100.0, 0.0]
14
+ }
15
+ )}
16
+
17
+ it { l.should be_valid }
18
+
19
+ it "address" do
20
+ l.address = ""
21
+ l.should_not be_valid
22
+ l.errors.messages.should == {:address => ["can't be blank"]}
23
+ end
24
+
25
+ it "geometry" do
26
+ l.geometry = {:type => "Point"}
27
+ l.geometry.should be_nil
28
+ l.should_not be_valid
29
+ end
30
+ end
31
+ end
32
+
33
+ describe ".interpret" do
34
+ it "should interpret a parsed json block of location data" do
35
+ l = ATDIS::Location.interpret(
36
+ :address => "123 Fourfivesix Street Neutral Bay NSW 2089",
37
+ :land_title_ref => {
38
+ :lot => "10",
39
+ :section => "ABC",
40
+ :dpsp_id => "DP2013-0381"
41
+ })
42
+
43
+ l.address.should == "123 Fourfivesix Street Neutral Bay NSW 2089"
44
+ l.lot.should == "10"
45
+ l.section.should == "ABC"
46
+ l.dpsp_id.should == "DP2013-0381"
47
+ end
48
+
49
+ it "should gracefully handle the land_title_ref block being missing" do
50
+ l = ATDIS::Location.interpret(:address => "123 Fourfivesix Street Neutral Bay NSW 2089")
51
+
52
+ l.address.should == "123 Fourfivesix Street Neutral Bay NSW 2089"
53
+ l.lot.should be_nil
54
+ l.section.should be_nil
55
+ l.dpsp_id.should be_nil
56
+ end
57
+
58
+ it "should pass on the responsibility for parsing the geometry section" do
59
+ # TODO Not 100% clear from section 4.3.3 of ATDIS-1.0.3 if this is the correct indentation
60
+ l = ATDIS::Location.interpret(
61
+ :geometry => {
62
+ :type => "Point",
63
+ :coordinates => [100.0, 0.0]
64
+ }
65
+ )
66
+ # TODO Check that the returned geometry is a point
67
+ l.geometry.x.should == 100
68
+ l.geometry.y.should == 0
69
+ end
70
+
71
+ it "should interpret a polygon in the geometry section" do
72
+ # TODO Not 100% clear from section 4.3.3 of ATDIS-1.0.3 if this is the correct indentation
73
+ l = ATDIS::Location.interpret(
74
+ :geometry => {
75
+ :type => "Polygon",
76
+ :coordinates => [
77
+ [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0],
78
+ [100.0, 1.0], [100.0, 0.0] ]
79
+ ]
80
+ }
81
+ )
82
+ # TODO Check that the returned geometry is a polygon
83
+ l.geometry.interior_rings.should be_empty
84
+ l.geometry.exterior_ring.points.count.should == 5
85
+ l.geometry.exterior_ring.points[0].x.should == 100
86
+ l.geometry.exterior_ring.points[0].y.should == 0
87
+ l.geometry.exterior_ring.points[1].x.should == 101
88
+ l.geometry.exterior_ring.points[1].y.should == 0
89
+ l.geometry.exterior_ring.points[2].x.should == 101
90
+ l.geometry.exterior_ring.points[2].y.should == 1
91
+ l.geometry.exterior_ring.points[3].x.should == 100
92
+ l.geometry.exterior_ring.points[3].y.should == 1
93
+ l.geometry.exterior_ring.points[4].x.should == 100
94
+ l.geometry.exterior_ring.points[4].y.should == 0
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,39 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe ATDIS::Model do
4
+ describe ".cast" do
5
+ it {ATDIS::Model.cast("2013-04-20T02:01:07Z", DateTime).should == DateTime.new(2013,4,20,2,1,7)}
6
+ it {ATDIS::Model.cast("2013-04-20", DateTime).should == DateTime.new(2013,4,20)}
7
+ it {ATDIS::Model.cast("2013-04-20T02:01:07+05:00", DateTime).should == DateTime.new(2013,4,20,2,1,7,"+5")}
8
+ it {ATDIS::Model.cast("2013-04-20T02:01:07-05:00", DateTime).should == DateTime.new(2013,4,20,2,1,7,"-5")}
9
+ it {ATDIS::Model.cast("2013-04", DateTime).should be_nil}
10
+ it {ATDIS::Model.cast("18 September 2013", DateTime).should be_nil}
11
+ it {ATDIS::Model.cast(DateTime.new(2013,4,20,2,1,7), DateTime).should == DateTime.new(2013,4,20,2,1,7)}
12
+
13
+ it "should cast arrays by casting each member" do
14
+ ATDIS::Model.cast([1, 2, 3], String).should == ["1", "2", "3"]
15
+ end
16
+
17
+ # This casting allows nil values
18
+ describe "casting Fixnum" do
19
+ it { ATDIS::Model.cast("3", Fixnum).should == 3}
20
+ it { ATDIS::Model.cast("4.0", Fixnum).should == 4}
21
+ it { ATDIS::Model.cast(5, Fixnum).should == 5}
22
+ it { ATDIS::Model.cast(0, Fixnum).should == 0}
23
+ it { ATDIS::Model.cast(nil, Fixnum).should be_nil}
24
+ end
25
+ end
26
+
27
+ describe ".map_fields" do
28
+ it do
29
+ ATDIS::Model.map_fields({:foo => :bar, :a => :b}, {:foo => 2, :a => 3, :d => 4}).should ==
30
+ {:bar => 2, :b => 3, :json_left_overs => {:d => 4}}
31
+ end
32
+
33
+ it do
34
+ ATDIS::Model.map_fields({:foo => :bar, :a => :b, :info => {:foo => :bar2, :a => :b2}},
35
+ {:foo => 2, :a => 3, :d => 4, :info => {:foo => 2, :a => 3, :d => 4}}).should ==
36
+ {:bar => 2, :b => 3, :bar2 => 2, :b2 => 3, :json_left_overs => {:d => 4, :info => {:d => 4}}}
37
+ end
38
+ end
39
+ end