|
20 | 20 | end |
21 | 21 |
|
22 | 22 | context 'when a child entity is empty' do |
23 | | - it 'class_kit_attributes are avaiable' do |
| 23 | + it 'class_kit_attributes are available' do |
24 | 24 | expect{ empty_child_entity.base1 }.not_to raise_error |
25 | 25 | end |
26 | 26 | end |
|
35 | 35 | expect(test_entity.int).to be 10 |
36 | 36 | end |
37 | 37 | end |
| 38 | + |
38 | 39 | context 'when an attribute is NOT allowed to be nil' do |
39 | 40 | context 'when attempting to set the value to nil' do |
40 | 41 | it 'should raise an invalid attribute value error' do |
41 | 42 | expect{ test_entity.int = nil }.to raise_error(ClassKit::Exceptions::InvalidAttributeValueError) |
42 | 43 | end |
43 | 44 | end |
44 | 45 | end |
| 46 | + |
45 | 47 | context 'when an attribute is allowed to be nil' do |
46 | 48 | it 'should not raise an error when setting to nil' do |
47 | 49 | expect{ test_entity.int_nil = nil }.not_to raise_error |
|
57 | 59 | expect(test_entity.int).to eq(20) |
58 | 60 | end |
59 | 61 | end |
| 62 | + |
60 | 63 | context 'from a string' do |
61 | 64 | context 'that can be parsed' do |
62 | 65 | it 'should parse and set the value' do |
63 | 66 | expect{ test_entity.int = '20' }.not_to raise_error |
64 | 67 | expect(test_entity.int).to eq(20) |
65 | 68 | end |
66 | 69 | end |
| 70 | + |
67 | 71 | context 'that can NOT be parsed' do |
68 | 72 | it 'should raise an error' do |
69 | 73 | expect{ test_entity.int = 'ABC' }.to raise_error(ClassKit::Exceptions::InvalidAttributeValueError) |
|
81 | 85 | expect(test_entity.float).to eq(0.05) |
82 | 86 | end |
83 | 87 | end |
| 88 | + |
84 | 89 | context 'from a string' do |
85 | 90 | context 'that can be parsed' do |
86 | 91 | it 'should parse and set the value' do |
87 | 92 | expect{ test_entity.float = '0.05' }.not_to raise_error |
88 | 93 | expect(test_entity.float).to eq(0.05) |
89 | 94 | end |
90 | 95 | end |
| 96 | + |
91 | 97 | context 'that can NOT be parsed' do |
92 | 98 | it 'should raise an error' do |
93 | 99 | expect{ test_entity.float = 'ABC' }.to raise_error(ClassKit::Exceptions::InvalidAttributeValueError) |
|
106 | 112 | expect(test_entity.date).to eq(date) |
107 | 113 | end |
108 | 114 | end |
| 115 | + |
109 | 116 | context 'from a string' do |
110 | 117 | context 'that can be parsed' do |
111 | 118 | let(:date) { Date.today } |
|
114 | 121 | expect(test_entity.date).to eq(date) |
115 | 122 | end |
116 | 123 | end |
| 124 | + |
117 | 125 | context 'that can NOT be parsed' do |
118 | 126 | it 'should raise an error' do |
119 | 127 | expect{ test_entity.date = 'ABC' }.to raise_error(ClassKit::Exceptions::InvalidAttributeValueError) |
|
132 | 140 | expect(test_entity.datetime).to eq(datetime) |
133 | 141 | end |
134 | 142 | end |
| 143 | + |
135 | 144 | context 'from a string' do |
136 | 145 | context 'that can be parsed' do |
137 | 146 | let(:datetime) { DateTime.now } |
|
140 | 149 | expect(test_entity.datetime).to eq(datetime) |
141 | 150 | end |
142 | 151 | end |
| 152 | + |
143 | 153 | context 'that can NOT be parsed' do |
144 | 154 | it 'should raise an error' do |
145 | 155 | expect{ test_entity.datetime = 'ABC' }.to raise_error(ClassKit::Exceptions::InvalidAttributeValueError) |
|
158 | 168 | expect(test_entity.time).to eq(time) |
159 | 169 | end |
160 | 170 | end |
| 171 | + |
161 | 172 | context 'from an integer' do |
162 | 173 | let(:time) { Time.now } |
163 | 174 | it 'should set the value' do |
164 | 175 | expect{ test_entity.time = time.to_i }.not_to raise_error |
165 | 176 | expect(test_entity.time.to_i).to eq(time.to_i) |
166 | 177 | end |
167 | 178 | end |
| 179 | + |
168 | 180 | context 'from a float' do |
169 | 181 | let(:time) { Time.now } |
170 | 182 | it 'should set the value' do |
171 | 183 | expect{ test_entity.time = time.to_f }.not_to raise_error |
172 | 184 | expect(test_entity.time.to_f).to eq(time.to_f) |
173 | 185 | end |
174 | 186 | end |
| 187 | + |
175 | 188 | context 'from a string' do |
176 | 189 | context 'that can be parsed' do |
177 | 190 | let(:time) { Time.now } |
|
180 | 193 | expect(test_entity.time).to eq(time) |
181 | 194 | end |
182 | 195 | end |
| 196 | + |
183 | 197 | context 'that can NOT be parsed' do |
184 | 198 | it 'should raise an error' do |
185 | 199 | expect{ test_entity.time = 'ABC' }.to raise_error(ClassKit::Exceptions::InvalidAttributeValueError) |
|
207 | 221 | expect{ test_entity.bool = true }.not_to raise_error |
208 | 222 | expect(test_entity.bool).to eq(true) |
209 | 223 | end |
| 224 | + |
210 | 225 | it 'should set the value to false' do |
211 | 226 | expect{ test_entity.bool = false }.not_to raise_error |
212 | 227 | expect(test_entity.bool).to eq(false) |
213 | 228 | end |
214 | 229 | end |
| 230 | + |
215 | 231 | context 'from a string' do |
216 | 232 | context 'that can be parsed' do |
217 | 233 | it 'should parse and set the value to true' do |
218 | 234 | expect{ test_entity.bool = 'true' }.not_to raise_error |
219 | 235 | expect(test_entity.bool).to eq(true) |
220 | 236 | end |
| 237 | + |
221 | 238 | it 'should parse and set the value to false' do |
222 | 239 | expect{ test_entity.bool = 'false' }.not_to raise_error |
223 | 240 | expect(test_entity.bool).to eq(false) |
224 | 241 | end |
225 | 242 | end |
| 243 | + |
226 | 244 | context 'that can NOT be parsed' do |
227 | 245 | it 'should raise an error' do |
228 | 246 | expect{ test_entity.bool = 'ABC' }.to raise_error(ClassKit::Exceptions::InvalidAttributeValueError) |
|
240 | 258 | end |
241 | 259 | end |
242 | 260 | end |
| 261 | + |
243 | 262 | context 'when allowed to be nil' do |
244 | 263 | it 'should not raise an error when setting to nil' do |
245 | 264 | expect{ test_entity.any_nil = nil }.not_to raise_error |
246 | 265 | expect(test_entity.any_nil).to be nil |
247 | 266 | end |
248 | 267 | end |
| 268 | + |
249 | 269 | it 'should allow any value type to be specified' do |
250 | 270 | expect{ test_entity.any = 'hello' }.not_to raise_error |
251 | 271 | expect{ test_entity.any = 5 }.not_to raise_error |
|
260 | 280 | expect{ test_entity.hash = { key1: 'value1' } }.not_to raise_error |
261 | 281 | end |
262 | 282 | end |
| 283 | + |
263 | 284 | context 'from a String' do |
264 | 285 | it 'should raise an error' do |
265 | 286 | expect{ test_entity.hash = 'ABC' }.to raise_error(ClassKit::Exceptions::InvalidAttributeValueError) |
|
275 | 296 | expect{ test_entity.array = ['value1', 'value2'] }.not_to raise_error |
276 | 297 | end |
277 | 298 | end |
| 299 | + |
278 | 300 | context 'from a String' do |
279 | 301 | it 'should raise an error' do |
280 | 302 | expect{ test_entity.array = 'ABC' }.to raise_error(ClassKit::Exceptions::InvalidAttributeValueError) |
|
283 | 305 | end |
284 | 306 | end |
285 | 307 |
|
| 308 | + context 'one_of attribute specified' do |
| 309 | + context 'when setting the attribute value' do |
| 310 | + context 'from an Array' do |
| 311 | + it 'should set the value' do |
| 312 | + expect{ test_entity.one_of = ['Happy Days'] }.not_to raise_error |
| 313 | + end |
| 314 | + end |
| 315 | + |
| 316 | + context 'from a Hash' do |
| 317 | + it 'should set the value' do |
| 318 | + expect{ test_entity.one_of = { 'some' => 'structured data' } }.not_to raise_error |
| 319 | + end |
| 320 | + end |
| 321 | + |
| 322 | + context 'from boolean' do |
| 323 | + it 'should parse and set the value to false' do |
| 324 | + expect{ test_entity.one_of = 'false' }.not_to raise_error |
| 325 | + expect(test_entity.one_of).to eq(false) |
| 326 | + end |
| 327 | + end |
| 328 | + end |
| 329 | + end |
| 330 | + |
286 | 331 | context 'Class Type attribute specified' do |
287 | 332 | context 'when setting the attribute value' do |
288 | 333 | context 'from a TestAddress' do |
289 | 334 | it 'should set the value' do |
290 | 335 | expect{ test_entity.address = TestAddress.new }.not_to raise_error |
291 | 336 | end |
292 | 337 | end |
| 338 | + |
293 | 339 | context 'from a String' do |
294 | 340 | it 'should raise an error' do |
295 | 341 | expect{ test_entity.address = 'ABC' }.to raise_error(ClassKit::Exceptions::InvalidAttributeValueError) |
296 | 342 | end |
297 | 343 | end |
298 | 344 | end |
| 345 | + |
299 | 346 | context 'when auto_init is true' do |
300 | 347 | context 'and the attribute has not been set' do |
301 | 348 | it 'should return a new instance of the attribute type' do |
|
305 | 352 | end |
306 | 353 | end |
307 | 354 | end |
308 | | - |
309 | 355 | end |
310 | 356 | end |
311 | | - |
312 | | - |
|
0 commit comments