atdis 0.3.11 → 0.5.0

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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +46 -0
  3. data/.ruby-version +1 -1
  4. data/.travis.yml +0 -4
  5. data/Gemfile +9 -7
  6. data/Guardfile +4 -3
  7. data/Rakefile +4 -2
  8. data/atdis.gemspec +10 -5
  9. data/lib/atdis.rb +2 -0
  10. data/lib/atdis/feed.rb +32 -24
  11. data/lib/atdis/model.rb +108 -95
  12. data/lib/atdis/models/address.rb +10 -4
  13. data/lib/atdis/models/application.rb +12 -9
  14. data/lib/atdis/models/authority.rb +11 -6
  15. data/lib/atdis/models/document.rb +8 -6
  16. data/lib/atdis/models/event.rb +10 -8
  17. data/lib/atdis/models/info.rb +73 -49
  18. data/lib/atdis/models/land_title_ref.rb +15 -7
  19. data/lib/atdis/models/location.rb +9 -7
  20. data/lib/atdis/models/page.rb +36 -21
  21. data/lib/atdis/models/pagination.rb +91 -32
  22. data/lib/atdis/models/person.rb +7 -5
  23. data/lib/atdis/models/reference.rb +7 -5
  24. data/lib/atdis/models/response.rb +5 -3
  25. data/lib/atdis/models/torrens_title.rb +9 -7
  26. data/lib/atdis/separated_url.rb +17 -15
  27. data/lib/atdis/validators.rb +46 -39
  28. data/lib/atdis/version.rb +3 -1
  29. data/spec/atdis/feed_spec.rb +128 -34
  30. data/spec/atdis/model_spec.rb +124 -51
  31. data/spec/atdis/models/address_spec.rb +18 -9
  32. data/spec/atdis/models/application_spec.rb +222 -155
  33. data/spec/atdis/models/authority_spec.rb +45 -15
  34. data/spec/atdis/models/document_spec.rb +10 -4
  35. data/spec/atdis/models/event_spec.rb +23 -11
  36. data/spec/atdis/models/info_spec.rb +197 -113
  37. data/spec/atdis/models/land_title_ref_spec.rb +32 -16
  38. data/spec/atdis/models/location_spec.rb +75 -60
  39. data/spec/atdis/models/page_spec.rb +244 -135
  40. data/spec/atdis/models/pagination_spec.rb +177 -77
  41. data/spec/atdis/models/person_spec.rb +8 -4
  42. data/spec/atdis/models/reference_spec.rb +29 -16
  43. data/spec/atdis/models/response_spec.rb +2 -1
  44. data/spec/atdis/models/torrens_title_spec.rb +24 -18
  45. data/spec/atdis/separated_url_spec.rb +14 -15
  46. data/spec/spec_helper.rb +14 -10
  47. metadata +62 -33
@@ -1,110 +1,204 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
4
 
3
5
  describe ATDIS::Feed do
4
- let(:feed) { ATDIS::Feed.new("http://www.council.nsw.gov.au/atdis/1.0") }
6
+ let(:feed) { ATDIS::Feed.new("http://www.council.nsw.gov.au/atdis/1.0", "UTC") }
5
7
  let(:page) { double }
6
8
 
7
9
  it "should return all the applications" do
8
- expect(ATDIS::Models::Page).to receive(:read_url).with("http://www.council.nsw.gov.au/atdis/1.0/applications.json").and_return(page)
9
- feed.applications.should == page
10
+ expect(ATDIS::Models::Page).to receive(:read_url).with(
11
+ "http://www.council.nsw.gov.au/atdis/1.0/applications.json",
12
+ "UTC",
13
+ false
14
+ ).and_return(page)
15
+ expect(feed.applications).to eq page
10
16
  end
11
17
 
12
18
  it "should return all the applications" do
13
- feed.applications_url.should == "http://www.council.nsw.gov.au/atdis/1.0/applications.json"
19
+ expect(feed.applications_url).to eq "http://www.council.nsw.gov.au/atdis/1.0/applications.json"
14
20
  end
15
21
 
16
22
  describe "should restrict search by postcode" do
17
23
  it "single postcode" do
18
- feed.applications_url(postcode: 2000).should == "http://www.council.nsw.gov.au/atdis/1.0/applications.json?postcode=2000"
24
+ expect(feed.applications_url(postcode: 2000)).to eq "http://www.council.nsw.gov.au/atdis/1.0/applications.json?postcode=2000"
19
25
  end
