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
@@ -27,7 +27,7 @@ module Granite
27
27
  end
28
28
 
29
29
  def build_attribute(owner, raw_value = Granite::Form::UNDEFINED)
30
- attribute = self.class.attribute_class.new(name, owner)
30
+ attribute = self.class.attribute_class.new(self, owner)
31
31
  attribute.write_value(raw_value, origin: :persistence) unless raw_value == Granite::Form::UNDEFINED
32
32
  attribute
33
33
  end
@@ -43,10 +43,6 @@ module Granite
43
43
  end
44
44
  end
45
45
 
46
- def typecaster
47
- @typecaster ||= Granite::Form.typecaster(type.ancestors.grep(Class))
48
- end
49
-
50
46
  def readonly
51
47
  @readonly ||= options[:readonly]
52
48
  end
@@ -30,10 +30,6 @@ module Granite
30
30
  RUBY
31
31
  end
32
32
 
33
- def type
34
- Object
35
- end
36
-
37
33
  def inspect_reflection
38
34
  "#{name}: (reference)"
39
35
  end
@@ -79,7 +79,7 @@ module Granite
79
79
  errors.where(from).each do |error|
80
80
  options = error.options
81
81
  # If we generate message for built-in validation, we don't want to later escape it in our monkey-patch
82
- options = options.merge(message: error.message.html_safe) unless options.key?(:message)
82
+ options = options.merge(message: error.message.html_safe)
83
83
 
84
84
  errors.add(to, error.type, **options)
85
85
  end
@@ -19,7 +19,7 @@ module Granite
19
19
  def self.import_errors(from, to, prefix)
20
20
  from.each do |error|
21
21
  key = "#{prefix}.#{error.attribute}"
22
- to.import(error, attribute: key) unless to.added?(key, error.type, error.options)
22
+ to.import(error, attribute: key) unless to.messages_for(key).include?(error.message)
23
23
  end
24
24
  end
25
25
  else
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Granite
4
+ module Form
5
+ module Types
6
+ module ActiveSupport
7
+ class TimeZone < Float
8
+ def typecast(value)
9
+ case value
10
+ when ::ActiveSupport::TimeZone
11
+ value
12
+ when ::TZInfo::Timezone
13
+ ::ActiveSupport::TimeZone[value.name]
14
+ when ::String, ::Numeric, ::ActiveSupport::Duration
15
+ ::ActiveSupport::TimeZone[super || value]
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Granite
4
+ module Form
5
+ module Types
6
+ class Array < Object
7
+ def typecast(value)
8
+ if value.is_a?(::String)
9
+ value.split(',').map(&:strip)
10
+ else
11
+ super
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Granite
4
+ module Form
5
+ module Types
6
+ class BigDecimal < Object
7
+ def typecast(value)
8
+ BigDecimal(Float(value).to_s) if value
9
+ rescue ArgumentError, TypeError
10
+ nil
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Granite
4
+ module Form
5
+ module Types
6
+ class Boolean < Object
7
+ MAPPING = {
8
+ 1 => true,
9
+ 0 => false,
10
+ '1' => true,
11
+ '0' => false,
12
+ 't' => true,
13
+ 'f' => false,
14
+ 'T' => true,
15
+ 'F' => false,
16
+ true => true,
17
+ false => false,
18
+ 'true' => true,
19
+ 'false' => false,
20
+ 'TRUE' => true,
21
+ 'FALSE' => false,
22
+ 'y' => true,
23
+ 'n' => false,
24
+ 'yes' => true,
25
+ 'no' => false
26
+ }.freeze
27
+
28
+ def self.typecast(value)
29
+ MAPPING[value]
30
+ end
31
+
32
+ def typecast(value)
33
+ self.class.typecast(value)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Granite
4
+ module Form
5
+ module Types
6
+ class Date < Object
7
+ def typecast(value)
8
+ value.try(:to_date)
9
+ rescue ArgumentError
10
+ nil
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Granite
4
+ module Form
5
+ module Types
6
+ class DateTime < Object
7
+ def typecast(value)
8
+ value.try(:to_datetime)
9
+ rescue ArgumentError
10
+ nil
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Granite
4
+ module Form
5
+ module Types
6
+ class Float < Object
7
+ def typecast(value)
8
+ Float(value)
9
+ rescue ArgumentError, TypeError
10
+ nil
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Granite
4
+ module Form
5
+ module Types
6
+ class HashWithActionControllerParameters < Object
7
+ def typecast(value)
8
+ case value
9
+ when ActionController::Parameters
10
+ value.to_h if value.permitted?
11
+ when ::Hash then
12
+ value
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Granite
4
+ module Form
5
+ module Types
6
+ class Integer < Float
7
+ def typecast(value)
8
+ super.try(:to_i)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Granite
4
+ module Form
5
+ module Types
6
+ class Object
7
+ attr_reader :reflection, :owner, :type
8
+ delegate :name, to: :reflection
9
+
10
+ def initialize(type, reflection, owner)
11
+ @type = type
12
+ @reflection = reflection
13
+ @owner = owner
14
+ end
15
+
16
+ def ensure_type(value)
17
+ if value.instance_of?(type)
18
+ value
19
+ elsif !value.nil?
20
+ typecast(value)
21
+ end
22
+ end
23
+
24
+ def typecast(value)
25
+ value if value.is_a?(type)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Granite
4
+ module Form
5
+ module Types
6
+ class String < Object
7
+ def typecast(value)
8
+ value.to_s
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Granite
4
+ module Form
5
+ module Types
6
+ class Time < Object
7
+ def typecast(value)
8
+ value.is_a?(::String) && ::Time.zone ? ::Time.zone.parse(value) : value.try(:to_time)
9
+ rescue ArgumentError
10
+ nil
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Granite
4
+ module Form
5
+ module Types
6
+ class UUID < Object
7
+ def typecast(value)
8
+ case value
9
+ when UUIDTools::UUID
10
+ Granite::Form::UUID.parse_raw value.raw
11
+ when Granite::Form::UUID
12
+ value
13
+ when ::String
14
+ Granite::Form::UUID.parse_string value
15
+ when ::Integer
16
+ Granite::Form::UUID.parse_int value
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'granite/form/types/object'
4
+ require 'granite/form/types/array'
5
+ require 'granite/form/types/big_decimal'
6
+ require 'granite/form/types/boolean'
7
+ require 'granite/form/types/date'
8
+ require 'granite/form/types/date_time'
9
+ require 'granite/form/types/hash_with_action_controller_parameters'
10
+ require 'granite/form/types/float'
11
+ require 'granite/form/types/integer'
12
+ require 'granite/form/types/string'
13
+ require 'granite/form/types/time'
14
+ require 'granite/form/types/uuid'
15
+ require 'granite/form/types/active_support/time_zone'
@@ -1,5 +1,5 @@
1
1
  module Granite
