granite-form 0.5.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +26 -48
  3. data/.rubocop_todo.yml +304 -27
  4. data/CHANGELOG.md +14 -2
  5. data/granite-form.gemspec +2 -1
  6. data/lib/granite/form/active_record/associations.rb +4 -3
  7. data/lib/granite/form/config.rb +1 -1
  8. data/lib/granite/form/errors.rb +34 -32
  9. data/lib/granite/form/extensions.rb +2 -1
  10. data/lib/granite/form/model/associations/base.rb +6 -2
  11. data/lib/granite/form/model/associations/collection/embedded.rb +1 -1
  12. data/lib/granite/form/model/associations/collection/proxy.rb +3 -3
  13. data/lib/granite/form/model/associations/embeds_any.rb +1 -1
  14. data/lib/granite/form/model/associations/embeds_many.rb +15 -11
  15. data/lib/granite/form/model/associations/embeds_one.rb +9 -8
  16. data/lib/granite/form/model/associations/nested_attributes.rb +60 -32
  17. data/lib/granite/form/model/associations/persistence_adapters/active_record/referenced_proxy.rb +2 -1
  18. data/lib/granite/form/model/associations/persistence_adapters/active_record.rb +7 -6
  19. data/lib/granite/form/model/associations/persistence_adapters/base.rb +8 -4
  20. data/lib/granite/form/model/associations/references_any.rb +1 -1
  21. data/lib/granite/form/model/associations/references_many.rb +3 -2
  22. data/lib/granite/form/model/associations/references_one.rb +1 -1
  23. data/lib/granite/form/model/associations/reflections/base.rb +3 -2
  24. data/lib/granite/form/model/associations/reflections/embeds_any.rb +4 -4
  25. data/lib/granite/form/model/associations/reflections/embeds_many.rb +4 -1
  26. data/lib/granite/form/model/associations/reflections/embeds_one.rb +4 -1
  27. data/lib/granite/form/model/associations/reflections/references_any.rb +6 -6
  28. data/lib/granite/form/model/associations/reflections/references_many.rb +1 -1
  29. data/lib/granite/form/model/associations/reflections/references_one.rb +1 -1
  30. data/lib/granite/form/model/associations/validations.rb +6 -6
  31. data/lib/granite/form/model/associations.rb +6 -4
  32. data/lib/granite/form/model/attributes/attribute.rb +1 -0
  33. data/lib/granite/form/model/attributes/base.rb +9 -7
  34. data/lib/granite/form/model/attributes/reference_one.rb +1 -1
  35. data/lib/granite/form/model/attributes/reflections/base/build_type_definition.rb +2 -1
  36. data/lib/granite/form/model/attributes/reflections/represents/build_type_definition.rb +2 -2
  37. data/lib/granite/form/model/attributes/represents.rb +1 -1
  38. data/lib/granite/form/model/attributes.rb +31 -14
  39. data/lib/granite/form/model/conventions.rb +1 -1
  40. data/lib/granite/form/model/persistence.rb +1 -1
  41. data/lib/granite/form/model/primary.rb +1 -1
  42. data/lib/granite/form/model/representation.rb +4 -4
  43. data/lib/granite/form/model/scopes.rb +5 -5
  44. data/lib/granite/form/model/validations.rb +4 -3
  45. data/lib/granite/form/types/active_support/time_zone.rb +1 -1
  46. data/lib/granite/form/types/array.rb +1 -1
  47. data/lib/granite/form/types/big_decimal.rb +1 -1
  48. data/lib/granite/form/types/boolean.rb +1 -1
  49. data/lib/granite/form/types/date.rb +1 -1
  50. data/lib/granite/form/types/date_time.rb +1 -1
  51. data/lib/granite/form/types/dictionary.rb +1 -1
  52. data/lib/granite/form/types/float.rb +1 -1
  53. data/lib/granite/form/types/has_subtype.rb +1 -0
  54. data/lib/granite/form/types/hash_with_action_controller_parameters.rb +2 -2
  55. data/lib/granite/form/types/integer.rb +1 -1
  56. data/lib/granite/form/types/object.rb +2 -1
  57. data/lib/granite/form/types/string.rb +1 -1
  58. data/lib/granite/form/types/time.rb +1 -1
  59. data/lib/granite/form/types/uuid.rb +1 -1
  60. data/lib/granite/form/util.rb +1 -1
  61. data/lib/granite/form/version.rb +1 -1
  62. data/spec/granite/form/active_record/associations_spec.rb +35 -13
  63. data/spec/granite/form/config_spec.rb +8 -4
  64. data/spec/granite/form/model/associations/embeds_many_spec.rb +99 -51
  65. data/spec/granite/form/model/associations/embeds_one_spec.rb +48 -25
  66. data/spec/granite/form/model/associations/persistence_adapters/active_record_spec.rb +12 -7
  67. data/spec/granite/form/model/associations/references_many_spec.rb +51 -10
  68. data/spec/granite/form/model/associations/references_one_spec.rb +17 -6
  69. data/spec/granite/form/model/associations/reflections/embeds_many_spec.rb +51 -16
  70. data/spec/granite/form/model/associations/reflections/embeds_one_spec.rb +19 -9
  71. data/spec/granite/form/model/associations/reflections/references_many_spec.rb +67 -15
  72. data/spec/granite/form/model/associations/reflections/references_one_spec.rb +34 -11
  73. data/spec/granite/form/model/associations/validations_spec.rb +16 -5
  74. data/spec/granite/form/model/associations_spec.rb +28 -9
  75. data/spec/granite/form/model/attributes/attribute_spec.rb +33 -11
  76. data/spec/granite/form/model/attributes/base_spec.rb +9 -3
  77. data/spec/granite/form/model/attributes/reflections/attribute_spec.rb +1 -0
  78. data/spec/granite/form/model/attributes/reflections/base_spec.rb +1 -0
  79. data/spec/granite/form/model/attributes/reflections/represents/build_type_definition_spec.rb +3 -1
  80. data/spec/granite/form/model/attributes/reflections/represents_spec.rb +2 -2
  81. data/spec/granite/form/model/attributes/represents_spec.rb +2 -2
  82. data/spec/granite/form/model/attributes_spec.rb +97 -36
  83. data/spec/granite/form/model/dirty_spec.rb +3 -0
  84. data/spec/granite/form/model/persistence_spec.rb +15 -5
  85. data/spec/granite/form/model/primary_spec.rb +17 -2
  86. data/spec/granite/form/model/representation_spec.rb +13 -3
  87. data/spec/granite/form/model/scopes_spec.rb +8 -3
  88. data/spec/granite/form/model/validations/associated_spec.rb +20 -6
  89. data/spec/granite/form/model/validations/nested_spec.rb +30 -14
  90. data/spec/granite/form/model/validations_spec.rb +1 -1
  91. data/spec/granite/form/model_spec.rb +1 -0
  92. data/spec/granite/form/types/collection_spec.rb +2 -1
  93. data/spec/granite/form/types/date_spec.rb +1 -1
  94. data/spec/granite/form/types/date_time_spec.rb +0 -2
  95. data/spec/granite/form/types/dictionary_spec.rb +1 -0
  96. data/spec/granite/form/types/has_subtype_spec.rb +6 -1
  97. data/spec/granite/form/types/hash_with_action_controller_parameters_spec.rb +1 -1
  98. data/spec/granite/form/types/object_spec.rb +2 -0
  99. data/spec/granite/form/types/time_spec.rb +0 -2
  100. data/spec/granite/form/util_spec.rb +6 -3
  101. data/spec/support/active_record.rb +13 -0
  102. data/spec/support/shared/nested_attribute_examples.rb +110 -54
  103. metadata +19 -6
  104. data/.github/CODEOWNERS +0 -1
