chanko 2.0.6 → 2.0.7
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/.travis.yml +2 -1
- data/CHANGELOG.md +4 -0
- data/Gemfile +0 -15
- data/README.md +1 -1
- data/chanko.gemspec +1 -1
- data/lib/chanko/invoker.rb +24 -21
- data/lib/chanko/version.rb +1 -1
- data/spec/chanko/controller_spec.rb +5 -5
- data/spec/chanko/deprecated_spec.rb +2 -2
- data/spec/chanko/exception_handler_spec.rb +1 -1
- data/spec/chanko/function_spec.rb +4 -4
- data/spec/chanko/helper_spec.rb +1 -1
- data/spec/chanko/invoker_spec.rb +41 -30
- data/spec/chanko/loader_spec.rb +4 -4
- data/spec/chanko/logger_spec.rb +5 -5
- data/spec/chanko/test_spec.rb +2 -2
- 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 +22 -22
- data/spec/controllers/application_controller_spec.rb +1 -1
- data/spec/fixtures/units/sensitive_inactive_unit/sensitive_inactive_unit.rb +9 -0
- data/spec/spec_helper.rb +15 -2
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f325906ba94cd59313a68d2cba3be3bb6d3b05f9
|
4
|
+
data.tar.gz: 5a7e857db28ef637d4fed3c77bd3c6976885fcc7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f456c90d96c0ad8002028cf1c8d5402878133c330ec59917a75bdffb5ddece6937ce412337270cc8e455331e8160833b77a8ac467f21cb84d5194a0052b6edd6
|
7
|
+
data.tar.gz: 5180320d9015bdcca75c76ba35c99ed2177e5f54da759e25680da76745fe17f160faa9304225a3f9891f9b5ab7998cc512a9c174a2df3226926cb392819bbbde
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
@@ -3,24 +3,9 @@ source "https://rubygems.org"
|
|
3
3
|
gemspec
|
4
4
|
|
5
5
|
group :development, :test, :production do
|
6
|
-
gem "jquery-rails"
|
7
6
|
gem "quiet_assets"
|
8
|
-
gem "rails", ">= 4.0.0"
|
9
|
-
gem "slim"
|
10
|
-
gem "sqlite3"
|
11
|
-
end
|
12
|
-
|
13
|
-
group :test do
|
14
|
-
gem "rspec-rails", "2.14.0"
|
15
7
|
end
|
16
8
|
|
17
9
|
group :development, :test do
|
18
10
|
gem "pry-rails"
|
19
|
-
gem "thin"
|
20
|
-
end
|
21
|
-
|
22
|
-
group :assets do
|
23
|
-
gem "sass-rails"
|
24
|
-
gem "coffee-rails"
|
25
|
-
gem "uglifier"
|
26
11
|
end
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Chanko [](https://travis-ci.org/cookpad/chanko) [](https://codeclimate.com/github/cookpad/chanko) [](https://coveralls.io/r/cookpad/chanko?branch=master)
|
2
2
|
|
3
3
|
http://cookpad.github.io/chanko/
|
4
4
|
|
data/chanko.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |gem|
|
|
21
21
|
gem.add_development_dependency "coveralls"
|
22
22
|
gem.add_development_dependency "jquery-rails"
|
23
23
|
gem.add_development_dependency "pry"
|
24
|
-
gem.add_development_dependency "rspec-rails", "
|
24
|
+
gem.add_development_dependency "rspec-rails", ">= 3.0.0"
|
25
25
|
gem.add_development_dependency "sass-rails", ">= 3.0.10"
|
26
26
|
gem.add_development_dependency "simplecov"
|
27
27
|
gem.add_development_dependency "slim"
|
data/lib/chanko/invoker.rb
CHANGED
@@ -40,18 +40,6 @@ module Chanko
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
def __current_run_default_depth
|
44
|
-
@__run_default_depth ||= 0
|
45
|
-
end
|
46
|
-
|
47
|
-
def __increment_run_default_depth
|
48
|
-
@__run_default_depth = __current_run_default_depth + 1
|
49
|
-
end
|
50
|
-
|
51
|
-
def __decrement_run_default_depth
|
52
|
-
@__run_default_depth = __current_run_default_depth - 1
|
53
|
-
end
|
54
|
-
|
55
43
|
def __find_unit_local(method_name)
|
56
44
|
__current_unit_locals.has_key?(method_name)
|
57
45
|
end
|
@@ -61,7 +49,7 @@ module Chanko
|
|
61
49
|
end
|
62
50
|
|
63
51
|
def __current_unit_locals
|
64
|
-
__unit_locals_stack
|
52
|
+
__unit_locals_stack.last || {}
|
65
53
|
end
|
66
54
|
|
67
55
|
def __unit_locals_stack
|
@@ -85,7 +73,7 @@ module Chanko
|
|
85
73
|
end
|
86
74
|
|
87
75
|
def __default_block
|
88
|
-
__defaults_stack
|
76
|
+
__defaults_stack.last
|
89
77
|
end
|
90
78
|
|
91
79
|
def __has_default_block?
|
@@ -95,14 +83,15 @@ module Chanko
|
|
95
83
|
def __invoke_default_block
|
96
84
|
current_default_block = __default_block
|
97
85
|
begin
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
86
|
+
__without_default_stack do
|
87
|
+
__without_locals_stack do
|
88
|
+
if view?
|
89
|
+
capture(¤t_default_block)
|
90
|
+
else
|
91
|
+
instance_exec(¤t_default_block)
|
92
|
+
end
|
93
|
+
end
|
103
94
|
end
|
104
|
-
ensure
|
105
|
-
__decrement_run_default_depth
|
106
95
|
end
|
107
96
|
end
|
108
97
|
|
@@ -119,5 +108,19 @@ module Chanko
|
|
119
108
|
ensure
|
120
109
|
__unit_locals_stack.pop
|
121
110
|
end
|
111
|
+
|
112
|
+
def __without_default_stack
|
113
|
+
default = __defaults_stack.pop
|
114
|
+
yield
|
115
|
+
ensure
|
116
|
+
__defaults_stack << default
|
117
|
+
end
|
118
|
+
|
119
|
+
def __without_locals_stack
|
120
|
+
locals = __unit_locals_stack.pop
|
121
|
+
yield
|
122
|
+
ensure
|
123
|
+
__unit_locals_stack << locals
|
124
|
+
end
|
122
125
|
end
|
123
126
|
end
|
data/lib/chanko/version.rb
CHANGED
@@ -22,21 +22,21 @@ module Chanko
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it "defines an action to invoke unit function" do
|
25
|
-
controller.test.
|
25
|
+
expect(controller.test).to eq("test")
|
26
26
|
end
|
27
27
|
|
28
28
|
it "defines 2 actions at one line" do
|
29
|
-
controller.foo.
|
30
|
-
controller.bar.
|
29
|
+
expect(controller.foo).to eq("foo")
|
30
|
+
expect(controller.bar).to eq("bar")
|
31
31
|
end
|
32
32
|
|
33
33
|
it "is aliased with `ext_action`" do
|
34
|
-
controller.alias.
|
34
|
+
expect(controller.alias).to eq("alias")
|
35
35
|
end
|
36
36
|
|
37
37
|
context "when invoke is fallen back" do
|
38
38
|
it "halts with 400 status code" do
|
39
|
-
controller.error.
|
39
|
+
expect(controller.error).to eq("Bad Request 400")
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
@@ -12,7 +12,7 @@ module Chanko
|
|
12
12
|
context "with option arguments" do
|
13
13
|
it "prints warning message on standard error output" do
|
14
14
|
ActiveIf.new(foo: "bar")
|
15
|
-
$stderr.string.
|
15
|
+
expect($stderr.string).to match(/\Aoptions in ActiveIf#new are deprecated and are never used at #{__FILE__}/)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -20,7 +20,7 @@ module Chanko
|
|
20
20
|
describe "#options" do
|
21
21
|
it "prints warning message on standard error output" do
|
22
22
|
ActiveIf.new.options
|
23
|
-
$stderr.string.
|
23
|
+
expect($stderr.string).to match(/\AActiveIf#options is deprecated and is never used at #{__FILE__}/)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -40,19 +40,19 @@ module Chanko
|
|
40
40
|
|
41
41
|
describe ".invoke" do
|
42
42
|
it "invokes block with given context and stacked unit" do
|
43
|
-
described_class.new(unit, :label) { current_unit }.invoke(context, options).
|
43
|
+
expect(described_class.new(unit, :label) { current_unit }.invoke(context, options)).to eq(unit)
|
44
44
|
end
|
45
45
|
|
46
46
|
context "when context is a view" do
|
47
47
|
it "invokes with unit's view path" do
|
48
|
-
described_class.new(unit, :label) { path }.invoke(context, options).
|
48
|
+
expect(described_class.new(unit, :label) { path }.invoke(context, options)).to eq(unit.view_path)
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
context "when context does not have view_paths" do
|
53
53
|
it "invokes successfully" do
|
54
|
-
described_class.new(unit, :label) { "test" }.
|
55
|
-
invoke(context_without_view_paths, options).
|
54
|
+
expect(described_class.new(unit, :label) { "test" }.
|
55
|
+
invoke(context_without_view_paths, options)).to eq("test")
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
data/spec/chanko/helper_spec.rb
CHANGED
data/spec/chanko/invoker_spec.rb
CHANGED
@@ -20,25 +20,25 @@ module Chanko
|
|
20
20
|
|
21
21
|
describe "#invoke" do
|
22
22
|
it "invokes in the same context with receiver" do
|
23
|
-
view.invoke(:example_unit, :self, :type => :plain).
|
23
|
+
expect(view.invoke(:example_unit, :self, :type => :plain)).to eq(view)
|
24
24
|
end
|
25
25
|
|
26
26
|
it "invokes with locals option" do
|
27
|
-
view.invoke(:example_unit, :locals, :locals => { :key => "value" }, :type => :plain).
|
28
|
-
|
27
|
+
expect(view.invoke(:example_unit, :locals, :locals => { :key => "value" }, :type => :plain)).
|
28
|
+
to eq("value")
|
29
29
|
end
|
30
30
|
|
31
31
|
it "invokes with falsy locals" do
|
32
|
-
view.invoke(:example_unit, :falsy, :locals => { :key => nil }, :type => :plain).
|
33
|
-
|
32
|
+
expect(view.invoke(:example_unit, :falsy, :locals => { :key => nil }, :type => :plain)).
|
33
|
+
to eq(true)
|
34
34
|
end
|
35
35
|
|
36
36
|
it "invokes with shared method" do
|
37
|
-
view.invoke(:example_unit, :shared, :type => :plain).
|
37
|
+
expect(view.invoke(:example_unit, :shared, :type => :plain)).to eq("shared args")
|
38
38
|
end
|
39
39
|
|
40
40
|
it "invokes with helper method in view context" do
|
41
|
-
view.invoke(:example_unit, :helper, :type => :plain).
|
41
|
+
expect(view.invoke(:example_unit, :helper, :type => :plain)).to eq("helper")
|
42
42
|
end
|
43
43
|
|
44
44
|
context 'when unit is referred from unit function' do
|
@@ -49,27 +49,29 @@ module Chanko
|
|
49
49
|
|
50
50
|
context "when invoked in view" do
|
51
51
|
it "invokes with partial view" do
|
52
|
-
view.invoke(:example_unit, :render, :type => :plain).
|
52
|
+
expect(view.invoke(:example_unit, :render, :type => :plain)).to eq("test\n")
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
56
|
context "when invoked in controller" do
|
57
57
|
it "invokes with unit views path" do
|
58
|
-
controller.invoke(:example_unit, :render, :type => :plain).
|
58
|
+
expect(controller.invoke(:example_unit, :render, :type => :plain)).to eq("test\n")
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
62
|
context "when short-hand style args is passed" do
|
63
63
|
it "recognizes args as locals option" do
|
64
|
-
view.invoke(:example_unit, :locals, :key => "value").
|
64
|
+
expect(view.invoke(:example_unit, :locals, :key => "value")).to eq(
|
65
65
|
'<div class="unit unit__example_unit unit__example_unit__locals">value</div>'
|
66
|
+
)
|
66
67
|
end
|
67
68
|
end
|
68
69
|
|
69
70
|
context "when type is not specified" do
|
70
71
|
it "invokes and returns result surrounded by div" do
|
71
|
-
view.invoke(:example_unit, :test).
|
72
|
+
expect(view.invoke(:example_unit, :test)).to eq(
|
72
73
|
'<div class="unit unit__example_unit unit__example_unit__test">test</div>'
|
74
|
+
)
|
73
75
|
end
|
74
76
|
end
|
75
77
|
|
@@ -79,39 +81,41 @@ module Chanko
|
|
79
81
|
end
|
80
82
|
|
81
83
|
it "invokes and returns result surrounded by div" do
|
82
|
-
view.invoke(:example_unit, :test).
|
84
|
+
expect(view.invoke(:example_unit, :test)).to eq(
|
83
85
|
'<div class="extension ext_example_unit ext_example_unit-test">test</div>'
|
86
|
+
)
|
84
87
|
end
|
85
88
|
end
|
86
89
|
|
87
90
|
context "when type is :plain" do
|
88
91
|
it "does not surround result with html element" do
|
89
|
-
view.invoke(:example_unit, :test, :type => :plain).
|
92
|
+
expect(view.invoke(:example_unit, :test, :type => :plain)).to eq("test")
|
90
93
|
end
|
91
94
|
end
|
92
95
|
|
93
96
|
context "when the result is blank" do
|
94
97
|
it "does not surround result with html element" do
|
95
|
-
view.invoke(:example_unit, :blank).
|
98
|
+
expect(view.invoke(:example_unit, :blank)).to eq(" ")
|
96
99
|
end
|
97
100
|
end
|
98
101
|
|
99
102
|
context "when type is :inline" do
|
100
103
|
it "invokes and returns result surrounded by span" do
|
101
|
-
view.invoke(:example_unit, :test, :type => :inline).
|
104
|
+
expect(view.invoke(:example_unit, :test, :type => :inline)).to eq(
|
102
105
|
'<span class="unit unit__example_unit unit__example_unit__test">test</span>'
|
106
|
+
)
|
103
107
|
end
|
104
108
|
end
|
105
109
|
|
106
110
|
context "when context is not a view" do
|
107
111
|
it "does not surround result with html tag" do
|
108
|
-
controller.invoke(:example_unit, :test).
|
112
|
+
expect(controller.invoke(:example_unit, :test)).to eq("test")
|
109
113
|
end
|
110
114
|
end
|
111
115
|
|
112
116
|
context "when run_default is called in function" do
|
113
117
|
it "invokes given block as a fallback" do
|
114
|
-
controller.invoke(:example_unit, :default) { "default" }.
|
118
|
+
expect(controller.invoke(:example_unit, :default) { "default" }).to eq("default")
|
115
119
|
end
|
116
120
|
end
|
117
121
|
|
@@ -120,34 +124,41 @@ module Chanko
|
|
120
124
|
Chanko::Loader.load("sensitive_unit")
|
121
125
|
expect(SensitiveUnit).to receive(:ping).once
|
122
126
|
|
123
|
-
controller.invoke(:sensitive_unit, :outer_default) do
|
127
|
+
expect(controller.invoke(:sensitive_unit, :outer_default) do
|
124
128
|
"default"
|
125
|
-
end.
|
129
|
+
end).to eq "default"
|
126
130
|
end
|
127
131
|
|
128
132
|
it 'use both locals' do
|
129
|
-
controller.invoke(:example_unit, :nesting_locals_outer, :locals => { :outer_one => "outer_one", :outer_two => "outer_two", :outer_three => "outer_three"}) do
|
133
|
+
expect(controller.invoke(:example_unit, :nesting_locals_outer, :locals => { :outer_one => "outer_one", :outer_two => "outer_two", :outer_three => "outer_three"}) do
|
130
134
|
"default"
|
131
|
-
end.
|
135
|
+
end).to eq "outer_one.inner_one.outer_two.default.inner_two.outer_three"
|
136
|
+
end
|
137
|
+
|
138
|
+
context 'active_if is false' do
|
139
|
+
it "invokes given block as a fallback " do
|
140
|
+
Chanko::Loader.load("sensitive_inactive_unit")
|
141
|
+
expect(controller.invoke(:sensitive_inactive_unit, :outer) { invoke(:sensitive_inactive_unit, :inner) }).to eq(nil)
|
142
|
+
end
|
132
143
|
end
|
133
144
|
end
|
134
145
|
|
135
146
|
context "when run_default is called but no block given" do
|
136
147
|
it "invokes given block as a fallback" do
|
137
|
-
controller.invoke(:example_unit, :default).
|
148
|
+
expect(controller.invoke(:example_unit, :default)).to eq(nil)
|
138
149
|
end
|
139
150
|
end
|
140
151
|
|
141
152
|
context "when non-existent unit is specified" do
|
142
153
|
it "does nothing" do
|
143
|
-
view.invoke(:non_existent_unit, :test, :type => :plain).
|
154
|
+
expect(view.invoke(:non_existent_unit, :test, :type => :plain)).to eq(nil)
|
144
155
|
end
|
145
156
|
end
|
146
157
|
|
147
158
|
context "when function is not found" do
|
148
159
|
it "runs default but not handled by ExceptionHandler" do
|
149
|
-
ExceptionHandler.
|
150
|
-
view.invoke(:example_unit, :non_existent_function) { "default" }.
|
160
|
+
expect(ExceptionHandler).not_to receive(:handle)
|
161
|
+
expect(view.invoke(:example_unit, :non_existent_function) { "default" }).to eq("default")
|
151
162
|
end
|
152
163
|
end
|
153
164
|
|
@@ -155,22 +166,22 @@ module Chanko
|
|
155
166
|
context "when block is given" do
|
156
167
|
context "when context is a view" do
|
157
168
|
it "captures given block as a fallback" do
|
158
|
-
view.
|
159
|
-
view.invoke(:example_unit, :error) { "error" }.
|
169
|
+
expect(view).to receive(:capture).and_call_original
|
170
|
+
expect(view.invoke(:example_unit, :error) { "error" }).to eq("error")
|
160
171
|
end
|
161
172
|
end
|
162
173
|
|
163
174
|
context "when context is not a view" do
|
164
175
|
it "calls given block as a fallback" do
|
165
|
-
controller.
|
166
|
-
controller.invoke(:example_unit, :error) { "error" }.
|
176
|
+
expect(controller).not_to receive(:capture)
|
177
|
+
expect(controller.invoke(:example_unit, :error) { "error" }).to eq("error")
|
167
178
|
end
|
168
179
|
end
|
169
180
|
end
|
170
181
|
|
171
182
|
context "when no block is given" do
|
172
183
|
it "rescues the error and does nothing" do
|
173
|
-
view.invoke(:example_unit, :error).
|
184
|
+
expect(view.invoke(:example_unit, :error)).to eq(nil)
|
174
185
|
end
|
175
186
|
end
|
176
187
|
end
|
data/spec/chanko/loader_spec.rb
CHANGED
@@ -9,19 +9,19 @@ module Chanko
|
|
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
|
-
described_class.load(:example_unit).
|
12
|
+
expect(described_class.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
|
-
described_class.load(:non_existent_unit).
|
18
|
+
expect(described_class.load(:non_existent_unit)).to eq(nil)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
context "when loader has ever loaded specified unit" do
|
23
23
|
it "load unit from cache" do
|
24
|
-
described_class.
|
24
|
+
expect_any_instance_of(described_class).to receive(:load_from_file).and_call_original
|
25
25
|
described_class.load(:example_unit)
|
26
26
|
described_class.load(:example_unit)
|
27
27
|
end
|
@@ -33,7 +33,7 @@ module Chanko
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it "load unit from cache" do
|
36
|
-
described_class.
|
36
|
+
expect_any_instance_of(described_class).to receive(:load_from_file).and_call_original
|
37
37
|
described_class.load(:non_existent_unit)
|
38
38
|
described_class.load(:non_existent_unit)
|
39
39
|
end
|
data/spec/chanko/logger_spec.rb
CHANGED
@@ -53,7 +53,7 @@ module Chanko
|
|
53
53
|
context "when given Exception" do
|
54
54
|
it "parses and logs it" do
|
55
55
|
described_class.debug(exception)
|
56
|
-
log.
|
56
|
+
expect(log).to eq(lines.join("\n"))
|
57
57
|
end
|
58
58
|
|
59
59
|
context "when Config.backtrace_limit is configured" do
|
@@ -63,7 +63,7 @@ module Chanko
|
|
63
63
|
|
64
64
|
it "prints backtrace up to configured depth" do
|
65
65
|
described_class.debug(exception)
|
66
|
-
log.
|
66
|
+
expect(log).to eq(lines[0..5].join("\n"))
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end
|
@@ -71,7 +71,7 @@ module Chanko
|
|
71
71
|
context "when given String" do
|
72
72
|
it "adds prefix" do
|
73
73
|
described_class.debug("test")
|
74
|
-
log.
|
74
|
+
expect(log).to eq(" [Chanko] test")
|
75
75
|
end
|
76
76
|
end
|
77
77
|
end
|
@@ -83,13 +83,13 @@ module Chanko
|
|
83
83
|
|
84
84
|
it "logs nothing" do
|
85
85
|
described_class.debug("test")
|
86
|
-
log.
|
86
|
+
expect(log).to eq("")
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
90
|
context "when Rails.logger is nil" do
|
91
91
|
before do
|
92
|
-
Rails.
|
92
|
+
allow(Rails).to receive(:logger)
|
93
93
|
end
|
94
94
|
|
95
95
|
it "does notihng" do
|
data/spec/chanko/test_spec.rb
CHANGED
@@ -14,14 +14,14 @@ module Chanko
|
|
14
14
|
describe "#enable_unit" do
|
15
15
|
it "forces to enable specified unit" do
|
16
16
|
enable_unit(:inactive_unit)
|
17
|
-
view.invoke(:inactive_unit, :inactive, :type => :plain).
|
17
|
+
expect(view.invoke(:inactive_unit, :inactive, :type => :plain)).to eq("inactive")
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
describe "#disable_unit" do
|
22
22
|
it "forces to disable specified unit" do
|
23
23
|
disable_unit(:example_unit)
|
24
|
-
view.invoke(:example_unit, :test).
|
24
|
+
expect(view.invoke(:example_unit, :test)).to eq(nil)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
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
|
data/spec/chanko/unit_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require "spec_helper"
|
|
3
3
|
module Chanko
|
4
4
|
describe Unit do
|
5
5
|
before do
|
6
|
-
unit.
|
6
|
+
allow(unit).to receive_messages(:name => "ExampleUnit")
|
7
7
|
end
|
8
8
|
|
9
9
|
let(:unit) do
|
@@ -29,7 +29,7 @@ module Chanko
|
|
29
29
|
describe ".active_if" do
|
30
30
|
context "in default configuration" do
|
31
31
|
it "is configured to return always true" do
|
32
|
-
|
32
|
+
is_expected.to eq(true)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -38,7 +38,7 @@ module Chanko
|
|
38
38
|
unit.active_if(:true, :false)
|
39
39
|
end
|
40
40
|
specify "all of defined conditions must pass" do
|
41
|
-
|
41
|
+
is_expected.to eq(false)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -47,7 +47,7 @@ module Chanko
|
|
47
47
|
unit.active_if(:true) { false }
|
48
48
|
end
|
49
49
|
specify "all of defined conditions and block must pass" do
|
50
|
-
|
50
|
+
is_expected.to eq(false)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -69,7 +69,7 @@ module Chanko
|
|
69
69
|
active_if any(:true, :false)
|
70
70
|
end
|
71
71
|
end
|
72
|
-
it {
|
72
|
+
it { is_expected.to eq(true) }
|
73
73
|
end
|
74
74
|
|
75
75
|
context "when all conditions returned false" do
|
@@ -78,7 +78,7 @@ module Chanko
|
|
78
78
|
active_if any(:false, :false)
|
79
79
|
end
|
80
80
|
end
|
81
|
-
it {
|
81
|
+
it { is_expected.to eq(false) }
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
@@ -89,7 +89,7 @@ module Chanko
|
|
89
89
|
active_if none(:false, :false)
|
90
90
|
end
|
91
91
|
end
|
92
|
-
it {
|
92
|
+
it { is_expected.to eq(true) }
|
93
93
|
end
|
94
94
|
|
95
95
|
context "when conditions returned true and false" do
|
@@ -98,7 +98,7 @@ module Chanko
|
|
98
98
|
active_if none(:true, :false)
|
99
99
|
end
|
100
100
|
end
|
101
|
-
it {
|
101
|
+
it { is_expected.to eq(false) }
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
@@ -110,7 +110,7 @@ module Chanko
|
|
110
110
|
end
|
111
111
|
end
|
112
112
|
it "returns negatived result of inner-expression" do
|
113
|
-
|
113
|
+
is_expected.to eq(false)
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
@@ -121,7 +121,7 @@ module Chanko
|
|
121
121
|
end
|
122
122
|
end
|
123
123
|
it "uses none(:true) as false" do
|
124
|
-
|
124
|
+
is_expected.to eq(false)
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
@@ -131,7 +131,7 @@ module Chanko
|
|
131
131
|
active_if any(any(none(:false), :false), :false)
|
132
132
|
end
|
133
133
|
end
|
134
|
-
it {
|
134
|
+
it { is_expected.to eq(true) }
|
135
135
|
end
|
136
136
|
end
|
137
137
|
end
|
@@ -139,13 +139,13 @@ module Chanko
|
|
139
139
|
describe ".scope" do
|
140
140
|
specify "given scope is recorded to used scope list" do
|
141
141
|
unit.scope(:view) { }
|
142
|
-
unit.scopes.keys.
|
142
|
+
expect(unit.scopes.keys).to eq([ActionView::Base])
|
143
143
|
end
|
144
144
|
|
145
145
|
context "in the scoped block" do
|
146
146
|
specify "current_scope returns given scope" do
|
147
147
|
unit.scope(:view) do
|
148
|
-
unit.current_scope.
|
148
|
+
expect(unit.current_scope).to eq(ActionView::Base)
|
149
149
|
end
|
150
150
|
end
|
151
151
|
end
|
@@ -153,7 +153,7 @@ module Chanko
|
|
153
153
|
context "out of the scoped block" do
|
154
154
|
specify "current_scope returns nil" do
|
155
155
|
unit.scope(:view) { }
|
156
|
-
unit.current_scope.
|
156
|
+
expect(unit.current_scope).to eq(nil)
|
157
157
|
end
|
158
158
|
end
|
159
159
|
end
|
@@ -165,7 +165,7 @@ module Chanko
|
|
165
165
|
"test"
|
166
166
|
end
|
167
167
|
end
|
168
|
-
unit.scopes[ActionView::Base][:test].block.call.
|
168
|
+
expect(unit.scopes[ActionView::Base][:test].block.call).to eq("test")
|
169
169
|
end
|
170
170
|
end
|
171
171
|
|
@@ -174,7 +174,7 @@ module Chanko
|
|
174
174
|
unit.shared(:test) do
|
175
175
|
"test"
|
176
176
|
end
|
177
|
-
unit.shared_methods[:test].call.
|
177
|
+
expect(unit.shared_methods[:test].call).to eq("test")
|
178
178
|
end
|
179
179
|
end
|
180
180
|
|
@@ -185,7 +185,7 @@ module Chanko
|
|
185
185
|
"test"
|
186
186
|
end
|
187
187
|
end
|
188
|
-
view.__example_unit_test.
|
188
|
+
expect(view.__example_unit_test).to eq("test")
|
189
189
|
end
|
190
190
|
end
|
191
191
|
|
@@ -230,25 +230,25 @@ module Chanko
|
|
230
230
|
end
|
231
231
|
|
232
232
|
it "defines instance methods with prefix" do
|
233
|
-
ExampleModel.new.__example_unit_test.
|
233
|
+
expect(ExampleModel.new.__example_unit_test).to eq("test")
|
234
234
|
end
|
235
235
|
|
236
236
|
it "defines class methods with prefix" do
|
237
|
-
ExampleModel.__example_unit_test.
|
237
|
+
expect(ExampleModel.__example_unit_test).to eq("test")
|
238
238
|
end
|
239
239
|
|
240
240
|
it "defines scope method with prefix" do
|
241
|
-
ExampleModel.__example_unit_active.
|
241
|
+
expect(ExampleModel.__example_unit_active).to eq("scoped")
|
242
242
|
end
|
243
243
|
|
244
244
|
it "defines has_one association method with prefix" do
|
245
|
-
ExampleModel.__example_unit_user.
|
245
|
+
expect(ExampleModel.__example_unit_user).to eq([:class_name => "User"])
|
246
246
|
end
|
247
247
|
end
|
248
248
|
|
249
249
|
describe ".view_path" do
|
250
250
|
it "returns path for its view directory" do
|
251
|
-
unit.view_path.
|
251
|
+
expect(unit.view_path).to eq("#{Config.units_directory_path}/example_unit/views")
|
252
252
|
end
|
253
253
|
end
|
254
254
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -12,19 +12,32 @@ require "chanko"
|
|
12
12
|
|
13
13
|
require File.expand_path("../dummy/config/environment", __FILE__)
|
14
14
|
require "rspec/rails"
|
15
|
-
require "rspec/autorun"
|
16
15
|
|
17
16
|
RSpec.configure do |config|
|
18
17
|
config.use_transactional_fixtures = true
|
19
18
|
config.infer_base_class_for_anonymous_controllers = false
|
20
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
21
19
|
config.run_all_when_everything_filtered = true
|
22
20
|
config.filter_run :focus
|
23
21
|
|
22
|
+
config.expect_with :rspec do |expectations|
|
23
|
+
expectations.syntax = :expect
|
24
|
+
end
|
25
|
+
|
24
26
|
config.after do
|
25
27
|
Chanko::Config.reset
|
26
28
|
Chanko::Config.units_directory_path = File.expand_path("../fixtures/units", __FILE__)
|
27
29
|
end
|
30
|
+
|
31
|
+
# rspec-rails 3 will no longer automatically infer an example group's spec type
|
32
|
+
# from the file location. You can explicitly opt-in to the feature using this
|
33
|
+
# config option.
|
34
|
+
# To explicitly tag specs without using automatic inference, set the `:type`
|
35
|
+
# metadata manually:
|
36
|
+
#
|
37
|
+
# describe ThingsController, :type => :controller do
|
38
|
+
# # Equivalent to being in spec/controllers
|
39
|
+
# end
|
40
|
+
config.infer_spec_type_from_file_location!
|
28
41
|
end
|
29
42
|
|
30
43
|
Chanko::Config.units_directory_path = File.expand_path("../fixtures/units", __FILE__)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chanko
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -84,16 +84,16 @@ dependencies:
|
|
84
84
|
name: rspec-rails
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 3.0.0
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 3.0.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: sass-rails
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -279,6 +279,7 @@ files:
|
|
279
279
|
- spec/fixtures/units/example_unit/views/_test.html.erb
|
280
280
|
- spec/fixtures/units/inactive_unit/inactive_unit.rb
|
281
281
|
- spec/fixtures/units/insensitive_unit/insensitive_unit.rb
|
282
|
+
- spec/fixtures/units/sensitive_inactive_unit/sensitive_inactive_unit.rb
|
282
283
|
- spec/fixtures/units/sensitive_unit/sensitive_unit.rb
|
283
284
|
- spec/spec_helper.rb
|
284
285
|
homepage: https://github.com/cookpad/chanko
|
@@ -367,5 +368,6 @@ test_files:
|
|
367
368
|
- spec/fixtures/units/example_unit/views/_test.html.erb
|
368
369
|
- spec/fixtures/units/inactive_unit/inactive_unit.rb
|
369
370
|
- spec/fixtures/units/insensitive_unit/insensitive_unit.rb
|
371
|
+
- spec/fixtures/units/sensitive_inactive_unit/sensitive_inactive_unit.rb
|
370
372
|
- spec/fixtures/units/sensitive_unit/sensitive_unit.rb
|
371
373
|
- spec/spec_helper.rb
|