roqua-support 0.1.9 → 0.1.10
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/.gitignore +3 -1
- data/CHANGELOG.md +5 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +78 -37
- data/README.md +31 -0
- data/lib/roqua-support.rb +7 -0
- data/lib/roqua-support/version.rb +1 -1
- data/lib/roqua/responders/active_interaction_aware_responder.rb +25 -0
- data/lib/roqua/responders/api_errors_responder.rb +15 -0
- data/lib/roqua/support/log_wrapper.rb +1 -1
- data/spec/roqua/responders/active_interaction_aware_responder_spec.rb +54 -0
- data/spec/roqua/responders/api_errors_responder_spec.rb +34 -0
- data/spec/roqua/support/errors_spec.rb +2 -0
- data/spec/roqua/support/logging_spec.rb +1 -1
- data/spec/spec_helper.rb +8 -0
- metadata +12 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 548055897fac03f26d5dddd82f144fa64d34d813
|
|
4
|
+
data.tar.gz: f497700a4fffb165d1b8b9a8d5ddc486bd77c841
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c8936bf834d18d7799e200de067c5739132b617c1aaf9e5cfe5fb44d2734ea277abad62ee3d7ecf7a60df0429b803919c757c1e9191fc8fcb02fe7726570b831
|
|
7
|
+
data.tar.gz: 6040338582c978cd5b0b00ff7d3bffdf728862c3551af1d7d517f579e57d3edb515d813c41ac9cab8b3acbb9c9247386d9514d1638b3599643b5394c1b991609
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -7,75 +7,116 @@ PATH
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
|
|
10
|
+
actionpack (4.1.6)
|
|
11
|
+
actionview (= 4.1.6)
|
|
12
|
+
activesupport (= 4.1.6)
|
|
13
|
+
rack (~> 1.5.2)
|
|
14
|
+
rack-test (~> 0.6.2)
|
|
15
|
+
actionview (4.1.6)
|
|
16
|
+
activesupport (= 4.1.6)
|
|
17
|
+
builder (~> 3.1)
|
|
18
|
+
erubis (~> 2.7.0)
|
|
19
|
+
active_interaction (1.3.0)
|
|
20
|
+
activemodel (>= 3.2, < 5)
|
|
21
|
+
activemodel (4.1.6)
|
|
22
|
+
activesupport (= 4.1.6)
|
|
23
|
+
builder (~> 3.1)
|
|
24
|
+
activesupport (4.1.6)
|
|
11
25
|
i18n (~> 0.6, >= 0.6.9)
|
|
12
26
|
json (~> 1.7, >= 1.7.7)
|
|
13
27
|
minitest (~> 5.1)
|
|
14
28
|
thread_safe (~> 0.1)
|
|
15
29
|
tzinfo (~> 1.1)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
celluloid (>= 0.15.0)
|
|
20
|
-
nio4r (>= 0.5.0)
|
|
30
|
+
builder (3.2.2)
|
|
31
|
+
celluloid (0.16.0)
|
|
32
|
+
timers (~> 4.0.0)
|
|
21
33
|
coderay (1.1.0)
|
|
34
|
+
combustion (0.5.2)
|
|
35
|
+
activesupport (>= 3.0.0)
|
|
36
|
+
railties (>= 3.0.0)
|
|
37
|
+
thor (>= 0.14.6)
|
|
22
38
|
diff-lcs (1.2.5)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
39
|
+
erubis (2.7.0)
|
|
40
|
+
ffi (1.9.6)
|
|
41
|
+
formatador (0.2.5)
|
|
42
|
+
fuubar (1.3.3)
|
|
26
43
|
rspec (>= 2.14.0, < 3.1.0)
|
|
27
|
-
ruby-progressbar (~> 1.
|
|
28
|
-
guard (2.
|
|
44
|
+
ruby-progressbar (~> 1.4)
|
|
45
|
+
guard (2.7.0)
|
|
29
46
|
formatador (>= 0.2.4)
|
|
30
|
-
listen (~> 2.
|
|
47
|
+
listen (~> 2.7)
|
|
31
48
|
lumberjack (~> 1.0)
|
|
32
49
|
pry (>= 0.9.12)
|
|
33
50
|
thor (>= 0.18.1)
|
|
34
|
-
guard-rspec (4.2.
|
|
51
|
+
guard-rspec (4.2.10)
|
|
35
52
|
guard (~> 2.1)
|
|
36
53
|
rspec (>= 2.14, < 4.0)
|
|
37
|
-
|
|
54
|
+
hitimes (1.2.2)
|
|
55
|
+
i18n (0.6.11)
|
|
38
56
|
json (1.8.1)
|
|
39
|
-
listen (2.
|
|
57
|
+
listen (2.7.11)
|
|
40
58
|
celluloid (>= 0.15.2)
|
|
41
|
-
celluloid-io (>= 0.15.0)
|
|
42
59
|
rb-fsevent (>= 0.9.3)
|
|
43
60
|
rb-inotify (>= 0.9)
|
|
44
|
-
lumberjack (1.0.
|
|
61
|
+
lumberjack (1.0.9)
|
|
45
62
|
method_source (0.8.2)
|
|
46
|
-
minitest (5.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
method_source (~> 0.8)
|
|
63
|
+
minitest (5.4.2)
|
|
64
|
+
pry (0.10.1)
|
|
65
|
+
coderay (~> 1.1.0)
|
|
66
|
+
method_source (~> 0.8.1)
|
|
51
67
|
slop (~> 3.4)
|
|
52
|
-
|
|
68
|
+
rack (1.5.2)
|
|
69
|
+
rack-test (0.6.2)
|
|
70
|
+
rack (>= 1.0)
|
|
71
|
+
railties (4.1.6)
|
|
72
|
+
actionpack (= 4.1.6)
|
|
73
|
+
activesupport (= 4.1.6)
|
|
74
|
+
rake (>= 0.8.7)
|
|
75
|
+
thor (>= 0.18.1, < 2.0)
|
|
76
|
+
rake (10.3.2)
|
|
53
77
|
rb-fsevent (0.9.4)
|
|
54
|
-
rb-inotify (0.9.
|
|
78
|
+
rb-inotify (0.9.5)
|
|
55
79
|
ffi (>= 0.5.0)
|
|
56
|
-
rspec (
|
|
57
|
-
rspec-core (~>
|
|
58
|
-
rspec-expectations (~>
|
|
59
|
-
rspec-mocks (~>
|
|
60
|
-
rspec-core (
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
80
|
+
rspec (3.0.0)
|
|
81
|
+
rspec-core (~> 3.0.0)
|
|
82
|
+
rspec-expectations (~> 3.0.0)
|
|
83
|
+
rspec-mocks (~> 3.0.0)
|
|
84
|
+
rspec-core (3.0.4)
|
|
85
|
+
rspec-support (~> 3.0.0)
|
|
86
|
+
rspec-expectations (3.0.4)
|
|
87
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
88
|
+
rspec-support (~> 3.0.0)
|
|
89
|
+
rspec-mocks (3.0.4)
|
|
90
|
+
rspec-support (~> 3.0.0)
|
|
91
|
+
rspec-rails (3.0.2)
|
|
92
|
+
actionpack (>= 3.0)
|
|
93
|
+
activesupport (>= 3.0)
|
|
94
|
+
railties (>= 3.0)
|
|
95
|
+
rspec-core (~> 3.0.0)
|
|
96
|
+
rspec-expectations (~> 3.0.0)
|
|
97
|
+
rspec-mocks (~> 3.0.0)
|
|
98
|
+
rspec-support (~> 3.0.0)
|
|
99
|
+
rspec-support (3.0.4)
|
|
100
|
+
ruby-progressbar (1.6.0)
|
|
101
|
+
slop (3.6.0)
|
|
102
|
+
thor (0.19.1)
|
|
67
103
|
thread_safe (0.3.4)
|
|
68
|
-
timers (
|
|
69
|
-
|
|
104
|
+
timers (4.0.1)
|
|
105
|
+
hitimes
|
|
106
|
+
tzinfo (1.2.2)
|
|
70
107
|
thread_safe (~> 0.1)
|
|
71
108
|
|
|
72
109
|
PLATFORMS
|
|
73
110
|
ruby
|
|
74
111
|
|
|
75
112
|
DEPENDENCIES
|
|
113
|
+
actionpack (~> 4.0)
|
|
114
|
+
active_interaction (~> 1.0)
|
|
76
115
|
bundler (~> 1.0)
|
|
116
|
+
combustion (~> 0.5.2)
|
|
77
117
|
fuubar (~> 1.3.2)
|
|
78
118
|
guard-rspec (~> 4.2.6)
|
|
79
119
|
rake
|
|
80
120
|
roqua-support!
|
|
81
121
|
rspec (>= 2.12.0, < 4.0)
|
|
122
|
+
rspec-rails
|
data/README.md
CHANGED
|
@@ -45,6 +45,37 @@ require 'roqua/support/request_logger'
|
|
|
45
45
|
Roqua::Support::RequestLogger.attach_to :action_controller
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
+
### Responders
|
|
49
|
+
|
|
50
|
+
#### option 1
|
|
51
|
+
|
|
52
|
+
Create responder including the required responder modules and use it in a controller.
|
|
53
|
+
|
|
54
|
+
```ruby
|
|
55
|
+
class ApiResponder < ActionController::Responder
|
|
56
|
+
include Roqua::Responders::ApiErrorsResponder
|
|
57
|
+
include Roqua::Responders::ActiveInteractionAwareResponder
|
|
58
|
+
end
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
class ApiAreaController < ApplicationController
|
|
63
|
+
self.responder = ApiResponder
|
|
64
|
+
...
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
#### option 2
|
|
68
|
+
|
|
69
|
+
Use gem 'responders'
|
|
70
|
+
|
|
71
|
+
And add required responder modules in a controller.
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
class ApiAreaController < ApplicationController
|
|
75
|
+
responders :flash, Roqua::Responders::ApiErrorsResponder, Roqua::Responders::ActiveInteractionAwareResponder
|
|
76
|
+
...
|
|
77
|
+
```
|
|
78
|
+
|
|
48
79
|
## Contributing
|
|
49
80
|
|
|
50
81
|
1. Fork it
|
data/lib/roqua-support.rb
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
require "roqua-support/version"
|
|
2
2
|
require "roqua/support"
|
|
3
|
+
|
|
4
|
+
module Roqua
|
|
5
|
+
module Responders
|
|
6
|
+
autoload :ApiErrorsResponder, 'roqua/responders/api_errors_responder'
|
|
7
|
+
autoload :ActiveInteractionAwareResponder, 'roqua/responders/active_interaction_aware_responder'
|
|
8
|
+
end
|
|
9
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# For json and xml, will render the result of an active_interaction operation if no errors where present.
|
|
2
|
+
# Otherwise renders the interaction
|
|
3
|
+
module Roqua
|
|
4
|
+
module Responders
|
|
5
|
+
module ActiveInteractionAwareResponder
|
|
6
|
+
def to_format
|
|
7
|
+
if resource.is_a?(ActiveInteraction::Base)
|
|
8
|
+
if resource.errors.empty?
|
|
9
|
+
@resource = resource.result
|
|
10
|
+
@resources[-1] = resource
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
super
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def json_resource_errors
|
|
17
|
+
if !resource.is_a?(ActiveInteraction::Base) || resource.errors.empty?
|
|
18
|
+
super
|
|
19
|
+
else
|
|
20
|
+
{:errors => resource.errors.as_json}
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Scopes json errors to the object-class:
|
|
2
|
+
#
|
|
3
|
+
# @example
|
|
4
|
+
# {errors: {person: name: ['blank']}}
|
|
5
|
+
#
|
|
6
|
+
# Does not play well with others, replaces json_resource_errors; when including multiple responders, ordering matters.
|
|
7
|
+
module Roqua
|
|
8
|
+
module Responders
|
|
9
|
+
module ApiErrorsResponder
|
|
10
|
+
def json_resource_errors
|
|
11
|
+
{:errors => {resource.class.name.underscore => resource.errors}}
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -27,7 +27,7 @@ module Roqua
|
|
|
27
27
|
info("#{message}:finished", {duration: duration}.merge(options))
|
|
28
28
|
value
|
|
29
29
|
rescue => e
|
|
30
|
-
error("#{message}:failed", {exception: e.class, message: e.message}.merge(options))
|
|
30
|
+
error("#{message}:failed", {exception: e.class.name, message: e.message}.merge(options))
|
|
31
31
|
raise
|
|
32
32
|
end
|
|
33
33
|
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
require 'roqua/responders/active_interaction_aware_responder'
|
|
4
|
+
class AIAResponder < ActionController::Responder
|
|
5
|
+
include Roqua::Responders::ActiveInteractionAwareResponder
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
require 'active_interaction'
|
|
9
|
+
class TestInteraction < ActiveInteraction::Base
|
|
10
|
+
string :some_string
|
|
11
|
+
def execute
|
|
12
|
+
{foo: some_string}
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
class ApplicationController < ActionController::Base
|
|
17
|
+
respond_to :json
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe Roqua::Responders::ActiveInteractionAwareResponder, type: :controller do
|
|
21
|
+
context 'with a valid interaction' do
|
|
22
|
+
controller(ApplicationController) do
|
|
23
|
+
self.responder = AIAResponder
|
|
24
|
+
def index
|
|
25
|
+
use_case = TestInteraction.run some_string: 'bla'
|
|
26
|
+
respond_with use_case
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
subject { get :index, format: :json }
|
|
31
|
+
|
|
32
|
+
it 'returns the result if valid' do
|
|
33
|
+
subject
|
|
34
|
+
expect(response.body).to eq '{"foo":"bla"}'
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
context 'with an invalid interaction' do
|
|
40
|
+
controller(ApplicationController) do
|
|
41
|
+
self.responder = AIAResponder
|
|
42
|
+
def index
|
|
43
|
+
use_case = TestInteraction.run
|
|
44
|
+
respond_with use_case
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
subject { post :index, format: :json }
|
|
48
|
+
|
|
49
|
+
it 'returns the interaction' do
|
|
50
|
+
subject
|
|
51
|
+
expect(response.body).to eq '{"errors":{"some_string":["is required"]}}'
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'roqua/responders/api_errors_responder'
|
|
3
|
+
class AEResponder < ActionController::Responder
|
|
4
|
+
include Roqua::Responders::ApiErrorsResponder
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
class ApplicationController < ActionController::Base
|
|
8
|
+
respond_to :json
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class SomeModel
|
|
12
|
+
include ActiveModel::Model
|
|
13
|
+
|
|
14
|
+
attr_accessor :name
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe Roqua::Responders::ApiErrorsResponder, type: :controller do
|
|
18
|
+
context 'with an invalid model' do
|
|
19
|
+
controller(ApplicationController) do
|
|
20
|
+
self.responder = AEResponder
|
|
21
|
+
def index
|
|
22
|
+
sm = SomeModel.new name: 'foo'
|
|
23
|
+
sm.errors.add :name, "That is not a real name"
|
|
24
|
+
respond_with sm
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
subject { post :index, format: :json }
|
|
28
|
+
|
|
29
|
+
it 'returns the errors scoped on the object name' do
|
|
30
|
+
subject
|
|
31
|
+
expect(response.body).to eq '{"errors":{"some_model":{"name":["That is not a real name"]}}}'
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
1
2
|
require 'roqua/support/errors'
|
|
2
3
|
|
|
3
4
|
describe 'Error reporting' do
|
|
@@ -12,6 +13,7 @@ describe 'Error reporting' do
|
|
|
12
13
|
let(:logwrapper) { Roqua::LogWrapper.new(logger) }
|
|
13
14
|
|
|
14
15
|
before do
|
|
16
|
+
Rails.env = 'foo' # in test we don't log
|
|
15
17
|
Roqua.logger = logwrapper
|
|
16
18
|
end
|
|
17
19
|
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: roqua-support
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.10
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Marten Veldthuis
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-
|
|
11
|
+
date: 2014-10-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -102,6 +102,8 @@ files:
|
|
|
102
102
|
- lib/roqua/core_ext/enumerable/sort_by_alphanum.rb
|
|
103
103
|
- lib/roqua/core_ext/fabrication/singleton.rb
|
|
104
104
|
- lib/roqua/core_ext/fixnum/clamp.rb
|
|
105
|
+
- lib/roqua/responders/active_interaction_aware_responder.rb
|
|
106
|
+
- lib/roqua/responders/api_errors_responder.rb
|
|
105
107
|
- lib/roqua/support.rb
|
|
106
108
|
- lib/roqua/support/command_runner.rb
|
|
107
109
|
- lib/roqua/support/errors.rb
|
|
@@ -114,10 +116,13 @@ files:
|
|
|
114
116
|
- spec/roqua/core_ext/enumerable/sort_by_alphanum_spec.rb
|
|
115
117
|
- spec/roqua/core_ext/fabrication/singleton_spec.rb
|
|
116
118
|
- spec/roqua/core_ext/fixnum/clamp_spec.rb
|
|
119
|
+
- spec/roqua/responders/active_interaction_aware_responder_spec.rb
|
|
120
|
+
- spec/roqua/responders/api_errors_responder_spec.rb
|
|
117
121
|
- spec/roqua/support/errors_spec.rb
|
|
118
122
|
- spec/roqua/support/logging_spec.rb
|
|
119
123
|
- spec/roqua/support/request_logger_spec.rb
|
|
120
124
|
- spec/roqua/support_spec.rb
|
|
125
|
+
- spec/spec_helper.rb
|
|
121
126
|
homepage: https://github.com/roqua/healthy
|
|
122
127
|
licenses:
|
|
123
128
|
- MIT
|
|
@@ -138,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
138
143
|
version: '0'
|
|
139
144
|
requirements: []
|
|
140
145
|
rubyforge_project:
|
|
141
|
-
rubygems_version: 2.
|
|
146
|
+
rubygems_version: 2.3.0
|
|
142
147
|
signing_key:
|
|
143
148
|
specification_version: 4
|
|
144
149
|
summary: Helper objects and proxies used by a lot of RoQua applications
|
|
@@ -148,7 +153,11 @@ test_files:
|
|
|
148
153
|
- spec/roqua/core_ext/enumerable/sort_by_alphanum_spec.rb
|
|
149
154
|
- spec/roqua/core_ext/fabrication/singleton_spec.rb
|
|
150
155
|
- spec/roqua/core_ext/fixnum/clamp_spec.rb
|
|
156
|
+
- spec/roqua/responders/active_interaction_aware_responder_spec.rb
|
|
157
|
+
- spec/roqua/responders/api_errors_responder_spec.rb
|
|
151
158
|
- spec/roqua/support/errors_spec.rb
|
|
152
159
|
- spec/roqua/support/logging_spec.rb
|
|
153
160
|
- spec/roqua/support/request_logger_spec.rb
|
|
154
161
|
- spec/roqua/support_spec.rb
|
|
162
|
+
- spec/spec_helper.rb
|
|
163
|
+
has_rdoc:
|