@@ -18,6 +18,7 @@ describe Granite::Form::Model::Primary do
18
18
 
19
19
  context do
20
20
  let(:object) { model.new(name: 'Hello') }
21
+
21
22
  specify { expect(object).not_to eq(object.clone.tap { |o| o.update(name: 'World') }) }
22
23
  specify { expect(object).not_to eql(object.clone.tap { |o| o.update(name: 'World') }) }
23
24
  end
@@ -43,6 +44,7 @@ describe Granite::Form::Model::Primary do
43
44
 
44
45
  context do
45
46
  let(:object) { model.new(name: 'Hello') }
47
+
46
48
  specify { expect(object).to eq(object.clone.tap { |o| o.update(name: 'World') }) }
47
49
  specify { expect(object).to eql(object.clone.tap { |o| o.update(name: 'World') }) }
48
50
  end
@@ -63,20 +65,33 @@ describe Granite::Form::Model::Primary do
63
65
  specify { expect(model.new.primary_attribute).to be_nil }
64
66
  specify { expect(model.new(name: 'Hello')).not_to eq(model.new(name: 'Hello')) }
65
67
  specify { expect(model.new(name: 'Hello')).not_to eql(model.new(name: 'Hello')) }
66
- specify { expect(model.new(name: 'Hello').tap { |o| o.id = 1 }).not_to eq(model.new(name: 'Hello').tap { |o| o.id = 2 }) }
67
- specify { expect(model.new(name: 'Hello').tap { |o| o.id = 1 }).not_to eql(model.new(name: 'Hello').tap { |o| o.id = 2 }) }
68
+
69
+ specify do
70
+ expect(model.new(name: 'Hello').tap { |o| o.id = 1 }).not_to eq(model.new(name: 'Hello').tap do |o|
71
+ o.id = 2
72
+ end)
73
+ end
74
+
75
+ specify do
76
+ expect(model.new(name: 'Hello').tap { |o| o.id = 1 }).not_to eql(model.new(name: 'Hello').tap do |o|
77
+ o.id = 2
78
+ end)
79
+ end
80
+
68
81
  specify { expect(model.new(id: 1).id).to be_nil }
