granite-form 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CODEOWNERS +2 -0
  3. data/.rubocop_todo.yml +1 -1
  4. data/CHANGELOG.md +9 -66
  5. data/README.md +53 -51
  6. data/Rakefile +4 -0
  7. data/granite-form.gemspec +1 -0
  8. data/lib/granite/form/config.rb +10 -10
  9. data/lib/granite/form/model/associations/nested_attributes.rb +3 -3
  10. data/lib/granite/form/model/associations/reflections/references_many.rb +3 -1
  11. data/lib/granite/form/model/associations/reflections/references_one.rb +3 -1
  12. data/lib/granite/form/model/attributes/attribute.rb +1 -1
  13. data/lib/granite/form/model/attributes/base.rb +13 -16
  14. data/lib/granite/form/model/attributes/collection.rb +1 -1
  15. data/lib/granite/form/model/attributes/dictionary.rb +1 -1
  16. data/lib/granite/form/model/attributes/localized.rb +1 -1
  17. data/lib/granite/form/model/attributes/reference_many.rb +1 -1
  18. data/lib/granite/form/model/attributes/reference_one.rb +1 -9
  19. data/lib/granite/form/model/attributes/reflections/base.rb +1 -5
  20. data/lib/granite/form/model/attributes/reflections/reference_one.rb +0 -4
  21. data/lib/granite/form/model/representation.rb +1 -1
  22. data/lib/granite/form/model/validations/nested.rb +1 -1
  23. data/lib/granite/form/types/active_support/time_zone.rb +22 -0
  24. data/lib/granite/form/types/array.rb +17 -0
  25. data/lib/granite/form/types/big_decimal.rb +15 -0
  26. data/lib/granite/form/types/boolean.rb +38 -0
  27. data/lib/granite/form/types/date.rb +15 -0
  28. data/lib/granite/form/types/date_time.rb +15 -0
  29. data/lib/granite/form/types/float.rb +15 -0
  30. data/lib/granite/form/types/hash_with_action_controller_parameters.rb +18 -0
  31. data/lib/granite/form/types/integer.rb +13 -0
  32. data/lib/granite/form/types/object.rb +30 -0
  33. data/lib/granite/form/types/string.rb +13 -0
  34. data/lib/granite/form/types/time.rb +15 -0
  35. data/lib/granite/form/types/uuid.rb +22 -0
  36. data/lib/granite/form/types.rb +15 -0
  37. data/lib/granite/form/version.rb +1 -1
  38. data/lib/granite/form.rb +19 -118
  39. data/spec/{lib/granite → granite}/form/active_record/associations_spec.rb +0 -0
  40. data/spec/{lib/granite → granite}/form/active_record/nested_attributes_spec.rb +0 -1
  41. data/spec/{lib/granite → granite}/form/config_spec.rb +22 -10
  42. data/spec/granite/form/extensions_spec.rb +12 -0
  43. data/spec/{lib/granite → granite}/form/model/associations/embeds_many_spec.rb +0 -0
  44. data/spec/{lib/granite → granite}/form/model/associations/embeds_one_spec.rb +0 -0
  45. data/spec/{lib/granite → granite}/form/model/associations/nested_attributes_spec.rb +0 -1
  46. data/spec/{lib/granite → granite}/form/model/associations/persistence_adapters/active_record_spec.rb +0 -0
  47. data/spec/{lib/granite → granite}/form/model/associations/references_many_spec.rb +0 -0
  48. data/spec/{lib/granite → granite}/form/model/associations/references_one_spec.rb +0 -0
  49. data/spec/{lib/granite → granite}/form/model/associations/reflections/embeds_any_spec.rb +0 -0
  50. data/spec/{lib/granite → granite}/form/model/associations/reflections/embeds_many_spec.rb +0 -0
  51. data/spec/{lib/granite → granite}/form/model/associations/reflections/embeds_one_spec.rb +0 -0
  52. data/spec/{lib/granite → granite}/form/model/associations/reflections/references_many_spec.rb +0 -0
  53. data/spec/{lib/granite → granite}/form/model/associations/reflections/references_one_spec.rb +0 -0
  54. data/spec/{lib/granite → granite}/form/model/associations/validations_spec.rb +0 -0
  55. data/spec/{lib/granite → granite}/form/model/associations_spec.rb +0 -0
  56. data/spec/{lib/granite → granite}/form/model/attributes/attribute_spec.rb +4 -46
  57. data/spec/{lib/granite → granite}/form/model/attributes/base_spec.rb +11 -2
  58. data/spec/{lib/granite → granite}/form/model/attributes/collection_spec.rb +0 -0
  59. data/spec/{lib/granite → granite}/form/model/attributes/dictionary_spec.rb +0 -0
  60. data/spec/{lib/granite → granite}/form/model/attributes/localized_spec.rb +1 -1
  61. data/spec/{lib/granite → granite}/form/model/attributes/reflections/attribute_spec.rb +0 -12
  62. data/spec/{lib/granite → granite}/form/model/attributes/reflections/base_spec.rb +1 -1
  63. data/spec/{lib/granite → granite}/form/model/attributes/reflections/collection_spec.rb +0 -0
  64. data/spec/{lib/granite → granite}/form/model/attributes/reflections/dictionary_spec.rb +0 -0
  65. data/spec/{lib/granite → granite}/form/model/attributes/reflections/localized_spec.rb +0 -0
  66. data/spec/{lib/granite → granite}/form/model/attributes/reflections/represents_spec.rb +0 -0
  67. data/spec/{lib/granite → granite}/form/model/attributes/represents_spec.rb +0 -0
  68. data/spec/{lib/granite → granite}/form/model/attributes_spec.rb +0 -0
  69. data/spec/{lib/granite → granite}/form/model/callbacks_spec.rb +0 -0
  70. data/spec/{lib/granite → granite}/form/model/conventions_spec.rb +0 -0
  71. data/spec/{lib/granite → granite}/form/model/dirty_spec.rb +0 -0
  72. data/spec/{lib/granite → granite}/form/model/lifecycle_spec.rb +0 -0
  73. data/spec/{lib/granite → granite}/form/model/persistence_spec.rb +0 -0
  74. data/spec/{lib/granite → granite}/form/model/primary_spec.rb +1 -1
  75. data/spec/{lib/granite → granite}/form/model/representation_spec.rb +14 -2
  76. data/spec/{lib/granite → granite}/form/model/scopes_spec.rb +0 -0
  77. data/spec/{lib/granite → granite}/form/model/validations/associated_spec.rb +0 -0
  78. data/spec/{lib/granite → granite}/form/model/validations/nested_spec.rb +55 -11
  79. data/spec/{lib/granite → granite}/form/model/validations_spec.rb +0 -0
  80. data/spec/{lib/granite → granite}/form/model_spec.rb +0 -0
  81. data/spec/granite/form/types/active_support/time_zone_spec.rb +24 -0
  82. data/spec/granite/form/types/array_spec.rb +13 -0
  83. data/spec/granite/form/types/big_decimal_spec.rb +19 -0
  84. data/spec/granite/form/types/boolean_spec.rb +21 -0
  85. data/spec/granite/form/types/date_spec.rb +18 -0
  86. data/spec/granite/form/types/date_time_spec.rb +20 -0
  87. data/spec/granite/form/types/float_spec.rb +19 -0
  88. data/spec/granite/form/types/hash_with_action_controller_parameters_spec.rb +22 -0
  89. data/spec/granite/form/types/integer_spec.rb +18 -0
  90. data/spec/granite/form/types/object_spec.rb +40 -0
  91. data/spec/granite/form/types/string_spec.rb +13 -0
  92. data/spec/granite/form/types/time_spec.rb +31 -0
  93. data/spec/granite/form/types/uuid_spec.rb +21 -0
  94. data/spec/{lib/granite → granite}/form_spec.rb +0 -0
  95. data/spec/spec_helper.rb +1 -2
  96. data/spec/{shared → support/shared}/nested_attribute_examples.rb +0 -0
  97. data/spec/support/shared/type_examples.rb +7 -0
  98. data/spec/support/translations.rb +6 -0
  99. metadata +150 -91
  100. data/spec/lib/granite/form/model/typecasting_spec.rb +0 -193
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: granite-form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pyromaniac
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-21 00:00:00.000000000 Z
11
+ date: 2022-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bump
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: database_cleaner
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -200,6 +214,7 @@ extensions: []
200
214
  extra_rdoc_files: []