20
26
 
21
27
  it "multiple postcodes in an array" do
22
- feed.applications_url(postcode: [2000,2001]).should == "http://www.council.nsw.gov.au/atdis/1.0/applications.json?postcode=2000,2001"
28
+ expect(feed.applications_url(postcode: [2000, 2001])).to eq "http://www.council.nsw.gov.au/atdis/1.0/applications.json?postcode=2000,2001"
23
29
  end
24
30
 
25
31
  it "multiple postcodes as a string" do
26
- feed.applications_url(postcode: "2000,2001").should == "http://www.council.nsw.gov.au/atdis/1.0/applications.json?postcode=2000,2001"
32
+ expect(feed.applications_url(postcode: "2000,2001")).to eq "http://www.council.nsw.gov.au/atdis/1.0/applications.json?postcode=2000,2001"
27
33
  end
28
34
  end
29
35
 
30
36
  describe "search by lodgement date" do
31
37
  it "just a lodgement start date as a date" do
32
- feed.applications_url(lodgement_date_start: Date.new(2001,2,1)).should == "http://www.council.nsw.gov.au/atdis/1.0/applications.json?lodgement_date_start=2001-02-01"
38
+ expect(feed.applications_url(lodgement_date_start: Date.new(2001, 2, 1))).to eq "http://www.council.nsw.gov.au/atdis/1.0/applications.json?lodgement_date_start=2001-02-01"
33
39
  end
34
40
 
35
41
  it "just a lodgement start date as a string" do
36
- feed.applications_url(lodgement_date_start: "2011-02-04").should == "http://www.council.nsw.gov.au/atdis/1.0/applications.json?lodgement_date_start=2011-02-04"
42
+ expect(feed.applications_url(lodgement_date_start: "2011-02-04")).to eq "http://www.council.nsw.gov.au/atdis/1.0/applications.json?lodgement_date_start=2011-02-04"
37
43
  end
38
44
 
39
45
  it "a lodgement start date and end date" do
40
- feed.applications_url(lodgement_date_start: Date.new(2001,2,1), lodgement_date_end: Date.new(2001,3,1)).should == "http://www.council.nsw.gov.au/atdis/1.0/applications.json?lodgement_date_end=2001-03-01&lodgement_date_start=2001-02-01"
46
+ expect(
47
+ feed.applications_url(
48
+ lodgement_date_start: Date.new(2001, 2, 1),
49
+ lodgement_date_end: Date.new(2001, 3, 1)
50
+ )
51
+ ).to eq(
52
+ "http://www.council.nsw.gov.au/atdis/1.0/applications.json?lodgement_date_end=2001-03-01&lodgement_date_start=2001-02-01"
53
+ )
41
54
  end
42
55
  end
43
56
 
44
57
  describe "search by last modified date" do
45
58
  it "just a last modified start date" do
46
- feed.applications_url(last_modified_date_start: Date.new(2001,2,1)).should == "http://www.council.nsw.gov.au/atdis/1.0/applications.json?last_modified_date_start=2001-02-01"
59
+ expect(feed.applications_url(last_modified_date_start: Date.new(2001, 2, 1))).to eq "http://www.council.nsw.gov.au/atdis/1.0/applications.json?last_modified_date_start=2001-02-01"
47
60
  end
48
61
 
49
62
  it "a last modified start date and end date" do
50
- feed.applications_url(last_modified_date_start: Date.new(2001,2,1), last_modified_date_end: Date.new(2001,3,1)).should == "http://www.council.nsw.gov.au/atdis/1.0/applications.json?last_modified_date_end=2001-03-01&last_modified_date_start=2001-02-01"
63
+ expect(
64
+ feed.applications_url(
65
+ last_modified_date_start: Date.new(2001, 2, 1),
66
+ last_modified_date_end: Date.new(2001, 3, 1)
67
+ )
68
+ ).to eq(
69
+ "http://www.council.nsw.gov.au/atdis/1.0/applications.json?last_modified_date_end=2001-03-01&last_modified_date_start=2001-02-01"
70
+ )
51
71
  end
52
72
  end
53
73
 
54
74
  describe "search by suburb" do
55
75
  it do
56
- feed.applications_url(suburb: ["willow tree", "foo", "bar"]).should == "http://www.council.nsw.gov.au/atdis/1.0/applications.json?suburb=willow+tree,foo,bar"
76
+ expect(feed.applications_url(suburb: ["willow tree", "foo", "bar"])).to eq "http://www.council.nsw.gov.au/atdis/1.0/applications.json?suburb=willow+tree,foo,bar"
57
77
  end