69
82
  specify { expect(model.new.tap { |o| o.assign_attributes(id: 1) }.id).to be_nil }
70
83
  specify { expect(model.new.tap { |o| o.id = 1 }.id).to eq(1) }
71
84
 
72
85
  context do
73
86
  let(:object) { model.new(name: 'Hello').tap { |o| o.id = 1 } }
87
+
74
88
  specify { expect(object).to eq(object.clone.tap { |o| o.update(name: 'World') }) }
75
89
  specify { expect(object).to eql(object.clone.tap { |o| o.update(name: 'World') }) }
76
90
  end
77
91
 
78
92
  context do
79
93
  let(:object) { model.new(name: 'Hello') }
94
+
80
95
  specify { expect(object).to eq(object) }
81
96
  specify { expect(object).to eql(object) }
82
97
  end
@@ -11,12 +11,16 @@ describe Granite::Form::Model::Representation do
11
11
  include Granite::Form::Model::Representation
12
12
 
13
13
  attribute :author, Object
14
+ attribute :foo_container, Object
14
15
  alias_attribute :a, :author
15
16
  represents :rate, of: :a
17
+ represents :foos, of: :foo_container
16
18
  alias_attribute :r, :rate
17
19
  end
18
20
  end
21
+
19
22
  let(:author) { Author.new(rate: '42') }
23
+ let(:foos) { %w[foo bar] }
20
24
 
21
25
  specify { expect(Post.reflect_on_attribute(:rate).reference).to eq('author') }
22
26
 
@@ -30,8 +34,13 @@ describe Granite::Form::Model::Representation do
30
34
  specify { expect(Post.new.rate).to be_nil }
31
35
  specify { expect(Post.new.rate_before_type_cast).to be_nil }
32
36
 
37
+ if ActiveModel.version >= Gem::Version.new('7.0.0')
38
+ specify { expect { Post.new(foo_container: FooContainer.new, foos: foos) }.not_to raise_exception }
39
+ end
40
+
33
41
  context 'ActionController::Parameters' do
34
- let(:params) { instance_double('ActionController::Parameters', to_unsafe_hash: {rate: '33', author: author}) }
42
+ let(:params) { instance_double('ActionController::Parameters', to_unsafe_hash: { rate: '33', author: author }) }
43
+
35
44
  specify { expect { Post.new(params) }.not_to raise_error }
36
45
  end
37
46
 
@@ -64,6 +73,7 @@ describe Granite::Form::Model::Representation do
64
73
  represents :name, of: :a
65
74
  end
66
75
  end
76
+
67
77
  let!(:author) { Author.create!(name: 42) }
68
78
 
69
79
  specify { expect(Post.reflect_on_attribute(:name).reference).to eq('author') }
@@ -129,13 +139,13 @@ describe Granite::Form::Model::Representation do
129
139
  if ActiveModel.version >= Gem::Version.new('6.1.0')
