atdis 0.3.13 → 0.4.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.
- checksums.yaml +4 -4
- data/.rubocop.yml +46 -0
- data/.ruby-version +1 -1
- data/Gemfile +9 -7
- data/Guardfile +4 -3
- data/Rakefile +4 -2
- data/atdis.gemspec +10 -5
- data/lib/atdis.rb +2 -0
- data/lib/atdis/feed.rb +31 -24
- data/lib/atdis/model.rb +101 -99
- data/lib/atdis/models/address.rb +10 -4
- data/lib/atdis/models/application.rb +12 -9
- data/lib/atdis/models/authority.rb +11 -6
- data/lib/atdis/models/document.rb +8 -6
- data/lib/atdis/models/event.rb +10 -8
- data/lib/atdis/models/info.rb +73 -49
- data/lib/atdis/models/land_title_ref.rb +15 -7
- data/lib/atdis/models/location.rb +9 -7
- data/lib/atdis/models/page.rb +34 -19
- data/lib/atdis/models/pagination.rb +91 -32
- data/lib/atdis/models/person.rb +7 -5
- data/lib/atdis/models/reference.rb +7 -5
- data/lib/atdis/models/response.rb +5 -3
- data/lib/atdis/models/torrens_title.rb +9 -7
- data/lib/atdis/separated_url.rb +17 -15
- data/lib/atdis/validators.rb +46 -39
- data/lib/atdis/version.rb +3 -1
- data/spec/atdis/feed_spec.rb +126 -34
- data/spec/atdis/model_spec.rb +124 -51
- data/spec/atdis/models/address_spec.rb +18 -9
- data/spec/atdis/models/application_spec.rb +222 -155
- data/spec/atdis/models/authority_spec.rb +45 -15
- data/spec/atdis/models/document_spec.rb +10 -4
- data/spec/atdis/models/event_spec.rb +23 -11
- data/spec/atdis/models/info_spec.rb +191 -116
- data/spec/atdis/models/land_title_ref_spec.rb +32 -16
- data/spec/atdis/models/location_spec.rb +75 -60
- data/spec/atdis/models/page_spec.rb +241 -135
- data/spec/atdis/models/pagination_spec.rb +177 -77
- data/spec/atdis/models/person_spec.rb +8 -4
- data/spec/atdis/models/reference_spec.rb +29 -16
- data/spec/atdis/models/response_spec.rb +2 -1
- data/spec/atdis/models/torrens_title_spec.rb +24 -18
- data/spec/atdis/separated_url_spec.rb +14 -15
- data/spec/spec_helper.rb +14 -10
- metadata +56 -27
data/lib/atdis/version.rb
CHANGED
data/spec/atdis/feed_spec.rb
CHANGED
@@ -1,110 +1,202 @@
|
|
1
|
-
|
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
|
-
|
9
|
-
|
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
|
+
).and_return(page)
|
14
|
+
expect(feed.applications).to eq page
|
10
15
|
end
|
11
16
|
|
12
17
|
it "should return all the applications" do
|
13
|
-
feed.applications_url.
|
18
|
+
expect(feed.applications_url).to eq "http://www.council.nsw.gov.au/atdis/1.0/applications.json"
|
14
19
|
end
|
15
20
|
|
16
21
|
describe "should restrict search by postcode" do
|
17
22
|
it "single postcode" do
|
18
|
-
feed.applications_url(postcode: 2000).
|
23
|
+
expect(feed.applications_url(postcode: 2000)).to eq "http://www.council.nsw.gov.au/atdis/1.0/applications.json?postcode=2000"
|
19
24
|
end
|
20
25
|
|
21
26
|
it "multiple postcodes in an array" do
|
22
|
-
feed.applications_url(postcode: [2000,2001]).
|
27
|
+
expect(feed.applications_url(postcode: [2000, 2001])).to eq "http://www.council.nsw.gov.au/atdis/1.0/applications.json?postcode=2000,2001"
|
23
28
|
end
|
24
29
|
|
25
30
|
it "multiple postcodes as a string" do
|
26
|
-
feed.applications_url(postcode: "2000,2001").
|
31
|
+
expect(feed.applications_url(postcode: "2000,2001")).to eq "http://www.council.nsw.gov.au/atdis/1.0/applications.json?postcode=2000,2001"
|
27
32
|
end
|
28
33
|
end
|
29
34
|
|
30
35
|
describe "search by lodgement date" do
|
31
36
|
it "just a lodgement start date as a date" do
|
32
|
-
feed.applications_url(lodgement_date_start: Date.new(2001,2,1)).
|
37
|
+
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
38
|
end
|
34
39
|
|
35
40
|
it "just a lodgement start date as a string" do
|
36
|
-
feed.applications_url(lodgement_date_start: "2011-02-04").
|
41
|
+
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
42
|
end
|
38
43
|
|
39
44
|
it "a lodgement start date and end date" do
|
40
|
-
|
45
|
+
expect(
|
46
|
+
feed.applications_url(
|
47
|
+
lodgement_date_start: Date.new(2001, 2, 1),
|
48
|
+
lodgement_date_end: Date.new(2001, 3, 1)
|
49
|
+
)
|
50
|
+
).to eq(
|
51
|
+
"http://www.council.nsw.gov.au/atdis/1.0/applications.json?lodgement_date_end=2001-03-01&lodgement_date_start=2001-02-01"
|
52
|
+
)
|
41
53
|
end
|
42
54
|
end
|
43
55
|
|
44
56
|
describe "search by last modified date" do
|
45
57
|
it "just a last modified start date" do
|
46
|
-
feed.applications_url(last_modified_date_start: Date.new(2001,2,1)).
|
58
|
+
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
59
|
end
|
48
60
|
|
49
61
|
it "a last modified start date and end date" do
|
50
|
-
|
62
|
+
expect(
|
63
|
+
feed.applications_url(
|
64
|
+
last_modified_date_start: Date.new(2001, 2, 1),
|
65
|
+
last_modified_date_end: Date.new(2001, 3, 1)
|
66
|
+
)
|
67
|
+
).to eq(
|
68
|
+
"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"
|
69
|
+
)
|
51
70
|
end
|
52
71
|
end
|
53
72
|
|
54
73
|
describe "search by suburb" do
|
55
74
|
it do
|
56
|
-
feed.applications_url(suburb: ["willow tree", "foo", "bar"]).
|
75
|
+
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
76
|
end
|
58
77
|
end
|
59
78
|
|
60
79
|
it "jump straight to the second page" do
|
61
|
-
feed.applications_url(page: 2).
|
80
|
+
expect(feed.applications_url(page: 2)).to eq "http://www.council.nsw.gov.au/atdis/1.0/applications.json?page=2"
|
62
81
|
end
|
63
82
|
|
64
83
|
it "passing an invalid option" do
|
65
|
-
expect {feed.applications_url(foo: 1)}.to raise_error "Unexpected options used: foo"
|
84
|
+
expect { feed.applications_url(foo: 1) }.to raise_error "Unexpected options used: foo"
|
66
85
|
end
|
67
86
|
|
68
87
|
describe ".base_url_from_url" do
|
69
|
-
it
|
70
|
-
|
88
|
+
it do
|
89
|
+
expect(
|
90
|
+
ATDIS::Feed.base_url_from_url(
|
91
|
+
"http://www.council.nsw.gov.au/atdis/1.0/applications.json?postcode=2000"
|
92
|
+
)
|
93
|
+
).to eq "http://www.council.nsw.gov.au/atdis/1.0"
|
94
|
+
end
|
95
|
+
it do
|
96
|
+
expect(
|
97
|
+
ATDIS::Feed.base_url_from_url(
|
98
|
+
"http://www.foo.nsw.gov.au/prefix/atdis/1.0/applications.json?postcode=2000#bar"
|
99
|
+
)
|
100
|
+
).to eq "http://www.foo.nsw.gov.au/prefix/atdis/1.0"
|
101
|
+
end
|
71
102
|
it "should assume that any query parameters that are not recognised are part of the base_url" do
|
72
|
-
|
103
|
+
expect(
|
104
|
+
ATDIS::Feed.base_url_from_url(
|
105
|
+
"http://www.foo.nsw.gov.au/prefix/atdis/1.0/applications.json?postcode=2000&foo=bar"
|
106
|
+
)
|
107
|
+
).to eq "http://www.foo.nsw.gov.au/prefix/atdis/1.0?foo=bar"
|
73
108
|
end
|
74
109
|
end
|
75
110
|
|
76
111
|
describe ".options_from_url" do
|
77
|
-
it
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
it
|
83
|
-
|
112
|
+
it do
|
113
|
+
expect(
|
114
|
+
ATDIS::Feed.options_from_url("http://www.council.nsw.gov.au/atdis/1.0/applications.json")
|
115
|
+
).to eq({})
|
116
|
+
end
|
117
|
+
it do
|
118
|
+
expect(
|
119
|
+
ATDIS::Feed.options_from_url(
|
120
|
+
"http://www.council.nsw.gov.au/atdis/1.0/applications.json?page=2"
|
121
|
+
)
|
122
|
+
).to eq(page: 2)
|
123
|
+
end
|
124
|
+
it do
|
125
|
+
expect(
|
126
|
+
ATDIS::Feed.options_from_url(
|
127
|
+
"http://www.council.nsw.gov.au/atdis/1.0/applications.json?postcode=2000,2001"
|
128
|
+
)
|
129
|
+
).to eq(postcode: "2000,2001")
|
130
|
+
end
|
131
|
+
it do
|
132
|
+
expect(
|
133
|
+
ATDIS::Feed.options_from_url(
|
134
|
+
"http://www.council.nsw.gov.au/atdis/1.0/applications.json?lodgement_date_end=2001-03-01&lodgement_date_start=2001-02-01"
|
135
|
+
)
|
136
|
+
).to eq(
|
137
|
+
lodgement_date_start: Date.new(2001, 2, 1), lodgement_date_end: Date.new(2001, 3, 1)
|
138
|
+
)
|
139
|
+
end
|
140
|
+
it do
|
141
|
+
expect(
|
142
|
+
ATDIS::Feed.options_from_url(
|
143
|
+
"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"
|
144
|
+
)
|
145
|
+
).to eq(
|
146
|
+
last_modified_date_start: Date.new(2001, 2, 1), last_modified_date_end: Date.new(2001, 3, 1)
|
147
|
+
)
|
148
|
+
end
|
84
149
|
it "should assume that any query parameters that are not recognised are part of the base_url" do
|
85
|
-
|
150
|
+
expect(
|
151
|
+
ATDIS::Feed.options_from_url(
|
152
|
+
"http://www.foo.nsw.gov.au/prefix/atdis/1.0/applications.json?postcode=2000&foo=bar"
|
153
|
+
)
|
154
|
+
).to eq(postcode: "2000")
|
86
155
|
end
|
87
156
|
|
88
157
|
it do
|
89
|
-
|
158
|
+
expect(
|
159
|
+
ATDIS::Feed.options_from_url(
|
160
|
+
"http://www.council.nsw.gov.au/atdis/1.0/applications.json?suburb=willow+tree,foo,bar"
|
161
|
+
)
|
162
|
+
).to eq(suburb: "willow tree,foo,bar")
|
90
163
|
end
|
91
164
|
|
92
165
|
it do
|
93
|
-
|
166
|
+
expect(
|
167
|
+
ATDIS::Feed.options_from_url(
|
168
|
+
"http://www.council.nsw.gov.au/atdis/1.0/applications.json?suburb=&postcode=2000"
|
169
|
+
)
|
170
|
+
).to eq(postcode: "2000", suburb: nil)
|
94
171
|
end
|
95
172
|
end
|
96
173
|
|
97
174
|
describe "#application_url" do
|
98
|
-
it
|
99
|
-
|
100
|
-
|
175
|
+
it do
|
176
|
+
expect(feed.application_url("27B6")).to eq(
|
177
|
+
"http://www.council.nsw.gov.au/atdis/1.0/27B6.json"
|
178
|
+
)
|
179
|
+
end
|
180
|
+
it do
|
181
|
+
expect(feed.application_url("27B stroke 6")).to eq(
|
182
|
+
"http://www.council.nsw.gov.au/atdis/1.0/27B+stroke+6.json"
|
183
|
+
)
|
184
|
+
end
|
185
|
+
it do
|
186
|
+
expect(feed.application_url("27B/6")).to eq(
|
187
|
+
"http://www.council.nsw.gov.au/atdis/1.0/27B%2F6.json"
|
188
|
+
)
|
189
|
+
end
|
101
190
|
end
|
102
191
|
|
103
192
|
describe "#application" do
|
104
193
|
it {
|
105
194
|
application = double
|
106
|
-
expect(ATDIS::Models::Application).to receive(:read_url).with(
|
107
|
-
|
195
|
+
expect(ATDIS::Models::Application).to receive(:read_url).with(
|
196
|
+
"http://www.council.nsw.gov.au/atdis/1.0/27B%2F6.json",
|
197
|
+
"UTC"
|
198
|
+
).and_return(application)
|
199
|
+
expect(feed.application("27B/6")).to eq application
|
108
200
|
}
|
109
201
|
end
|
110
202
|
end
|
data/spec/atdis/model_spec.rb
CHANGED
@@ -1,119 +1,192 @@
|
|
1
|
-
|
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
|
-
|
6
|
+
field_mappings(
|
5
7
|
bar: [String]
|
6
|
-
|
8
|
+
)
|
7
9
|
end
|
8
10
|
|
9
11
|
class ModelA < ATDIS::Model
|
10
|
-
|
11
|
-
bar:
|
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.
|
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.
|
30
|
-
|
31
|
-
|
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.
|
38
|
-
|
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.
|
44
|
-
a.hello[1].bar.
|
45
|
-
a.json_errors.
|
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.
|
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.
|
54
|
-
a.json_errors.
|
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.
|
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
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
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).
|
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
|
79
|
-
it { ATDIS::Model.cast("3",
|
80
|
-
it { ATDIS::Model.cast("4.0",
|
81
|
-
it { ATDIS::Model.cast(5,
|
82
|
-
it { ATDIS::Model.cast(0,
|
83
|
-
it { ATDIS::Model.cast(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:
|
90
|
-
ATDIS::Model.attribute_keys.
|
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.
|
97
|
-
ATDIS::Model.partition_by_used(
|
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.
|
104
|
-
ATDIS::Model.partition_by_used(
|
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.
|
112
|
-
ATDIS::Model.partition_by_used("hello").
|
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
|