58
78
  end
59
79
 
60
80
  it "jump straight to the second page" do
61
- feed.applications_url(page: 2).should == "http://www.council.nsw.gov.au/atdis/1.0/applications.json?page=2"
81
+ expect(feed.applications_url(page: 2)).to eq "http://www.council.nsw.gov.au/atdis/1.0/applications.json?page=2"
62
82
  end
63
83
 
64
84
  it "passing an invalid option" do
65
- expect {feed.applications_url(foo: 1)}.to raise_error "Unexpected options used: foo"
85
+ expect { feed.applications_url(foo: 1) }.to raise_error "Unexpected options used: foo"
66
86
  end
67
87
 
68
88
  describe ".base_url_from_url" do
69
- it { ATDIS::Feed.base_url_from_url("http://www.council.nsw.gov.au/atdis/1.0/applications.json?postcode=2000").should == "http://www.council.nsw.gov.au/atdis/1.0" }
70
- it { ATDIS::Feed.base_url_from_url("http://www.foo.nsw.gov.au/prefix/atdis/1.0/applications.json?postcode=2000#bar").should == "http://www.foo.nsw.gov.au/prefix/atdis/1.0" }
89
+ it do
90
+ expect(
91
+ ATDIS::Feed.base_url_from_url(
92
+ "http://www.council.nsw.gov.au/atdis/1.0/applications.json?postcode=2000"
93
+ )
94
+ ).to eq "http://www.council.nsw.gov.au/atdis/1.0"
95
+ end
96
+ it do
97
+ expect(
98
+ ATDIS::Feed.base_url_from_url(
99
+ "http://www.foo.nsw.gov.au/prefix/atdis/1.0/applications.json?postcode=2000#bar"
100
+ )
101
+ ).to eq "http://www.foo.nsw.gov.au/prefix/atdis/1.0"
102
+ end
71
103
  it "should assume that any query parameters that are not recognised are part of the base_url" do
72
- ATDIS::Feed.base_url_from_url("http://www.foo.nsw.gov.au/prefix/atdis/1.0/applications.json?postcode=2000&foo=bar").should == "http://www.foo.nsw.gov.au/prefix/atdis/1.0?foo=bar"
104
+ expect(
105
+ ATDIS::Feed.base_url_from_url(
106
+ "http://www.foo.nsw.gov.au/prefix/atdis/1.0/applications.json?postcode=2000&foo=bar"
107
+ )
108
+ ).to eq "http://www.foo.nsw.gov.au/prefix/atdis/1.0?foo=bar"
73
109
  end
74
110
  end
75
111
 
76
112
  describe ".options_from_url" do
77
- it { ATDIS::Feed.options_from_url("http://www.council.nsw.gov.au/atdis/1.0/applications.json").should == {} }
78
- it { ATDIS::Feed.options_from_url("http://www.council.nsw.gov.au/atdis/1.0/applications.json?page=2").should == {page: 2} }
79
- it { ATDIS::Feed.options_from_url("http://www.council.nsw.gov.au/atdis/1.0/applications.json?postcode=2000,2001").should == {postcode: "2000,2001"} }
80
- it { ATDIS::Feed.options_from_url("http://www.council.nsw.gov.au/atdis/1.0/applications.json?lodgement_date_end=2001-03-01&lodgement_date_start=2001-02-01").should ==
81
- {lodgement_date_start: Date.new(2001,2,1), lodgement_date_end: Date.new(2001,3,1)} }
82
- it { ATDIS::Feed.options_from_url("http://www.council.nsw.gov.au/atdis/1.0/applications.json?last_modified_date_end=2001-03-01&last_modified_date_start=2001-02-01").should ==
83
- {last_modified_date_start: Date.new(2001,2,1), last_modified_date_end: Date.new(2001,3,1)} }
113
+ it do
114
+ expect(
115
+ ATDIS::Feed.options_from_url("http://www.council.nsw.gov.au/atdis/1.0/applications.json")
116
+ ).to eq({})
117
+ end
118
+ it do
119
+ expect(
120
+ ATDIS::Feed.options_from_url(
121
+ "http://www.council.nsw.gov.au/atdis/1.0/applications.json?page=2"
122
+ )
123
+ ).to eq(page: 2)
124
+ end
125
+ it do
126
+ expect(
127
+ ATDIS::Feed.options_from_url(
128
+ "http://www.council.nsw.gov.au/atdis/1.0/applications.json?postcode=2000,2001"
129
+ )
130
+ ).to eq(postcode: "2000,2001")
131
+ end
132
+ it do
133
+ expect(
134
+ ATDIS::Feed.options_from_url(
135
+ "http://www.council.nsw.gov.au/atdis/1.0/applications.json?lodgement_date_end=2001-03-01&lodgement_date_start=2001-02-01"
136
+ )
137
+ ).to eq(
138
+ lodgement_date_start: Date.new(2001, 2, 1), lodgement_date_end: Date.new(2001, 3, 1)
139
+ )
140
+ end
141
+ it do
142
+ expect(
143
+ ATDIS::Feed.options_from_url(
144
+ "http://www.council.nsw.gov.au/atdis/1.0/applications.json?last_modified_date_end=2001-03-01&last_modified_date_start=2001-02-01"
145
+ )
146
+ ).to eq(
147
+ last_modified_date_start: Date.new(2001, 2, 1), last_modified_date_end: Date.new(2001, 3, 1)
148
+ )
149
+ end
84
150
  it "should assume that any query parameters that are not recognised are part of the base_url" do