130
140
  specify do
131
141
  expect { post.validate }.to change { post.errors.details }
132
- .to('author.user.email': [{error: 'is invalid'}], name: [{error: :blank}])
142
+ .to('author.user.email': [{ error: 'is invalid' }], name: [{ error: :blank }])
133
143
  end
134
144
  end
135
145
 
136
146
  context 'when using symbol in error message of represented model' do
137
147
  before do
138
- Author.validates :name, inclusion: {in: ['Author'], message: :invalid_name, allow_blank: true}
148
+ Author.validates :name, inclusion: { in: ['Author'], message: :invalid_name, allow_blank: true }
139
149
  post.author.name = 'Not Author'
140
150
  end
141
151
 
@@ -9,14 +9,14 @@ describe Granite::Form::Model::Scopes do
9
9
 
10
10
  class << self
11
11
  def except_first
12
- scope[1..-1]
12
+ scope[1..]
13
13
  end
14
14
 
15
15
  def no_mars
16
16
  scope.delete_if { |i| i.name == 'Mars' }
17
17
  end
18
18
 
19
- private
19
+ private
20
20
 
21
21
  def hidden_method() end
22
22
  end
@@ -45,7 +45,12 @@ describe Granite::Form::Model::Scopes do
45
45
  let(:scope) { model.scope([model.new(name: 'Hello'), model.new(name: 'World'), model.new(name: 'Mars')]) }
46
46
 
47
47
  specify { expect(scope).to be_instance_of model.scope_class }
48
- specify { expect { model.scope([model.new(name: 'Hello'), {}]) }.to raise_error Granite::Form::AssociationTypeMismatch }
48
+
49
+ specify do
50
+ expect do
51
+ model.scope([model.new(name: 'Hello'), {}])
52
+ end.to raise_error Granite::Form::AssociationTypeMismatch
53
+ end
49
54
 
50
55
  context 'scopes' do
51
56
  specify { expect(scope.except_first).to be_instance_of model.scope_class }
@@ -33,13 +33,16 @@ describe Granite::Form::Model::Validations::AssociatedValidator do
33
33
  end
34
34
 
35
35
  context do
36
- subject(:instance) { Main.instantiate name: 'hello', validated_one: {name: 'name'} }
36
+ subject(:instance) { Main.instantiate name: 'hello', validated_one: { name: 'name' } }
37
+
37
38
  it { is_expected.to be_valid }
38
39
  end
39
40
 
40
41
  context do
41
42
  subject(:instance) { Main.instantiate name: 'hello', validated_one: {} }
43
+
42
44
  it { is_expected.not_to be_valid }
45
+
43
46
  specify do
44
47
  expect { instance.validate }.to change { instance.errors.messages }
45
48
  .to(validated_one: ['is invalid'])
@@ -47,23 +50,28 @@ describe Granite::Form::Model::Validations::AssociatedValidator do
47
50
  end
48
51
 
49
52
  context do
50
- subject(:instance) { Main.instantiate name: 'hello', unvalidated_one: {name: 'name'} }
53
+ subject(:instance) { Main.instantiate name: 'hello', unvalidated_one: { name: 'name' } }
54
+
51
55
  it { is_expected.to be_valid }
52
56
  end
53
57
 
54
58
  context do
55
59
  subject(:instance) { Main.instantiate name: 'hello', unvalidated_one: {} }
60
+
56
61
  it { is_expected.to be_valid }
57
62
  end
58
63
 
59
64
  context do
60
- subject(:instance) { Main.instantiate name: 'hello', validated_many: [{name: 'name'}] }
65
+ subject(:instance) { Main.instantiate name: 'hello', validated_many: [{ name: 'name' }] }
66
+
61
67
  it { is_expected.to be_valid }
62
68
  end
63
69
 
64
70
  context do
65
71
  subject(:instance) { Main.instantiate name: 'hello', validated_many: [{}] }
72
+
66
73
  it { is_expected.not_to be_valid }
74
+
67
75
  specify do
68
76
  expect { instance.validate }.to change { instance.errors.messages }
69
77
  .to('validated_many.0.name': ["can't be blank"], validated_many: ['is invalid'])
@@ -71,18 +79,22 @@ describe Granite::Form::Model::Validations::AssociatedValidator do
71
79
  end
