lev 2.0.4 → 2.0.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.
- data/.travis.yml +9 -0
- data/Gemfile.lock +18 -16
- data/Rakefile +6 -0
- data/lev.gemspec +1 -0
- data/lib/lev/error_translator.rb +3 -2
- data/lib/lev/version.rb +1 -1
- data/spec/create_sprocket_spec.rb +7 -2
- data/spec/routine_spec.rb +2 -2
- data/spec/spec_helper.rb +17 -1
- data/spec/sprocket_handler_spec.rb +28 -0
- data/spec/support/create_sprocket.rb +3 -3
- data/spec/support/sprocket.rb +2 -5
- data/spec/support/sprocket_handler.rb +20 -0
- metadata +25 -4
data/.travis.yml
ADDED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lev (2.0.
|
4
|
+
lev (2.0.5)
|
5
5
|
actionpack (>= 3.0)
|
6
6
|
active_attr
|
7
7
|
activemodel (>= 3.0)
|
@@ -13,8 +13,8 @@ PATH
|
|
13
13
|
GEM
|
14
14
|
remote: https://rubygems.org/
|
15
15
|
specs:
|
16
|
-
actionpack (4.0.
|
17
|
-
activesupport (= 4.0.
|
16
|
+
actionpack (4.0.3)
|
17
|
+
activesupport (= 4.0.3)
|
18
18
|
builder (~> 3.1.0)
|
19
19
|
erubis (~> 2.7.0)
|
20
20
|
rack (~> 1.5.2)
|
@@ -22,23 +22,23 @@ GEM
|
|
22
22
|
active_attr (0.8.2)
|
23
23
|
activemodel (>= 3.0.2, < 4.1)
|
24
24
|
activesupport (>= 3.0.2, < 4.1)
|
25
|
-
activemodel (4.0.
|
26
|
-
activesupport (= 4.0.
|
25
|
+
activemodel (4.0.3)
|
26
|
+
activesupport (= 4.0.3)
|
27
27
|
builder (~> 3.1.0)
|
28
|
-
activerecord (4.0.
|
29
|
-
activemodel (= 4.0.
|
28
|
+
activerecord (4.0.3)
|
29
|
+
activemodel (= 4.0.3)
|
30
30
|
activerecord-deprecated_finders (~> 1.0.2)
|
31
|
-
activesupport (= 4.0.
|
31
|
+
activesupport (= 4.0.3)
|
32
32
|
arel (~> 4.0.0)
|
33
33
|
activerecord-deprecated_finders (1.0.3)
|
34
|
-
activesupport (4.0.
|
34
|
+
activesupport (4.0.3)
|
35
35
|
i18n (~> 0.6, >= 0.6.4)
|
36
36
|
minitest (~> 4.2)
|
37
37
|
multi_json (~> 1.3)
|
38
38
|
thread_safe (~> 0.1)
|
39
39
|
tzinfo (~> 0.3.37)
|
40
|
-
arel (4.0.
|
41
|
-
atomic (1.1.
|
40
|
+
arel (4.0.2)
|
41
|
+
atomic (1.1.15)
|
42
42
|
builder (3.1.4)
|
43
43
|
columnize (0.3.6)
|
44
44
|
debugger (1.6.2)
|
@@ -50,9 +50,9 @@ GEM
|
|
50
50
|
diff-lcs (1.2.4)
|
51
51
|
erubis (2.7.0)
|
52
52
|
hashie (2.0.5)
|
53
|
-
i18n (0.6.
|
53
|
+
i18n (0.6.9)
|
54
54
|
minitest (4.7.5)
|
55
|
-
multi_json (1.8.
|
55
|
+
multi_json (1.8.4)
|
56
56
|
rack (1.5.2)
|
57
57
|
rack-test (0.6.2)
|
58
58
|
rack (>= 1.0)
|
@@ -65,14 +65,15 @@ GEM
|
|
65
65
|
rspec-expectations (2.14.3)
|
66
66
|
diff-lcs (>= 1.1.3, < 2.0)
|
67
67
|
rspec-mocks (2.14.3)
|
68
|
-
|
69
|
-
|
68
|
+
sqlite3 (1.3.9)
|
69
|
+
thread_safe (0.2.0)
|
70
|
+
atomic (>= 1.1.7, < 2)
|
70
71
|
transaction_isolation (1.0.3)
|
71
72
|
activerecord (>= 3.0.11)
|
72
73
|
transaction_retry (1.0.2)
|
73
74
|
activerecord (>= 3.0.11)
|
74
75
|
transaction_isolation (>= 1.0.2)
|
75
|
-
tzinfo (0.3.
|
76
|
+
tzinfo (0.3.38)
|
76
77
|
|
77
78
|
PLATFORMS
|
78
79
|
ruby
|
@@ -83,3 +84,4 @@ DEPENDENCIES
|
|
83
84
|
lev!
|
84
85
|
rake
|
85
86
|
rspec
|
87
|
+
sqlite3
|
data/Rakefile
CHANGED
data/lev.gemspec
CHANGED
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.add_development_dependency "bundler", "~> 1.3"
|
30
30
|
spec.add_development_dependency "rake"
|
31
31
|
spec.add_development_dependency "rspec"
|
32
|
+
spec.add_development_dependency "sqlite3"
|
32
33
|
spec.add_development_dependency "debugger"
|
33
34
|
|
34
35
|
end
|
data/lib/lev/error_translator.rb
CHANGED
@@ -11,10 +11,11 @@ module Lev
|
|
11
11
|
message = error.message || Lev::BetterActiveModelErrors.generate_message(model, attribute, error.code)
|
12
12
|
Lev::BetterActiveModelErrors.full_message(model, attribute, message)
|
13
13
|
else
|
14
|
-
error.
|
14
|
+
message = error.message.to_s
|
15
|
+
message.empty? ? error.code.to_s : message
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
18
19
|
end
|
19
20
|
|
20
|
-
end
|
21
|
+
end
|
data/lib/lev/version.rb
CHANGED
@@ -3,7 +3,12 @@ require 'spec_helper'
|
|
3
3
|
describe CreateSprocket do
|
4
4
|
|
5
5
|
it "should transfer errors appropriately" do
|
6
|
-
|
6
|
+
result = CreateSprocket.call(1,"42")
|
7
|
+
errors = result.errors.collect { |error| error.translate }
|
8
|
+
expect(errors).to eq([
|
9
|
+
'Integer gt 2 must be greater than or equal to 3',
|
10
|
+
'Text only letters can only contain letters',
|
11
|
+
])
|
7
12
|
end
|
8
13
|
|
9
|
-
end
|
14
|
+
end
|
data/spec/routine_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -19,4 +19,20 @@ end
|
|
19
19
|
|
20
20
|
require 'lev'
|
21
21
|
|
22
|
-
Dir[(File.expand_path('../support', __FILE__)) + ("/**/*.rb")].each { |f| require f }
|
22
|
+
Dir[(File.expand_path('../support', __FILE__)) + ("/**/*.rb")].each { |f| require f }
|
23
|
+
|
24
|
+
ActiveRecord::Base.establish_connection(
|
25
|
+
adapter: :sqlite3,
|
26
|
+
database: ':memory:',
|
27
|
+
)
|
28
|
+
ActiveRecord::ConnectionAdapters::SQLiteAdapter = ActiveRecord::ConnectionAdapters::SQLite3Adapter
|
29
|
+
TransactionIsolation.apply_activerecord_patch
|
30
|
+
|
31
|
+
unless Sprocket.table_exists?
|
32
|
+
ActiveRecord::Schema.define do
|
33
|
+
create_table 'sprockets', force: true do |t|
|
34
|
+
t.integer 'integer_gt_2'
|
35
|
+
t.string 'text_only_letters'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SprocketHandler do
|
4
|
+
it 'should return fatal error messages' do
|
5
|
+
SprocketHandler.any_instance.stub(:params).and_return({
|
6
|
+
sprocket: {
|
7
|
+
integer_gt_2: '1',
|
8
|
+
text_only_letters: '42',
|
9
|
+
}
|
10
|
+
})
|
11
|
+
result = SprocketHandler.handle
|
12
|
+
errors = result.errors.collect { |error| error.translate }
|
13
|
+
expect(errors).to eq(['Code cannot be blank'])
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should return fatal error codes if messages are missing' do
|
17
|
+
SprocketHandler.any_instance.stub(:params).and_return({
|
18
|
+
sprocket: {
|
19
|
+
integer_gt_2: '1',
|
20
|
+
text_only_letters: '42',
|
21
|
+
},
|
22
|
+
code: '1111',
|
23
|
+
})
|
24
|
+
result = SprocketHandler.handle
|
25
|
+
errors = result.errors.collect { |error| error.translate }
|
26
|
+
expect(errors).to eq(['invalid_code'])
|
27
|
+
end
|
28
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class CreateSprocket
|
2
2
|
|
3
|
-
|
3
|
+
include Lev::Routine
|
4
4
|
|
5
5
|
protected
|
6
6
|
|
@@ -8,7 +8,7 @@ protected
|
|
8
8
|
sprocket = Sprocket.new(integer_gt_2: number, text_only_letters: text)
|
9
9
|
sprocket.valid?
|
10
10
|
|
11
|
-
transfer_errors_from(sprocket)
|
11
|
+
transfer_errors_from(sprocket, {scope: :sprocket})
|
12
12
|
end
|
13
13
|
|
14
|
-
end
|
14
|
+
end
|
data/spec/support/sprocket.rb
CHANGED
@@ -1,10 +1,7 @@
|
|
1
|
-
class Sprocket
|
2
|
-
include ActiveAttr::Model
|
1
|
+
class Sprocket < ActiveRecord::Base
|
3
2
|
|
4
|
-
attribute :integer_gt_2, type: Integer
|
5
3
|
validates :integer_gt_2, numericality: { only_integer: true,
|
6
4
|
greater_than_or_equal_to: 3 }
|
7
|
-
attribute :text_only_letters, type: String
|
8
5
|
validates :text_only_letters, allow_blank: true,
|
9
6
|
format: { with: /\A[a-zA-Z]+\z/, message: "can only contain letters" }
|
10
|
-
end
|
7
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class SprocketHandler
|
2
|
+
|
3
|
+
include Lev::Handler
|
4
|
+
|
5
|
+
uses_routine CreateSprocket
|
6
|
+
|
7
|
+
protected
|
8
|
+
|
9
|
+
def authorized?
|
10
|
+
true
|
11
|
+
end
|
12
|
+
|
13
|
+
def handle
|
14
|
+
fatal_error(code: :no_code, message: 'Code cannot be blank') if params[:code].nil?
|
15
|
+
fatal_error(code: :invalid_code) if params[:code] != 'code'
|
16
|
+
run(CreateSprocket, params[:sprocket][:integer_gt_2],
|
17
|
+
params[:sprocket][:text_only_letters])
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lev
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-03-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -171,6 +171,22 @@ dependencies:
|
|
171
171
|
- - ! '>='
|
172
172
|
- !ruby/object:Gem::Version
|
173
173
|
version: '0'
|
174
|
+
- !ruby/object:Gem::Dependency
|
175
|
+
name: sqlite3
|
176
|
+
requirement: !ruby/object:Gem::Requirement
|
177
|
+
none: false
|
178
|
+
requirements:
|
179
|
+
- - ! '>='
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '0'
|
182
|
+
type: :development
|
183
|
+
prerelease: false
|
184
|
+
version_requirements: !ruby/object:Gem::Requirement
|
185
|
+
none: false
|
186
|
+
requirements:
|
187
|
+
- - ! '>='
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: '0'
|
174
190
|
- !ruby/object:Gem::Dependency
|
175
191
|
name: debugger
|
176
192
|
requirement: !ruby/object:Gem::Requirement
|
@@ -198,6 +214,7 @@ files:
|
|
198
214
|
- .rspec
|
199
215
|
- .ruby-gemset
|
200
216
|
- .ruby-version
|
217
|
+
- .travis.yml
|
201
218
|
- Gemfile
|
202
219
|
- Gemfile.lock
|
203
220
|
- LICENSE.txt
|
@@ -228,9 +245,11 @@ files:
|
|
228
245
|
- spec/outputs_spec.rb
|
229
246
|
- spec/routine_spec.rb
|
230
247
|
- spec/spec_helper.rb
|
248
|
+
- spec/sprocket_handler_spec.rb
|
231
249
|
- spec/sprocket_spec.rb
|
232
250
|
- spec/support/create_sprocket.rb
|
233
251
|
- spec/support/sprocket.rb
|
252
|
+
- spec/support/sprocket_handler.rb
|
234
253
|
homepage: http://github.com/lml/lev
|
235
254
|
licenses:
|
236
255
|
- MIT
|
@@ -246,7 +265,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
246
265
|
version: '0'
|
247
266
|
segments:
|
248
267
|
- 0
|
249
|
-
hash:
|
268
|
+
hash: -2969297821958856203
|
250
269
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
251
270
|
none: false
|
252
271
|
requirements:
|
@@ -255,7 +274,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
255
274
|
version: '0'
|
256
275
|
segments:
|
257
276
|
- 0
|
258
|
-
hash:
|
277
|
+
hash: -2969297821958856203
|
259
278
|
requirements: []
|
260
279
|
rubyforge_project:
|
261
280
|
rubygems_version: 1.8.25
|
@@ -268,6 +287,8 @@ test_files:
|
|
268
287
|
- spec/outputs_spec.rb
|
269
288
|
- spec/routine_spec.rb
|
270
289
|
- spec/spec_helper.rb
|
290
|
+
- spec/sprocket_handler_spec.rb
|
271
291
|
- spec/sprocket_spec.rb
|
272
292
|
- spec/support/create_sprocket.rb
|
273
293
|
- spec/support/sprocket.rb
|
294
|
+
- spec/support/sprocket_handler.rb
|