2
2
  module Form
3
- VERSION = '0.1.0'.freeze
3
+ VERSION = '0.2.0'.freeze
4
4
  end
5
5
  end
data/lib/granite/form.rb CHANGED
@@ -11,6 +11,7 @@ require 'granite/form/version'
11
11
  require 'granite/form/errors'
12
12
  require 'granite/form/extensions'
13
13
  require 'granite/form/undefined_class'
14
+ require 'granite/form/types'
14
15
  require 'granite/form/config'
15
16
  require 'granite/form/railtie' if defined? Rails
16
17
  require 'granite/form/model'
@@ -19,130 +20,26 @@ require 'granite/form/model/associations/persistence_adapters/active_record'
19
20
 
20
21
  module Granite
21
22
  module Form
22
- BOOLEAN_MAPPING = {
23
- 1 => true,
24
- 0 => false,
25
- '1' => true,
26
- '0' => false,
27
- 't' => true,
28
- 'f' => false,
29
- 'T' => true,
30
- 'F' => false,
31
- true => true,
32
- false => false,
33
- 'true' => true,
34
- 'false' => false,
35
- 'TRUE' => true,
36
- 'FALSE' => false,
37
- 'y' => true,
38
- 'n' => false,
39
- 'yes' => true,
40
- 'no' => false
41
- }.freeze
42
-
43
23
  def self.config
44
24
  Granite::Form::Config.instance
45
25
  end
46
26
 
47
27
  singleton_class.delegate(*Granite::Form::Config.delegated, to: :config)
48
28
 
49
- typecaster('Object') { |value, attribute| value if value.class < attribute.type }
50
- typecaster('String') { |value, _| value.to_s }
51
- typecaster('Array') do |value|
52
- case value
53
- when ::Array then
54
- value
55
- when ::String then
56
- value.split(',').map(&:strip)
57
- end
58
- end
59
- typecaster('Hash') do |value|
60
- case value
61
- when ::Hash then
62
- value
63
- end
64
- end
65
- ActiveSupport.on_load :action_controller do
66
- Granite::Form.typecaster('Hash') do |value|
67
- case value
68
- when ActionController::Parameters
69
- value.to_h if value.permitted?
70
- when ::Hash then
71
- value
72
- end
73
- end
74
- end
75
- typecaster('Date') do |value|
76
- begin
77
- value.to_date
78
- rescue ArgumentError, NoMethodError
79
- nil
80
- end
81
- end
82
- typecaster('DateTime') do |value|
83
- begin
84
- value.to_datetime
85
- rescue ArgumentError
86
- nil
87
- end
88
- end
89
- typecaster('Time') do |value|
90
- begin
91
- value.is_a?(String) && ::Time.zone ? ::Time.zone.parse(value) : value.to_time
92
- rescue ArgumentError
93
- nil
94
- end
95
- end
96
- typecaster('ActiveSupport::TimeZone') do |value|
97
- case value
98
- when ActiveSupport::TimeZone
99
- value
100
- when ::TZInfo::Timezone
101
- ActiveSupport::TimeZone[value.name]
102
- when String, Numeric, ActiveSupport::Duration
103
- value = begin
104
- Float(value)
105
- rescue ArgumentError, TypeError
106
- value
107
- end
108
- ActiveSupport::TimeZone[value]
109
- end
110
- end
111
- typecaster('BigDecimal') do |value|
112
- next unless value
113
- begin
114
- BigDecimal(Float(value).to_s)
115
- rescue ArgumentError, TypeError
116
- nil
117
- end
118
- end
119
- typecaster('Float') do |value|
120
- begin
121
- Float(value)
122
- rescue ArgumentError, TypeError
123
- nil
124
- end
125
- end
126
- typecaster('Integer') do |value|
127
- begin
128
- Float(value).to_i
129
- rescue ArgumentError, TypeError
130
- nil
131
- end
132
- end
133
- typecaster('Boolean') { |value| BOOLEAN_MAPPING[value] }
134
- typecaster('Granite::Form::UUID') do |value|
135
- case value
136
- when UUIDTools::UUID
137
- Granite::Form::UUID.parse_raw value.raw
138
- when Granite::Form::UUID
139
- value
140
- when String
141
- Granite::Form::UUID.parse_string value
142
- when Integer
143
- Granite::Form::UUID.parse_int value
144
- end
145
- end
29
+ config.types = {
30
+ 'Object' => Types::Object,
31
+ 'String' => Types::String,
32
+ 'Array' => Types::Array,
33
+ 'Date' => Types::Date,
34
+ 'DateTime' => Types::DateTime,
35
+ 'Time' => Types::Time,
36
+ 'ActiveSupport::TimeZone' => Types::ActiveSupport::TimeZone,
37
+ 'BigDecimal' => Types::BigDecimal,
38
+ 'Float' => Types::Float,
39
+ 'Integer' => Types::Integer,
40
+ 'Boolean' => Types::Boolean,
41
+ 'Granite::Form::UUID' => Types::UUID
42
+ }
146
43
  end