72
80
 
73
81
  context do
74
- subject(:instance) { Main.instantiate name: 'hello', unvalidated_many: [{name: 'name'}] }
82
+ subject(:instance) { Main.instantiate name: 'hello', unvalidated_many: [{ name: 'name' }] }
83
+
75
84
  it { is_expected.to be_valid }
76
85
  end
77
86
 
78
87
  context do
79
88
  subject(:instance) { Main.instantiate name: 'hello', unvalidated_many: [{}] }
89
+
80
90
  it { is_expected.to be_valid }
81
91
  end
82
92
 
83
93
  context do
84
- subject(:instance) { Main.instantiate name: 'hello', validated_many: [{name: 'name'}], validated_one: {} }
94
+ subject(:instance) { Main.instantiate name: 'hello', validated_many: [{ name: 'name' }], validated_one: {} }
95
+
85
96
  it { is_expected.not_to be_valid }
97
+
86
98
  specify do
87
99
  expect { instance.validate }.to change { instance.errors.messages }
88
100
  .to(validated_one: ['is invalid'])
@@ -90,8 +102,10 @@ describe Granite::Form::Model::Validations::AssociatedValidator do
90
102
  end
91
103
 
92
104
  context do
93
- subject(:instance) { Main.instantiate name: 'hello', validated_many: [{}], validated_one: {name: 'name'} }
105
+ subject(:instance) { Main.instantiate name: 'hello', validated_many: [{}], validated_one: { name: 'name' } }
106
+
94
107
  it { is_expected.not_to be_valid }
108
+
95
109
  specify do
96
110
  expect { instance.validate }.to change { instance.errors.messages }
97
111
  .to('validated_many.0.name': ["can't be blank"], validated_many: ['is invalid'])
@@ -34,13 +34,16 @@ describe Granite::Form::Model::Validations::NestedValidator do
34
34
  end
35
35
 
36
36
  context do
37
- subject(:instance) { Main.instantiate name: 'hello', validated_one: {name: 'name'} }
37
+ subject(:instance) { Main.instantiate name: 'hello', validated_one: { name: 'name' } }
38
+
38
39
  it { is_expected.to be_valid }
39
40
  end
40
41
 
41
42
  context do
42
43
  subject(:instance) { Main.instantiate name: 'hello', validated_one: {} }
44
+
43
45
  it { is_expected.not_to be_valid }
46
+
44
47
  specify do
45
48
  expect { instance.validate }.to change { instance.errors.messages }
46
49
  .to('validated_one.name': ["can't be blank"])
@@ -48,23 +51,28 @@ describe Granite::Form::Model::Validations::NestedValidator do
48
51
  end
49
52
 
50
53
  context do
51
- subject(:instance) { Main.instantiate name: 'hello', unvalidated_one: {name: 'name'} }
54
+ subject(:instance) { Main.instantiate name: 'hello', unvalidated_one: { name: 'name' } }
55
+
52
56
  it { is_expected.to be_valid }
53
57
  end
54
58
 
55
59
  context do
56
60
  subject(:instance) { Main.instantiate name: 'hello', unvalidated_one: {} }
61
+
57
62
  it { is_expected.to be_valid }
58
63
  end
59
64
 
60
65
  context do
61
- subject(:instance) { Main.instantiate name: 'hello', validated_many: [{name: 'name'}] }
66
+ subject(:instance) { Main.instantiate name: 'hello', validated_many: [{ name: 'name' }] }
67
+
62
68
  it { is_expected.to be_valid }
63
69
  end
64
70
 
65
71
  context do
66
72
  subject(:instance) { Main.instantiate name: 'hello', validated_many: [{}] }
73
+
67
74
  it { is_expected.not_to be_valid }
75
+
68
76
  specify do
69
77
  expect { instance.validate }.to change { instance.errors.messages }
70
78
  .to('validated_many.0.name': ["can't be blank"])
@@ -72,18 +80,22 @@ describe Granite::Form::Model::Validations::NestedValidator do
72
80
  end
73
81
 
74
82
  context do
75
- subject(:instance) { Main.instantiate name: 'hello', unvalidated_many: [{name: 'name'}] }
83
+ subject(:instance) { Main.instantiate name: 'hello', unvalidated_many: [{ name: 'name' }] }
84
+
76
85
  it { is_expected.to be_valid }
