lev 9.0.0 → 9.0.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/lib/lev/better_active_model_errors.rb +8 -7
- data/lib/lev/version.rb +1 -1
- data/spec/better_active_model_errors_spec.rb +25 -0
- metadata +18 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d1863a4a2253c9d582fabc34ec0b3347bfac6ab
|
4
|
+
data.tar.gz: dc9eadf03105c2863fc432dae3096431bfcef8b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92f85896091e416faa19e243d55c3035f933b3cccf0c15030bac7d883521dc04afaf61ac4d1f5e00bfea63974060628bedeba70b01f3f3df07084d830ef6e716
|
7
|
+
data.tar.gz: 0fb631e0ad4d3a0f9930f60abd9a258a76fea71a6389566be0f7baab05bc5131388d7d9e280a3e032e5e5de9542fdb9d43a28dac2ab69b95841d63df882c17e6
|
@@ -105,27 +105,28 @@ module Lev
|
|
105
105
|
|
106
106
|
# Do the error messages include an error with key +error+?
|
107
107
|
def include?(error)
|
108
|
-
(v = messages[error]) && v.any?
|
108
|
+
(v = messages[error.to_sym]) && v.any?
|
109
109
|
end
|
110
110
|
alias :has_key? :include?
|
111
111
|
|
112
112
|
# Get messages for +key+
|
113
113
|
def get(key)
|
114
|
-
messages[key]
|
114
|
+
messages[key.to_sym]
|
115
115
|
end
|
116
116
|
|
117
117
|
def get_type(key)
|
118
|
-
types[key]
|
118
|
+
types[key.to_sym]
|
119
119
|
end
|
120
120
|
|
121
121
|
# Set messages for +key+ to +value+
|
122
122
|
def set(key, value)
|
123
|
-
types[key] = (value == [] ? [] : (value.is_a?(Symbol) ? value : nil))
|
124
|
-
messages[key] = value
|
123
|
+
types[key.to_sym] = (value == [] ? [] : (value.is_a?(Symbol) ? value : nil))
|
124
|
+
messages[key.to_sym] = value
|
125
125
|
end
|
126
126
|
|
127
127
|
# Delete messages for +key+
|
128
128
|
def delete(key)
|
129
|
+
key = key.to_sym
|
129
130
|
types.delete(key)
|
130
131
|
messages.delete(key)
|
131
132
|
end
|
@@ -261,7 +262,7 @@ module Lev
|
|
261
262
|
end
|
262
263
|
|
263
264
|
self[attribute] << normalized_message
|
264
|
-
self.types[attribute] << message.try(:to_sym)
|
265
|
+
self.types[attribute.to_sym] << message.try(:to_sym)
|
265
266
|
end
|
266
267
|
|
267
268
|
# Will add an error message to each of the attributes in +attributes+ that is empty.
|
@@ -354,7 +355,7 @@ module Lev
|
|
354
355
|
# TODO maybe don't need this method split out any more?
|
355
356
|
def self.generate_message(model, attribute, type = :invalid, options = {})
|
356
357
|
type = options.delete(:message) if options[:message].is_a?(Symbol)
|
357
|
-
|
358
|
+
attribute = attribute.to_sym
|
358
359
|
if model.class.respond_to?(:i18n_scope)
|
359
360
|
defaults = model.class.lookup_ancestors.map do |klass|
|
360
361
|
[ :"#{model.class.i18n_scope}.errors.models.#{klass.model_name.i18n_key}.attributes.#{attribute}.#{type}",
|
data/lib/lev/version.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'Better active model errors' do
|
4
|
+
|
5
|
+
class DummyModel
|
6
|
+
def self.human_attribute_name(attr, default='')
|
7
|
+
return attr.capitalize
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:test_model) { DummyModel.new }
|
12
|
+
let(:errors) { Lev::BetterActiveModelErrors.new(test_model) }
|
13
|
+
|
14
|
+
it 'can record errors' do
|
15
|
+
errors[:foo] = 'bar'
|
16
|
+
expect(errors.any?).to be(true)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'can add using strings' do
|
20
|
+
errors.add('crash', 'is a bad bad value')
|
21
|
+
expect(errors[:crash]).to eq ['is a bad bad value']
|
22
|
+
expect(errors.include?('crash')).to be true
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lev
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 9.0.
|
4
|
+
version: 9.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JP Slavinsky
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -255,6 +255,7 @@ files:
|
|
255
255
|
- lib/lev/utilities.rb
|
256
256
|
- lib/lev/version.rb
|
257
257
|
- spec/active_job_routines_spec.rb
|
258
|
+
- spec/better_active_model_errors_spec.rb
|
258
259
|
- spec/create_sprocket_spec.rb
|
259
260
|
- spec/deep_merge_spec.rb
|
260
261
|
- spec/delegates_to_spec.rb
|
@@ -298,22 +299,23 @@ signing_key:
|
|
298
299
|
specification_version: 4
|
299
300
|
summary: Ride the rails but don't touch them.
|
300
301
|
test_files:
|
301
|
-
- spec/
|
302
|
-
- spec/
|
303
|
-
- spec/sprocket_handler_spec.rb
|
302
|
+
- spec/active_job_routines_spec.rb
|
303
|
+
- spec/better_active_model_errors_spec.rb
|
304
304
|
- spec/create_sprocket_spec.rb
|
305
|
-
- spec/delegates_to_spec.rb
|
306
|
-
- spec/transaction_spec.rb
|
307
305
|
- spec/deep_merge_spec.rb
|
308
|
-
- spec/
|
309
|
-
- spec/support/sprocket_handler.rb
|
310
|
-
- spec/support/paramify_handler_a.rb
|
311
|
-
- spec/support/delegating_routine.rb
|
312
|
-
- spec/support/create_sprocket.rb
|
313
|
-
- spec/support/delegated_routine.rb
|
314
|
-
- spec/support/sprocket.rb
|
315
|
-
- spec/sprocket_spec.rb
|
306
|
+
- spec/delegates_to_spec.rb
|
316
307
|
- spec/outputs_spec.rb
|
308
|
+
- spec/paramify_handler_spec.rb
|
317
309
|
- spec/routine_spec.rb
|
318
|
-
- spec/
|
310
|
+
- spec/spec_helper.rb
|
311
|
+
- spec/sprocket_handler_spec.rb
|
312
|
+
- spec/sprocket_spec.rb
|
319
313
|
- spec/statused_routines_spec.rb
|
314
|
+
- spec/support/create_sprocket.rb
|
315
|
+
- spec/support/delegated_routine.rb
|
316
|
+
- spec/support/delegating_routine.rb
|
317
|
+
- spec/support/paramify_handler_a.rb
|
318
|
+
- spec/support/paramify_handler_b.rb
|
319
|
+
- spec/support/sprocket.rb
|
320
|
+
- spec/support/sprocket_handler.rb
|
321
|
+
- spec/transaction_spec.rb
|