201
215
  files:
202
216
  - ".codeclimate.yml"
217
+ - ".github/CODEOWNERS"
203
218
  - ".github/workflows/ci.yml"
204
219
  - ".github/workflows/main.yml"
205
220
  - ".gitignore"
@@ -282,55 +297,84 @@ files:
282
297
  - lib/granite/form/model/validations/associated.rb
283
298
  - lib/granite/form/model/validations/nested.rb
284
299
  - lib/granite/form/railtie.rb
300
+ - lib/granite/form/types.rb
301
+ - lib/granite/form/types/active_support/time_zone.rb
302
+ - lib/granite/form/types/array.rb
303
+ - lib/granite/form/types/big_decimal.rb
304
+ - lib/granite/form/types/boolean.rb
305
+ - lib/granite/form/types/date.rb
306
+ - lib/granite/form/types/date_time.rb
307
+ - lib/granite/form/types/float.rb
308
+ - lib/granite/form/types/hash_with_action_controller_parameters.rb
309
+ - lib/granite/form/types/integer.rb
310
+ - lib/granite/form/types/object.rb
311
+ - lib/granite/form/types/string.rb
312
+ - lib/granite/form/types/time.rb
313
+ - lib/granite/form/types/uuid.rb
285
314
  - lib/granite/form/undefined_class.rb