77
86
  end
78
87
 
79
88
  context do
80
89
  subject(:instance) { Main.instantiate name: 'hello', unvalidated_many: [{}] }
90
+
81
91
  it { is_expected.to be_valid }
82
92
  end
83
93
 
84
94
  context do
85
- subject(:instance) { Main.instantiate name: 'hello', validated_many: [{name: 'name'}], validated_one: {} }
95
+ subject(:instance) { Main.instantiate name: 'hello', validated_many: [{ name: 'name' }], validated_one: {} }
96
+
86
97
  it { is_expected.not_to be_valid }
98
+
87
99
  specify do
88
100
  expect { instance.validate }.to change { instance.errors.messages }
89
101
  .to('validated_one.name': ["can't be blank"])
@@ -91,26 +103,30 @@ describe Granite::Form::Model::Validations::NestedValidator do
91
103
  end
92
104
 
93
105
  context 'accepts nested attributes for one' do
106
+ subject(:instance) { Main.instantiate name: 'hello', validated_one: { id: 1, name: 'name' } }
107
+
94
108
  before { Main.accepts_nested_attributes_for :validated_one, allow_destroy: true }
95
- subject(:instance) { Main.instantiate name: 'hello', validated_one: {id: 1, name: 'name'} }
96
109
 
97
110
  specify do
98
- instance.validated_one_attributes = {id: 1, name: '', _destroy: true}
99
- is_expected.to be_valid
111
+ instance.validated_one_attributes = { id: 1, name: '', _destroy: true }
112
+ expect(subject).to be_valid
100
113
  end
101
114
  end
102
115
 
103
116
  context 'accepts nested attributes for many' do
117
+ subject(:instance) { Main.instantiate name: 'hello', validated_many: [{ id: 1, name: 'name' }] }
118
+
104
119
  before { Main.accepts_nested_attributes_for :validated_many, allow_destroy: true }
105
- subject(:instance) { Main.instantiate name: 'hello', validated_many: [{id: 1, name: 'name'}] }
106
120
 
107
121
  specify do
108
- instance.validated_many_attributes = [{id: 1, name: '', _destroy: true}]
109
- is_expected.to be_valid
122
+ instance.validated_many_attributes = [{ id: 1, name: '', _destroy: true }]
123
+ expect(subject).to be_valid
110
124
  end
111
125
  end
112
126
 
113
127
  context 'object field is invalid and referenced object does not include AutosaveAssociation' do
128
+ subject(:instance) { Main.instantiate name: 'hello', object: object }
129
+
114
130
  before do
115
131
  stub_model(:validated_object) do
116
132
  attribute :title, String
@@ -125,8 +141,6 @@ describe Granite::Form::Model::Validations::NestedValidator do
125
141
  end
126
142
  end
127
143
 
128
- subject(:instance) { Main.instantiate name: 'hello', object: object }
129
-
130
144
  context 'nested object is valid' do
131
145
  let(:object) { ValidatedObject.new(title: 'Mr.') }
132
146
 
@@ -190,8 +204,10 @@ describe Granite::Form::Model::Validations::NestedValidator do
190
204
  end
191
205
 
192
206
  context do
193
- subject(:instance) { Main.instantiate name: 'hello', validated_many: [{}], validated_one: {name: 'name'} }
207
+ subject(:instance) { Main.instantiate name: 'hello', validated_many: [{}], validated_one: { name: 'name' } }
208
+
194
209
  it { is_expected.not_to be_valid }
210
+
195
211
  specify do
196
212
  expect { instance.validate }.to change { instance.errors.messages }
197
213
  .to('validated_many.0.name': ["can't be blank"])
@@ -29,7 +29,7 @@ describe Granite::Form::Model::Validations do
29
29
  end
30
30
 
31
31
  context 'when attribute has different validations' do
32
- let(:add_validations) { model.validates :name, length: {maximum: 100} }
32
+ let(:add_validations) { model.validates :name, length: { maximum: 100 } }
33
33
 
34
34
  it { is_expected.to be_falsey }
35
35
  end
@@ -2,6 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Granite::Form::Model do
4
4
  let(:model) { stub_model }
5
+
5
6
  specify { expect { model.blablabla }.to raise_error NoMethodError }
6
7
 
7
8
  context 'Fault tolerance' do