147
44
  end
148
45
 
@@ -150,6 +47,10 @@ require 'granite/form/base'
150
47
 
151
48
  Granite::Form.base_class = Granite::Form::Base
152
49
 
50
+ ActiveSupport.on_load :action_controller do
51
+ Granite::Form.config.types['Hash'] = Granite::Form::Types::HashWithActionControllerParameters
52
+ end
53
+
153
54
  ActiveSupport.on_load :active_record do
154
55
  require 'granite/form/active_record/associations'
155
56
  require 'granite/form/active_record/nested_attributes'
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'shared/nested_attribute_examples'
3
2
 
4
3
  describe Granite::Form::ActiveRecord::NestedAttributes do
5
4
  before do
@@ -47,20 +47,32 @@ describe Granite::Form::Config do
47
47
 
48
48
  describe '#typecaster' do
49
49
  specify do
50
- expect { subject.typecaster('Object') {} }
51
- .to change { muffle(Granite::Form::TypecasterMissing) { subject.typecaster(Time, Object) } }
52
- .from(nil).to(an_instance_of(Proc))
50
+ expect { subject.typecaster('Object', &:to_s) }
51
+ .to change { subject.types['Object'] }.from(nil).to(an_instance_of(Class))
52
+
53
+ expect(subject.types['Object'].new(Object, nil, stub_model.new).typecast(1)).to eq('1')
53
54
  end
55
+
56
+ specify do
57
+ expect { subject.typecaster(Object) {} }
58
+ .to change { subject.types['Object'] }.from(nil).to(an_instance_of(Class))
59
+ end
60
+
54
61
  specify do
55
- expect { subject.typecaster('Object') {} }
56
- .to change { muffle(Granite::Form::TypecasterMissing) { subject.typecaster('time', 'object') } }
57
- .from(nil).to(an_instance_of(Proc))
62
+ expect { subject.typecaster('object') {} }
63
+ .to change { subject.types['Object'] }.from(nil).to(an_instance_of(Class))
58
64
  end
65
+ end
66
+
67
+ describe '#type_for' do
68
+ let(:definition) { subject.types['Numeric'] }
69
+
70
+ before { subject.typecaster('Numeric') {} }
71
+
59
72
  specify do
60
- expect { subject.typecaster('Object') {} }
61
- .to change { muffle(Granite::Form::TypecasterMissing) { subject.typecaster(Object) } }
62
- .from(nil).to(an_instance_of(Proc))
73
+ expect(subject.type_for(Numeric)).to eq(definition)
74
+ expect(subject.type_for(Integer)).to eq(definition)
75
+ expect { subject.type_for(String) }.to raise_error(Granite::Form::TypecasterMissing)
63
76
  end
64
- specify { expect { subject.typecaster(Object) }.to raise_error Granite::Form::TypecasterMissing }
65
77
  end
66
78
  end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Granite::Form::UUID do
6
+ subject(:uuid) { Granite::Form::UUID.random_create }
7
+
8
+ specify { expect(uuid.as_json).to eq(uuid.to_s) }
9
+ specify { expect(uuid.to_json).to eq("\"#{uuid}\"") }
10
+ specify { expect(uuid.to_param).to eq(uuid.to_s) }
11
+ specify { expect(uuid.to_query(:key)).to eq("key=#{uuid}") }
12
+ end
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'shared/nested_attribute_examples'
3
2
 
4
3
  describe Granite::Form::Model::Associations::NestedAttributes do
5
4
  context '' do