mini_form 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6d0c0c470b74ebc5e81006fa9f4f226de8d821d6
4
- data.tar.gz: 38393dfb6c142a1f85dca47a2aa16072a63f657f
3
+ metadata.gz: e2ce5edc41122a2b5bd8053b3d41fa696c26c1cc
4
+ data.tar.gz: 1851cb3f9154ee58adedbdcec78c91655b83b731
5
5
  SHA512:
6
- metadata.gz: 1f8c4900a91ceedd1b9f7c12b73e5b2fc30f033fd47783ae792a4c9e8dbb3f0bae93c65953da6ddebf1bbc75e3bb8c4484e863e33925b67672f11246e4b094b6
7
- data.tar.gz: 5a3a73ad3547ba949a1900918a1cdcfefc73c8bf77d0764d89fa0858c6fe8ae075a0493066f80b65d62429160e5a93d2734303d75fcc66d8b8746596d3455730
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
- AllCops:
4
- RunRailsCops: true
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
@@ -1,10 +1,12 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0
4
- - 2.1
5
- - 2.2
3
+ - 2.2.5
4
+ - 2.3.3
5
+ - 2.4.0
6
6
  script:
7
7
  - bundle exec rubocop
8
8
  - bundle exec rspec spec
9
+ sudo: false
10
+ cache: bundle
9
11
  notifications:
10
12
  email: false
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased 0.2.1
4
+
5
+ * Fix typo in `assignment` callbaks
6
+ * Alias `assignment` to `assigment` for backwards compatibility
7
+
3
8
  ## Version 0.2.0
4
9
 
5
10
  * Don't expose model name on `model`. _(security fix)_
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>#before_assigment</td>
270
+ <td>#before_assignment</td>
271
271
  <td>Meant to be overwritten.</td>
272
272
  </tr>
273
273
  <tr>
274
- <td>#after_assigment</td>
274
+ <td>#after_assignment</td>
275
275
  <td>Meant to be overwritten.</td>
276
276
  </tr>
277
277
  <tr>
@@ -3,7 +3,7 @@ require 'active_model'
3
3
 
4
4
  module MiniForm
5
5
  module Model
6
- def self.included(base) # rubocop:disable MethodLength
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 :assigment do
38
- attributes.slice(*self.class.attribute_names).each do |name, value|
39
- public_send "#{name}=", value
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
- alias_method :assign_attributes, :attributes=
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
- fail InvalidForm, self unless update attributes
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
@@ -1,3 +1,3 @@
1
1
  module MiniForm
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'.freeze
3
3
  end
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(/^bin\//) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(/^(spec)\//)
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'
@@ -204,7 +204,7 @@ module MiniForm
204
204
 
205
205
  model :user, attributes: %i(name), save: true
206
206
 
207
- def initialize(user: 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
- expect(object).to receive(:perform)
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
- expect(object).to receive(:before_update)
246
- expect(object).to receive(:after_update)
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
- expect(object).to receive(:before_assigment)
255
- expect(object).to receive(:after_assigment)
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
- expect(object).not_to receive(:perform)
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
- expect(object).to receive(:update).with(:attributes).and_return true
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.0
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: 2015-05-28 00:00:00.000000000 Z
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