@@ -2,6 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  RSpec.describe Granite::Form::Types::Collection do
4
4
  subject(:type) { described_class.new(subtype_definition) }
5
+
5
6
  let(:element_type) { Dummy }
6
7
  let(:subtype_definition) { Granite::Form::Types::Object.new(element_type, reflection, nil) }
7
8
  let(:reflection) { Granite::Form::Model::Attributes::Reflections::Base.new(:field) }
@@ -16,7 +17,7 @@ RSpec.describe Granite::Form::Types::Collection do
16
17
  context 'with Hash collection' do
17
18
  let(:element_type) { Hash }
18
19
 
19
- specify { expect(subject.prepare([{key: 'value'}])).to eq([{key: 'value'}]) }
20
+ specify { expect(subject.prepare([{ key: 'value' }])).to eq([{ key: 'value' }]) }
20
21
  end
21
22
  end
22
23
  end
@@ -11,7 +11,7 @@ RSpec.describe Granite::Form::Types::Date do
11
11
  specify { expect(typecast('2013-06-13')).to eq(date) }
12
12
  specify { expect(typecast('2013-55-55')).to be_nil }
13
13
  specify { expect(typecast('blablabla')).to be_nil }
14
- specify { expect(typecast(DateTime.new(2013, 6, 13, 23, 13))).to eq(date) } # rubocop:disable Style/DateTime
14
+ specify { expect(typecast(DateTime.new(2013, 6, 13, 23, 13))).to eq(date) }
15
15
  specify { expect(typecast(Time.new(2013, 6, 13, 23, 13))).to eq(date) }
16
16
  specify { expect(typecast(Date.new(2013, 6, 13))).to eq(date) }
17
17
  end
@@ -3,7 +3,6 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe Granite::Form::Types::DateTime do
6
- # rubocop:disable Style/DateTime
7
6
  describe 'typecasting' do
8
7
  include_context 'type setup', 'DateTime'
9
8
  let(:datetime) { DateTime.new(2013, 6, 13, 23, 13) }
@@ -16,5 +15,4 @@ RSpec.describe Granite::Form::Types::DateTime do
16
15
  specify { expect(typecast(Time.utc(2013, 6, 13, 23, 13).utc)).to eq(datetime) }
17
16
  specify { expect(typecast(DateTime.new(2013, 6, 13, 23, 13))).to eq(datetime) }
18
17
  end
19
- # rubocop:enable Style/DateTime
20
18
  end
@@ -4,6 +4,7 @@ require 'spec_helper'
4
4
 
5
5
  describe Granite::Form::Types::Dictionary do
6
6
  subject(:type) { described_class.new(subtype_definition) }
7
+
7
8
  let(:element_type) { Dummy }
8
9
  let(:subtype_definition) { Granite::Form::Types::Object.new(element_type, reflection, nil) }
9
10
  let(:reflection) { build_reflection }
@@ -4,6 +4,7 @@ require 'spec_helper'
4
4
 
5
5
  describe Granite::Form::Types::HasSubtype do
6
6
  subject(:type) { described_class.new(subtype_definition) }
7
+
7
8
  let(:subtype_definition) { Granite::Form::Types::Object.new(Dummy, reflection, nil) }
8
9
  let(:reflection) { Granite::Form::Model::Attributes::Reflections::Base.new(:field) }
9
10
  let(:dummy_object) { Dummy.new }
@@ -12,9 +13,13 @@ describe Granite::Form::Types::HasSubtype do
12
13
 
13
14
  describe '#build_duplicate' do
14
15
  subject { type.build_duplicate(new_reflection, new_model) }
16
+
15
17
  let(:new_model) { double('new_model') }
16
18
  let(:new_reflection) { double('new_reflection') }
17
19
 
18
- it { is_expected.to have_attributes(subtype_definition: have_attributes(type: Dummy, reflection: new_reflection, owner: new_model)) }
20
+ it {
21
+ expect(subject).to have_attributes(subtype_definition: have_attributes(type: Dummy, reflection: new_reflection,
22
+ owner: new_model))
23
+ }
19
24
  end
20
25
  end
@@ -11,7 +11,7 @@ RSpec.describe Granite::Form::Types::HashWithActionControllerParameters do
11
11
  Class.new(ActionController::Base)