286
315
  - lib/granite/form/version.rb
287
- - spec/lib/granite/form/active_record/associations_spec.rb
288
- - spec/lib/granite/form/active_record/nested_attributes_spec.rb
289
- - spec/lib/granite/form/config_spec.rb
290
- - spec/lib/granite/form/model/associations/embeds_many_spec.rb
291
- - spec/lib/granite/form/model/associations/embeds_one_spec.rb
292
- - spec/lib/granite/form/model/associations/nested_attributes_spec.rb
293
- - spec/lib/granite/form/model/associations/persistence_adapters/active_record_spec.rb
294
- - spec/lib/granite/form/model/associations/references_many_spec.rb
295
- - spec/lib/granite/form/model/associations/references_one_spec.rb
296
- - spec/lib/granite/form/model/associations/reflections/embeds_any_spec.rb
297
- - spec/lib/granite/form/model/associations/reflections/embeds_many_spec.rb
298
- - spec/lib/granite/form/model/associations/reflections/embeds_one_spec.rb
299
- - spec/lib/granite/form/model/associations/reflections/references_many_spec.rb
300
- - spec/lib/granite/form/model/associations/reflections/references_one_spec.rb
301
- - spec/lib/granite/form/model/associations/validations_spec.rb
302
- - spec/lib/granite/form/model/associations_spec.rb
303
- - spec/lib/granite/form/model/attributes/attribute_spec.rb
304
- - spec/lib/granite/form/model/attributes/base_spec.rb
305
- - spec/lib/granite/form/model/attributes/collection_spec.rb
306
- - spec/lib/granite/form/model/attributes/dictionary_spec.rb
307
- - spec/lib/granite/form/model/attributes/localized_spec.rb
308
- - spec/lib/granite/form/model/attributes/reflections/attribute_spec.rb
309
- - spec/lib/granite/form/model/attributes/reflections/base_spec.rb
310
- - spec/lib/granite/form/model/attributes/reflections/collection_spec.rb
311
- - spec/lib/granite/form/model/attributes/reflections/dictionary_spec.rb
312
- - spec/lib/granite/form/model/attributes/reflections/localized_spec.rb
313
- - spec/lib/granite/form/model/attributes/reflections/represents_spec.rb
314
- - spec/lib/granite/form/model/attributes/represents_spec.rb
315
- - spec/lib/granite/form/model/attributes_spec.rb
316
- - spec/lib/granite/form/model/callbacks_spec.rb
317
- - spec/lib/granite/form/model/conventions_spec.rb
318
- - spec/lib/granite/form/model/dirty_spec.rb
319
- - spec/lib/granite/form/model/lifecycle_spec.rb
320
- - spec/lib/granite/form/model/persistence_spec.rb
321
- - spec/lib/granite/form/model/primary_spec.rb
322
- - spec/lib/granite/form/model/representation_spec.rb
323
- - spec/lib/granite/form/model/scopes_spec.rb
324
- - spec/lib/granite/form/model/typecasting_spec.rb
325
- - spec/lib/granite/form/model/validations/associated_spec.rb
326
- - spec/lib/granite/form/model/validations/nested_spec.rb
327
- - spec/lib/granite/form/model/validations_spec.rb
328
- - spec/lib/granite/form/model_spec.rb
329
- - spec/lib/granite/form_spec.rb
330
- - spec/shared/nested_attribute_examples.rb
316
+ - spec/granite/form/active_record/associations_spec.rb
317
+ - spec/granite/form/active_record/nested_attributes_spec.rb
318
+ - spec/granite/form/config_spec.rb
319
+ - spec/granite/form/extensions_spec.rb
320
+ - spec/granite/form/model/associations/embeds_many_spec.rb
321
+ - spec/granite/form/model/associations/embeds_one_spec.rb
322
+ - spec/granite/form/model/associations/nested_attributes_spec.rb
323
+ - spec/granite/form/model/associations/persistence_adapters/active_record_spec.rb
324
+ - spec/granite/form/model/associations/references_many_spec.rb
325
+ - spec/granite/form/model/associations/references_one_spec.rb
326
+ - spec/granite/form/model/associations/reflections/embeds_any_spec.rb
327
+ - spec/granite/form/model/associations/reflections/embeds_many_spec.rb
328
+ - spec/granite/form/model/associations/reflections/embeds_one_spec.rb
329
+ - spec/granite/form/model/associations/reflections/references_many_spec.rb
330
+ - spec/granite/form/model/associations/reflections/references_one_spec.rb
331
+ - spec/granite/form/model/associations/validations_spec.rb
332
+ - spec/granite/form/model/associations_spec.rb
333
+ - spec/granite/form/model/attributes/attribute_spec.rb
334
+ - spec/granite/form/model/attributes/base_spec.rb
335
+ - spec/granite/form/model/attributes/collection_spec.rb
336
+ - spec/granite/form/model/attributes/dictionary_spec.rb
337
+ - spec/granite/form/model/attributes/localized_spec.rb
338
+ - spec/granite/form/model/attributes/reflections/attribute_spec.rb
339
+ - spec/granite/form/model/attributes/reflections/base_spec.rb
340
+ - spec/granite/form/model/attributes/reflections/collection_spec.rb
341
+ - spec/granite/form/model/attributes/reflections/dictionary_spec.rb
342
+ - spec/granite/form/model/attributes/reflections/localized_spec.rb
343
+ - spec/granite/form/model/attributes/reflections/represents_spec.rb
344
+ - spec/granite/form/model/attributes/represents_spec.rb
345
+ - spec/granite/form/model/attributes_spec.rb
346
+ - spec/granite/form/model/callbacks_spec.rb
347
+ - spec/granite/form/model/conventions_spec.rb
348
+ - spec/granite/form/model/dirty_spec.rb
349
+ - spec/granite/form/model/lifecycle_spec.rb
350
+ - spec/granite/form/model/persistence_spec.rb
351
+ - spec/granite/form/model/primary_spec.rb
352
+ - spec/granite/form/model/representation_spec.rb
353
+ - spec/granite/form/model/scopes_spec.rb
354
+ - spec/granite/form/model/validations/associated_spec.rb
355
+ - spec/granite/form/model/validations/nested_spec.rb
356
+ - spec/granite/form/model/validations_spec.rb
357
+ - spec/granite/form/model_spec.rb
358
+ - spec/granite/form/types/active_support/time_zone_spec.rb
359
+ - spec/granite/form/types/array_spec.rb
360
+ - spec/granite/form/types/big_decimal_spec.rb
361
+ - spec/granite/form/types/boolean_spec.rb
362
+ - spec/granite/form/types/date_spec.rb
363
+ - spec/granite/form/types/date_time_spec.rb
364
+ - spec/granite/form/types/float_spec.rb
365
+ - spec/granite/form/types/hash_with_action_controller_parameters_spec.rb
366
+ - spec/granite/form/types/integer_spec.rb
367
+ - spec/granite/form/types/object_spec.rb
368
+ - spec/granite/form/types/string_spec.rb
369
+ - spec/granite/form/types/time_spec.rb
370
+ - spec/granite/form/types/uuid_spec.rb
371
+ - spec/granite/form_spec.rb
331
372
  - spec/spec_helper.rb