85
- ATDIS::Feed.options_from_url("http://www.foo.nsw.gov.au/prefix/atdis/1.0/applications.json?postcode=2000&foo=bar").should == {postcode: "2000"}
151
+ expect(
152
+ ATDIS::Feed.options_from_url(
153
+ "http://www.foo.nsw.gov.au/prefix/atdis/1.0/applications.json?postcode=2000&foo=bar"
154
+ )
155
+ ).to eq(postcode: "2000")
86
156
  end
87
157
 
88
158
  it do
89
- ATDIS::Feed.options_from_url("http://www.council.nsw.gov.au/atdis/1.0/applications.json?suburb=willow+tree,foo,bar").should == {suburb: "willow tree,foo,bar"}
159
+ expect(
160
+ ATDIS::Feed.options_from_url(
161
+ "http://www.council.nsw.gov.au/atdis/1.0/applications.json?suburb=willow+tree,foo,bar"
162
+ )
163
+ ).to eq(suburb: "willow tree,foo,bar")
90
164
  end
91
165
 
92
166
  it do
93
- ATDIS::Feed.options_from_url("http://www.council.nsw.gov.au/atdis/1.0/applications.json?suburb=&postcode=2000").should == {postcode: "2000", suburb: nil}
167
+ expect(
168
+ ATDIS::Feed.options_from_url(
169
+ "http://www.council.nsw.gov.au/atdis/1.0/applications.json?suburb=&postcode=2000"
170
+ )
171
+ ).to eq(postcode: "2000", suburb: nil)
94
172
  end
95
173
  end
96
174
 
97
175
  describe "#application_url" do
98
- it { feed.application_url("27B6").should == "http://www.council.nsw.gov.au/atdis/1.0/27B6.json" }
99
- it { feed.application_url("27B stroke 6").should == "http://www.council.nsw.gov.au/atdis/1.0/27B+stroke+6.json" }
100
- it { feed.application_url("27B/6").should == "http://www.council.nsw.gov.au/atdis/1.0/27B%2F6.json" }
176
+ it do
177
+ expect(feed.application_url("27B6")).to eq(
178
+ "http://www.council.nsw.gov.au/atdis/1.0/27B6.json"
179
+ )
180
+ end
181
+ it do
182
+ expect(feed.application_url("27B stroke 6")).to eq(
183
+ "http://www.council.nsw.gov.au/atdis/1.0/27B+stroke+6.json"
184
+ )
185
+ end
186
+ it do
187
+ expect(feed.application_url("27B/6")).to eq(
188
+ "http://www.council.nsw.gov.au/atdis/1.0/27B%2F6.json"
189
+ )
190
+ end
101
191
  end
102
192
 
103
193
  describe "#application" do
104
194
  it {
105
195
  application = double
106
- expect(ATDIS::Models::Application).to receive(:read_url).with("http://www.council.nsw.gov.au/atdis/1.0/27B%2F6.json").and_return(application)
107
- feed.application("27B/6").should == application
196
+ expect(ATDIS::Models::Application).to receive(:read_url).with(
197
+ "http://www.council.nsw.gov.au/atdis/1.0/27B%2F6.json",
198
+ "UTC",
199
+ false
200
+ ).and_return(application)
201
+ expect(feed.application("27B/6")).to eq application
108
202
  }
