mini_form 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +33 -0
- data/.rubocop.yml +17 -15
- data/CHANGELOG.md +4 -0
- data/Gemfile +2 -0
- data/README.md +21 -2
- data/Rakefile +2 -0
- data/lib/mini_form/errors.rb +2 -0
- data/lib/mini_form/model.rb +10 -1
- data/lib/mini_form/nested_validator.rb +2 -0
- data/lib/mini_form/version.rb +3 -1
- data/lib/mini_form.rb +2 -0
- data/mini_form.gemspec +2 -2
- data/spec/mini_form/nested_validator_spec.rb +20 -16
- data/spec/mini_form_spec.rb +119 -79
- data/spec/spec_helper.rb +2 -0
- metadata +12 -12
- data/.travis.yml +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05110a58fa226872117674c65d40a1312b20f368d2c3091abcf1f1d76ca8556f
|
4
|
+
data.tar.gz: 5046659d5998b2786b304bb47e0190dd21605863be6482106c9bb259453847e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ebdb289c2f4a3c975be13ae53e52032ff33130658cdf9b580373f9cc988d60eb8e62732280c5c71889aeac7021c50857957bfd459b689e27f8716c45e142c64
|
7
|
+
data.tar.gz: '078b887c19a8049f34ff73cbe6bc1a686f5b9219ee7e499c6176de023c80ad283529d4c5b56b3a673688b08ce175f0ca6d893e02034b39f9ca3d5a10b97ed3be'
|
@@ -0,0 +1,33 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
|
14
|
+
strategy:
|
15
|
+
matrix:
|
16
|
+
ruby-version: ['2.6', '2.7', '3.0', '3.1']
|
17
|
+
|
18
|
+
steps:
|
19
|
+
- uses: actions/checkout@v3
|
20
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
21
|
+
uses: ruby/setup-ruby@0a29871fe2b0200a17a4497bae54fe5df0d973aa # v1.115.3
|
22
|
+
with:
|
23
|
+
ruby-version: ${{ matrix.ruby-version }}
|
24
|
+
|
25
|
+
- name: Install dependencies
|
26
|
+
run: bundle install
|
27
|
+
|
28
|
+
- name: Run linters
|
29
|
+
run: bundle exec rubocop
|
30
|
+
|
31
|
+
- name: Run tests
|
32
|
+
run: bundle exec rspec spec
|
33
|
+
|
data/.rubocop.yml
CHANGED
@@ -1,34 +1,34 @@
|
|
1
1
|
require: rubocop-rspec
|
2
2
|
|
3
|
-
|
4
|
-
Enabled: true
|
3
|
+
AllCops:
|
5
4
|
Exclude:
|
6
|
-
-
|
7
|
-
|
8
|
-
|
5
|
+
- mini_form.gemspec
|
6
|
+
|
7
|
+
SuggestExtensions: false
|
8
|
+
NewCops: disable
|
9
9
|
|
10
10
|
# Disables "Module definition is too long"
|
11
|
-
ModuleLength:
|
11
|
+
Metrics/ModuleLength:
|
12
12
|
Enabled: false
|
13
13
|
|
14
14
|
# Disables "Line is too long"
|
15
|
-
LineLength:
|
15
|
+
Layout/LineLength:
|
16
16
|
Enabled: false
|
17
17
|
|
18
18
|
# Disables "Method is too long"
|
19
|
-
MethodLength:
|
19
|
+
Metrics/MethodLength:
|
20
20
|
Enabled: false
|
21
21
|
|
22
22
|
# Disables "Assignment Branch Condition size for included is too high"
|
23
|
-
AbcSize:
|
23
|
+
Metrics/AbcSize:
|
24
24
|
Enabled: false
|
25
25
|
|
26
26
|
# Disables "Block has too many lines"
|
27
|
-
BlockLength:
|
27
|
+
Metrics/BlockLength:
|
28
28
|
Enabled: false
|
29
29
|
|
30
30
|
# Disables "Missing top-level class documentation comment"
|
31
|
-
Documentation:
|
31
|
+
Style/Documentation:
|
32
32
|
Enabled: false
|
33
33
|
|
34
34
|
# Disables "Use each_with_object instead of inject"
|
@@ -43,10 +43,6 @@ Style/CollectionMethods:
|
|
43
43
|
Style/PercentLiteralDelimiters:
|
44
44
|
Enabled: false
|
45
45
|
|
46
|
-
# Disables "Use tr instead of gsubs"
|
47
|
-
Performance/StringReplacement:
|
48
|
-
Enabled: false
|
49
|
-
|
50
46
|
# Disables "Example has too many expectations"
|
51
47
|
RSpec/MultipleExpectations:
|
52
48
|
Enabled: false
|
@@ -54,3 +50,9 @@ RSpec/MultipleExpectations:
|
|
54
50
|
# Disables "Example has too many lines"
|
55
51
|
RSpec/ExampleLength:
|
56
52
|
Enabled: false
|
53
|
+
|
54
|
+
Style/HashSyntax:
|
55
|
+
Enabled: false
|
56
|
+
|
57
|
+
Lint/MissingSuper:
|
58
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
[](http://badge.fury.io/rb/mini_form)
|
2
2
|
[](https://codeclimate.com/github/RStankov/MiniForm)
|
3
|
-
[](http://travis-ci.org/RStankov/MiniForm)
|
4
3
|
[](https://coveralls.io/r/RStankov/MiniForm)
|
5
4
|
|
6
5
|
# MiniForm
|
@@ -194,6 +193,26 @@ class SignUpForm
|
|
194
193
|
end
|
195
194
|
```
|
196
195
|
|
196
|
+
### Using in forms
|
197
|
+
|
198
|
+
Using `main_model` will delegate `id`, `to_param`, `persisted?` and `new_record?` to the model. Allowing you to use it in forms.
|
199
|
+
|
200
|
+
```ruby
|
201
|
+
class SignUpForm
|
202
|
+
include MiniForm::Model
|
203
|
+
|
204
|
+
main_model :user
|
205
|
+
|
206
|
+
def initialize
|
207
|
+
@user = User.new(account: @account)
|
208
|
+
end
|
209
|
+
end
|
210
|
+
```
|
211
|
+
|
212
|
+
```eruby
|
213
|
+
<% form_for SignUpForm.new %>
|
214
|
+
```
|
215
|
+
|
197
216
|
### Delegating model attributes
|
198
217
|
|
199
218
|
```ruby
|
@@ -203,7 +222,7 @@ class SignUpForm
|
|
203
222
|
model :user, attributes: %i(name email), read: %i(id)
|
204
223
|
|
205
224
|
def initialize
|
206
|
-
@user
|
225
|
+
@user = User.new(account: @account)
|
207
226
|
end
|
208
227
|
end
|
209
228
|
```
|
data/Rakefile
CHANGED
data/lib/mini_form/errors.rb
CHANGED
data/lib/mini_form/model.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_support/all'
|
2
4
|
require 'active_model'
|
3
5
|
|
@@ -73,6 +75,7 @@ module MiniForm
|
|
73
75
|
|
74
76
|
def update!(attributes = {})
|
75
77
|
raise InvalidForm, self unless update attributes
|
78
|
+
|
76
79
|
self
|
77
80
|
end
|
78
81
|
|
@@ -156,7 +159,7 @@ module MiniForm
|
|
156
159
|
end
|
157
160
|
end
|
158
161
|
|
159
|
-
def model(name, attributes: [], read: [], prefix: nil, allow_nil: nil, save: false) # rubocop:disable ParameterLists
|
162
|
+
def model(name, attributes: [], read: [], prefix: nil, allow_nil: nil, save: false) # rubocop:disable Metrics/ParameterLists
|
160
163
|
attr_accessor name
|
161
164
|
|
162
165
|
attributes(*attributes, delegate: name, prefix: prefix, allow_nil: allow_nil) unless attributes.empty?
|
@@ -167,6 +170,12 @@ module MiniForm
|
|
167
170
|
|
168
171
|
models_to_save << name if save
|
169
172
|
end
|
173
|
+
|
174
|
+
def main_model(model_name, **args)
|
175
|
+
delegate :id, :persisted?, :to_param, :new_record?, to: model_name
|
176
|
+
|
177
|
+
model model_name, **args
|
178
|
+
end
|
170
179
|
end
|
171
180
|
end
|
172
181
|
end
|
data/lib/mini_form/version.rb
CHANGED
data/lib/mini_form.rb
CHANGED
data/mini_form.gemspec
CHANGED
@@ -22,8 +22,8 @@ Gem::Specification.new do |spec|
|
|
22
22
|
|
23
23
|
spec.add_development_dependency 'bundler', '>= 2.1.4'
|
24
24
|
spec.add_development_dependency 'rake', '>= 12.3.3'
|
25
|
-
spec.add_development_dependency 'rspec', '
|
26
|
-
spec.add_development_dependency 'rspec-mocks', '
|
25
|
+
spec.add_development_dependency 'rspec', '3.12.0'
|
26
|
+
spec.add_development_dependency 'rspec-mocks', '3.12.0'
|
27
27
|
spec.add_development_dependency 'coveralls'
|
28
28
|
spec.add_development_dependency 'rubocop'
|
29
29
|
spec.add_development_dependency 'rubocop-rspec'
|
@@ -1,28 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
include ActiveModel::Model
|
5
|
+
module SpecSupport
|
6
|
+
class Person
|
7
|
+
include ActiveModel::Model
|
7
8
|
|
8
|
-
|
9
|
+
attr_accessor :name
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
validates :name, presence: true
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
14
|
+
class Record
|
15
|
+
include ActiveModel::Validations
|
15
16
|
|
16
|
-
|
17
|
+
attr_accessor :user
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
end
|
19
|
+
def initialize(user)
|
20
|
+
@user = user
|
21
21
|
end
|
22
|
+
end
|
23
|
+
end
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
let(:
|
25
|
+
module MiniForm
|
26
|
+
describe NestedValidator do
|
27
|
+
let(:validator) { described_class.new(attributes: [:user]) }
|
28
|
+
let(:user) { SpecSupport::Person.new }
|
29
|
+
let(:record) { SpecSupport::Record.new(user) }
|
26
30
|
|
27
31
|
it 'copies errors from submodel to model' do
|
28
32
|
validator.validate(record)
|
data/spec/mini_form_spec.rb
CHANGED
@@ -1,42 +1,96 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
module
|
4
|
-
|
5
|
-
|
5
|
+
module SpecSupport
|
6
|
+
class User
|
7
|
+
include ActiveModel::Model
|
6
8
|
|
7
|
-
|
8
|
-
include ActiveModel::Model
|
9
|
+
attr_accessor :id, :name, :age
|
9
10
|
|
10
|
-
|
11
|
+
validates :name, presence: true
|
11
12
|
|
12
|
-
|
13
|
+
def to_param
|
14
|
+
"user-#{id}"
|
13
15
|
end
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
+
def persisted?
|
18
|
+
id.present?
|
19
|
+
end
|
17
20
|
|
18
|
-
|
21
|
+
def new_record?
|
22
|
+
!persisted?
|
19
23
|
end
|
24
|
+
end
|
20
25
|
|
21
|
-
|
22
|
-
|
26
|
+
class Example
|
27
|
+
include MiniForm::Model
|
23
28
|
|
24
|
-
|
29
|
+
attributes :name, :price
|
30
|
+
end
|
25
31
|
|
26
|
-
|
27
|
-
|
28
|
-
attributes :name, delegate: :user, prefix: 'full'
|
32
|
+
class ExampleWithDelegate
|
33
|
+
include MiniForm::Model
|
29
34
|
|
30
|
-
|
31
|
-
|
32
|
-
|
35
|
+
attr_reader :user
|
36
|
+
|
37
|
+
attributes :name, delegate: :user
|
38
|
+
attributes :id, delegate: :user, prefix: true
|
39
|
+
attributes :name, delegate: :user, prefix: 'full'
|
40
|
+
|
41
|
+
def initialize(user)
|
42
|
+
@user = user
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class ExampleWithModel
|
47
|
+
include MiniForm::Model
|
48
|
+
|
49
|
+
model :user, attributes: %i(name), read: %i(id)
|
50
|
+
|
51
|
+
def initialize(user)
|
52
|
+
self.user = user
|
33
53
|
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class ExampleForUpdate
|
57
|
+
include MiniForm::Model
|
58
|
+
|
59
|
+
attributes :name
|
60
|
+
|
61
|
+
validates :name, presence: true
|
62
|
+
end
|
63
|
+
|
64
|
+
class ExampleForSave
|
65
|
+
include MiniForm::Model
|
66
|
+
|
67
|
+
model :user, attributes: %i(name), save: true
|
68
|
+
|
69
|
+
def initialize(user:)
|
70
|
+
self.user = user
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
class ExampleFormModel
|
75
|
+
include MiniForm::Model
|
76
|
+
|
77
|
+
main_model :user
|
78
|
+
|
79
|
+
def initialize(user:)
|
80
|
+
self.user = user
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
module MiniForm
|
86
|
+
describe Model do
|
87
|
+
let(:user) { SpecSupport::User.new id: 1, name: 'name', age: 28 }
|
34
88
|
|
35
89
|
describe 'acts as ActiveModel' do
|
36
90
|
include ActiveModel::Lint::Tests
|
37
91
|
|
38
92
|
before do
|
39
|
-
@model = Example.new
|
93
|
+
@model = SpecSupport::Example.new
|
40
94
|
end
|
41
95
|
|
42
96
|
def assert(condition, message = nil)
|
@@ -79,24 +133,24 @@ module MiniForm
|
|
79
133
|
|
80
134
|
describe '.attributes' do
|
81
135
|
it 'generates getters' do
|
82
|
-
object = Example.new name: 'value'
|
136
|
+
object = SpecSupport::Example.new name: 'value'
|
83
137
|
expect(object.name).to eq 'value'
|
84
138
|
end
|
85
139
|
|
86
140
|
it 'generates setters' do
|
87
|
-
object = Example.new
|
141
|
+
object = SpecSupport::Example.new
|
88
142
|
object.name = 'value'
|
89
143
|
|
90
144
|
expect(object.name).to eq 'value'
|
91
145
|
end
|
92
146
|
|
93
147
|
it 'can delegate getter' do
|
94
|
-
object = ExampleWithDelegate.new user
|
148
|
+
object = SpecSupport::ExampleWithDelegate.new user
|
95
149
|
expect(object.name).to eq user.name
|
96
150
|
end
|
97
151
|
|
98
152
|
it 'can delegate setter' do
|
99
|
-
object = ExampleWithDelegate.new user
|
153
|
+
object = SpecSupport::ExampleWithDelegate.new user
|
100
154
|
|
101
155
|
object.name = 'New Name'
|
102
156
|
|
@@ -106,71 +160,75 @@ module MiniForm
|
|
106
160
|
end
|
107
161
|
|
108
162
|
describe '.model' do
|
109
|
-
ExampleWithModel = Class.new do
|
110
|
-
include Model
|
111
|
-
|
112
|
-
model :user, attributes: %i(name), read: %i(id)
|
113
|
-
|
114
|
-
def initialize(user)
|
115
|
-
self.user = user
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
163
|
it 'generates model accessors' do
|
120
|
-
object = ExampleWithModel.new user
|
164
|
+
object = SpecSupport::ExampleWithModel.new user
|
121
165
|
expect(object.user).to eq user
|
122
166
|
end
|
123
167
|
|
124
168
|
it 'can delegate only a reader' do
|
125
|
-
object = ExampleWithModel.new user
|
169
|
+
object = SpecSupport::ExampleWithModel.new user
|
126
170
|
|
127
171
|
expect(object).not_to respond_to :id=
|
128
172
|
expect(object.id).to eq user.id
|
129
173
|
end
|
130
174
|
|
131
175
|
it 'can delegate model attributes' do
|
132
|
-
object = ExampleWithModel.new user
|
176
|
+
object = SpecSupport::ExampleWithModel.new user
|
133
177
|
expect(object.name).to eq user.name
|
134
178
|
end
|
135
179
|
|
136
180
|
it 'performs nested validation for model' do
|
137
|
-
user = User.new
|
138
|
-
object = ExampleWithModel.new user
|
181
|
+
user = SpecSupport::User.new
|
182
|
+
object = SpecSupport::ExampleWithModel.new user
|
139
183
|
|
140
184
|
expect(object).not_to be_valid
|
141
185
|
expect(object.errors[:name]).to be_present
|
142
186
|
end
|
143
187
|
end
|
144
188
|
|
189
|
+
describe '.main_model' do
|
190
|
+
it 'delegates Rails form attributes to the model' do
|
191
|
+
user = SpecSupport::User.new
|
192
|
+
object = SpecSupport::ExampleFormModel.new(user: user)
|
193
|
+
|
194
|
+
expect(object).to have_attributes(
|
195
|
+
id: user.id,
|
196
|
+
to_param: user.to_param,
|
197
|
+
persisted?: user.persisted?,
|
198
|
+
new_record?: user.new_record?
|
199
|
+
)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
145
203
|
describe '.attributes_names' do
|
146
204
|
it 'returns attribute names' do
|
147
|
-
expect(Example.attribute_names).to eq %i(name price)
|
205
|
+
expect(SpecSupport::Example.attribute_names).to eq %i(name price)
|
148
206
|
end
|
149
207
|
|
150
208
|
it 'can handle prefixes' do
|
151
|
-
expect(ExampleWithDelegate.attribute_names).to include :user_id
|
152
|
-
expect(ExampleWithDelegate.attribute_names).to include :full_name
|
209
|
+
expect(SpecSupport::ExampleWithDelegate.attribute_names).to include :user_id
|
210
|
+
expect(SpecSupport::ExampleWithDelegate.attribute_names).to include :full_name
|
153
211
|
end
|
154
212
|
end
|
155
213
|
|
156
214
|
describe '#initialize' do
|
157
215
|
it 'can be called with no arguments' do
|
158
|
-
expect { Example.new }.not_to raise_error
|
216
|
+
expect { SpecSupport::Example.new }.not_to raise_error
|
159
217
|
end
|
160
218
|
|
161
219
|
it 'assign the passed attributes' do
|
162
|
-
object = Example.new price: '$5'
|
220
|
+
object = SpecSupport::Example.new price: '$5'
|
163
221
|
|
164
222
|
expect(object.price).to eq '$5'
|
165
223
|
end
|
166
224
|
|
167
225
|
it 'ignores invalid attributes' do
|
168
|
-
expect { Example.new invalid: 'attribute' }.not_to raise_error
|
226
|
+
expect { SpecSupport::Example.new invalid: 'attribute' }.not_to raise_error
|
169
227
|
end
|
170
228
|
|
171
229
|
it 'handles HashWithIndifferentAccess hashes' do
|
172
230
|
hash = ActiveSupport::HashWithIndifferentAccess.new 'price' => '$5'
|
173
|
-
object = Example.new hash
|
231
|
+
object = SpecSupport::Example.new hash
|
174
232
|
|
175
233
|
expect(object.price).to eq '$5'
|
176
234
|
end
|
@@ -178,7 +236,7 @@ module MiniForm
|
|
178
236
|
|
179
237
|
describe '#attributes' do
|
180
238
|
it 'returns attributes' do
|
181
|
-
object = Example.new name: 'iPhone', price: '$5'
|
239
|
+
object = SpecSupport::Example.new name: 'iPhone', price: '$5'
|
182
240
|
expect(object.attributes).to eq name: 'iPhone', price: '$5'
|
183
241
|
end
|
184
242
|
end
|
@@ -186,14 +244,14 @@ module MiniForm
|
|
186
244
|
['attributes=', 'assign_attributes'].each do |method_name|
|
187
245
|
describe "##{method_name}" do
|
188
246
|
it 'sets attributes' do
|
189
|
-
object = Example.new
|
247
|
+
object = SpecSupport::Example.new
|
190
248
|
object.public_send method_name, name: 'iPhone', price: '$5'
|
191
249
|
|
192
250
|
expect(object.attributes).to eq name: 'iPhone', price: '$5'
|
193
251
|
end
|
194
252
|
|
195
253
|
it 'ignores not listed attributes' do
|
196
|
-
object = Example.new
|
254
|
+
object = SpecSupport::Example.new
|
197
255
|
object.public_send method_name, invalid: 'value'
|
198
256
|
|
199
257
|
expect(object.attributes).to eq name: nil, price: nil
|
@@ -202,38 +260,20 @@ module MiniForm
|
|
202
260
|
end
|
203
261
|
|
204
262
|
describe '#update' do
|
205
|
-
ExampleForUpdate = Class.new do
|
206
|
-
include Model
|
207
|
-
|
208
|
-
attributes :name
|
209
|
-
|
210
|
-
validates :name, presence: true
|
211
|
-
end
|
212
|
-
|
213
|
-
ExampleForSave = Class.new do
|
214
|
-
include Model
|
215
|
-
|
216
|
-
model :user, attributes: %i(name), save: true
|
217
|
-
|
218
|
-
def initialize(user:)
|
219
|
-
self.user = user
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
263
|
it 'updates attributes' do
|
224
|
-
object = ExampleForUpdate.new name: 'value'
|
264
|
+
object = SpecSupport::ExampleForUpdate.new name: 'value'
|
225
265
|
|
226
266
|
expect { object.update(name: 'new value') }.to change { object.name }.to 'new value'
|
227
267
|
end
|
228
268
|
|
229
269
|
it 'returns true when validations pass' do
|
230
|
-
object = ExampleForUpdate.new name: 'value'
|
270
|
+
object = SpecSupport::ExampleForUpdate.new name: 'value'
|
231
271
|
|
232
272
|
expect(object.update).to eq true
|
233
273
|
end
|
234
274
|
|
235
275
|
it 'calls "perfom" method when validation pass' do
|
236
|
-
object = ExampleForUpdate.new name: 'value'
|
276
|
+
object = SpecSupport::ExampleForUpdate.new name: 'value'
|
237
277
|
|
238
278
|
allow(object).to receive(:perform)
|
239
279
|
|
@@ -243,7 +283,7 @@ module MiniForm
|
|
243
283
|
end
|
244
284
|
|
245
285
|
it 'calls "save" for the model' do
|
246
|
-
object = ExampleForSave.new user: user
|
286
|
+
object = SpecSupport::ExampleForSave.new user: user
|
247
287
|
|
248
288
|
allow(user).to receive(:save!)
|
249
289
|
|
@@ -253,7 +293,7 @@ module MiniForm
|
|
253
293
|
end
|
254
294
|
|
255
295
|
it 'supports update callbacks' do
|
256
|
-
object = ExampleForUpdate.new name: 'value'
|
296
|
+
object = SpecSupport::ExampleForUpdate.new name: 'value'
|
257
297
|
|
258
298
|
allow(object).to receive(:before_update)
|
259
299
|
allow(object).to receive(:after_update)
|
@@ -265,7 +305,7 @@ module MiniForm
|
|
265
305
|
end
|
266
306
|
|
267
307
|
it 'supports legacy assig callbacks' do
|
268
|
-
object = ExampleForUpdate.new
|
308
|
+
object = SpecSupport::ExampleForUpdate.new
|
269
309
|
|
270
310
|
allow(object).to receive(:before_assigment)
|
271
311
|
allow(object).to receive(:after_assigment)
|
@@ -277,7 +317,7 @@ module MiniForm
|
|
277
317
|
end
|
278
318
|
|
279
319
|
it 'supports assign callbacks' do
|
280
|
-
object = ExampleForUpdate.new
|
320
|
+
object = SpecSupport::ExampleForUpdate.new
|
281
321
|
|
282
322
|
allow(object).to receive(:before_assignment)
|
283
323
|
allow(object).to receive(:after_assignment)
|
@@ -289,13 +329,13 @@ module MiniForm
|
|
289
329
|
end
|
290
330
|
|
291
331
|
it 'returns false when validations fail' do
|
292
|
-
object = ExampleForUpdate.new name: nil
|
332
|
+
object = SpecSupport::ExampleForUpdate.new name: nil
|
293
333
|
|
294
334
|
expect(object.update).to eq false
|
295
335
|
end
|
296
336
|
|
297
337
|
it 'does not call "perfom" method when validation fail' do
|
298
|
-
object = ExampleForUpdate.new name: nil
|
338
|
+
object = SpecSupport::ExampleForUpdate.new name: nil
|
299
339
|
|
300
340
|
allow(object).to receive(:perform)
|
301
341
|
|
@@ -307,12 +347,12 @@ module MiniForm
|
|
307
347
|
|
308
348
|
describe '#update!' do
|
309
349
|
it 'returns self' do
|
310
|
-
object = Example.new
|
350
|
+
object = SpecSupport::Example.new
|
311
351
|
expect(object.update!).to eq object
|
312
352
|
end
|
313
353
|
|
314
354
|
it 'calls update with given arguments' do
|
315
|
-
object = Example.new
|
355
|
+
object = SpecSupport::Example.new
|
316
356
|
|
317
357
|
allow(object).to receive(:update).and_return true
|
318
358
|
|
@@ -322,7 +362,7 @@ module MiniForm
|
|
322
362
|
end
|
323
363
|
|
324
364
|
it 'raises error when update fails' do
|
325
|
-
object = Example.new
|
365
|
+
object = SpecSupport::Example.new
|
326
366
|
|
327
367
|
allow(object).to receive(:update).and_return false
|
328
368
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mini_form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Radoslav Stankov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -56,30 +56,30 @@ dependencies:
|
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 3.12.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 3.12.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec-mocks
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - '='
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 3.12.0
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - '='
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 3.12.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: coveralls
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -129,11 +129,11 @@ executables: []
|
|
129
129
|
extensions: []
|
130
130
|
extra_rdoc_files: []
|
131
131
|
files:
|
132
|
+
- ".github/workflows/ci.yml"
|
132
133
|
- ".gitignore"
|
133
134
|
- ".projections.json"
|
134
135
|
- ".rspec"
|
135
136
|
- ".rubocop.yml"
|
136
|
-
- ".travis.yml"
|
137
137
|
- CHANGELOG.md
|
138
138
|
- Gemfile
|
139
139
|
- LICENSE.txt
|
@@ -167,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
167
|
- !ruby/object:Gem::Version
|
168
168
|
version: '0'
|
169
169
|
requirements: []
|
170
|
-
rubygems_version: 3.
|
170
|
+
rubygems_version: 3.3.7
|
171
171
|
signing_key:
|
172
172
|
specification_version: 4
|
173
173
|
summary: Easy to use form objects in Rails projects
|