332
373
  - spec/support/model_helpers.rb
333
374
  - spec/support/muffle_helper.rb
375
+ - spec/support/shared/nested_attribute_examples.rb
376
+ - spec/support/shared/type_examples.rb
377
+ - spec/support/translations.rb
334
378
  homepage: ''
335
379
  licenses: []
336
380
  metadata: {}
@@ -349,55 +393,70 @@ required_rubygems_version: !ruby/object:Gem::Requirement
349
393
  - !ruby/object:Gem::Version
350
394
  version: '0'
351
395
  requirements: []
352
- rubygems_version: 3.2.33
396
+ rubygems_version: 3.3.26
353
397
  signing_key:
354
398
  specification_version: 4
355
399
  summary: Working with hashes in AR style
356
400
  test_files:
357
- - spec/lib/granite/form/active_record/associations_spec.rb
358
- - spec/lib/granite/form/active_record/nested_attributes_spec.rb
359
- - spec/lib/granite/form/config_spec.rb
360
- - spec/lib/granite/form/model/associations/embeds_many_spec.rb
361
- - spec/lib/granite/form/model/associations/embeds_one_spec.rb
362
- - spec/lib/granite/form/model/associations/nested_attributes_spec.rb
363
- - spec/lib/granite/form/model/associations/persistence_adapters/active_record_spec.rb
364
- - spec/lib/granite/form/model/associations/references_many_spec.rb
365
- - spec/lib/granite/form/model/associations/references_one_spec.rb
366
- - spec/lib/granite/form/model/associations/reflections/embeds_any_spec.rb
367
- - spec/lib/granite/form/model/associations/reflections/embeds_many_spec.rb
368
- - spec/lib/granite/form/model/associations/reflections/embeds_one_spec.rb
369
- - spec/lib/granite/form/model/associations/reflections/references_many_spec.rb
370
- - spec/lib/granite/form/model/associations/reflections/references_one_spec.rb
371
- - spec/lib/granite/form/model/associations/validations_spec.rb
372
- - spec/lib/granite/form/model/associations_spec.rb
373
- - spec/lib/granite/form/model/attributes/attribute_spec.rb
374
- - spec/lib/granite/form/model/attributes/base_spec.rb
375
- - spec/lib/granite/form/model/attributes/collection_spec.rb
376
- - spec/lib/granite/form/model/attributes/dictionary_spec.rb
377
- - spec/lib/granite/form/model/attributes/localized_spec.rb
378
- - spec/lib/granite/form/model/attributes/reflections/attribute_spec.rb
379
- - spec/lib/granite/form/model/attributes/reflections/base_spec.rb
380
- - spec/lib/granite/form/model/attributes/reflections/collection_spec.rb
381
- - spec/lib/granite/form/model/attributes/reflections/dictionary_spec.rb
382
- - spec/lib/granite/form/model/attributes/reflections/localized_spec.rb
383
- - spec/lib/granite/form/model/attributes/reflections/represents_spec.rb
384
- - spec/lib/granite/form/model/attributes/represents_spec.rb
385
- - spec/lib/granite/form/model/attributes_spec.rb
386
- - spec/lib/granite/form/model/callbacks_spec.rb
387
- - spec/lib/granite/form/model/conventions_spec.rb
388
- - spec/lib/granite/form/model/dirty_spec.rb
389
- - spec/lib/granite/form/model/lifecycle_spec.rb
390
- - spec/lib/granite/form/model/persistence_spec.rb
391
- - spec/lib/granite/form/model/primary_spec.rb
392
- - spec/lib/granite/form/model/representation_spec.rb
393
- - spec/lib/granite/form/model/scopes_spec.rb
394
- - spec/lib/granite/form/model/typecasting_spec.rb
395
- - spec/lib/granite/form/model/validations/associated_spec.rb
396
- - spec/lib/granite/form/model/validations/nested_spec.rb
397
- - spec/lib/granite/form/model/validations_spec.rb
398
- - spec/lib/granite/form/model_spec.rb
399
- - spec/lib/granite/form_spec.rb
400
- - spec/shared/nested_attribute_examples.rb
401
+ - spec/granite/form/active_record/associations_spec.rb
402
+ - spec/granite/form/active_record/nested_attributes_spec.rb
403
+ - spec/granite/form/config_spec.rb
404
+ - spec/granite/form/extensions_spec.rb
405
+ - spec/granite/form/model/associations/embeds_many_spec.rb
406
+ - spec/granite/form/model/associations/embeds_one_spec.rb
407
+ - spec/granite/form/model/associations/nested_attributes_spec.rb
408
+ - spec/granite/form/model/associations/persistence_adapters/active_record_spec.rb
409
+ - spec/granite/form/model/associations/references_many_spec.rb
410
+ - spec/granite/form/model/associations/references_one_spec.rb
411
+ - spec/granite/form/model/associations/reflections/embeds_any_spec.rb
412
+ - spec/granite/form/model/associations/reflections/embeds_many_spec.rb
413
+ - spec/granite/form/model/associations/reflections/embeds_one_spec.rb
414
+ - spec/granite/form/model/associations/reflections/references_many_spec.rb
415
+ - spec/granite/form/model/associations/reflections/references_one_spec.rb
416
+ - spec/granite/form/model/associations/validations_spec.rb
417
+ - spec/granite/form/model/associations_spec.rb
418
+ - spec/granite/form/model/attributes/attribute_spec.rb
419
+ - spec/granite/form/model/attributes/base_spec.rb
420
+ - spec/granite/form/model/attributes/collection_spec.rb
421
+ - spec/granite/form/model/attributes/dictionary_spec.rb
422
+ - spec/granite/form/model/attributes/localized_spec.rb
423
+ - spec/granite/form/model/attributes/reflections/attribute_spec.rb
424
+ - spec/granite/form/model/attributes/reflections/base_spec.rb
425
+ - spec/granite/form/model/attributes/reflections/collection_spec.rb
426
+ - spec/granite/form/model/attributes/reflections/dictionary_spec.rb
427
+ - spec/granite/form/model/attributes/reflections/localized_spec.rb
428
+ - spec/granite/form/model/attributes/reflections/represents_spec.rb
429
+ - spec/granite/form/model/attributes/represents_spec.rb
430
+ - spec/granite/form/model/attributes_spec.rb
431
+ - spec/granite/form/model/callbacks_spec.rb
432
+ - spec/granite/form/model/conventions_spec.rb
433
+ - spec/granite/form/model/dirty_spec.rb
434
+ - spec/granite/form/model/lifecycle_spec.rb
435
+ - spec/granite/form/model/persistence_spec.rb
436
+ - spec/granite/form/model/primary_spec.rb
437
+ - spec/granite/form/model/representation_spec.rb
438
+ - spec/granite/form/model/scopes_spec.rb
439
+ - spec/granite/form/model/validations/associated_spec.rb
440
+ - spec/granite/form/model/validations/nested_spec.rb
441
+ - spec/granite/form/model/validations_spec.rb
442
+ - spec/granite/form/model_spec.rb
443
+ - spec/granite/form/types/active_support/time_zone_spec.rb
444
+ - spec/granite/form/types/array_spec.rb
445
+ - spec/granite/form/types/big_decimal_spec.rb
446
+ - spec/granite/form/types/boolean_spec.rb
447
+ - spec/granite/form/types/date_spec.rb
448
+ - spec/granite/form/types/date_time_spec.rb
449
+ - spec/granite/form/types/float_spec.rb
450
+ - spec/granite/form/types/hash_with_action_controller_parameters_spec.rb
451
+ - spec/granite/form/types/integer_spec.rb
452
+ - spec/granite/form/types/object_spec.rb
453
+ - spec/granite/form/types/string_spec.rb
454
+ - spec/granite/form/types/time_spec.rb
455
+ - spec/granite/form/types/uuid_spec.rb
456
+ - spec/granite/form_spec.rb
401
457
  - spec/spec_helper.rb