109
203
  end
110
204
  end
@@ -1,119 +1,192 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
4
 
3
5
  class ModelB < ATDIS::Model
4
- set_field_mappings ({
6
+ field_mappings(
5
7
  bar: [String]
6
- })
8
+ )
7
9
  end
8
10
 
9
11
  class ModelA < ATDIS::Model
10
- set_field_mappings ({
11
- bar: [String],
12
+ field_mappings(
13
+ bar: [String],
12
14
  hello: [ModelB]
13
- })
15
+ )
14
16
  end
15
17
 
16
18
  describe ATDIS::Model do
17
19
  describe ".attributes" do
18
20
  it do
19
- a = ModelA.new(bar: "foo")
20
- a.attributes.should == {"bar" => "foo"}
21
+ a = ModelA.new({ bar: "foo" }, "UTC")
22
+ expect(a.attributes).to eq("bar" => "foo")
21
23
  end
22
24
  end
23
25
 
24
26
  describe "#json_errors" do
25
27
  it "should return the json attribute with the errors" do
26
- a = ModelA.interpret(bar: "Hello")
28
+ a = ModelA.interpret({ bar: "Hello" }, "UTC")
27
29
  a.errors.add(:bar, ATDIS::ErrorMessage["can not be so friendly", "4.5"])
28
30
  a.errors.add(:bar, ATDIS::ErrorMessage["and something else", "4.6"])
29
- a.json_errors.should == [[{bar: "Hello"}, [
30
- ATDIS::ErrorMessage["bar can not be so friendly", "4.5"],
31
- ATDIS::ErrorMessage["bar and something else", "4.6"]]]]
31
+ expect(a.json_errors).to eq(
32
+ [[
33
+ { bar: "Hello" },
34
+ [
35
+ ATDIS::ErrorMessage["bar can not be so friendly", "4.5"],
36
+ ATDIS::ErrorMessage["bar and something else", "4.6"]
37
+ ]
38
+ ]]
39
+ )
32
40
  end
33
41
 
34
42
  it "should include the errors from child objects" do
35
- a = ModelA.interpret(hello: {bar: "Kat"})
43
+ a = ModelA.interpret({ hello: { bar: "Kat" } }, "UTC")
36
44
  a.hello.errors.add(:bar, ATDIS::ErrorMessage["can't be a name", "2.3"])
37
- a.hello.json_errors.should == [[{bar: "Kat"}, [ATDIS::ErrorMessage["bar can't be a name", "2.3"]]]]
38
- a.json_errors.should == [[{hello: {bar: "Kat"}}, [ATDIS::ErrorMessage["bar can't be a name", "2.3"]]]]
45
+ expect(a.hello.json_errors).to eq(
46
+ [[{ bar: "Kat" }, [ATDIS::ErrorMessage["bar can't be a name", "2.3"]]]]
47
+ )
48
+ expect(a.json_errors).to eq(
49
+ [[{ hello: { bar: "Kat" } }, [ATDIS::ErrorMessage["bar can't be a name", "2.3"]]]]
50
+ )
39
51
  end
40
52
 
41
53
  it "should include the errors from only the first child object in an array" do
42
- a = ModelA.interpret(hello: [{bar: "Kat"}, {bar: "Mat"}])
43
- a.hello[0].bar.should == "Kat"
44
- a.hello[1].bar.should == "Mat"
45
- a.json_errors.should == []
54
+ a = ModelA.interpret({ hello: [{ bar: "Kat" }, { bar: "Mat" }] }, "UTC")
55
+ expect(a.hello[0].bar).to eq "Kat"
56
+ expect(a.hello[1].bar).to eq "Mat"
57
+ expect(a.json_errors).to eq []
46
58
  a.hello[0].errors.add(:bar, ATDIS::ErrorMessage["can't be a name", "1.2"])
47
59
  a.hello[1].errors.add(:bar, ATDIS::ErrorMessage["can't be a name", "1.2"])
48
- a.json_errors.should == [[{hello: [{bar: "Kat"}]}, [ATDIS::ErrorMessage["bar can't be a name", "1.2"]]]]
60
+ expect(a.json_errors).to eq(
61
+ [[{ hello: [{ bar: "Kat" }] }, [ATDIS::ErrorMessage["bar can't be a name", "1.2"]]]]
62
+ )
49
63
  end
