unchained 0.0.2 → 0.0.3
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/README.md +0 -1
- data/lib/unchained/client.rb +8 -0
- data/lib/unchained/client/archetypes.rb +10 -2
- data/lib/unchained/client/attributes.rb +12 -4
- data/lib/unchained/client/factions.rb +9 -1
- data/lib/unchained/client/mixins/resource.rb +13 -1
- data/lib/unchained/client/patcher.rb +10 -2
- data/lib/unchained/client/races.rb +10 -2
- data/lib/unchained/client/servers.rb +9 -2
- data/lib/unchained/request.rb +14 -2
- data/lib/unchained/version.rb +1 -1
- data/test/_fixtures/vcr_cassettes/archetypes.yml +380 -2
- data/test/_fixtures/vcr_cassettes/attribute_offsets.yml +3446 -2
- data/test/_fixtures/vcr_cassettes/faction.yml +45 -0
- data/test/_fixtures/vcr_cassettes/races.yml +254 -2
- data/test/unchained/client/archetypes_test.rb +35 -1
- data/test/unchained/client/attributes_test.rb +36 -0
- data/test/unchained/client/factions_test.rb +28 -0
- data/test/unchained/client/mixins/resource_test.rb +85 -5
- data/test/unchained/client/motd_test.rb +5 -0
- data/test/unchained/client/patcher_test.rb +19 -0
- data/test/unchained/client/races_test.rb +36 -0
- data/test/unchained/client/servers_test.rb +8 -0
- data/test/unchained/client_test.rb +55 -0
- data/test/unchained/configuration_test.rb +54 -0
- data/test/unchained_test.rb +24 -0
- metadata +6 -2
@@ -0,0 +1,45 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://api.camelotunchained.com/v1/gamedata/factions
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- application/json
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip, deflate
|
14
|
+
Logintoken:
|
15
|
+
- ''
|
16
|
+
User-Agent:
|
17
|
+
- Ruby
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 200
|
21
|
+
message: OK
|
22
|
+
headers:
|
23
|
+
Content-Length:
|
24
|
+
- '362'
|
25
|
+
Content-Type:
|
26
|
+
- application/json; charset=utf-8
|
27
|
+
Server:
|
28
|
+
- Microsoft-HTTPAPI/2.0
|
29
|
+
Date:
|
30
|
+
- Sun, 24 Apr 2016 02:02:11 GMT
|
31
|
+
body:
|
32
|
+
encoding: ASCII-8BIT
|
33
|
+
string: !binary |-
|
34
|
+
W3siZGVzY3JpcHRpb24iOiJObyBGYWN0aW9uIG9yIEFsbCBGYWN0aW9ucyAo
|
35
|
+
TlBDIE9ubHkpIiwiaWQiOjAsIm5hbWUiOiJGYWN0aW9ubGVzcyIsInNob3J0
|
36
|
+
TmFtZSI6IkZhY3Rpb25sZXNzIn0seyJkZXNjcmlwdGlvbiI6IlRoZSBUdWF0
|
37
|
+
aGEgRMOpIERhbmFubiIsImlkIjoxLCJuYW1lIjoiVHVhdGhhIETDqSBEYW5h
|
38
|
+
bm4iLCJzaG9ydE5hbWUiOiJUREQifSx7ImRlc2NyaXB0aW9uIjoiVGhlIFZp
|
39
|
+
a2luZ3MiLCJpZCI6MiwibmFtZSI6IlZpa2luZ3MiLCJzaG9ydE5hbWUiOiJW
|
40
|
+
aWtpbmcifSx7ImRlc2NyaXB0aW9uIjoiVGhlIEFydGh1cmlhbnMiLCJpZCI6
|
41
|
+
MywibmFtZSI6IkFydGh1cmlhbnMiLCJzaG9ydE5hbWUiOiJBcnRodXJpYW4i
|
42
|
+
fV0=
|
43
|
+
http_version:
|
44
|
+
recorded_at: Sun, 24 Apr 2016 02:02:15 GMT
|
45
|
+
recorded_with: VCR 3.0.1
|
@@ -27,12 +27,264 @@ http_interactions:
|
|
27
27
|
Server:
|
28
28
|
- Microsoft-HTTPAPI/2.0
|
29
29
|
Date:
|
30
|
-
- Fri, 22 Apr 2016
|
30
|
+
- Fri, 22 Apr 2016 23:09:31 GMT
|
31
31
|
body:
|
32
32
|
encoding: UTF-8
|
33
33
|
string: '[{"name":"Luchorpan","description":"Luchorpan","faction":1,"id":2},{"name":"Valkyrie","description":"Valkyrie","faction":2,"id":4},{"name":"Human","description":"Viking
|
34
34
|
Human","faction":2,"id":15},{"name":"Human","description":"Arthurian Human","faction":3,"id":16},{"name":"Human","description":"TDD
|
35
35
|
Human","faction":1,"id":17},{"name":"Pict","description":"Pictish?","faction":3,"id":18}]'
|
36
36
|
http_version:
|
37
|
-
recorded_at: Fri, 22 Apr 2016
|
37
|
+
recorded_at: Fri, 22 Apr 2016 23:09:53 GMT
|
38
|
+
- request:
|
39
|
+
method: get
|
40
|
+
uri: http://api.camelotunchained.com/v1/gamedata/factions
|
41
|
+
body:
|
42
|
+
encoding: US-ASCII
|
43
|
+
string: ''
|
44
|
+
headers:
|
45
|
+
Accept:
|
46
|
+
- application/json
|
47
|
+
Accept-Encoding:
|
48
|
+
- gzip, deflate
|
49
|
+
Logintoken:
|
50
|
+
- ''
|
51
|
+
User-Agent:
|
52
|
+
- Ruby
|
53
|
+
response:
|
54
|
+
status:
|
55
|
+
code: 200
|
56
|
+
message: OK
|
57
|
+
headers:
|
58
|
+
Content-Length:
|
59
|
+
- '362'
|
60
|
+
Content-Type:
|
61
|
+
- application/json; charset=utf-8
|
62
|
+
Server:
|
63
|
+
- Microsoft-HTTPAPI/2.0
|
64
|
+
Date:
|
65
|
+
- Fri, 22 Apr 2016 23:09:32 GMT
|
66
|
+
body:
|
67
|
+
encoding: ASCII-8BIT
|
68
|
+
string: !binary |-
|
69
|
+
W3siZGVzY3JpcHRpb24iOiJObyBGYWN0aW9uIG9yIEFsbCBGYWN0aW9ucyAo
|
70
|
+
TlBDIE9ubHkpIiwiaWQiOjAsIm5hbWUiOiJGYWN0aW9ubGVzcyIsInNob3J0
|
71
|
+
TmFtZSI6IkZhY3Rpb25sZXNzIn0seyJkZXNjcmlwdGlvbiI6IlRoZSBUdWF0
|
72
|
+
aGEgRMOpIERhbmFubiIsImlkIjoxLCJuYW1lIjoiVHVhdGhhIETDqSBEYW5h
|
73
|
+
bm4iLCJzaG9ydE5hbWUiOiJUREQifSx7ImRlc2NyaXB0aW9uIjoiVGhlIFZp
|
74
|
+
a2luZ3MiLCJpZCI6MiwibmFtZSI6IlZpa2luZ3MiLCJzaG9ydE5hbWUiOiJW
|
75
|
+
aWtpbmcifSx7ImRlc2NyaXB0aW9uIjoiVGhlIEFydGh1cmlhbnMiLCJpZCI6
|
76
|
+
MywibmFtZSI6IkFydGh1cmlhbnMiLCJzaG9ydE5hbWUiOiJBcnRodXJpYW4i
|
77
|
+
fV0=
|
78
|
+
http_version:
|
79
|
+
recorded_at: Fri, 22 Apr 2016 23:09:53 GMT
|
80
|
+
- request:
|
81
|
+
method: get
|
82
|
+
uri: http://api.camelotunchained.com/v1/gamedata/factions
|
83
|
+
body:
|
84
|
+
encoding: US-ASCII
|
85
|
+
string: ''
|
86
|
+
headers:
|
87
|
+
Accept:
|
88
|
+
- application/json
|
89
|
+
Accept-Encoding:
|
90
|
+
- gzip, deflate
|
91
|
+
Logintoken:
|
92
|
+
- ''
|
93
|
+
User-Agent:
|
94
|
+
- Ruby
|
95
|
+
response:
|
96
|
+
status:
|
97
|
+
code: 200
|
98
|
+
message: OK
|
99
|
+
headers:
|
100
|
+
Content-Length:
|
101
|
+
- '362'
|
102
|
+
Content-Type:
|
103
|
+
- application/json; charset=utf-8
|
104
|
+
Server:
|
105
|
+
- Microsoft-HTTPAPI/2.0
|
106
|
+
Date:
|
107
|
+
- Fri, 22 Apr 2016 23:09:32 GMT
|
108
|
+
body:
|
109
|
+
encoding: ASCII-8BIT
|
110
|
+
string: !binary |-
|
111
|
+
W3siZGVzY3JpcHRpb24iOiJObyBGYWN0aW9uIG9yIEFsbCBGYWN0aW9ucyAo
|
112
|
+
TlBDIE9ubHkpIiwiaWQiOjAsIm5hbWUiOiJGYWN0aW9ubGVzcyIsInNob3J0
|
113
|
+
TmFtZSI6IkZhY3Rpb25sZXNzIn0seyJkZXNjcmlwdGlvbiI6IlRoZSBUdWF0
|
114
|
+
aGEgRMOpIERhbmFubiIsImlkIjoxLCJuYW1lIjoiVHVhdGhhIETDqSBEYW5h
|
115
|
+
bm4iLCJzaG9ydE5hbWUiOiJUREQifSx7ImRlc2NyaXB0aW9uIjoiVGhlIFZp
|
116
|
+
a2luZ3MiLCJpZCI6MiwibmFtZSI6IlZpa2luZ3MiLCJzaG9ydE5hbWUiOiJW
|
117
|
+
aWtpbmcifSx7ImRlc2NyaXB0aW9uIjoiVGhlIEFydGh1cmlhbnMiLCJpZCI6
|
118
|
+
MywibmFtZSI6IkFydGh1cmlhbnMiLCJzaG9ydE5hbWUiOiJBcnRodXJpYW4i
|
119
|
+
fV0=
|
120
|
+
http_version:
|
121
|
+
recorded_at: Fri, 22 Apr 2016 23:09:53 GMT
|
122
|
+
- request:
|
123
|
+
method: get
|
124
|
+
uri: http://api.camelotunchained.com/v1/gamedata/factions
|
125
|
+
body:
|
126
|
+
encoding: US-ASCII
|
127
|
+
string: ''
|
128
|
+
headers:
|
129
|
+
Accept:
|
130
|
+
- application/json
|
131
|
+
Accept-Encoding:
|
132
|
+
- gzip, deflate
|
133
|
+
Logintoken:
|
134
|
+
- ''
|
135
|
+
User-Agent:
|
136
|
+
- Ruby
|
137
|
+
response:
|
138
|
+
status:
|
139
|
+
code: 200
|
140
|
+
message: OK
|
141
|
+
headers:
|
142
|
+
Content-Length:
|
143
|
+
- '362'
|
144
|
+
Content-Type:
|
145
|
+
- application/json; charset=utf-8
|
146
|
+
Server:
|
147
|
+
- Microsoft-HTTPAPI/2.0
|
148
|
+
Date:
|
149
|
+
- Fri, 22 Apr 2016 23:09:32 GMT
|
150
|
+
body:
|
151
|
+
encoding: ASCII-8BIT
|
152
|
+
string: !binary |-
|
153
|
+
W3siZGVzY3JpcHRpb24iOiJObyBGYWN0aW9uIG9yIEFsbCBGYWN0aW9ucyAo
|
154
|
+
TlBDIE9ubHkpIiwiaWQiOjAsIm5hbWUiOiJGYWN0aW9ubGVzcyIsInNob3J0
|
155
|
+
TmFtZSI6IkZhY3Rpb25sZXNzIn0seyJkZXNjcmlwdGlvbiI6IlRoZSBUdWF0
|
156
|
+
aGEgRMOpIERhbmFubiIsImlkIjoxLCJuYW1lIjoiVHVhdGhhIETDqSBEYW5h
|
157
|
+
bm4iLCJzaG9ydE5hbWUiOiJUREQifSx7ImRlc2NyaXB0aW9uIjoiVGhlIFZp
|
158
|
+
a2luZ3MiLCJpZCI6MiwibmFtZSI6IlZpa2luZ3MiLCJzaG9ydE5hbWUiOiJW
|
159
|
+
aWtpbmcifSx7ImRlc2NyaXB0aW9uIjoiVGhlIEFydGh1cmlhbnMiLCJpZCI6
|
160
|
+
MywibmFtZSI6IkFydGh1cmlhbnMiLCJzaG9ydE5hbWUiOiJBcnRodXJpYW4i
|
161
|
+
fV0=
|
162
|
+
http_version:
|
163
|
+
recorded_at: Fri, 22 Apr 2016 23:09:54 GMT
|
164
|
+
- request:
|
165
|
+
method: get
|
166
|
+
uri: http://api.camelotunchained.com/v1/gamedata/factions
|
167
|
+
body:
|
168
|
+
encoding: US-ASCII
|
169
|
+
string: ''
|
170
|
+
headers:
|
171
|
+
Accept:
|
172
|
+
- application/json
|
173
|
+
Accept-Encoding:
|
174
|
+
- gzip, deflate
|
175
|
+
Logintoken:
|
176
|
+
- ''
|
177
|
+
User-Agent:
|
178
|
+
- Ruby
|
179
|
+
response:
|
180
|
+
status:
|
181
|
+
code: 200
|
182
|
+
message: OK
|
183
|
+
headers:
|
184
|
+
Content-Length:
|
185
|
+
- '362'
|
186
|
+
Content-Type:
|
187
|
+
- application/json; charset=utf-8
|
188
|
+
Server:
|
189
|
+
- Microsoft-HTTPAPI/2.0
|
190
|
+
Date:
|
191
|
+
- Fri, 22 Apr 2016 23:09:32 GMT
|
192
|
+
body:
|
193
|
+
encoding: ASCII-8BIT
|
194
|
+
string: !binary |-
|
195
|
+
W3siZGVzY3JpcHRpb24iOiJObyBGYWN0aW9uIG9yIEFsbCBGYWN0aW9ucyAo
|
196
|
+
TlBDIE9ubHkpIiwiaWQiOjAsIm5hbWUiOiJGYWN0aW9ubGVzcyIsInNob3J0
|
197
|
+
TmFtZSI6IkZhY3Rpb25sZXNzIn0seyJkZXNjcmlwdGlvbiI6IlRoZSBUdWF0
|
198
|
+
aGEgRMOpIERhbmFubiIsImlkIjoxLCJuYW1lIjoiVHVhdGhhIETDqSBEYW5h
|
199
|
+
bm4iLCJzaG9ydE5hbWUiOiJUREQifSx7ImRlc2NyaXB0aW9uIjoiVGhlIFZp
|
200
|
+
a2luZ3MiLCJpZCI6MiwibmFtZSI6IlZpa2luZ3MiLCJzaG9ydE5hbWUiOiJW
|
201
|
+
aWtpbmcifSx7ImRlc2NyaXB0aW9uIjoiVGhlIEFydGh1cmlhbnMiLCJpZCI6
|
202
|
+
MywibmFtZSI6IkFydGh1cmlhbnMiLCJzaG9ydE5hbWUiOiJBcnRodXJpYW4i
|
203
|
+
fV0=
|
204
|
+
http_version:
|
205
|
+
recorded_at: Fri, 22 Apr 2016 23:09:54 GMT
|
206
|
+
- request:
|
207
|
+
method: get
|
208
|
+
uri: http://api.camelotunchained.com/v1/gamedata/factions
|
209
|
+
body:
|
210
|
+
encoding: US-ASCII
|
211
|
+
string: ''
|
212
|
+
headers:
|
213
|
+
Accept:
|
214
|
+
- application/json
|
215
|
+
Accept-Encoding:
|
216
|
+
- gzip, deflate
|
217
|
+
Logintoken:
|
218
|
+
- ''
|
219
|
+
User-Agent:
|
220
|
+
- Ruby
|
221
|
+
response:
|
222
|
+
status:
|
223
|
+
code: 200
|
224
|
+
message: OK
|
225
|
+
headers:
|
226
|
+
Content-Length:
|
227
|
+
- '362'
|
228
|
+
Content-Type:
|
229
|
+
- application/json; charset=utf-8
|
230
|
+
Server:
|
231
|
+
- Microsoft-HTTPAPI/2.0
|
232
|
+
Date:
|
233
|
+
- Fri, 22 Apr 2016 23:09:32 GMT
|
234
|
+
body:
|
235
|
+
encoding: ASCII-8BIT
|
236
|
+
string: !binary |-
|
237
|
+
W3siZGVzY3JpcHRpb24iOiJObyBGYWN0aW9uIG9yIEFsbCBGYWN0aW9ucyAo
|
238
|
+
TlBDIE9ubHkpIiwiaWQiOjAsIm5hbWUiOiJGYWN0aW9ubGVzcyIsInNob3J0
|
239
|
+
TmFtZSI6IkZhY3Rpb25sZXNzIn0seyJkZXNjcmlwdGlvbiI6IlRoZSBUdWF0
|
240
|
+
aGEgRMOpIERhbmFubiIsImlkIjoxLCJuYW1lIjoiVHVhdGhhIETDqSBEYW5h
|
241
|
+
bm4iLCJzaG9ydE5hbWUiOiJUREQifSx7ImRlc2NyaXB0aW9uIjoiVGhlIFZp
|
242
|
+
a2luZ3MiLCJpZCI6MiwibmFtZSI6IlZpa2luZ3MiLCJzaG9ydE5hbWUiOiJW
|
243
|
+
aWtpbmcifSx7ImRlc2NyaXB0aW9uIjoiVGhlIEFydGh1cmlhbnMiLCJpZCI6
|
244
|
+
MywibmFtZSI6IkFydGh1cmlhbnMiLCJzaG9ydE5hbWUiOiJBcnRodXJpYW4i
|
245
|
+
fV0=
|
246
|
+
http_version:
|
247
|
+
recorded_at: Fri, 22 Apr 2016 23:09:54 GMT
|
248
|
+
- request:
|
249
|
+
method: get
|
250
|
+
uri: http://api.camelotunchained.com/v1/gamedata/factions
|
251
|
+
body:
|
252
|
+
encoding: US-ASCII
|
253
|
+
string: ''
|
254
|
+
headers:
|
255
|
+
Accept:
|
256
|
+
- application/json
|
257
|
+
Accept-Encoding:
|
258
|
+
- gzip, deflate
|
259
|
+
Logintoken:
|
260
|
+
- ''
|
261
|
+
User-Agent:
|
262
|
+
- Ruby
|
263
|
+
response:
|
264
|
+
status:
|
265
|
+
code: 200
|
266
|
+
message: OK
|
267
|
+
headers:
|
268
|
+
Content-Length:
|
269
|
+
- '362'
|
270
|
+
Content-Type:
|
271
|
+
- application/json; charset=utf-8
|
272
|
+
Server:
|
273
|
+
- Microsoft-HTTPAPI/2.0
|
274
|
+
Date:
|
275
|
+
- Fri, 22 Apr 2016 23:09:32 GMT
|
276
|
+
body:
|
277
|
+
encoding: ASCII-8BIT
|
278
|
+
string: !binary |-
|
279
|
+
W3siZGVzY3JpcHRpb24iOiJObyBGYWN0aW9uIG9yIEFsbCBGYWN0aW9ucyAo
|
280
|
+
TlBDIE9ubHkpIiwiaWQiOjAsIm5hbWUiOiJGYWN0aW9ubGVzcyIsInNob3J0
|
281
|
+
TmFtZSI6IkZhY3Rpb25sZXNzIn0seyJkZXNjcmlwdGlvbiI6IlRoZSBUdWF0
|
282
|
+
aGEgRMOpIERhbmFubiIsImlkIjoxLCJuYW1lIjoiVHVhdGhhIETDqSBEYW5h
|
283
|
+
bm4iLCJzaG9ydE5hbWUiOiJUREQifSx7ImRlc2NyaXB0aW9uIjoiVGhlIFZp
|
284
|
+
a2luZ3MiLCJpZCI6MiwibmFtZSI6IlZpa2luZ3MiLCJzaG9ydE5hbWUiOiJW
|
285
|
+
aWtpbmcifSx7ImRlc2NyaXB0aW9uIjoiVGhlIEFydGh1cmlhbnMiLCJpZCI6
|
286
|
+
MywibmFtZSI6IkFydGh1cmlhbnMiLCJzaG9ydE5hbWUiOiJBcnRodXJpYW4i
|
287
|
+
fV0=
|
288
|
+
http_version:
|
289
|
+
recorded_at: Fri, 22 Apr 2016 23:09:54 GMT
|
38
290
|
recorded_with: VCR 3.0.1
|
@@ -13,10 +13,44 @@ describe Unchained::Client::Archetypes do
|
|
13
13
|
assert_equal(9, archetypes.count, "Expected 9 archetypes")
|
14
14
|
|
15
15
|
archetype = archetypes.first
|
16
|
+
|
17
|
+
assert(
|
18
|
+
archetype.is_a?(Unchained::Client::Archetypes::Archetype),
|
19
|
+
'Expected `archetypes` to return Archetypes.',
|
20
|
+
)
|
21
|
+
|
16
22
|
assert_equal('The Dark Knight', archetype.description)
|
17
|
-
assert_equal(3, archetype.faction)
|
18
23
|
assert_equal(7, archetype.id)
|
19
24
|
assert_equal('Black Knight', archetype.name)
|
25
|
+
|
26
|
+
# check that it expands the faction
|
27
|
+
assert(
|
28
|
+
archetype.faction.is_a?(Unchained::Client::Factions::Faction),
|
29
|
+
'Expected `faction` to be expanded.',
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '.archetype' do
|
36
|
+
it 'should fetch from the API' do
|
37
|
+
VCR.use_cassette('archetypes') do
|
38
|
+
archetype = @client.archetype(7)
|
39
|
+
|
40
|
+
assert(
|
41
|
+
archetype.is_a?(Unchained::Client::Archetypes::Archetype),
|
42
|
+
'Expected `archetype` to return an Archetype.',
|
43
|
+
)
|
44
|
+
|
45
|
+
assert_equal('The Dark Knight', archetype.description)
|
46
|
+
assert_equal(7, archetype.id)
|
47
|
+
assert_equal('Black Knight', archetype.name)
|
48
|
+
|
49
|
+
# check that it expands the faction
|
50
|
+
assert(
|
51
|
+
archetype.faction.is_a?(Unchained::Client::Factions::Faction),
|
52
|
+
'Expected `faction` to be expanded.',
|
53
|
+
)
|
20
54
|
end
|
21
55
|
end
|
22
56
|
end
|
@@ -11,6 +11,20 @@ describe Unchained::Client::Attributes do
|
|
11
11
|
VCR.use_cassette('attributes') do
|
12
12
|
attributes = @client.attributes(1)
|
13
13
|
assert_equal(37, attributes.count)
|
14
|
+
|
15
|
+
attribute = attributes.first
|
16
|
+
assert(
|
17
|
+
attribute.is_a?(Unchained::Client::Attributes::AttributeInfo),
|
18
|
+
'Expected `attributes(i)` to return AttributeInfos.',
|
19
|
+
)
|
20
|
+
|
21
|
+
assert_equal(30.0, attribute.base_value)
|
22
|
+
assert_equal('None', attribute.derived_from)
|
23
|
+
assert_match(/power of the character's magic effects/, attribute.description)
|
24
|
+
assert_equal(100.0, attribute.max_or_multiplier)
|
25
|
+
assert_equal('Attunement', attribute.name)
|
26
|
+
assert_equal(1, attribute.type)
|
27
|
+
assert_equal('units', attribute.units)
|
14
28
|
end
|
15
29
|
end
|
16
30
|
end
|
@@ -20,6 +34,28 @@ describe Unchained::Client::Attributes do
|
|
20
34
|
VCR.use_cassette('attribute_offsets') do
|
21
35
|
offsets = @client.attribute_offsets(1)
|
22
36
|
assert_equal(12, offsets.count)
|
37
|
+
|
38
|
+
offset = offsets.first
|
39
|
+
assert(
|
40
|
+
offset.is_a?(Unchained::Client::Attributes::AttributeOffset),
|
41
|
+
'Expected `attribute_offsets` to return AttributeOffsets.',
|
42
|
+
)
|
43
|
+
|
44
|
+
assert(
|
45
|
+
offset.race.is_a?(Unchained::Client::Races::Race),
|
46
|
+
'Expected `race` to be a Race.',
|
47
|
+
)
|
48
|
+
|
49
|
+
assert_equal(1, offset.gender)
|
50
|
+
|
51
|
+
# Assert a few of the hash elements.
|
52
|
+
assert(
|
53
|
+
offset.offsets.is_a?(Hash),
|
54
|
+
'Expected `offsets` to be a Hash.',
|
55
|
+
)
|
56
|
+
assert_equal(1.0, offset.offsets['Strength'])
|
57
|
+
assert_equal(-4.0, offset.offsets['Attunement'])
|
58
|
+
assert_equal(5.0, offset.offsets['Presence'])
|
23
59
|
end
|
24
60
|
end
|
25
61
|
end
|
@@ -11,6 +11,34 @@ describe Unchained::Client::Factions do
|
|
11
11
|
VCR.use_cassette('factions') do
|
12
12
|
factions = @client.factions
|
13
13
|
assert_equal(4, factions.count)
|
14
|
+
|
15
|
+
faction = factions.first
|
16
|
+
assert(
|
17
|
+
faction.is_a?(Unchained::Client::Factions::Faction),
|
18
|
+
'Expected `factions` to return Factions.',
|
19
|
+
)
|
20
|
+
|
21
|
+
assert_equal(0, faction.id)
|
22
|
+
assert_match(/NPC Only/, faction.description)
|
23
|
+
assert_equal('Factionless', faction.name)
|
24
|
+
assert_equal('Factionless', faction.short_name)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '.faction' do
|
30
|
+
it 'should fetch from the API' do
|
31
|
+
VCR.use_cassette('faction') do
|
32
|
+
faction = @client.faction(1)
|
33
|
+
assert(
|
34
|
+
faction.is_a?(Unchained::Client::Factions::Faction),
|
35
|
+
'Expected `factions` to return Factions.',
|
36
|
+
)
|
37
|
+
|
38
|
+
assert_equal(1, faction.id)
|
39
|
+
assert_equal('The Tuatha Dé Danann', faction.description)
|
40
|
+
assert_equal('Tuatha Dé Danann', faction.name)
|
41
|
+
assert_equal('TDD', faction.short_name)
|
14
42
|
end
|
15
43
|
end
|
16
44
|
end
|
@@ -7,32 +7,112 @@ describe 'Resource Mixin' do
|
|
7
7
|
|
8
8
|
attribute :company, String, allow_nil: true
|
9
9
|
attribute :name, String, allow_nil: false
|
10
|
-
attribute :city, String
|
10
|
+
attribute :city, String, json: 'someField'
|
11
|
+
attribute :expanded, String, expand: :foo
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'attributes' do
|
15
|
+
it 'should set up instance methods for each attribute' do
|
16
|
+
resource = SampleResource.new
|
17
|
+
resource.company = 'CSE'
|
18
|
+
assert_equal('CSE', resource.company)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should let you get a list of attributes from the class' do
|
22
|
+
attributes = SampleResource.attributes
|
23
|
+
assert_equal(4, attributes.count)
|
24
|
+
|
25
|
+
attribute = attributes.find{|a| a.name == :company}
|
26
|
+
assert(attribute, 'Expected an attribute with a name of `:company`.')
|
27
|
+
|
28
|
+
assert_equal(:company, attribute.name)
|
29
|
+
assert_equal(String, attribute.type)
|
30
|
+
assert_equal({allow_nil: true}, attribute.opts)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should not let you set the attributes on the class' do
|
34
|
+
refute(
|
35
|
+
SampleResource.respond_to?("attributes="),
|
36
|
+
'The Resource should not setup `attributes=`.',
|
37
|
+
)
|
38
|
+
end
|
11
39
|
end
|
12
40
|
|
13
41
|
describe 'nil attributes' do
|
14
42
|
it 'should allow nil values' do
|
15
|
-
resource = SampleResource.
|
43
|
+
resource = SampleResource.from_hash(company: nil)
|
16
44
|
assert_nil(resource.company, 'Expected `company` to be nil')
|
17
45
|
end
|
18
46
|
|
19
47
|
it 'should parse non-nil values correctly' do
|
20
|
-
resource = SampleResource.
|
48
|
+
resource = SampleResource.from_hash(company: 'CSE')
|
21
49
|
assert_equal('CSE', resource.company, 'Expected `company` to be set.')
|
22
50
|
end
|
23
51
|
|
24
52
|
it 'should allow you to disable nil explicitly' do
|
25
53
|
assert_raises(Unchained::InvalidValue) do
|
26
|
-
SampleResource.
|
54
|
+
SampleResource.from_hash(name: nil)
|
27
55
|
end
|
28
56
|
end
|
29
57
|
|
30
58
|
it 'should default to not allow nil' do
|
31
59
|
assert_raises(Unchained::InvalidValue) do
|
32
|
-
SampleResource.
|
60
|
+
SampleResource.from_hash(someField: nil)
|
33
61
|
end
|
34
62
|
end
|
35
63
|
end
|
36
64
|
|
65
|
+
describe 'helper methods' do
|
66
|
+
before do
|
67
|
+
@resource = SampleResource.new
|
68
|
+
end
|
69
|
+
|
70
|
+
def find_attribute(name)
|
71
|
+
SampleResource.attributes.find{|a| a.name == name}
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#json_field' do
|
75
|
+
it 'should default to the name' do
|
76
|
+
attribute = find_attribute(:company)
|
77
|
+
assert_equal('company', attribute.json_field)
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should allow you to override' do
|
81
|
+
attribute = find_attribute(:city)
|
82
|
+
assert_equal('someField', attribute.json_field)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe '#allow_nil?' do
|
87
|
+
it 'should default to false' do
|
88
|
+
attribute = find_attribute(:city)
|
89
|
+
refute(
|
90
|
+
attribute.allow_nil?,
|
91
|
+
'Expected `allow_nil?` to default to false.',
|
92
|
+
)
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should allow you to override' do
|
96
|
+
attribute = find_attribute(:company)
|
97
|
+
assert(
|
98
|
+
attribute.allow_nil?,
|
99
|
+
'Expected `allow_nil?` to be set to true.',
|
100
|
+
)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe '#expand_method' do
|
105
|
+
it 'should default to nil' do
|
106
|
+
attribute = find_attribute(:name)
|
107
|
+
assert_nil(attribute.expand_method)
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'should allow you to override' do
|
111
|
+
attribute = find_attribute(:expanded)
|
112
|
+
assert_equal(:foo, attribute.expand_method)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
37
117
|
end
|
38
118
|
|