granite-form 0.1.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/CODEOWNERS +1 -2
- data/.github/workflows/{ci.yml → ruby.yml} +22 -4
- data/.rubocop.yml +1 -1
- data/.rubocop_todo.yml +3 -3
- data/Appraisals +1 -2
- data/CHANGELOG.md +14 -0
- data/README.md +0 -2
- data/Rakefile +4 -0
- data/docker-compose.yml +14 -0
- data/gemfiles/rails.5.0.gemfile +0 -1
- data/gemfiles/rails.5.1.gemfile +0 -1
- data/gemfiles/rails.5.2.gemfile +0 -1
- data/granite-form.gemspec +16 -15
- data/lib/granite/form/active_record/associations.rb +1 -1
- data/lib/granite/form/base.rb +1 -2
- data/lib/granite/form/config.rb +10 -10
- data/lib/granite/form/errors.rb +0 -15
- data/lib/granite/form/model/associations/base.rb +0 -4
- data/lib/granite/form/model/associations/collection/embedded.rb +2 -1
- data/lib/granite/form/model/associations/collection/proxy.rb +1 -1
- data/lib/granite/form/model/associations/embeds_any.rb +7 -0
- data/lib/granite/form/model/associations/embeds_many.rb +9 -58
- data/lib/granite/form/model/associations/embeds_one.rb +7 -36
- data/lib/granite/form/model/associations/nested_attributes.rb +8 -8
- data/lib/granite/form/model/associations/persistence_adapters/active_record.rb +0 -4
- data/lib/granite/form/model/associations/persistence_adapters/base.rb +0 -4
- data/lib/granite/form/model/associations/references_many.rb +0 -32
- data/lib/granite/form/model/associations/references_one.rb +0 -28
- data/lib/granite/form/model/associations/reflections/embeds_any.rb +1 -1
- data/lib/granite/form/model/associations/reflections/references_any.rb +0 -4
- data/lib/granite/form/model/associations/reflections/references_many.rb +3 -1
- data/lib/granite/form/model/associations/reflections/references_one.rb +3 -3
- data/lib/granite/form/model/associations/reflections/singular.rb +0 -8
- data/lib/granite/form/model/associations.rb +0 -6
- data/lib/granite/form/model/attributes/attribute.rb +1 -1
- data/lib/granite/form/model/attributes/base.rb +14 -17
- data/lib/granite/form/model/attributes/collection.rb +1 -1
- data/lib/granite/form/model/attributes/dictionary.rb +1 -1
- data/lib/granite/form/model/attributes/localized.rb +1 -1
- data/lib/granite/form/model/attributes/reference_many.rb +1 -1
- data/lib/granite/form/model/attributes/reference_one.rb +1 -9
- data/lib/granite/form/model/attributes/reflections/attribute.rb +0 -6
- data/lib/granite/form/model/attributes/reflections/base.rb +9 -12
- data/lib/granite/form/model/attributes/reflections/reference_one.rb +0 -10
- data/lib/granite/form/model/persistence.rb +1 -19
- data/lib/granite/form/model/validations/nested.rb +1 -1
- data/lib/granite/form/model.rb +0 -2
- data/lib/granite/form/types/active_support/time_zone.rb +22 -0
- data/lib/granite/form/types/array.rb +17 -0
- data/lib/granite/form/types/big_decimal.rb +15 -0
- data/lib/granite/form/types/boolean.rb +38 -0
- data/lib/granite/form/types/date.rb +15 -0
- data/lib/granite/form/types/date_time.rb +15 -0
- data/lib/granite/form/types/float.rb +15 -0
- data/lib/granite/form/types/hash_with_action_controller_parameters.rb +18 -0
- data/lib/granite/form/types/integer.rb +13 -0
- data/lib/granite/form/types/object.rb +30 -0
- data/lib/granite/form/types/string.rb +13 -0
- data/lib/granite/form/types/time.rb +15 -0
- data/lib/granite/form/types/uuid.rb +22 -0
- data/lib/granite/form/types.rb +15 -0
- data/lib/granite/form/version.rb +1 -1
- data/lib/granite/form.rb +19 -118
- data/spec/{lib/granite → granite}/form/active_record/associations_spec.rb +16 -18
- data/spec/{lib/granite → granite}/form/active_record/nested_attributes_spec.rb +0 -1
- data/spec/{lib/granite → granite}/form/config_spec.rb +22 -10
- data/spec/granite/form/extensions_spec.rb +12 -0
- data/spec/{lib/granite → granite}/form/model/associations/embeds_many_spec.rb +29 -305
- data/spec/{lib/granite → granite}/form/model/associations/embeds_one_spec.rb +27 -212
- data/spec/granite/form/model/associations/nested_attributes_spec.rb +23 -0
- data/spec/{lib/granite → granite}/form/model/associations/persistence_adapters/active_record_spec.rb +0 -0
- data/spec/granite/form/model/associations/references_many_spec.rb +251 -0
- data/spec/granite/form/model/associations/references_one_spec.rb +173 -0
- data/spec/{lib/granite → granite}/form/model/associations/reflections/embeds_any_spec.rb +1 -2
- data/spec/{lib/granite → granite}/form/model/associations/reflections/embeds_many_spec.rb +18 -26
- data/spec/{lib/granite → granite}/form/model/associations/reflections/embeds_one_spec.rb +16 -23
- data/spec/{lib/granite → granite}/form/model/associations/reflections/references_many_spec.rb +1 -1
- data/spec/{lib/granite → granite}/form/model/associations/reflections/references_one_spec.rb +1 -22
- data/spec/{lib/granite → granite}/form/model/associations/validations_spec.rb +0 -3
- data/spec/{lib/granite → granite}/form/model/associations_spec.rb +3 -24
- data/spec/{lib/granite → granite}/form/model/attributes/attribute_spec.rb +4 -46
- data/spec/{lib/granite → granite}/form/model/attributes/base_spec.rb +11 -2
- data/spec/{lib/granite → granite}/form/model/attributes/collection_spec.rb +0 -0
- data/spec/{lib/granite → granite}/form/model/attributes/dictionary_spec.rb +0 -0
- data/spec/{lib/granite → granite}/form/model/attributes/localized_spec.rb +1 -1
- data/spec/{lib/granite → granite}/form/model/attributes/reflections/attribute_spec.rb +0 -12
- data/spec/{lib/granite → granite}/form/model/attributes/reflections/base_spec.rb +1 -1
- data/spec/{lib/granite → granite}/form/model/attributes/reflections/collection_spec.rb +0 -0
- data/spec/{lib/granite → granite}/form/model/attributes/reflections/dictionary_spec.rb +0 -0
- data/spec/{lib/granite → granite}/form/model/attributes/reflections/localized_spec.rb +0 -0
- data/spec/{lib/granite → granite}/form/model/attributes/reflections/represents_spec.rb +0 -0
- data/spec/{lib/granite → granite}/form/model/attributes/represents_spec.rb +0 -0
- data/spec/{lib/granite → granite}/form/model/attributes_spec.rb +0 -0
- data/spec/{lib/granite → granite}/form/model/conventions_spec.rb +0 -0
- data/spec/{lib/granite → granite}/form/model/dirty_spec.rb +1 -1
- data/spec/{lib/granite → granite}/form/model/persistence_spec.rb +0 -2
- data/spec/{lib/granite → granite}/form/model/primary_spec.rb +1 -1
- data/spec/{lib/granite → granite}/form/model/representation_spec.rb +0 -0
- data/spec/{lib/granite → granite}/form/model/scopes_spec.rb +0 -0
- data/spec/{lib/granite → granite}/form/model/validations/associated_spec.rb +2 -4
- data/spec/{lib/granite → granite}/form/model/validations/nested_spec.rb +57 -15
- data/spec/{lib/granite → granite}/form/model/validations_spec.rb +0 -0
- data/spec/{lib/granite → granite}/form/model_spec.rb +0 -0
- data/spec/granite/form/types/active_support/time_zone_spec.rb +24 -0
- data/spec/granite/form/types/array_spec.rb +13 -0
- data/spec/granite/form/types/big_decimal_spec.rb +19 -0
- data/spec/granite/form/types/boolean_spec.rb +21 -0
- data/spec/granite/form/types/date_spec.rb +18 -0
- data/spec/granite/form/types/date_time_spec.rb +20 -0
- data/spec/granite/form/types/float_spec.rb +19 -0
- data/spec/granite/form/types/hash_with_action_controller_parameters_spec.rb +22 -0
- data/spec/granite/form/types/integer_spec.rb +18 -0
- data/spec/granite/form/types/object_spec.rb +40 -0
- data/spec/granite/form/types/string_spec.rb +13 -0
- data/spec/granite/form/types/time_spec.rb +31 -0
- data/spec/granite/form/types/uuid_spec.rb +21 -0
- data/spec/{lib/granite → granite}/form_spec.rb +0 -0
- data/spec/spec_helper.rb +0 -15
- data/spec/support/active_record.rb +20 -0
- data/spec/{shared → support/shared}/nested_attribute_examples.rb +3 -21
- data/spec/support/shared/type_examples.rb +7 -0
- metadata +173 -123
- data/.github/workflows/main.yml +0 -29
- data/gemfiles/rails.4.2.gemfile +0 -15
- data/lib/granite/form/model/callbacks.rb +0 -72
- data/lib/granite/form/model/lifecycle.rb +0 -309
- data/spec/lib/granite/form/model/associations/nested_attributes_spec.rb +0 -119
- data/spec/lib/granite/form/model/associations/references_many_spec.rb +0 -572
- data/spec/lib/granite/form/model/associations/references_one_spec.rb +0 -445
- data/spec/lib/granite/form/model/callbacks_spec.rb +0 -337
- data/spec/lib/granite/form/model/lifecycle_spec.rb +0 -356
- data/spec/lib/granite/form/model/typecasting_spec.rb +0 -193
@@ -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'
|
data/lib/granite/form/version.rb
CHANGED
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
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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'
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Granite::Form::ActiveRecord::Associations do
|
4
4
|
before do
|
5
5
|
stub_model(:project) do
|
6
|
-
include Granite::Form::Model::
|
6
|
+
include Granite::Form::Model::Persistence
|
7
7
|
include Granite::Form::Model::Associations
|
8
8
|
|
9
9
|
attribute :title, String
|
@@ -18,7 +18,8 @@ describe Granite::Form::ActiveRecord::Associations do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
stub_model(:profile) do
|
21
|
-
include Granite::Form::Model::
|
21
|
+
include Granite::Form::Model::Persistence
|
22
|
+
include Granite::Form::Model::Associations
|
22
23
|
|
23
24
|
attribute :first_name, String
|
24
25
|
attribute :last_name, String
|
@@ -89,7 +90,10 @@ describe Granite::Form::ActiveRecord::Associations do
|
|
89
90
|
end
|
90
91
|
|
91
92
|
context 'with profile already set' do
|
92
|
-
before
|
93
|
+
before do
|
94
|
+
user.build_profile(admin: true)
|
95
|
+
user.save!
|
96
|
+
end
|
93
97
|
|
94
98
|
specify do
|
95
99
|
user.profile.admin = false
|
@@ -104,13 +108,9 @@ describe Granite::Form::ActiveRecord::Associations do
|
|
104
108
|
let(:user) { User.create }
|
105
109
|
|
106
110
|
describe '#projects' do
|
107
|
-
specify do
|
108
|
-
expect { user.projects << Project.new }
|
109
|
-
.not_to change { user.read_attribute(:projects) }
|
110
|
-
end
|
111
111
|
specify do
|
112
112
|
expect { user.projects << Project.new(title: 'First') }
|
113
|
-
.
|
113
|
+
.not_to change { user.read_attribute(:projects) }
|
114
114
|
end
|
115
115
|
specify do
|
116
116
|
user.projects << Project.new(title: 'First')
|
@@ -124,15 +124,14 @@ describe Granite::Form::ActiveRecord::Associations do
|
|
124
124
|
|
125
125
|
specify do
|
126
126
|
expect { user.projects << project }
|
127
|
-
.
|
128
|
-
.to([{'title' => 'First', 'author' => {'name' => 'Author'}}])
|
127
|
+
.not_to change { user.read_attribute(:projects) }
|
129
128
|
end
|
130
129
|
specify do
|
131
130
|
expect do
|
132
131
|
user.projects << project
|
133
132
|
user.save
|
134
133
|
end
|
135
|
-
.to change { user.reload.read_attribute(:projects) }.from(
|
134
|
+
.to change { user.reload.read_attribute(:projects) }.from([])
|
136
135
|
.to([{'title' => 'First', 'author' => {'name' => 'Author'}}])
|
137
136
|
end
|
138
137
|
end
|
@@ -150,8 +149,7 @@ describe Granite::Form::ActiveRecord::Associations do
|
|
150
149
|
end
|
151
150
|
specify do
|
152
151
|
expect { user.profile = Profile.new(first_name: 'google.com') }
|
153
|
-
.
|
154
|
-
.to({first_name: 'google.com', last_name: nil, admin: nil}.to_json)
|
152
|
+
.not_to change { user.read_attribute(:profile) }
|
155
153
|
end
|
156
154
|
specify do
|
157
155
|
expect do
|
@@ -196,16 +194,16 @@ describe Granite::Form::ActiveRecord::Associations do
|
|
196
194
|
|
197
195
|
specify { expect(User.reflect_on_association(:projects).klass).to eq(User::Project) }
|
198
196
|
specify { expect(User.new.projects).to eq([]) }
|
199
|
-
specify { expect(User.new.tap { |u| u.projects.
|
200
|
-
specify { expect(User.new.tap { |u| u.projects.
|
197
|
+
specify { expect(User.new.tap { |u| u.projects.build(title: 'Project') }.projects).to be_a(Granite::Form::Model::Associations::Collection::Embedded) }
|
198
|
+
specify { expect(User.new.tap { |u| u.projects.build(title: 'Project') }.projects).to match([have_attributes(title: 'Project')]) }
|
201
199
|
|
202
200
|
specify { expect(User.reflect_on_association(:profile).klass).to eq(User::Profile) }
|
203
201
|
specify { expect(User.reflect_on_association(:profile).klass).to be < Profile }
|
204
202
|
specify { expect(User.new.profile).to be_nil }
|
205
|
-
specify { expect(User.new.tap { |u| u.
|
203
|
+
specify { expect(User.new.tap { |u| u.build_profile(first_name: 'Profile') }.profile).to be_a(User::Profile) }
|
206
204
|
specify do
|
207
|
-
expect(User.new.tap { |u| u.
|
208
|
-
.to
|
205
|
+
expect(User.new.tap { |u| u.build_profile(first_name: 'Profile') }.profile)
|
206
|
+
.to have_attributes(first_name: 'Profile', last_name: nil, admin: nil, age: nil)
|
209
207
|
end
|
210
208
|
end
|
211
209
|
end
|
@@ -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 {
|
52
|
-
|
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('
|
56
|
-
.to change {
|
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
|
61
|
-
|
62
|
-
|
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
|