mini_form 0.2.0 → 0.2.1
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/.rubocop.yml +30 -2
- data/.travis.yml +5 -3
- data/CHANGELOG.md +5 -0
- data/README.md +2 -2
- data/lib/mini_form/model.rb +23 -6
- data/lib/mini_form/version.rb +1 -1
- data/mini_form.gemspec +3 -3
- data/spec/mini_form_spec.rb +32 -8
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2ce5edc41122a2b5bd8053b3d41fa696c26c1cc
|
4
|
+
data.tar.gz: 1851cb3f9154ee58adedbdcec78c91655b83b731
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5f02066e7377bb4eb6439fee9a96c97df91d884d0fff99e11d31199560f541fd10592c1135a8002553fc82dead710115113e4de7a8192f9e0ba7eeb77e7eb75
|
7
|
+
data.tar.gz: fad81e7df2308e9c93dd7ff7adf229e4d185372bd5f73a5bd4cec09a1041a80c368a403af56024b47f25f1d33d04330ca729036a53fec83f3cd48624fecb7a92
|
data/.rubocop.yml
CHANGED
@@ -1,16 +1,32 @@
|
|
1
1
|
require: rubocop-rspec
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
Rails:
|
4
|
+
Enabled: true
|
5
5
|
Exclude:
|
6
6
|
- example/db/**/*
|
7
7
|
- example/config/**/*
|
8
8
|
- search_object.gemspec
|
9
9
|
|
10
|
+
# Disables "Module definition is too long"
|
11
|
+
ModuleLength:
|
12
|
+
Enabled: false
|
13
|
+
|
10
14
|
# Disables "Line is too long"
|
11
15
|
LineLength:
|
12
16
|
Enabled: false
|
13
17
|
|
18
|
+
# Disables "Method is too long"
|
19
|
+
MethodLength:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
# Disables "Assignment Branch Condition size for included is too high"
|
23
|
+
AbcSize:
|
24
|
+
Enabled: false
|
25
|
+
|
26
|
+
# Disables "Block has too many lines"
|
27
|
+
BlockLength:
|
28
|
+
Enabled: false
|
29
|
+
|
14
30
|
# Disables "Missing top-level class documentation comment"
|
15
31
|
Documentation:
|
16
32
|
Enabled: false
|
@@ -22,3 +38,15 @@ Style/EachWithObject:
|
|
22
38
|
# Disables "Prefer reduce over inject."
|
23
39
|
Style/CollectionMethods:
|
24
40
|
Enabled: false
|
41
|
+
|
42
|
+
# Disables "Use tr instead of gsubs"
|
43
|
+
Performance/StringReplacement:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
# Disables "Example has too many expectations"
|
47
|
+
RSpec/MultipleExpectations:
|
48
|
+
Enabled: false
|
49
|
+
|
50
|
+
# Disables "Example has too many lines"
|
51
|
+
RSpec/ExampleLength:
|
52
|
+
Enabled: false
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -267,11 +267,11 @@ form.id = 42 # => raises `NoMethodError`
|
|
267
267
|
<td>Meant to be overwritten.</td>
|
268
268
|
</tr>
|
269
269
|
<tr>
|
270
|
-
<td>#
|
270
|
+
<td>#before_assignment</td>
|
271
271
|
<td>Meant to be overwritten.</td>
|
272
272
|
</tr>
|
273
273
|
<tr>
|
274
|
-
<td>#
|
274
|
+
<td>#after_assignment</td>
|
275
275
|
<td>Meant to be overwritten.</td>
|
276
276
|
</tr>
|
277
277
|
<tr>
|
data/lib/mini_form/model.rb
CHANGED
@@ -3,7 +3,7 @@ require 'active_model'
|
|
3
3
|
|
4
4
|
module MiniForm
|
5
5
|
module Model
|
6
|
-
def self.included(base)
|
6
|
+
def self.included(base)
|
7
7
|
base.class_eval do
|
8
8
|
include ActiveModel::Validations
|
9
9
|
include ActiveModel::Validations::Callbacks
|
@@ -15,11 +15,18 @@ module MiniForm
|
|
15
15
|
extend ClassMethods
|
16
16
|
|
17
17
|
define_model_callbacks :update
|
18
|
+
define_model_callbacks :assignment
|
19
|
+
|
20
|
+
# For backwards compatibility purpose
|
18
21
|
define_model_callbacks :assigment
|
19
22
|
|
20
23
|
before_update :before_update
|
21
24
|
after_update :after_update
|
22
25
|
|
26
|
+
before_assignment :before_assignment
|
27
|
+
after_assignment :after_assignment
|
28
|
+
|
29
|
+
# For backwards compatibility purpose
|
23
30
|
before_assigment :before_assigment
|
24
31
|
after_assigment :after_assigment
|
25
32
|
end
|
@@ -34,14 +41,16 @@ module MiniForm
|
|
34
41
|
end
|
35
42
|
|
36
43
|
def attributes=(attributes)
|
37
|
-
run_callbacks :
|
38
|
-
|
39
|
-
|
44
|
+
run_callbacks :assignment do
|
45
|
+
run_callbacks :assigment do
|
46
|
+
attributes.slice(*self.class.attribute_names).each do |name, value|
|
47
|
+
public_send "#{name}=", value
|
48
|
+
end
|
40
49
|
end
|
41
50
|
end
|
42
51
|
end
|
43
52
|
|
44
|
-
|
53
|
+
alias assign_attributes attributes=
|
45
54
|
|
46
55
|
def attributes
|
47
56
|
Hash[self.class.attribute_names.map { |name| [name, public_send(name)] }]
|
@@ -63,7 +72,7 @@ module MiniForm
|
|
63
72
|
end
|
64
73
|
|
65
74
|
def update!(attributes = {})
|
66
|
-
|
75
|
+
raise InvalidForm, self unless update attributes
|
67
76
|
self
|
68
77
|
end
|
69
78
|
|
@@ -94,6 +103,14 @@ module MiniForm
|
|
94
103
|
# noop
|
95
104
|
end
|
96
105
|
|
106
|
+
def before_assignment
|
107
|
+
# noop
|
108
|
+
end
|
109
|
+
|
110
|
+
def after_assignment
|
111
|
+
# noop
|
112
|
+
end
|
113
|
+
|
97
114
|
def before_assigment
|
98
115
|
# noop
|
99
116
|
end
|
data/lib/mini_form/version.rb
CHANGED
data/mini_form.gemspec
CHANGED
@@ -14,14 +14,14 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
17
|
-
spec.executables = spec.files.grep(
|
18
|
-
spec.test_files = spec.files.grep(
|
17
|
+
spec.executables = spec.files.grep(%r{^bin\/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(spec)\/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
21
|
spec.add_dependency 'activemodel', '~> 4.0'
|
22
22
|
|
23
23
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
24
|
-
spec.add_development_dependency 'rake'
|
24
|
+
spec.add_development_dependency 'rake', '< 11.0'
|
25
25
|
spec.add_development_dependency 'rspec', '~> 2.14'
|
26
26
|
spec.add_development_dependency 'rspec-mocks', '>= 2.12.3'
|
27
27
|
spec.add_development_dependency 'coveralls'
|
data/spec/mini_form_spec.rb
CHANGED
@@ -204,7 +204,7 @@ module MiniForm
|
|
204
204
|
|
205
205
|
model :user, attributes: %i(name), save: true
|
206
206
|
|
207
|
-
def initialize(user:
|
207
|
+
def initialize(user:)
|
208
208
|
self.user = user
|
209
209
|
end
|
210
210
|
end
|
@@ -224,9 +224,11 @@ module MiniForm
|
|
224
224
|
it 'calls "perfom" method when validation pass' do
|
225
225
|
object = ExampleForUpdate.new name: 'value'
|
226
226
|
|
227
|
-
|
227
|
+
allow(object).to receive(:perform)
|
228
228
|
|
229
229
|
object.update
|
230
|
+
|
231
|
+
expect(object).to have_received(:perform)
|
230
232
|
end
|
231
233
|
|
232
234
|
it 'calls "save" for the model' do
|
@@ -242,19 +244,37 @@ module MiniForm
|
|
242
244
|
it 'supports update callbacks' do
|
243
245
|
object = ExampleForUpdate.new name: 'value'
|
244
246
|
|
245
|
-
|
246
|
-
|
247
|
+
allow(object).to receive(:before_update)
|
248
|
+
allow(object).to receive(:after_update)
|
247
249
|
|
248
250
|
object.update
|
251
|
+
|
252
|
+
expect(object).to have_received(:before_update)
|
253
|
+
expect(object).to have_received(:after_update)
|
254
|
+
end
|
255
|
+
|
256
|
+
it 'supports legacy assig callbacks' do
|
257
|
+
object = ExampleForUpdate.new
|
258
|
+
|
259
|
+
allow(object).to receive(:before_assigment)
|
260
|
+
allow(object).to receive(:after_assigment)
|
261
|
+
|
262
|
+
object.update name: 'value'
|
263
|
+
|
264
|
+
expect(object).to have_received(:before_assigment)
|
265
|
+
expect(object).to have_received(:after_assigment)
|
249
266
|
end
|
250
267
|
|
251
268
|
it 'supports assign callbacks' do
|
252
269
|
object = ExampleForUpdate.new
|
253
270
|
|
254
|
-
|
255
|
-
|
271
|
+
allow(object).to receive(:before_assignment)
|
272
|
+
allow(object).to receive(:after_assignment)
|
256
273
|
|
257
274
|
object.update name: 'value'
|
275
|
+
|
276
|
+
expect(object).to have_received(:before_assignment)
|
277
|
+
expect(object).to have_received(:after_assignment)
|
258
278
|
end
|
259
279
|
|
260
280
|
it 'returns false when validations fail' do
|
@@ -266,9 +286,11 @@ module MiniForm
|
|
266
286
|
it 'does not call "perfom" method when validation fail' do
|
267
287
|
object = ExampleForUpdate.new name: nil
|
268
288
|
|
269
|
-
|
289
|
+
allow(object).to receive(:perform)
|
270
290
|
|
271
291
|
object.update
|
292
|
+
|
293
|
+
expect(object).not_to have_received(:perform)
|
272
294
|
end
|
273
295
|
end
|
274
296
|
|
@@ -281,9 +303,11 @@ module MiniForm
|
|
281
303
|
it 'calls update with given arguments' do
|
282
304
|
object = Example.new
|
283
305
|
|
284
|
-
|
306
|
+
allow(object).to receive(:update).and_return true
|
285
307
|
|
286
308
|
object.update! :attributes
|
309
|
+
|
310
|
+
expect(object).to have_received(:update).with(:attributes)
|
287
311
|
end
|
288
312
|
|
289
313
|
it 'raises error when update fails' do
|
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.1
|
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: 2017-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "<"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
47
|
+
version: '11.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "<"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
54
|
+
version: '11.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|