50
64
 
51
65
  it "should show json parsing errors" do
52
- a = ModelA.interpret(invalid: {parameter: "foo"})
53
- a.should_not be_valid
54
- a.json_errors.should == [[nil, [ATDIS::ErrorMessage['Unexpected parameters in json data: {"invalid":{"parameter":"foo"}}', "4"]]]]
66
+ a = ModelA.interpret({ invalid: { parameter: "foo" } }, "UTC")
67
+ expect(a).to_not be_valid
68
+ expect(a.json_errors).to eq(
69
+ [[
70
+ nil,
71
+ [
72
+ ATDIS::ErrorMessage[
73
+ 'Unexpected parameters in json data: {"invalid":{"parameter":"foo"}}',
74
+ "4"
75
+ ]
76
+ ]
77
+ ]]
78
+ )
55
79
  end
56
80
 
57
81
  it "should json errors even if value is nil" do
58
- b = ModelB.new
82
+ b = ModelB.new({}, "UTC")
59
83
  b.errors.add(:bar, ATDIS::ErrorMessage.new("can't be nil", "1.2"))
60
- b.json_errors.should == [[{bar: nil}, [ATDIS::ErrorMessage.new("bar can't be nil", "1.2")]]]
84
+ expect(b.json_errors).to eq(
85
+ [[{ bar: nil }, [ATDIS::ErrorMessage.new("bar can't be nil", "1.2")]]]
86
+ )
61
87
  end
62
88
  end
63
89
 
64
90
  describe ".cast" do
65
- it {ATDIS::Model.cast("2013-04-20T02:01:07Z", DateTime).should == DateTime.new(2013,4,20,2,1,7)}
66
- it {ATDIS::Model.cast("2013-04-20", DateTime).should == DateTime.new(2013,4,20)}
67
- it {ATDIS::Model.cast("2013-04-20T02:01:07+05:00", DateTime).should == DateTime.new(2013,4,20,2,1,7,"+5")}
68
- it {ATDIS::Model.cast("2013-04-20T02:01:07-05:00", DateTime).should == DateTime.new(2013,4,20,2,1,7,"-5")}
69
- it {ATDIS::Model.cast("2013-04", DateTime).should be_nil}
70
- it {ATDIS::Model.cast("18 September 2013", DateTime).should be_nil}
71
- it {ATDIS::Model.cast(DateTime.new(2013,4,20,2,1,7), DateTime).should == DateTime.new(2013,4,20,2,1,7)}
91
+ describe "DateTime" do
92
+ describe "timezone given in string" do
93
+ context "in default timezone" do
94
+ let(:value) { ATDIS::Model.cast("2013-04-20T02:01:07Z", DateTime, "UTC") }
95
+ it { expect(value).to eq(DateTime.new(2013, 4, 20, 2, 1, 7, 0)) }
96
+ it { expect(value.zone).to eq "+00:00" }
97
+ end
98
+
99
+ context "in Sydney timezone" do
100
+ let(:value) { ATDIS::Model.cast("2013-04-20T02:01:07Z", DateTime, "Sydney") }
101
+ it { expect(value).to eq(DateTime.new(2013, 4, 20, 2, 1, 7, 0)) }
102
+ it { expect(value.zone).to eq "+10:00" }
103
+ end
104
+
105
+ it do
106
+ expect(
107
+ ATDIS::Model.cast("2013-04-20T02:01:07+05:00", DateTime, "UTC")
108
+ ).to eq(DateTime.new(2013, 4, 20, 2, 1, 7, "+5"))
109
+ end
110
+
111
+ it do
112
+ expect(
113
+ ATDIS::Model.cast("2013-04-20T02:01:07-05:00", DateTime, "UTC")
114
+ ).to eq(DateTime.new(2013, 4, 20, 2, 1, 7, "-5"))
115
+ end
116
+ end
117
+
118
+ describe "timezone not given in string" do
119
+ context "in default timezone" do
120
+ let(:value) { ATDIS::Model.cast("2013-04-20", DateTime, "UTC") }
121
+ it { expect(value).to eq(DateTime.new(2013, 4, 20, 0, 0, 0, 0)) }
122
+ it { expect(value.zone).to eq "+00:00" }
123
+ end
124
+
125
+ context "in Sydney timezone" do
126
+ let(:value) { ATDIS::Model.cast("2013-04-20", DateTime, "Sydney") }
127
+ it { expect(value).to eq(DateTime.new(2013, 4, 20, 0, 0, 0, "+10")) }
128
+ it { expect(value.zone).to eq "+10:00" }
129
+ end
130
+ end
131
+
132
+ it do
133
+ expect(ATDIS::Model.cast("2013-04", DateTime, "UTC")).to be_nil
134
+ end
135
+
136
+ it do
137
+ expect(ATDIS::Model.cast("18 September 2013", DateTime, "UTC")).to be_nil
138
+ end
139
+
140
+ it do
141
+ expect(
142
+ ATDIS::Model.cast(DateTime.new(2013, 4, 20, 2, 1, 7, 0), DateTime, "UTC")
143
+ ).to eq(DateTime.new(2013, 4, 20, 2, 1, 7, 0))
144
+ end
145
+ end
72
146
 
