substation 0.0.10.beta2 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +7 -3
- data/Changelog.md +99 -24
- data/Gemfile +8 -1
- data/Gemfile.devtools +37 -21
- data/Guardfile +1 -1
- data/README.md +118 -46
- data/TODO.md +1 -0
- data/config/flay.yml +2 -2
- data/config/flog.yml +1 -1
- data/config/reek.yml +41 -16
- data/config/rubocop.yml +44 -0
- data/config/yardstick.yml +1 -1
- data/lib/substation.rb +41 -5
- data/lib/substation/chain.rb +73 -84
- data/lib/substation/chain/definition.rb +147 -0
- data/lib/substation/chain/dsl.rb +150 -112
- data/lib/substation/chain/dsl/config.rb +55 -0
- data/lib/substation/chain/dsl/module_builder.rb +84 -0
- data/lib/substation/dispatcher.rb +20 -229
- data/lib/substation/dsl/guard.rb +96 -0
- data/lib/substation/dsl/registry.rb +181 -0
- data/lib/substation/environment.rb +126 -23
- data/lib/substation/environment/dsl.rb +31 -12
- data/lib/substation/processor.rb +238 -7
- data/lib/substation/processor/builder.rb +26 -0
- data/lib/substation/processor/config.rb +24 -0
- data/lib/substation/processor/evaluator.rb +66 -42
- data/lib/substation/processor/evaluator/handler.rb +54 -0
- data/lib/substation/processor/evaluator/result.rb +24 -0
- data/lib/substation/processor/executor.rb +46 -0
- data/lib/substation/processor/nest.rb +40 -0
- data/lib/substation/processor/transformer.rb +46 -0
- data/lib/substation/processor/wrapper.rb +16 -5
- data/lib/substation/request.rb +29 -27
- data/lib/substation/response.rb +19 -34
- data/lib/substation/response/api.rb +37 -0
- data/lib/substation/response/exception.rb +20 -0
- data/lib/substation/response/exception/output.rb +59 -0
- data/lib/substation/response/failure.rb +11 -0
- data/lib/substation/response/success.rb +11 -0
- data/lib/substation/version.rb +3 -1
- data/spec/demo/core.rb +64 -0
- data/spec/demo/core/action.rb +49 -0
- data/spec/demo/core/action/create_person.rb +28 -0
- data/spec/demo/core/errors.rb +16 -0
- data/spec/demo/core/facade.rb +38 -0
- data/spec/demo/core/handler.rb +21 -0
- data/spec/demo/core/handler/acceptor.rb +47 -0
- data/spec/demo/core/handler/authenticator.rb +36 -0
- data/spec/demo/core/handler/authorizer.rb +38 -0
- data/spec/demo/core/input.rb +15 -0
- data/spec/demo/core/observers.rb +10 -0
- data/spec/demo/core/validator.rb +21 -0
- data/spec/demo/domain/actor.rb +29 -0
- data/spec/demo/domain/dto/person.rb +18 -0
- data/spec/demo/domain/environment.rb +55 -0
- data/spec/demo/domain/storage.rb +49 -0
- data/spec/demo/web.rb +26 -0
- data/spec/demo/web/errors.rb +9 -0
- data/spec/demo/web/facade.rb +60 -0
- data/spec/demo/web/handler/deserializer.rb +36 -0
- data/spec/demo/web/presenter.rb +38 -0
- data/spec/demo/web/presenter/person.rb +19 -0
- data/spec/demo/web/renderer.rb +45 -0
- data/spec/demo/web/sanitizer.rb +35 -0
- data/spec/demo/web/sanitizer/person.rb +20 -0
- data/spec/demo/web/views.rb +28 -0
- data/spec/integration/demo/core_spec.rb +97 -0
- data/spec/integration/demo/web_spec.rb +114 -0
- data/spec/shared/context/integration/demo.rb +33 -0
- data/spec/shared/context/unit/chain.rb +13 -0
- data/spec/shared/context/unit/processor.rb +58 -0
- data/spec/shared/context/unit/request.rb +8 -0
- data/spec/shared/examples/integration/demo.rb +35 -0
- data/spec/shared/examples/unit/processor.rb +72 -0
- data/spec/spec_helper.rb +52 -23
- data/spec/unit/substation/chain/definition_spec.rb +141 -0
- data/spec/unit/substation/chain/dsl/config/dsl_module_spec.rb +13 -0
- data/spec/unit/substation/chain/dsl/config/registry_spec.rb +13 -0
- data/spec/unit/substation/chain/dsl/config_spec.rb +18 -0
- data/spec/unit/substation/chain/dsl/module_builder_spec.rb +77 -0
- data/spec/unit/substation/chain/dsl_spec.rb +175 -0
- data/spec/unit/substation/chain_spec.rb +303 -0
- data/spec/unit/substation/dispatcher_spec.rb +68 -0
- data/spec/unit/substation/dsl/guard_spec.rb +72 -0
- data/spec/unit/substation/dsl/registry_spec.rb +181 -0
- data/spec/unit/substation/environment/dsl_spec.rb +156 -0
- data/spec/unit/substation/environment_spec.rb +259 -0
- data/spec/unit/substation/processor/builder_spec.rb +21 -0
- data/spec/unit/substation/processor/config_spec.rb +40 -0
- data/spec/unit/substation/processor/evaluator/handler_spec.rb +20 -0
- data/spec/unit/substation/processor/evaluator/pivot_spec.rb +42 -0
- data/spec/unit/substation/processor/evaluator/request_spec.rb +11 -0
- data/spec/unit/substation/processor/evaluator/result/failure_spec.rb +14 -0
- data/spec/unit/substation/processor/evaluator/result/success_spec.rb +14 -0
- data/spec/unit/substation/processor/evaluator/result_spec.rb +13 -0
- data/spec/unit/substation/processor/evaluator_spec.rb +18 -0
- data/spec/unit/substation/processor/executor/null_spec.rb +25 -0
- data/spec/unit/substation/processor/executor_spec.rb +32 -0
- data/spec/unit/substation/processor/fallible_spec.rb +24 -0
- data/spec/unit/substation/processor/incoming_spec.rb +17 -0
- data/spec/unit/substation/processor/nest/incoming_spec.rb +56 -0
- data/spec/unit/substation/processor/nest_spec.rb +6 -0
- data/spec/unit/substation/processor/outgoing_spec.rb +47 -0
- data/spec/unit/substation/processor/transformer/incoming_spec.rb +17 -0
- data/spec/unit/substation/processor/transformer/outgoing_spec.rb +17 -0
- data/spec/unit/substation/processor/wrapper/incoming_spec.rb +15 -0
- data/spec/unit/substation/processor/wrapper/outgoing_spec.rb +15 -0
- data/spec/unit/substation/processor/wrapper_spec.rb +24 -0
- data/spec/unit/substation/processor_spec.rb +68 -0
- data/spec/unit/substation/request_spec.rb +70 -0
- data/spec/unit/substation/response/api_spec.rb +22 -0
- data/spec/unit/substation/response/exception/output_spec.rb +46 -0
- data/spec/unit/substation/response/exception_spec.rb +25 -0
- data/spec/unit/substation/response/failure_spec.rb +25 -0
- data/spec/unit/substation/response/success_spec.rb +24 -0
- data/spec/unit/substation/response_spec.rb +73 -0
- data/substation.gemspec +7 -6
- metadata +157 -67
- checksums.yaml +0 -7
- data/TODO +0 -0
- data/lib/substation/observer.rb +0 -66
- data/lib/substation/processor/pivot.rb +0 -25
- data/lib/substation/utils.rb +0 -68
- data/spec/integration/substation/dispatcher/call_spec.rb +0 -260
- data/spec/unit/substation/chain/call_spec.rb +0 -63
- data/spec/unit/substation/chain/dsl/builder/class_methods/call_spec.rb +0 -19
- data/spec/unit/substation/chain/dsl/builder/dsl_spec.rb +0 -21
- data/spec/unit/substation/chain/dsl/builder/failure_chain_spec.rb +0 -30
- data/spec/unit/substation/chain/dsl/chain_spec.rb +0 -15
- data/spec/unit/substation/chain/dsl/class_methods/processors_spec.rb +0 -24
- data/spec/unit/substation/chain/dsl/initialize_spec.rb +0 -19
- data/spec/unit/substation/chain/dsl/processors_spec.rb +0 -42
- data/spec/unit/substation/chain/dsl/use_spec.rb +0 -14
- data/spec/unit/substation/chain/each_spec.rb +0 -46
- data/spec/unit/substation/chain/incoming/result_spec.rb +0 -21
- data/spec/unit/substation/chain/outgoing/call_spec.rb +0 -25
- data/spec/unit/substation/chain/outgoing/result_spec.rb +0 -21
- data/spec/unit/substation/dispatcher/action/call_spec.rb +0 -23
- data/spec/unit/substation/dispatcher/action/class_methods/coerce_spec.rb +0 -61
- data/spec/unit/substation/dispatcher/action_names_spec.rb +0 -14
- data/spec/unit/substation/dispatcher/call_spec.rb +0 -47
- data/spec/unit/substation/dispatcher/class_methods/coerce_spec.rb +0 -20
- data/spec/unit/substation/environment/chain_spec.rb +0 -50
- data/spec/unit/substation/environment/class_methods/build_spec.rb +0 -11
- data/spec/unit/substation/environment/dsl/class_methods/registry_spec.rb +0 -18
- data/spec/unit/substation/environment/dsl/register_spec.rb +0 -14
- data/spec/unit/substation/environment/dsl/registry_spec.rb +0 -19
- data/spec/unit/substation/observer/chain/call_spec.rb +0 -26
- data/spec/unit/substation/observer/class_methods/coerce_spec.rb +0 -33
- data/spec/unit/substation/observer/null/call_spec.rb +0 -12
- data/spec/unit/substation/processor/evaluator/call_spec.rb +0 -49
- data/spec/unit/substation/processor/pivot/call_spec.rb +0 -17
- data/spec/unit/substation/processor/wrapper/call_spec.rb +0 -20
- data/spec/unit/substation/request/env_spec.rb +0 -14
- data/spec/unit/substation/request/error_spec.rb +0 -15
- data/spec/unit/substation/request/input_spec.rb +0 -14
- data/spec/unit/substation/request/success_spec.rb +0 -15
- data/spec/unit/substation/response/env_spec.rb +0 -16
- data/spec/unit/substation/response/failure/success_predicate_spec.rb +0 -15
- data/spec/unit/substation/response/input_spec.rb +0 -16
- data/spec/unit/substation/response/output_spec.rb +0 -16
- data/spec/unit/substation/response/request_spec.rb +0 -16
- data/spec/unit/substation/response/success/success_predicate_spec.rb +0 -15
- data/spec/unit/substation/utils/class_methods/coerce_callable_spec.rb +0 -46
- data/spec/unit/substation/utils/class_methods/const_get_spec.rb +0 -46
- data/spec/unit/substation/utils/class_methods/symbolize_keys_spec.rb +0 -20
@@ -1,19 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Chain::DSL::Builder, '.call' do
|
6
|
-
subject { described_class.call(registry) }
|
7
|
-
|
8
|
-
let(:registry) { { :test => Spec::Processor } }
|
9
|
-
|
10
|
-
let(:builder) { double(:dsl => dsl) }
|
11
|
-
let(:dsl) { double }
|
12
|
-
|
13
|
-
before do
|
14
|
-
described_class.should_receive(:new).with(registry).and_return(builder)
|
15
|
-
builder.should_receive(:dsl).and_return(dsl)
|
16
|
-
end
|
17
|
-
|
18
|
-
it { should be(dsl) }
|
19
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Chain::DSL::Builder, '#dsl' do
|
6
|
-
subject { dsl.new(env, processors, &block) }
|
7
|
-
|
8
|
-
let(:env) { Spec::FAKE_ENV }
|
9
|
-
let(:dsl) { builder.dsl }
|
10
|
-
let(:builder) { described_class.new(registry) }
|
11
|
-
let(:registry) { { :test => Spec::Processor } }
|
12
|
-
let(:processors) { [] }
|
13
|
-
let(:block) { lambda { |_| test(Spec::FAKE_HANDLER) } }
|
14
|
-
let(:processor) { Spec::FAKE_PROCESSOR }
|
15
|
-
|
16
|
-
its(:processors) { should include(processor) }
|
17
|
-
|
18
|
-
it "should create a subclass of Chain::DSL" do
|
19
|
-
subject.class.should be < Chain::DSL
|
20
|
-
end
|
21
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe "Initializing a processor's failure chain" do
|
6
|
-
subject { chain.call(request) }
|
7
|
-
|
8
|
-
let(:env) {
|
9
|
-
Environment.build {
|
10
|
-
register :evaluate, Processor::Evaluator
|
11
|
-
register :wrap, Processor::Wrapper
|
12
|
-
}
|
13
|
-
}
|
14
|
-
|
15
|
-
let(:chain) {
|
16
|
-
env.chain {
|
17
|
-
evaluate(Spec::Handler::Evaluator) {
|
18
|
-
wrap Spec::Presenter
|
19
|
-
}
|
20
|
-
}
|
21
|
-
}
|
22
|
-
|
23
|
-
let(:request) { Request.new(app_env, input) }
|
24
|
-
let(:app_env) { double }
|
25
|
-
let(:input) { :invalid }
|
26
|
-
|
27
|
-
let(:response) { Response::Failure.new(request, Spec::Presenter.new(:failure)) }
|
28
|
-
|
29
|
-
it { should eql(response) }
|
30
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Chain::DSL, '#chain' do
|
6
|
-
subject { object.chain(other) }
|
7
|
-
|
8
|
-
let(:object) { described_class.new(env, chain) }
|
9
|
-
let(:env) { Spec::FAKE_ENV }
|
10
|
-
let(:chain) { Chain::EMPTY }
|
11
|
-
let(:other) { [ processor ] }
|
12
|
-
let(:processor) { Spec::FAKE_PROCESSOR }
|
13
|
-
|
14
|
-
its(:processors) { should include(processor) }
|
15
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Chain::DSL, '.processors' do
|
6
|
-
|
7
|
-
let(:env) { Spec::FAKE_ENV }
|
8
|
-
let(:chain) { Chain::EMPTY }
|
9
|
-
|
10
|
-
context "and a block is given" do
|
11
|
-
subject { described_class.processors(env, chain, &block) }
|
12
|
-
|
13
|
-
let(:block) { lambda { |_| use(Spec::FAKE_PROCESSOR) } }
|
14
|
-
let(:processor) { Spec::FAKE_PROCESSOR }
|
15
|
-
|
16
|
-
it { should include(processor) }
|
17
|
-
end
|
18
|
-
|
19
|
-
context "and no block is given" do
|
20
|
-
subject { described_class.processors(env, chain) }
|
21
|
-
|
22
|
-
it { should be_empty }
|
23
|
-
end
|
24
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
# Test wether env is correctly passed down
|
6
|
-
describe Chain::DSL, '#initialize' do
|
7
|
-
subject { dsl.new(env, processors, &block) }
|
8
|
-
|
9
|
-
let(:env) { Spec::FAKE_ENV }
|
10
|
-
let(:dsl) { builder.dsl }
|
11
|
-
let(:builder) { described_class::Builder.new(registry) }
|
12
|
-
let(:registry) { { :test => Spec::Processor } }
|
13
|
-
let(:processors) { [] }
|
14
|
-
let(:block) { lambda { |_| test(Spec::FAKE_HANDLER) } }
|
15
|
-
|
16
|
-
let(:processor) { Spec::FAKE_PROCESSOR }
|
17
|
-
|
18
|
-
its(:processors) { should include(processor) }
|
19
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Chain::DSL, '#processors' do
|
6
|
-
subject { object.processors }
|
7
|
-
|
8
|
-
let(:env) { Spec::FAKE_ENV }
|
9
|
-
let(:processor) { Spec::FAKE_PROCESSOR }
|
10
|
-
|
11
|
-
context "and a block is given" do
|
12
|
-
let(:object) { described_class.new(env, chain, &block) }
|
13
|
-
let(:chain) { Chain::EMPTY }
|
14
|
-
let(:block) { lambda { |_| use(Spec::FAKE_PROCESSOR) } }
|
15
|
-
|
16
|
-
it { should include(processor) }
|
17
|
-
|
18
|
-
its(:length) { should == 1 }
|
19
|
-
end
|
20
|
-
|
21
|
-
context "and no block is given" do
|
22
|
-
let(:object) { described_class.new(env, chain) }
|
23
|
-
let(:chain) { Chain.new([ processor ]) }
|
24
|
-
|
25
|
-
it { should include(processor) }
|
26
|
-
|
27
|
-
its(:length) { should == 1 }
|
28
|
-
end
|
29
|
-
|
30
|
-
# TODO move this elsewhere once mutant supports it
|
31
|
-
context "test DSL#initialize" do
|
32
|
-
let(:object) { described_class.new(env, chain, &block) }
|
33
|
-
let(:chain) { Chain::EMPTY }
|
34
|
-
let(:block) { lambda { |_| use(Spec::FAKE_PROCESSOR) } }
|
35
|
-
|
36
|
-
it { should include(processor) }
|
37
|
-
|
38
|
-
it "passes down the env to registered processors" do
|
39
|
-
subject.first.env.should be(env)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Chain::DSL, '#use' do
|
6
|
-
subject { object.use(processor) }
|
7
|
-
|
8
|
-
let(:object) { described_class.new(env, chain) }
|
9
|
-
let(:env) { Spec::FAKE_ENV }
|
10
|
-
let(:chain) { Chain::EMPTY }
|
11
|
-
let(:processor) { Spec::FAKE_PROCESSOR }
|
12
|
-
|
13
|
-
its(:processors) { should include(processor) }
|
14
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Chain, '#each' do
|
6
|
-
subject { object.each { |tuple| yields << processor } }
|
7
|
-
|
8
|
-
let(:object) { described_class.new(processors) }
|
9
|
-
let(:processors) { [ processor ] }
|
10
|
-
let(:processor) { Spec::FAKE_PROCESSOR }
|
11
|
-
let(:yields) { [] }
|
12
|
-
|
13
|
-
before do
|
14
|
-
object.should be_instance_of(described_class)
|
15
|
-
end
|
16
|
-
|
17
|
-
it_should_behave_like 'an #each method'
|
18
|
-
|
19
|
-
it 'yields only processors' do
|
20
|
-
subject
|
21
|
-
yields.each { |processor| processor.should be_instance_of(Spec::Processor) }
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'yields only processors with the expected handler' do
|
25
|
-
expect { subject }.to change { yields.dup }.
|
26
|
-
from([]).
|
27
|
-
to([ processor ])
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe Chain do
|
32
|
-
subject { described_class.new(processors) }
|
33
|
-
|
34
|
-
let(:processors) { [ processor ] }
|
35
|
-
let(:processor) { Spec::FAKE_PROCESSOR }
|
36
|
-
|
37
|
-
before do
|
38
|
-
subject.should be_instance_of(described_class)
|
39
|
-
end
|
40
|
-
|
41
|
-
it { should be_kind_of(Enumerable) }
|
42
|
-
|
43
|
-
it 'case matches Enumerable' do
|
44
|
-
(Enumerable === subject).should be(true)
|
45
|
-
end
|
46
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Chain::Incoming, '#result' do
|
6
|
-
|
7
|
-
subject { object.result(response) }
|
8
|
-
|
9
|
-
let(:object) {
|
10
|
-
Class.new {
|
11
|
-
include Substation::Chain::Incoming
|
12
|
-
}.new
|
13
|
-
}
|
14
|
-
|
15
|
-
let(:response) { Response::Success.new(request, input) }
|
16
|
-
let(:request) { Request.new(env, input) }
|
17
|
-
let(:env) { double }
|
18
|
-
let(:input) { double }
|
19
|
-
|
20
|
-
it { should eql(request) }
|
21
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Chain::Outgoing, '#call' do
|
6
|
-
|
7
|
-
subject { object.call(request) }
|
8
|
-
|
9
|
-
let(:object) {
|
10
|
-
Class.new {
|
11
|
-
include Substation::Chain::Outgoing
|
12
|
-
def call(request)
|
13
|
-
response = request.success(request.input)
|
14
|
-
respond_with(response, :altered)
|
15
|
-
end
|
16
|
-
}.new
|
17
|
-
}
|
18
|
-
|
19
|
-
let(:response) { Response::Success.new(request, :altered) }
|
20
|
-
let(:request) { Request.new(env, input) }
|
21
|
-
let(:env) { double }
|
22
|
-
let(:input) { double }
|
23
|
-
|
24
|
-
it { should eql(response) }
|
25
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Chain::Outgoing, '#result' do
|
6
|
-
|
7
|
-
subject { object.result(response) }
|
8
|
-
|
9
|
-
let(:object) {
|
10
|
-
Class.new {
|
11
|
-
include Substation::Chain::Outgoing
|
12
|
-
}.new
|
13
|
-
}
|
14
|
-
|
15
|
-
let(:response) { Response::Success.new(request, input) }
|
16
|
-
let(:request) { Request.new(env, input) }
|
17
|
-
let(:env) { double }
|
18
|
-
let(:input) { double }
|
19
|
-
|
20
|
-
it { should be(response) }
|
21
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Dispatcher::Action, '#call' do
|
6
|
-
|
7
|
-
subject { object.call(request) }
|
8
|
-
|
9
|
-
let(:object) { described_class.new(klass, observer) }
|
10
|
-
let(:klass) { double }
|
11
|
-
let(:observer) { double }
|
12
|
-
let(:request) { Request.new(env, input) }
|
13
|
-
let(:env) { double }
|
14
|
-
let(:input) { double }
|
15
|
-
let(:response) { double }
|
16
|
-
|
17
|
-
before do
|
18
|
-
klass.should_receive(:call).with(request).and_return(response)
|
19
|
-
observer.should_receive(:call).with(response)
|
20
|
-
end
|
21
|
-
|
22
|
-
it { should eql(response) }
|
23
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Dispatcher::Action, '.coerce' do
|
6
|
-
|
7
|
-
subject { described_class.coerce(config) }
|
8
|
-
|
9
|
-
let(:action) { Spec::Action::Success }
|
10
|
-
let(:coerced) { Dispatcher::Action.new(action, observer) }
|
11
|
-
|
12
|
-
context "when config is a hash" do
|
13
|
-
context "and coercion is possible" do
|
14
|
-
|
15
|
-
let(:config) {{
|
16
|
-
:action => action,
|
17
|
-
:observer => observer_value
|
18
|
-
}}
|
19
|
-
|
20
|
-
before do
|
21
|
-
Observer.should_receive(:coerce).with(observer_value).and_return(observer)
|
22
|
-
Utils.should_receive(:coerce_callable).with(action).and_return(action)
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'with an action and an observer' do
|
26
|
-
let(:observer_value) { observer }
|
27
|
-
let(:observer) { Spec::Observer }
|
28
|
-
|
29
|
-
it { should eql(coerced) }
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'with an action and no observer' do
|
33
|
-
let(:observer_value) { nil }
|
34
|
-
let(:observer) { Observer::NULL }
|
35
|
-
|
36
|
-
it { should eql(coerced) }
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context 'with no action' do
|
41
|
-
let(:config) { {} }
|
42
|
-
|
43
|
-
specify {
|
44
|
-
expect { subject }.to raise_error(described_class::MissingHandlerError)
|
45
|
-
}
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context "when config is no hash" do
|
50
|
-
let(:config) { action }
|
51
|
-
let(:observer_value) { nil }
|
52
|
-
let(:observer) { Observer::NULL }
|
53
|
-
|
54
|
-
before do
|
55
|
-
Observer.should_receive(:coerce).with(observer_value).and_return(observer)
|
56
|
-
Utils.should_receive(:coerce_callable).with(config).and_return(action)
|
57
|
-
end
|
58
|
-
|
59
|
-
it { should eql(coerced) }
|
60
|
-
end
|
61
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Dispatcher, '#action_names' do
|
6
|
-
|
7
|
-
subject { object.action_names }
|
8
|
-
|
9
|
-
let(:object) { described_class.new(config, env) }
|
10
|
-
let(:config) { { :test => { :action => Spec::Action::Success } } }
|
11
|
-
let(:env) { double }
|
12
|
-
|
13
|
-
it { should eql(Set[ :test ]) }
|
14
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Dispatcher, '#call' do
|
6
|
-
|
7
|
-
subject { object.call(action_name, input) }
|
8
|
-
|
9
|
-
let(:object) { described_class.coerce(config, env) }
|
10
|
-
let(:config) { { 'test' => { 'action' => 'Spec::Action::Success' } } }
|
11
|
-
let(:request) { Request.new(env, input) }
|
12
|
-
let(:input) { double }
|
13
|
-
let(:env) { double }
|
14
|
-
|
15
|
-
let(:expected_response) do
|
16
|
-
Spec::Action::Success.call(request)
|
17
|
-
end
|
18
|
-
|
19
|
-
context 'when the action is registered' do
|
20
|
-
let(:action_name) { :test }
|
21
|
-
|
22
|
-
context 'without callbacks' do
|
23
|
-
it { should eql(expected_response) }
|
24
|
-
end
|
25
|
-
|
26
|
-
context 'with observers' do
|
27
|
-
let(:config) {
|
28
|
-
config = super()
|
29
|
-
config['test']['observer'] = 'Spec::Observer'
|
30
|
-
config
|
31
|
-
}
|
32
|
-
|
33
|
-
it 'should call callback with response' do
|
34
|
-
Spec::Observer.should_receive(:call).with(expected_response)
|
35
|
-
should eql(expected_response)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context 'when the action is not registered' do
|
41
|
-
let(:action_name) { :unknown }
|
42
|
-
|
43
|
-
specify do
|
44
|
-
expect { subject }.to raise_error(described_class::UnknownActionError)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|