ballast 1.9.3 → 2.0.0
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/.rubocop.yml +35 -0
- data/.travis-gemfile +4 -5
- data/.travis.yml +3 -2
- data/CHANGELOG.md +62 -6
- data/Gemfile +7 -8
- data/README.md +2 -2
- data/ballast.gemspec +9 -12
- data/doc/Ballast/AjaxResponse.html +1380 -0
- data/doc/Ballast/Concerns/AjaxHandling.html +662 -0
- data/doc/Ballast/Concerns/Common.html +81 -361
- data/doc/Ballast/Concerns/ErrorsHandling.html +18 -36
- data/doc/Ballast/Concerns/View.html +181 -157
- data/doc/Ballast/Concerns.html +6 -6
- data/doc/Ballast/Configuration.html +204 -31
- data/doc/Ballast/Emoji/Character.html +411 -0
- data/doc/Ballast/Emoji/Utils.html +794 -0
- data/doc/Ballast/Emoji.html +125 -0
- data/doc/Ballast/Errors/{BaseError.html → Base.html} +61 -34
- data/doc/Ballast/Errors/{PerformError.html → Failure.html} +21 -17
- data/doc/Ballast/Errors/InvalidDomain.html +11 -11
- data/doc/Ballast/Errors/{ValidationError.html → ValidationFailure.html} +24 -16
- data/doc/Ballast/Errors.html +5 -5
- data/doc/Ballast/Middlewares/DefaultHost.html +6 -6
- data/doc/Ballast/Middlewares.html +4 -4
- data/doc/Ballast/RequestDomainMatcher.html +28 -28
- data/doc/Ballast/Service/Response.html +1243 -0
- data/doc/Ballast/Service.html +1314 -0
- data/doc/Ballast/Version.html +7 -7
- data/doc/Ballast.html +15 -15
- data/doc/_index.html +59 -30
- data/doc/class_list.html +6 -2
- data/doc/css/style.css +1 -0
- data/doc/file.README.html +6 -6
- data/doc/file_list.html +5 -1
- data/doc/frames.html +1 -1
- data/doc/index.html +6 -6
- data/doc/js/full_list.js +4 -1
- data/doc/method_list.html +167 -79
- data/doc/top-level-namespace.html +41 -4
- data/lib/ballast/ajax_response.rb +76 -0
- data/lib/ballast/concerns/ajax_handling.rb +73 -0
- data/lib/ballast/concerns/common.rb +25 -47
- data/lib/ballast/concerns/errors_handling.rb +21 -30
- data/lib/ballast/concerns/view.rb +24 -22
- data/lib/ballast/configuration.rb +30 -10
- data/lib/ballast/emoji.rb +114 -0
- data/lib/ballast/errors.rb +16 -13
- data/lib/ballast/middlewares/default_host.rb +3 -3
- data/lib/ballast/request_domain_matcher.rb +7 -7
- data/lib/ballast/service.rb +147 -0
- data/lib/ballast/version.rb +3 -3
- data/lib/ballast.rb +22 -22
- data/spec/ballast/ajax_response_spec.rb +61 -0
- data/spec/ballast/concerns/ajax_handling_spec.rb +86 -0
- data/spec/ballast/concerns/common_spec.rb +17 -52
- data/spec/ballast/concerns/errors_handling_spec.rb +35 -29
- data/spec/ballast/concerns/view_spec.rb +21 -32
- data/spec/ballast/configuration_spec.rb +66 -16
- data/spec/ballast/emoji_spec.rb +103 -0
- data/spec/ballast/errors_spec.rb +5 -5
- data/spec/ballast/middlewares/default_host_spec.rb +3 -5
- data/spec/ballast/request_domain_matcher_spec.rb +4 -4
- data/spec/ballast/service_spec.rb +137 -0
- data/spec/spec_helper.rb +1 -13
- metadata +42 -80
- data/doc/Ballast/Concerns/Ajax.html +0 -945
- data/doc/Ballast/Context.html +0 -417
- data/doc/Ballast/Operation.html +0 -1304
- data/doc/Ballast/OperationsChain.html +0 -597
- data/lib/ballast/concerns/ajax.rb +0 -134
- data/lib/ballast/context.rb +0 -38
- data/lib/ballast/operation.rb +0 -136
- data/lib/ballast/operations_chain.rb +0 -45
- data/spec/ballast/concerns/ajax_spec.rb +0 -141
- data/spec/ballast/context_spec.rb +0 -23
- data/spec/ballast/operation_spec.rb +0 -177
- data/spec/ballast/operations_chain_spec.rb +0 -61
@@ -1,177 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# This file is part of the ballast gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
|
3
|
-
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
|
4
|
-
#
|
5
|
-
|
6
|
-
require "spec_helper"
|
7
|
-
|
8
|
-
describe Ballast::Operation do
|
9
|
-
describe ".perform" do
|
10
|
-
it "should call the superclass implementation with no changes if the first arg is of the right class" do
|
11
|
-
context = Ballast::Context.new
|
12
|
-
|
13
|
-
expect(Ballast::Context).not_to receive(:build)
|
14
|
-
|
15
|
-
Ballast::Operation.perform(context)
|
16
|
-
Ballast::Operation.perform(nil, context: context)
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should create a context on the fly if the first arg is NOT of the right class" do
|
20
|
-
expect(Ballast::Context).to receive(:build).with("OWNER", {}).and_return("ONTHEFLY")
|
21
|
-
Ballast::Operation.perform("OWNER")
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "#initialize" do
|
26
|
-
it "should save the context and then call #setup" do
|
27
|
-
expect_any_instance_of(Ballast::Operation).to receive(:setup)
|
28
|
-
subject = Ballast::Operation.new("CONTEXT")
|
29
|
-
|
30
|
-
expect(subject.context).to eq("CONTEXT")
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe "#in_em_thread" do
|
35
|
-
it "should call Ballast.in_em_thread" do
|
36
|
-
expect(Ballast).to receive(:in_em_thread).and_call_original
|
37
|
-
|
38
|
-
counter = 0
|
39
|
-
allow(EM).to receive(:reactor_running?).and_return(true)
|
40
|
-
expect(EM::Synchrony).to receive(:defer){|&block| block.call }
|
41
|
-
|
42
|
-
Ballast::Operation.new({}).in_em_thread { counter = 1 }
|
43
|
-
expect(counter).to eq(1)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "#setup_response" do
|
48
|
-
it "should save instance variables into the context response" do
|
49
|
-
subject = Ballast::Operation.new(Ballast::Context.build(nil, response: {a: 1, b: 2, c: 3, d: 4}))
|
50
|
-
subject.instance_variable_set(:@first, "A")
|
51
|
-
subject.instance_variable_set(:@second, "B")
|
52
|
-
subject.instance_variable_set(:@third, "C")
|
53
|
-
|
54
|
-
subject.setup_response
|
55
|
-
expect(subject.response).to eq({a: 1, b: 2, c: 3, d: 4, first: "A", second: "B", third: "C"}.with_indifferent_access)
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should not do anything if interactor failed" do
|
59
|
-
subject = Ballast::Operation.new(Ballast::Context.build(nil, response: {a: 1, b: 2, c: 3, d: 4}))
|
60
|
-
expect(subject).to receive(:success?).and_return(false)
|
61
|
-
|
62
|
-
subject.instance_variable_set(:@first, "A")
|
63
|
-
subject.instance_variable_set(:@second, "B")
|
64
|
-
subject.instance_variable_set(:@third, "C")
|
65
|
-
|
66
|
-
subject.setup_response
|
67
|
-
expect(subject.response).to eq({a: 1, b: 2, c: 3, d: 4}.with_indifferent_access)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe "#import_response" do
|
72
|
-
before(:each) do
|
73
|
-
@subject = Ballast::Operation.new(Ballast::Context.build(nil, response: {a: 1, b: 2, c: 3, d: 4}))
|
74
|
-
@target = Object.new
|
75
|
-
@target.instance_variable_set(:@c, 1)
|
76
|
-
@target.instance_variable_set(:@d, 2)
|
77
|
-
end
|
78
|
-
|
79
|
-
it "should load instance variables from the context response" do
|
80
|
-
@subject.import_response(@target, :a, :b)
|
81
|
-
expect(@target.instance_variable_get(:@a)).to eq(1)
|
82
|
-
expect(@target.instance_variable_get(:@b)).to eq(2)
|
83
|
-
end
|
84
|
-
|
85
|
-
it "should overwrite a variable by default" do
|
86
|
-
expect { @subject.import_response(@target, :c) }.not_to raise_error
|
87
|
-
expect(@target.instance_variable_get(:@c)).to eq(3)
|
88
|
-
end
|
89
|
-
|
90
|
-
it "should raise an error if a variable is already defined and overwrite is disabled" do
|
91
|
-
expect { @subject.import_response(@target, :c, overwrite: false) }.to raise_error(ArgumentError)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
describe "#perform_with_handling" do
|
96
|
-
before(:each) do
|
97
|
-
@subject = Ballast::Operation.new({})
|
98
|
-
end
|
99
|
-
|
100
|
-
it "should yield the block" do
|
101
|
-
expect(@subject).to receive(:setup_response)
|
102
|
-
|
103
|
-
counter = 0
|
104
|
-
@subject.perform_with_handling { counter = 1 }
|
105
|
-
expect(counter).to eq(1)
|
106
|
-
end
|
107
|
-
|
108
|
-
it "should propagate debug dumps" do
|
109
|
-
expect { @subject.perform_with_handling { "DEBUG".for_debug } }.to raise_error(Lazier::Exceptions::Debug)
|
110
|
-
end
|
111
|
-
|
112
|
-
it "should handle BaseError" do
|
113
|
-
expect(@subject).to receive(:setup_response)
|
114
|
-
expect(@subject).to receive(:fail!).with("RESPONSE")
|
115
|
-
expect { @subject.perform_with_handling { raise Ballast::Errors::BaseError.new("RESPONSE") } }.not_to raise_error
|
116
|
-
end
|
117
|
-
|
118
|
-
it "should propagate the error otherwise" do
|
119
|
-
expect { @subject.perform_with_handling { raise RuntimeError.new("ERROR") } }.to raise_error(RuntimeError)
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
describe "#fail!" do
|
124
|
-
it "should append the error and mark the failure" do
|
125
|
-
subject = Ballast::Operation.new(Ballast::Context.build(nil))
|
126
|
-
subject.fail!("NO")
|
127
|
-
|
128
|
-
expect(subject.failure?).to be(true)
|
129
|
-
expect(subject.errors).to eq(["NO"])
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
describe "#import_error" do
|
134
|
-
before(:each) do
|
135
|
-
@subject = Ballast::Operation.new(Ballast::Context.build(nil, errors: [{status: 401, error: "Unauthorized"}, {status: 403, error: "Forbidden"}]))
|
136
|
-
end
|
137
|
-
|
138
|
-
it "should set the flash of the target" do
|
139
|
-
target = OpenStruct.new(flash: {})
|
140
|
-
@subject.import_error(target)
|
141
|
-
expect(target.flash[:error]).to eq("Unauthorized")
|
142
|
-
end
|
143
|
-
|
144
|
-
it "should set instance variable if request to" do
|
145
|
-
target = OpenStruct.new(flash: {})
|
146
|
-
@subject.import_error(target, false)
|
147
|
-
expect(target.instance_variable_get(:@error)).to eq({status: 401, error: "Unauthorized"}.with_indifferent_access)
|
148
|
-
end
|
149
|
-
|
150
|
-
it "should import all errors if requested to" do
|
151
|
-
target = OpenStruct.new(flash: {})
|
152
|
-
@subject.import_error(target, true, false)
|
153
|
-
@subject.import_error(target, false, false)
|
154
|
-
expect(target.flash[:error]).to eq(["Unauthorized", "Forbidden"])
|
155
|
-
expect(target.instance_variable_get(:@error)).to eq([{status: 401, error: "Unauthorized"}.with_indifferent_access, {status: 403, error: "Forbidden"}.with_indifferent_access])
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
describe "#resolve_error" do
|
160
|
-
it "should format AJAX error" do
|
161
|
-
subject = Ballast::Operation.new({})
|
162
|
-
expect(subject.resolve_error(nil)).to eq({status: 500, error: "Oops! We're having some issue. Please try again later."})
|
163
|
-
expect(subject.resolve_error("A")).to eq({status: 500, error: "Oops! We're having some issue. Please try again later."})
|
164
|
-
expect(subject.resolve_error("A", {500 => "ERROR"})).to eq({status: 500, error: "ERROR"})
|
165
|
-
expect(subject.resolve_error(OpenStruct.new(response: 403))).to eq({status: 403, error: "Oops! We're having some issue. Please try again later."})
|
166
|
-
expect(subject.resolve_error(OpenStruct.new(response: 403), {403 => "ERROR"})).to eq({status: 403, error: "ERROR"})
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
describe "method_missing" do
|
171
|
-
it "should forward call to the owner" do
|
172
|
-
subject = Ballast::Operation.new(OpenStruct.new(owner: " ABC "))
|
173
|
-
expect(subject.strip).to eq("ABC")
|
174
|
-
expect { subject.not_strip }.to raise_error(NoMethodError)
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# This file is part of the ballast gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
|
3
|
-
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
|
4
|
-
#
|
5
|
-
|
6
|
-
require "spec_helper"
|
7
|
-
|
8
|
-
describe Ballast::OperationsChain do
|
9
|
-
describe ".perform" do
|
10
|
-
class SuccessOperation < Ballast::Operation
|
11
|
-
def perform
|
12
|
-
response[:result] ||= 0
|
13
|
-
response[:result] += 1
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class FailureOperation < Ballast::Operation
|
18
|
-
def perform
|
19
|
-
fail!
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
class FinalOperation < Ballast::Operation
|
24
|
-
def perform
|
25
|
-
response[:result] = "#{response[:result]}F"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe ".perform" do
|
30
|
-
before(:each) do
|
31
|
-
expect_any_instance_of(Ballast::OperationsChain).to receive(:perform)
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should initialize with the set of operations and the first argument as context" do
|
35
|
-
context = Ballast::Context.new
|
36
|
-
expect(Ballast::Context).not_to receive(:build)
|
37
|
-
expect(Ballast::OperationsChain).to receive(:new).with([:A, :B, :C], context).and_call_original
|
38
|
-
Ballast::OperationsChain.perform(context, [:A, :B, :C])
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should use the provided owner and context" do
|
42
|
-
context = Ballast::Context.new
|
43
|
-
expect(Ballast::Context).not_to receive(:build)
|
44
|
-
expect(Ballast::OperationsChain).to receive(:new).with([:A, :B, :C], context).and_call_original
|
45
|
-
Ballast::OperationsChain.perform(nil, [:A, :B, :C], context: context)
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should created the context on the fly if needed" do
|
49
|
-
expect(Ballast::Context).to receive(:build).with("A", {a: 1})
|
50
|
-
Ballast::OperationsChain.perform("A", [:A, :B, :C], params: {a: 1})
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe "#perform" do
|
55
|
-
it "should execute the operations unless they fail" do
|
56
|
-
expect(Ballast::OperationsChain.perform(nil, [SuccessOperation, FinalOperation]).response[:result]).to eq("1F")
|
57
|
-
expect(Ballast::OperationsChain.perform(nil, [SuccessOperation, FailureOperation, FinalOperation]).response[:result].to_s).not_to match(/F$/)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|