73
147
  it "should cast arrays by casting each member" do
74
- ATDIS::Model.cast([1, 2, 3], String).should == ["1", "2", "3"]
148
+ expect(ATDIS::Model.cast([1, 2, 3], String, "UTC")).to eq %w[1 2 3]
75
149
  end
76
150
 
77
151
  # This casting allows nil values
78
- describe "casting Fixnum" do
79
- it { ATDIS::Model.cast("3", Fixnum).should == 3}
80
- it { ATDIS::Model.cast("4.0", Fixnum).should == 4}
81
- it { ATDIS::Model.cast(5, Fixnum).should == 5}
82
- it { ATDIS::Model.cast(0, Fixnum).should == 0}
83
- it { ATDIS::Model.cast(nil, Fixnum).should be_nil}
152
+ describe "casting Integer" do
153
+ it { expect(ATDIS::Model.cast("3", Integer, "UTC")).to eq 3 }
154
+ it { expect(ATDIS::Model.cast("4.0", Integer, "UTC")).to eq 4 }
155
+ it { expect(ATDIS::Model.cast(5, Integer, "UTC")).to eq 5 }
156
+ it { expect(ATDIS::Model.cast(0, Integer, "UTC")).to eq 0 }
157
+ it { expect(ATDIS::Model.cast(nil, Integer, "UTC")).to be_nil }
84
158
  end
85
159
  end
86
160
 
87
161
  describe ".attribute_keys" do
88
162
  it do
89
- ATDIS::Model.attribute_types = {foo: String, a: Fixnum, info: String}
90
- ATDIS::Model.attribute_keys.should == [:foo, :a, :info]
163
+ ATDIS::Model.attribute_types = { foo: String, a: Integer, info: String }
164
+ expect(ATDIS::Model.attribute_keys).to eq %i[foo a info]
91
165
  end
92
166
  end
93
167
 
94
168
  describe ".partition_by_used" do
95
169
  it do
96
- ATDIS::Model.stub(:attribute_keys).and_return([:foo])
97
- ATDIS::Model.partition_by_used({foo: 2}).should == [
98
- {foo: 2}, {}
170
+ allow(ATDIS::Model).to receive(:attribute_keys).and_return([:foo])
171
+ expect(ATDIS::Model.partition_by_used(foo: 2)).to eq [
172
+ { foo: 2 }, {}
99
173
  ]
100
174
  end
101
175
 
102
176
  it do
103
- ATDIS::Model.stub(:attribute_keys).and_return([:foo, :a])
104
- ATDIS::Model.partition_by_used({foo: 2, a: 3, d: 4}).should == [
105
- {foo: 2, a: 3},
106
- {d: 4}
177
+ allow(ATDIS::Model).to receive(:attribute_keys).and_return(%i[foo a])
178
+ expect(ATDIS::Model.partition_by_used(foo: 2, a: 3, d: 4)).to eq [
179
+ { foo: 2, a: 3 },
180
+ { d: 4 }
107
181
  ]
108
182
  end
109
183
 
110
184
  it "something that isn't a hash will never get used" do
111
- ATDIS::Model.stub(:attribute_keys).and_return([:foo, :a])
112
- ATDIS::Model.partition_by_used("hello").should == [
185
+ allow(ATDIS::Model).to receive(:attribute_keys).and_return(%i[foo a])
186
+ expect(ATDIS::Model.partition_by_used("hello")).to eq [
113
187
  {},
114
188
  "hello"
115
189
  ]
116
-
117
190
  end
118
191
  end
119
192
  end