chanko 2.0.0 → 2.3.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 +7 -0
- data/.github/workflows/master_and_pr.yml +64 -0
- data/CHANGELOG.md +42 -0
- data/MIT-LICENSE +1 -1
- data/README.md +30 -9
- data/Rakefile +2 -9
- data/bin/setup +8 -0
- data/bin/test +7 -0
- data/chanko.gemspec +8 -4
- data/gemfiles/Gemfile_rails_5.0.rb +6 -0
- data/gemfiles/Gemfile_rails_5.0.rb.lock +203 -0
- data/gemfiles/Gemfile_rails_5.1.rb +6 -0
- data/gemfiles/Gemfile_rails_5.1.rb.lock +203 -0
- data/gemfiles/Gemfile_rails_5.2.rb +6 -0
- data/gemfiles/Gemfile_rails_5.2.rb.lock +209 -0
- data/gemfiles/Gemfile_rails_6.0.rb +8 -0
- data/gemfiles/Gemfile_rails_6.0.rb.lock +238 -0
- data/gemfiles/Gemfile_rails_6.1.rb +8 -0
- data/gemfiles/Gemfile_rails_6.1.rb.lock +241 -0
- data/lib/chanko/active_if.rb +42 -10
- data/lib/chanko/config.rb +20 -2
- data/lib/chanko/controller.rb +1 -1
- data/lib/chanko/exception_handler.rb +32 -5
- data/lib/chanko/function.rb +3 -1
- data/lib/chanko/invoker.rb +25 -4
- data/lib/chanko/loader.rb +127 -43
- data/lib/chanko/railtie.rb +33 -6
- data/lib/chanko/resolver/no_cache_file_system_resolver.rb +13 -0
- data/lib/chanko/test.rb +6 -1
- data/lib/chanko/unit/scope_finder.rb +7 -7
- data/lib/chanko/unit.rb +5 -1
- data/lib/chanko/unit_proxy.rb +4 -0
- data/lib/chanko/version.rb +1 -1
- data/lib/generators/chanko/unit/templates/unit.rb.erb +7 -1
- data/spec/chanko/controller_spec.rb +5 -5
- data/spec/chanko/deprecated_spec.rb +27 -0
- data/spec/chanko/exception_handler_spec.rb +23 -2
- data/spec/chanko/function_spec.rb +34 -8
- data/spec/chanko/helper_spec.rb +1 -1
- data/spec/chanko/invoker_spec.rb +62 -36
- data/spec/chanko/loader_spec.rb +14 -12
- data/spec/chanko/logger_spec.rb +13 -7
- data/spec/chanko/test_spec.rb +17 -7
- data/spec/chanko/unit/extender_spec.rb +3 -3
- data/spec/chanko/unit/scope_finder_spec.rb +4 -4
- data/spec/chanko/unit_proxy_provider_spec.rb +12 -12
- data/spec/chanko/unit_proxy_spec.rb +3 -3
- data/spec/chanko/unit_spec.rb +107 -33
- data/spec/controllers/application_controller_spec.rb +2 -2
- data/spec/dummy/README.md +12 -0
- data/spec/dummy/app/assets/config/manifest.js +3 -0
- data/spec/dummy/app/controllers/entries_controller.rb +2 -2
- data/spec/dummy/app/models/entry.rb +0 -1
- data/spec/dummy/app/units/entry_deletion/entry_deletion.rb +6 -0
- data/spec/dummy/config/application.rb +15 -17
- data/spec/dummy/config/boot.rb +4 -5
- data/spec/dummy/config/environment.rb +1 -1
- data/spec/dummy/config/environments/development.rb +2 -16
- data/spec/dummy/config/environments/production.rb +5 -1
- data/spec/dummy/config/environments/test.rb +10 -7
- data/spec/dummy/config/initializers/chanko_initializer.rb +0 -0
- data/spec/dummy/config/initializers/secret_token.rb +1 -0
- data/spec/dummy/config/storage.yml +1 -0
- data/spec/fixtures/units/example_unit/example_unit.rb +17 -0
- data/spec/fixtures/units/sensitive_inactive_unit/sensitive_inactive_unit.rb +9 -0
- data/spec/fixtures/units/sensitive_unit/sensitive_unit.rb +16 -0
- data/spec/spec_helper.rb +35 -5
- metadata +112 -70
- data/.travis.yml +0 -5
- data/Gemfile +0 -26
- data/spec/dummy/README.rdoc +0 -261
|
@@ -14,6 +14,27 @@ module Chanko
|
|
|
14
14
|
Exception.new
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
+
context "when Config.propagated_errors includes given error" do
|
|
18
|
+
before do
|
|
19
|
+
Config.propagated_errors << Exception
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "raises up error without any logging" do
|
|
23
|
+
expect(Logger).not_to receive(:debug)
|
|
24
|
+
expect { described_class.handle(error, insensitive_unit) }.to raise_error(error)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
context "when Config.propagated_errors does not include given error" do
|
|
29
|
+
before do
|
|
30
|
+
Config.propagated_errors << StandardError
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "raises up no error" do
|
|
34
|
+
expect { described_class.handle(error, insensitive_unit) }.not_to raise_error
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
17
38
|
context "when Config.raise_error is false" do
|
|
18
39
|
it "raises up no error" do
|
|
19
40
|
expect { described_class.handle(error, insensitive_unit) }.not_to raise_error
|
|
@@ -26,13 +47,13 @@ module Chanko
|
|
|
26
47
|
end
|
|
27
48
|
|
|
28
49
|
it "raises up error" do
|
|
29
|
-
expect { described_class.handle(error, insensitive_unit) }.to raise_error
|
|
50
|
+
expect { described_class.handle(error, insensitive_unit) }.to raise_error(error)
|
|
30
51
|
end
|
|
31
52
|
end
|
|
32
53
|
|
|
33
54
|
context "when unit.raise_error is configured" do
|
|
34
55
|
it "raises up error" do
|
|
35
|
-
expect { described_class.handle(error, sensitive_unit) }.to raise_error
|
|
56
|
+
expect { described_class.handle(error, sensitive_unit) }.to raise_error(error)
|
|
36
57
|
end
|
|
37
58
|
end
|
|
38
59
|
end
|
|
@@ -6,10 +6,25 @@ module Chanko
|
|
|
6
6
|
Loader.load(:example_unit)
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
Class.new(ActionView::Base) do
|
|
11
|
-
|
|
9
|
+
def rails5_action_view_instance
|
|
10
|
+
klass = Class.new(ActionView::Base) do
|
|
11
|
+
def current_unit
|
|
12
|
+
units.last
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def units
|
|
16
|
+
@units ||= []
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def path
|
|
20
|
+
view_paths.first.to_s
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
klass.new
|
|
24
|
+
end
|
|
12
25
|
|
|
26
|
+
def rails6_action_view_instance
|
|
27
|
+
klass = Class.new(ActionView::Base.with_empty_template_cache) do
|
|
13
28
|
def current_unit
|
|
14
29
|
units.last
|
|
15
30
|
end
|
|
@@ -21,7 +36,18 @@ module Chanko
|
|
|
21
36
|
def path
|
|
22
37
|
view_paths.first.to_s
|
|
23
38
|
end
|
|
24
|
-
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
klass.with_view_paths([], {}, nil)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
let(:context) do
|
|
45
|
+
case Rails::VERSION::MAJOR
|
|
46
|
+
when 5
|
|
47
|
+
rails5_action_view_instance
|
|
48
|
+
when 6
|
|
49
|
+
rails6_action_view_instance
|
|
50
|
+
end
|
|
25
51
|
end
|
|
26
52
|
|
|
27
53
|
let(:context_without_view_paths) do
|
|
@@ -40,19 +66,19 @@ module Chanko
|
|
|
40
66
|
|
|
41
67
|
describe ".invoke" do
|
|
42
68
|
it "invokes block with given context and stacked unit" do
|
|
43
|
-
described_class.new(unit, :label) { current_unit }.invoke(context, options).
|
|
69
|
+
expect(described_class.new(unit, :label) { current_unit }.invoke(context, options)).to eq(unit)
|
|
44
70
|
end
|
|
45
71
|
|
|
46
72
|
context "when context is a view" do
|
|
47
73
|
it "invokes with unit's view path" do
|
|
48
|
-
described_class.new(unit, :label) { path }.invoke(context, options).
|
|
74
|
+
expect(described_class.new(unit, :label) { path }.invoke(context, options)).to eq(unit.view_path)
|
|
49
75
|
end
|
|
50
76
|
end
|
|
51
77
|
|
|
52
78
|
context "when context does not have view_paths" do
|
|
53
79
|
it "invokes successfully" do
|
|
54
|
-
described_class.new(unit, :label) { "test" }.
|
|
55
|
-
invoke(context_without_view_paths, options).
|
|
80
|
+
expect(described_class.new(unit, :label) { "test" }.
|
|
81
|
+
invoke(context_without_view_paths, options)).to eq("test")
|
|
56
82
|
end
|
|
57
83
|
end
|
|
58
84
|
end
|
data/spec/chanko/helper_spec.rb
CHANGED
data/spec/chanko/invoker_spec.rb
CHANGED
|
@@ -3,67 +3,67 @@ require "spec_helper"
|
|
|
3
3
|
module Chanko
|
|
4
4
|
describe Invoker do
|
|
5
5
|
let(:view) do
|
|
6
|
-
|
|
7
|
-
include Chanko::Invoker
|
|
8
|
-
include Chanko::Helper
|
|
9
|
-
include Chanko::UnitProxyProvider
|
|
10
|
-
end.new
|
|
6
|
+
controller.helpers
|
|
11
7
|
end
|
|
12
8
|
|
|
13
9
|
let(:controller) do
|
|
14
|
-
Class.new(ActionController::Base)
|
|
15
|
-
include Chanko::Invoker
|
|
16
|
-
include Chanko::Helper
|
|
17
|
-
include Chanko::UnitProxyProvider
|
|
18
|
-
end.new
|
|
10
|
+
Class.new(ActionController::Base).new
|
|
19
11
|
end
|
|
20
12
|
|
|
21
13
|
describe "#invoke" do
|
|
22
14
|
it "invokes in the same context with receiver" do
|
|
23
|
-
view.invoke(:example_unit, :self, :type => :plain).
|
|
15
|
+
expect(view.invoke(:example_unit, :self, :type => :plain)).to eq(view)
|
|
24
16
|
end
|
|
25
17
|
|
|
26
18
|
it "invokes with locals option" do
|
|
27
|
-
view.invoke(:example_unit, :locals, :locals => { :key => "value" }, :type => :plain).
|
|
28
|
-
|
|
19
|
+
expect(view.invoke(:example_unit, :locals, :locals => { :key => "value" }, :type => :plain)).
|
|
20
|
+
to eq("value")
|
|
29
21
|
end
|
|
30
22
|
|
|
31
23
|
it "invokes with falsy locals" do
|
|
32
|
-
view.invoke(:example_unit, :falsy, :locals => { :key => nil }, :type => :plain).
|
|
33
|
-
|
|
24
|
+
expect(view.invoke(:example_unit, :falsy, :locals => { :key => nil }, :type => :plain)).
|
|
25
|
+
to eq(true)
|
|
34
26
|
end
|
|
35
27
|
|
|
36
28
|
it "invokes with shared method" do
|
|
37
|
-
view.invoke(:example_unit, :shared, :type => :plain).
|
|
29
|
+
expect(view.invoke(:example_unit, :shared, :type => :plain)).to eq("shared args")
|
|
38
30
|
end
|
|
39
31
|
|
|
40
32
|
it "invokes with helper method in view context" do
|
|
41
|
-
view.invoke(:example_unit, :helper, :type => :plain).
|
|
33
|
+
expect(view.invoke(:example_unit, :helper, :type => :plain)).to eq("helper")
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
context 'when unit is referred from unit function' do
|
|
37
|
+
it 'responds to method which the context responds to' do
|
|
38
|
+
expect(view.invoke(:example_unit, :respond_to_helper?, type: :plain)).to eq(true)
|
|
39
|
+
end
|
|
42
40
|
end
|
|
43
41
|
|
|
44
42
|
context "when invoked in view" do
|
|
45
43
|
it "invokes with partial view" do
|
|
46
|
-
view.invoke(:example_unit, :render, :type => :plain).
|
|
44
|
+
expect(view.invoke(:example_unit, :render, :type => :plain)).to eq("test\n")
|
|
47
45
|
end
|
|
48
46
|
end
|
|
49
47
|
|
|
50
48
|
context "when invoked in controller" do
|
|
51
49
|
it "invokes with unit views path" do
|
|
52
|
-
controller.invoke(:example_unit, :render, :type => :plain).
|
|
50
|
+
expect(controller.invoke(:example_unit, :render, :type => :plain)).to eq("test\n")
|
|
53
51
|
end
|
|
54
52
|
end
|
|
55
53
|
|
|
56
54
|
context "when short-hand style args is passed" do
|
|
57
55
|
it "recognizes args as locals option" do
|
|
58
|
-
view.invoke(:example_unit, :locals, :key => "value").
|
|
56
|
+
expect(view.invoke(:example_unit, :locals, :key => "value")).to eq(
|
|
59
57
|
'<div class="unit unit__example_unit unit__example_unit__locals">value</div>'
|
|
58
|
+
)
|
|
60
59
|
end
|
|
61
60
|
end
|
|
62
61
|
|
|
63
62
|
context "when type is not specified" do
|
|
64
63
|
it "invokes and returns result surrounded by div" do
|
|
65
|
-
view.invoke(:example_unit, :test).
|
|
64
|
+
expect(view.invoke(:example_unit, :test)).to eq(
|
|
66
65
|
'<div class="unit unit__example_unit unit__example_unit__test">test</div>'
|
|
66
|
+
)
|
|
67
67
|
end
|
|
68
68
|
end
|
|
69
69
|
|
|
@@ -73,58 +73,84 @@ module Chanko
|
|
|
73
73
|
end
|
|
74
74
|
|
|
75
75
|
it "invokes and returns result surrounded by div" do
|
|
76
|
-
view.invoke(:example_unit, :test).
|
|
76
|
+
expect(view.invoke(:example_unit, :test)).to eq(
|
|
77
77
|
'<div class="extension ext_example_unit ext_example_unit-test">test</div>'
|
|
78
|
+
)
|
|
78
79
|
end
|
|
79
80
|
end
|
|
80
81
|
|
|
81
82
|
context "when type is :plain" do
|
|
82
83
|
it "does not surround result with html element" do
|
|
83
|
-
view.invoke(:example_unit, :test, :type => :plain).
|
|
84
|
+
expect(view.invoke(:example_unit, :test, :type => :plain)).to eq("test")
|
|
84
85
|
end
|
|
85
86
|
end
|
|
86
87
|
|
|
87
88
|
context "when the result is blank" do
|
|
88
89
|
it "does not surround result with html element" do
|
|
89
|
-
view.invoke(:example_unit, :blank).
|
|
90
|
+
expect(view.invoke(:example_unit, :blank)).to eq(" ")
|
|
90
91
|
end
|
|
91
92
|
end
|
|
92
93
|
|
|
93
94
|
context "when type is :inline" do
|
|
94
95
|
it "invokes and returns result surrounded by span" do
|
|
95
|
-
view.invoke(:example_unit, :test, :type => :inline).
|
|
96
|
+
expect(view.invoke(:example_unit, :test, :type => :inline)).to eq(
|
|
96
97
|
'<span class="unit unit__example_unit unit__example_unit__test">test</span>'
|
|
98
|
+
)
|
|
97
99
|
end
|
|
98
100
|
end
|
|
99
101
|
|
|
100
102
|
context "when context is not a view" do
|
|
101
103
|
it "does not surround result with html tag" do
|
|
102
|
-
controller.invoke(:example_unit, :test).
|
|
104
|
+
expect(controller.invoke(:example_unit, :test)).to eq("test")
|
|
103
105
|
end
|
|
104
106
|
end
|
|
105
107
|
|
|
106
108
|
context "when run_default is called in function" do
|
|
107
109
|
it "invokes given block as a fallback" do
|
|
108
|
-
controller.invoke(:example_unit, :default) { "default" }.
|
|
110
|
+
expect(controller.invoke(:example_unit, :default) { "default" }).to eq("default")
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
context "when nested run_default is called in function" do
|
|
115
|
+
it "invokes given block as a fallback" do
|
|
116
|
+
Chanko::Loader.load("sensitive_unit")
|
|
117
|
+
expect(SensitiveUnit).to receive(:ping).once
|
|
118
|
+
|
|
119
|
+
expect(controller.invoke(:sensitive_unit, :outer_default) do
|
|
120
|
+
"default"
|
|
121
|
+
end).to eq "default"
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
it 'use both locals' do
|
|
125
|
+
expect(controller.invoke(:example_unit, :nesting_locals_outer, :locals => { :outer_one => "outer_one", :outer_two => "outer_two", :outer_three => "outer_three"}) do
|
|
126
|
+
"default"
|
|
127
|
+
end).to eq "outer_one.inner_one.outer_two.default.inner_two.outer_three"
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
context 'active_if is false' do
|
|
131
|
+
it "invokes given block as a fallback " do
|
|
132
|
+
Chanko::Loader.load("sensitive_inactive_unit")
|
|
133
|
+
expect(controller.invoke(:sensitive_inactive_unit, :outer) { invoke(:sensitive_inactive_unit, :inner) }).to eq(nil)
|
|
134
|
+
end
|
|
109
135
|
end
|
|
110
136
|
end
|
|
111
137
|
|
|
112
138
|
context "when run_default is called but no block given" do
|
|
113
139
|
it "invokes given block as a fallback" do
|
|
114
|
-
controller.invoke(:example_unit, :default).
|
|
140
|
+
expect(controller.invoke(:example_unit, :default)).to eq(nil)
|
|
115
141
|
end
|
|
116
142
|
end
|
|
117
143
|
|
|
118
144
|
context "when non-existent unit is specified" do
|
|
119
145
|
it "does nothing" do
|
|
120
|
-
view.invoke(:non_existent_unit, :test, :type => :plain).
|
|
146
|
+
expect(view.invoke(:non_existent_unit, :test, :type => :plain)).to eq(nil)
|
|
121
147
|
end
|
|
122
148
|
end
|
|
123
149
|
|
|
124
150
|
context "when function is not found" do
|
|
125
151
|
it "runs default but not handled by ExceptionHandler" do
|
|
126
|
-
ExceptionHandler.
|
|
127
|
-
view.invoke(:example_unit, :non_existent_function) { "default" }.
|
|
152
|
+
expect(ExceptionHandler).not_to receive(:handle)
|
|
153
|
+
expect(view.invoke(:example_unit, :non_existent_function) { "default" }).to eq("default")
|
|
128
154
|
end
|
|
129
155
|
end
|
|
130
156
|
|
|
@@ -132,22 +158,22 @@ module Chanko
|
|
|
132
158
|
context "when block is given" do
|
|
133
159
|
context "when context is a view" do
|
|
134
160
|
it "captures given block as a fallback" do
|
|
135
|
-
view.
|
|
136
|
-
view.invoke(:example_unit, :error) { "error" }.
|
|
161
|
+
expect(view).to receive(:capture).and_call_original
|
|
162
|
+
expect(view.invoke(:example_unit, :error) { "error" }).to eq("error")
|
|
137
163
|
end
|
|
138
164
|
end
|
|
139
165
|
|
|
140
166
|
context "when context is not a view" do
|
|
141
167
|
it "calls given block as a fallback" do
|
|
142
|
-
controller.
|
|
143
|
-
controller.invoke(:example_unit, :error) { "error" }.
|
|
168
|
+
expect(controller).not_to receive(:capture)
|
|
169
|
+
expect(controller.invoke(:example_unit, :error) { "error" }).to eq("error")
|
|
144
170
|
end
|
|
145
171
|
end
|
|
146
172
|
end
|
|
147
173
|
|
|
148
174
|
context "when no block is given" do
|
|
149
175
|
it "rescues the error and does nothing" do
|
|
150
|
-
view.invoke(:example_unit, :error).
|
|
176
|
+
expect(view.invoke(:example_unit, :error)).to eq(nil)
|
|
151
177
|
end
|
|
152
178
|
end
|
|
153
179
|
end
|
data/spec/chanko/loader_spec.rb
CHANGED
|
@@ -4,38 +4,40 @@ module Chanko
|
|
|
4
4
|
describe Loader do
|
|
5
5
|
describe ".load" do
|
|
6
6
|
after do
|
|
7
|
-
|
|
7
|
+
Chanko::Loader.cache.clear
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
context "when existent unit name is passed" do
|
|
11
11
|
it "loads unit in units directory and returns the Module" do
|
|
12
|
-
|
|
12
|
+
expect(Chanko::Loader.load(:example_unit)).to eq(ExampleUnit)
|
|
13
13
|
end
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
context "when non-existent unit name is passed" do
|
|
17
17
|
it "returns nil" do
|
|
18
|
-
|
|
18
|
+
expect(Chanko::Loader.load(:non_existent_unit)).to eq(false)
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
context "when loader has ever loaded specified unit" do
|
|
23
|
-
it "load unit from cache" do
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
it "load unit from cache", classic: true do
|
|
24
|
+
expect(Chanko::Loader::ClassicLoader).to receive(:load_from_cache).twice.and_call_original
|
|
25
|
+
expect(Chanko::Loader::ClassicLoader).to receive(:save_to_cache).with(anything, ExampleUnit).and_call_original
|
|
26
|
+
expect(Chanko::Loader.load(:example_unit)).to eq(ExampleUnit)
|
|
27
|
+
expect(Chanko::Loader.load(:example_unit)).to eq(ExampleUnit)
|
|
27
28
|
end
|
|
28
29
|
end
|
|
29
30
|
|
|
30
31
|
context "when loader has ever loaded specified wrong unit" do
|
|
31
32
|
before do
|
|
32
|
-
|
|
33
|
+
Chanko::Loader.cache.clear
|
|
33
34
|
end
|
|
34
35
|
|
|
35
|
-
it "load unit from cache" do
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
it "load unit from cache", classic: true do
|
|
37
|
+
expect(Chanko::Loader::ClassicLoader).to receive(:load_from_cache).twice.and_call_original
|
|
38
|
+
expect(Chanko::Loader::ClassicLoader).to receive(:save_to_cache).with(anything, false).and_call_original
|
|
39
|
+
expect(Chanko::Loader.load(:non_existent_unit)).to eq(false)
|
|
40
|
+
expect(Chanko::Loader.load(:non_existent_unit)).to eq(false)
|
|
39
41
|
end
|
|
40
42
|
end
|
|
41
43
|
end
|
data/spec/chanko/logger_spec.rb
CHANGED
|
@@ -4,11 +4,17 @@ require "stringio"
|
|
|
4
4
|
module Chanko
|
|
5
5
|
describe Logger do
|
|
6
6
|
around do |example|
|
|
7
|
-
origin, Rails.logger = Rails.logger,
|
|
7
|
+
origin, Rails.logger = Rails.logger, logger
|
|
8
8
|
example.run
|
|
9
9
|
Rails.logger = origin
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
+
let(:logger) do
|
|
13
|
+
logger = ::Logger.new(io)
|
|
14
|
+
logger.formatter = lambda {|severity, time, progname, message| message }
|
|
15
|
+
logger
|
|
16
|
+
end
|
|
17
|
+
|
|
12
18
|
let(:io) do
|
|
13
19
|
StringIO.new
|
|
14
20
|
end
|
|
@@ -47,7 +53,7 @@ module Chanko
|
|
|
47
53
|
context "when given Exception" do
|
|
48
54
|
it "parses and logs it" do
|
|
49
55
|
described_class.debug(exception)
|
|
50
|
-
log.
|
|
56
|
+
expect(log).to eq(lines.join("\n"))
|
|
51
57
|
end
|
|
52
58
|
|
|
53
59
|
context "when Config.backtrace_limit is configured" do
|
|
@@ -57,7 +63,7 @@ module Chanko
|
|
|
57
63
|
|
|
58
64
|
it "prints backtrace up to configured depth" do
|
|
59
65
|
described_class.debug(exception)
|
|
60
|
-
log.
|
|
66
|
+
expect(log).to eq(lines[0..5].join("\n"))
|
|
61
67
|
end
|
|
62
68
|
end
|
|
63
69
|
end
|
|
@@ -65,7 +71,7 @@ module Chanko
|
|
|
65
71
|
context "when given String" do
|
|
66
72
|
it "adds prefix" do
|
|
67
73
|
described_class.debug("test")
|
|
68
|
-
log.
|
|
74
|
+
expect(log).to eq(" [Chanko] test")
|
|
69
75
|
end
|
|
70
76
|
end
|
|
71
77
|
end
|
|
@@ -77,17 +83,17 @@ module Chanko
|
|
|
77
83
|
|
|
78
84
|
it "logs nothing" do
|
|
79
85
|
described_class.debug("test")
|
|
80
|
-
log.
|
|
86
|
+
expect(log).to eq("")
|
|
81
87
|
end
|
|
82
88
|
end
|
|
83
89
|
|
|
84
90
|
context "when Rails.logger is nil" do
|
|
85
91
|
before do
|
|
86
|
-
Rails.
|
|
92
|
+
allow(Rails).to receive(:logger)
|
|
87
93
|
end
|
|
88
94
|
|
|
89
95
|
it "does notihng" do
|
|
90
|
-
expect { described_class.debug(exception) }.not_to raise_error
|
|
96
|
+
expect { described_class.debug(exception) }.not_to raise_error
|
|
91
97
|
end
|
|
92
98
|
end
|
|
93
99
|
end
|
data/spec/chanko/test_spec.rb
CHANGED
|
@@ -3,25 +3,35 @@ require "chanko/test"
|
|
|
3
3
|
|
|
4
4
|
module Chanko
|
|
5
5
|
describe Test do
|
|
6
|
+
def rails5_action_view_instance
|
|
7
|
+
Class.new(ActionView::Base).new
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def rails6_action_view_instance
|
|
11
|
+
klass = Class.new(ActionView::Base.with_empty_template_cache)
|
|
12
|
+
klass.with_view_paths(nil, {}, nil)
|
|
13
|
+
end
|
|
14
|
+
|
|
6
15
|
let(:view) do
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
16
|
+
case Rails::VERSION::MAJOR
|
|
17
|
+
when 5
|
|
18
|
+
rails5_action_view_instance
|
|
19
|
+
when 6
|
|
20
|
+
rails6_action_view_instance
|
|
21
|
+
end
|
|
12
22
|
end
|
|
13
23
|
|
|
14
24
|
describe "#enable_unit" do
|
|
15
25
|
it "forces to enable specified unit" do
|
|
16
26
|
enable_unit(:inactive_unit)
|
|
17
|
-
view.invoke(:inactive_unit, :inactive, :type => :plain).
|
|
27
|
+
expect(view.invoke(:inactive_unit, :inactive, :type => :plain)).to eq("inactive")
|
|
18
28
|
end
|
|
19
29
|
end
|
|
20
30
|
|
|
21
31
|
describe "#disable_unit" do
|
|
22
32
|
it "forces to disable specified unit" do
|
|
23
33
|
disable_unit(:example_unit)
|
|
24
|
-
view.invoke(:example_unit, :test).
|
|
34
|
+
expect(view.invoke(:example_unit, :test)).to eq(nil)
|
|
25
35
|
end
|
|
26
36
|
end
|
|
27
37
|
end
|
|
@@ -13,7 +13,7 @@ module Chanko
|
|
|
13
13
|
"test"
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
|
-
ExampleClass.new.test.
|
|
16
|
+
expect(ExampleClass.new.test).to eq("test")
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
it "extends class methods" do
|
|
@@ -24,7 +24,7 @@ module Chanko
|
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
|
-
ExampleClass.test.
|
|
27
|
+
expect(ExampleClass.test).to eq("test")
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
it "extends instance methods with prefix" do
|
|
@@ -33,7 +33,7 @@ module Chanko
|
|
|
33
33
|
"test"
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
|
-
ExampleClass.new.__prefix_test.
|
|
36
|
+
expect(ExampleClass.new.__prefix_test).to eq("test")
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
39
|
end
|
|
@@ -7,28 +7,28 @@ module Chanko
|
|
|
7
7
|
context "when identifier is a class" do
|
|
8
8
|
it "returns identifier with no change" do
|
|
9
9
|
identifier = ActionView::Base
|
|
10
|
-
described_class.find(identifier).
|
|
10
|
+
expect(described_class.find(identifier)).to eq(ActionView::Base)
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
context "when identifier is a reserved label" do
|
|
15
15
|
it "returns reserved class for that" do
|
|
16
16
|
identifier = :view
|
|
17
|
-
described_class.find(identifier).
|
|
17
|
+
expect(described_class.find(identifier)).to eq(ActionView::Base)
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
context "when identifier is a string that means a class" do
|
|
22
22
|
it "returns class of that string" do
|
|
23
23
|
identifier = "ActionView::Base"
|
|
24
|
-
described_class.find(identifier).
|
|
24
|
+
expect(described_class.find(identifier)).to eq(ActionView::Base)
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
context "when no class is found" do
|
|
29
29
|
it "returns nil" do
|
|
30
30
|
identifier = "Non::Existent::Class"
|
|
31
|
-
described_class.find(identifier).
|
|
31
|
+
expect(described_class.find(identifier)).to eq(nil)
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
34
|
end
|
|
@@ -10,8 +10,8 @@ module Chanko
|
|
|
10
10
|
context "when given unit name" do
|
|
11
11
|
it "returns proxy for specified unit" do
|
|
12
12
|
proxy = view.unit(:example_unit)
|
|
13
|
-
proxy.
|
|
14
|
-
proxy.unit.
|
|
13
|
+
expect(proxy).to be_a UnitProxy
|
|
14
|
+
expect(proxy.unit).to eq(ExampleUnit)
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
|
|
@@ -26,7 +26,7 @@ module Chanko
|
|
|
26
26
|
|
|
27
27
|
it "returns proxy for the top unit of current unit stack" do
|
|
28
28
|
proxy = view.unit
|
|
29
|
-
proxy.unit.
|
|
29
|
+
expect(proxy.unit).to eq(ExampleUnit)
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
32
|
|
|
@@ -39,10 +39,10 @@ module Chanko
|
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
it "change this method name with it" do
|
|
42
|
-
view.
|
|
42
|
+
expect(view).not_to be_respond_to(:proxy)
|
|
43
43
|
proxy = view.proxy(:example_unit)
|
|
44
|
-
proxy.
|
|
45
|
-
view.
|
|
44
|
+
expect(proxy).to be_a UnitProxy
|
|
45
|
+
expect(view).to be_respond_to(:proxy)
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
48
|
|
|
@@ -55,12 +55,12 @@ module Chanko
|
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
it "change this method name with it" do
|
|
58
|
-
view.
|
|
59
|
-
view.
|
|
60
|
-
view.proxy1(:example_unit).
|
|
61
|
-
view.proxy2(:example_unit).
|
|
62
|
-
view.
|
|
63
|
-
view.
|
|
58
|
+
expect(view).not_to be_respond_to(:proxy1)
|
|
59
|
+
expect(view).not_to be_respond_to(:proxy2)
|
|
60
|
+
expect(view.proxy1(:example_unit)).to be_a UnitProxy
|
|
61
|
+
expect(view.proxy2(:example_unit)).to be_a UnitProxy
|
|
62
|
+
expect(view).to be_respond_to(:proxy1)
|
|
63
|
+
expect(view).to be_respond_to(:proxy2)
|
|
64
64
|
end
|
|
65
65
|
end
|
|
66
66
|
end
|
|
@@ -8,14 +8,14 @@ module Chanko
|
|
|
8
8
|
|
|
9
9
|
describe "#active?" do
|
|
10
10
|
it "returns activation status of unit" do
|
|
11
|
-
view.unit(:example_unit).
|
|
12
|
-
view.unit(:inactive_unit).
|
|
11
|
+
expect(view.unit(:example_unit)).to be_active
|
|
12
|
+
expect(view.unit(:inactive_unit)).not_to be_active
|
|
13
13
|
end
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
describe "#method_missing" do
|
|
17
17
|
it "calls prefixed method" do
|
|
18
|
-
view.
|
|
18
|
+
expect(view).to receive(:__example_unit_test)
|
|
19
19
|
view.unit(:example_unit).test
|
|
20
20
|
end
|
|
21
21
|
end
|