12
12
  end
13
13
 
14
- let(:to_h) { {'x' => {'foo' => 'bar'}, 'y' => 2} }
14
+ let(:to_h) { { 'x' => { 'foo' => 'bar' }, 'y' => 2 } }
15
15
  let(:parameters) { ActionController::Parameters.new(to_h) }
16
16
 
17
17
  specify { expect(typecast(nil)).to be_nil }
@@ -4,6 +4,7 @@ require 'spec_helper'
4
4
 
5
5
  RSpec.describe Granite::Form::Types::Object do
6
6
  subject(:type) { build_type(reflection: reflection) }
7
+
7
8
  let(:model) { Model.new }
8
9
  let(:reflection) { build_reflection }
9
10
 
@@ -25,6 +26,7 @@ RSpec.describe Granite::Form::Types::Object do
25
26
 
26
27
  describe '#build_duplicate' do
27
28
  subject { type.build_duplicate(new_reflection, new_model) }
29
+
28
30
  let(:new_model) { double('new_model') }
29
31
  let(:new_reflection) { Granite::Form::Model::Attributes::Reflections::Base.new(:new_field) }
30
32
 
@@ -3,7 +3,6 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe Granite::Form::Types::Time do
6
- # rubocop:disable Style/DateTime
7
6
  describe 'typecasting' do
8
7
  include_context 'type setup', 'Time'
9
8
 
@@ -27,5 +26,4 @@ RSpec.describe Granite::Form::Types::Time do
27
26
  specify { expect(typecast(Time.new(2013, 6, 13, 23, 13))).to eq(Time.new(2013, 6, 13, 23, 13)) }
28
27
  end
29
28
  end
30
- # rubocop:enable Style/DateTime
31
29
  end
@@ -21,6 +21,7 @@ RSpec.describe Granite::Form::Util do
21
21
 
22
22
  describe '#evaluate' do
23
23
  subject { dummy.evaluate(target) }
24
+
24
25
  let(:target) { 'Peter' }
25
26
 
26
27
  it { is_expected.to eq('Peter') }
@@ -56,6 +57,7 @@ RSpec.describe Granite::Form::Util do
56
57
 
57
58
  describe '#evaluate_if_proc' do
58
59
  subject { dummy.evaluate(target) }
60
+
59
61
  let(:target) { 'Peter' }
60
62
 
61
63
  it { is_expected.to eq('Peter') }
@@ -77,7 +79,8 @@ RSpec.describe Granite::Form::Util do
77
79
 
78
80
  describe '#conditions_satisfied?' do
79
81
  subject { dummy.conditions_satisfied?(**conditions) }
80
- let(:conditions) { {if: -> { name == 'John' }} }
82
+
83
+ let(:conditions) { { if: -> { name == 'John' } } }
81
84
 
82
85
  it { is_expected.to be_truthy }
83
86
 
@@ -88,7 +91,7 @@ RSpec.describe Granite::Form::Util do
88
91
  end
89
92
 
90
93
  context 'when unless condition is passed' do
91
- let(:conditions) { {unless: :name} }
94
+ let(:conditions) { { unless: :name } }
92
95
 
93
96
  it { is_expected.to be_falsey }
94
97
  end
@@ -100,7 +103,7 @@ RSpec.describe Granite::Form::Util do
100
103
  end
101
104
 
102
105
  context 'when both if & unless are passed' do
103
- let(:conditions) { {if: :name, unless: :name} }
106
+ let(:conditions) { { if: :name, unless: :name } }
104
107
 
105
108
  it { expect { subject }.to raise_error(ArgumentError) }
106
109
  end
@@ -20,4 +20,17 @@ ActiveRecord::Schema.define do
20
20
  t.column :related_ids, :integer, array: true
21
21
  t.column :data, :text
22
22
  end
23
+
24
+ if ActiveModel.version >= Gem::Version.new('7.0.0')
25
+ create_enum 'foo', %w[foo bar baz]
26
+
27
+ create_table :foo_containers, force: :cascade do |t|
28
+ t.enum :foos, enum_type: 'foo', array: true
29
+ end
30
+ end
31
+ end
32
+
33
+ if ActiveModel.version >= Gem::Version.new('7.0.0')
34
+ class FooContainer < ActiveRecord::Base
35
+ end
23
36
  end