402
458
  - spec/support/model_helpers.rb
403
459
  - spec/support/muffle_helper.rb
460
+ - spec/support/shared/nested_attribute_examples.rb
461
+ - spec/support/shared/type_examples.rb
462
+ - spec/support/translations.rb
@@ -1,193 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Granite::Form::Model::Attributes do
4
- subject { model.new }
5
-
6
- context 'object' do
7
- before { stub_class(:descendant) }
8
- let(:model) { stub_model { attribute :column, Object } }
9
-
10
- specify { expect(model.new(column: 'hello').column).to eq('hello') }
11
- specify { expect(model.new(column: []).column).to eq([]) }
12
- specify { expect(model.new(column: Descendant.new).column).to be_a(Descendant) }
13
- specify { expect(model.new(column: Object.new).column).to be_a(Object) }
14
- specify { expect(model.new(column: nil).column).to be_nil }
15
-
16
- context do
17
- before { stub_class(:descendant2, Descendant) }
18
- let(:model) { stub_model { attribute :column, Descendant } }
19
-
20
- specify { expect(model.new(column: 'hello').column).to be_nil }
21
- specify { expect(model.new(column: []).column).to be_nil }
22
- specify { expect(model.new(column: Descendant.new).column).to be_a(Descendant) }
23
- specify { expect(model.new(column: Descendant2.new).column).to be_a(Descendant2) }
24
- specify { expect(model.new(column: Object.new).column).to be_nil }
25
- specify { expect(model.new(column: nil).column).to be_nil }
26
- end
27
- end
28
-
29
- context 'string' do
30
- let(:model) { stub_model { attribute :column, String } }
31
-
32
- specify { expect(model.new(column: 'hello').column).to eq('hello') }
33
- specify { expect(model.new(column: 123).column).to eq('123') }
34
- specify { expect(model.new(column: nil).column).to be_nil }
35
- end
36
-
37
- context 'integer' do
38
- let(:model) { stub_model { attribute :column, Integer } }
39
-
40
- specify { expect(model.new(column: 'hello').column).to be_nil }
41
- specify { expect(model.new(column: '123hello').column).to be_nil }
42
- specify { expect(model.new(column: '123').column).to eq(123) }
43
- specify { expect(model.new(column: '123.5').column).to eq(123) }
44
- specify { expect(model.new(column: 123).column).to eq(123) }
45
- specify { expect(model.new(column: 123.5).column).to eq(123) }
46
- specify { expect(model.new(column: nil).column).to be_nil }
47
- specify { expect(model.new(column: [123]).column).to be_nil }
48
- end
49
-
50
- context 'float' do
51
- let(:model) { stub_model { attribute :column, Float } }
52
-
53
- specify { expect(model.new(column: 'hello').column).to be_nil }
54
- specify { expect(model.new(column: '123hello').column).to be_nil }
55
- specify { expect(model.new(column: '123').column).to eq(123.0) }
56
- specify { expect(model.new(column: '123.').column).to be_nil }
57
- specify { expect(model.new(column: '123.5').column).to eq(123.5) }
58
- specify { expect(model.new(column: 123).column).to eq(123.0) }
59
- specify { expect(model.new(column: 123.5).column).to eq(123.5) }
60
- specify { expect(model.new(column: nil).column).to be_nil }
61
- specify { expect(model.new(column: [123.5]).column).to be_nil }
62
- end
63
-
64
- context 'big_decimal' do
65
- let(:model) { stub_model { attribute :column, BigDecimal } }
66
-
67
- specify { expect(model.new(column: 'hello').column).to be_nil }
68
- specify { expect(model.new(column: '123hello').column).to be_nil }
69
- specify { expect(model.new(column: '123').column).to eq(BigDecimal('123.0')) }
70
- specify { expect(model.new(column: '123.').column).to be_nil }
71
- specify { expect(model.new(column: '123.5').column).to eq(BigDecimal('123.5')) }
72
- specify { expect(model.new(column: 123).column).to eq(BigDecimal('123.0')) }
73
- specify { expect(model.new(column: 123.5).column).to eq(BigDecimal('123.5')) }
74
- specify { expect(model.new(column: nil).column).to be_nil }
75
- specify { expect(model.new(column: [123.5]).column).to be_nil }
76
- end
77
-
78
- context 'boolean' do
79
- let(:model) { stub_model { attribute :column, Boolean } }
80
-
81
- specify { expect(model.new(column: 'hello').column).to be_nil }
82
- specify { expect(model.new(column: 'true').column).to eq(true) }
83
- specify { expect(model.new(column: 'false').column).to eq(false) }
84
- specify { expect(model.new(column: '1').column).to eq(true) }
85
- specify { expect(model.new(column: '0').column).to eq(false) }
86
- specify { expect(model.new(column: true).column).to eq(true) }
87
- specify { expect(model.new(column: false).column).to eq(false) }
88
- specify { expect(model.new(column: 1).column).to eq(true) }
89
- specify { expect(model.new(column: 0).column).to eq(false) }
90
- specify { expect(model.new(column: nil).column).to be_nil }
91
- specify { expect(model.new(column: [123]).column).to be_nil }
92
- end
93
-
94
- context 'array' do
95
- let(:model) { stub_model { attribute :column, Array } }
96
-
97
- specify { expect(model.new(column: [1, 2, 3]).column).to eq([1, 2, 3]) }
98
- specify { expect(model.new(column: 'hello, world').column).to eq(%w[hello world]) }
99
- specify { expect(model.new(column: 10).column).to be_nil }
100
- end
101
-
102
- # rubocop:disable Style/DateTime
103
- context 'date' do
104
- let(:model) { stub_model { attribute :column, Date } }
105
- let(:date) { Date.new(2013, 6, 13) }
106
-
107
- specify { expect(model.new(column: nil).column).to be_nil }
108
- specify { expect(model.new(column: '2013-06-13').column).to eq(date) }
109
- specify { expect(model.new(column: '2013-55-55').column).to be_nil }
110
- specify { expect(model.new(column: 'blablabla').column).to be_nil }
111
- specify { expect(model.new(column: DateTime.new(2013, 6, 13, 23, 13)).column).to eq(date) }
112
- specify { expect(model.new(column: Time.new(2013, 6, 13, 23, 13)).column).to eq(date) }
113
- specify { expect(model.new(column: Date.new(2013, 6, 13)).column).to eq(date) }
114
- end
115
-
116
- context 'datetime' do
117
- let(:model) { stub_model { attribute :column, DateTime } }
118
- let(:datetime) { DateTime.new(2013, 6, 13, 23, 13) }
119
-
120
- specify { expect(model.new(column: nil).column).to be_nil }
121
- specify { expect(model.new(column: '2013-06-13 23:13').column).to eq(datetime) }
122
- specify { expect(model.new(column: '2013-55-55 55:55').column).to be_nil }
123
- specify { expect(model.new(column: 'blablabla').column).to be_nil }
124
- specify { expect(model.new(column: Date.new(2013, 6, 13)).column).to eq(DateTime.new(2013, 6, 13, 0, 0)) }
125
- specify { expect(model.new(column: Time.utc(2013, 6, 13, 23, 13).utc).column).to eq(DateTime.new(2013, 6, 13, 23, 13)) }
126
- specify { expect(model.new(column: DateTime.new(2013, 6, 13, 23, 13)).column).to eq(DateTime.new(2013, 6, 13, 23, 13)) }
127
- end
128
-
129
- context 'time' do
130
- let(:model) { stub_model { attribute :column, Time } }
131
-
132
- specify { expect(model.new(column: nil).column).to be_nil }
133
- specify { expect(model.new(column: '2013-06-13 23:13').column).to eq('2013-06-13 23:13'.to_time) }
134
- specify { expect(model.new(column: '2013-55-55 55:55').column).to be_nil }
135
- specify { expect(model.new(column: 'blablabla').column).to be_nil }
136
- specify { expect(model.new(column: Date.new(2013, 6, 13)).column).to eq(Time.new(2013, 6, 13, 0, 0)) }
137
- specify { expect(model.new(column: DateTime.new(2013, 6, 13, 19, 13)).column).to eq(DateTime.new(2013, 6, 13, 19, 13).to_time) }
138
- specify { expect(model.new(column: Time.new(2013, 6, 13, 23, 13)).column).to eq(Time.new(2013, 6, 13, 23, 13)) }
139
-
140
- context 'Time.zone set' do
141
- around { |example| Time.use_zone('Bangkok', &example) }
142
-
143
- specify { expect(model.new(column: nil).column).to be_nil }
144
- specify { expect(model.new(column: '2013-06-13 23:13').column).to eq(Time.zone.parse('2013-06-13 23:13')) }
145
- specify { expect(model.new(column: '2013-55-55 55:55').column).to be_nil }
146
- specify { expect(model.new(column: 'blablabla').column).to be_nil }
147
- specify { expect(model.new(column: Date.new(2013, 6, 13)).column).to eq(Time.new(2013, 6, 13, 0, 0)) }
148
- specify { expect(model.new(column: DateTime.new(2013, 6, 13, 19, 13)).column).to eq(DateTime.new(2013, 6, 13, 19, 13).to_time) }
149
- specify { expect(model.new(column: Time.new(2013, 6, 13, 23, 13)).column).to eq(Time.new(2013, 6, 13, 23, 13)) }
150
- end
151
- end
152
- # rubocop:enable Style/DateTime
153
-
154
- context 'time_zone' do
155
- let(:model) { stub_model { attribute :column, ActiveSupport::TimeZone } }
156
-
157
- specify { expect(model.new(column: nil).column).to be_nil }
158
- specify { expect(model.new(column: Object.new).column).to be_nil }
159
- specify { expect(model.new(column: Time.now).column).to be_nil }
160
- specify { expect(model.new(column: 'blablabla').column).to be_nil }
161
- specify { expect(model.new(column: TZInfo::Timezone.all.first).column).to be_a ActiveSupport::TimeZone }
162
- specify { expect(model.new(column: 'Moscow').column).to be_a ActiveSupport::TimeZone }
163
- specify { expect(model.new(column: '+4').column).to be_a ActiveSupport::TimeZone }
164
- specify { expect(model.new(column: '-3').column).to be_a ActiveSupport::TimeZone }
165
- specify { expect(model.new(column: '3600').column).to be_a ActiveSupport::TimeZone }
166
- specify { expect(model.new(column: '-7200').column).to be_a ActiveSupport::TimeZone }
167
- specify { expect(model.new(column: 4).column).to be_a ActiveSupport::TimeZone }
168
- specify { expect(model.new(column: -3).column).to be_a ActiveSupport::TimeZone }
169
- specify { expect(model.new(column: 3600).column).to be_a ActiveSupport::TimeZone }
170
- specify { expect(model.new(column: -7200).column).to be_a ActiveSupport::TimeZone }
171
- end
172
-
173
- context 'uuid' do
174
- let(:model) { stub_model { attribute :column, Granite::Form::UUID } }
175
- let(:uuid) { Granite::Form::UUID.random_create }
176
- let(:uuid_tools) { UUIDTools::UUID.random_create }
177
-
178
- specify { expect(uuid.as_json).to eq(uuid.to_s) }
179
- specify { expect(uuid.to_json).to eq("\"#{uuid}\"") }
180
- specify { expect(uuid.to_param).to eq(uuid.to_s) }
181
- specify { expect(uuid.to_query(:key)).to eq("key=#{uuid}") }
182
-
183
- specify { expect(model.new(column: nil).column).to be_nil }
184
- specify { expect(model.new(column: Object.new).column).to be_nil }
185
- specify { expect(model.new(column: uuid_tools).column).to be_a Granite::Form::UUID }
186
- specify { expect(model.new(column: uuid_tools).column).to eq(uuid_tools) }
187
- specify { expect(model.new(column: uuid).column).to eq(uuid) }
188
- specify { expect(model.new(column: uuid.to_s).column).to eq(uuid) }
189
- specify { expect(model.new(column: uuid.to_i).column).to eq(uuid) }
190
- specify { expect(model.new(column: uuid.hexdigest).column).to eq(uuid) }
191
- specify { expect(model.new(column: uuid.raw).column).to eq(uuid) }
192
- end
193
- end