hanami 2.0.3 → 2.1.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +37 -2
- data/LICENSE.md +1 -1
- data/README.md +26 -10
- data/hanami.gemspec +2 -2
- data/lib/hanami/app.rb +5 -0
- data/lib/hanami/config/actions.rb +4 -11
- data/lib/hanami/config/assets.rb +84 -0
- data/lib/hanami/config/null_config.rb +3 -0
- data/lib/hanami/config/views.rb +0 -4
- data/lib/hanami/config.rb +71 -5
- data/lib/hanami/extensions/action/slice_configured_action.rb +15 -7
- data/lib/hanami/extensions/action.rb +8 -6
- data/lib/hanami/extensions/router/errors.rb +58 -0
- data/lib/hanami/extensions/view/context.rb +129 -60
- data/lib/hanami/extensions/view/part.rb +26 -0
- data/lib/hanami/extensions/view/scope.rb +26 -0
- data/lib/hanami/extensions/view/slice_configured_context.rb +0 -2
- data/lib/hanami/extensions/view/slice_configured_helpers.rb +44 -0
- data/lib/hanami/extensions/view/slice_configured_view.rb +106 -21
- data/lib/hanami/extensions/view/standard_helpers.rb +18 -0
- data/lib/hanami/extensions.rb +10 -3
- data/lib/hanami/helpers/assets_helper.rb +752 -0
- data/lib/hanami/helpers/form_helper/form_builder.rb +1391 -0
- data/lib/hanami/helpers/form_helper/values.rb +75 -0
- data/lib/hanami/helpers/form_helper.rb +213 -0
- data/lib/hanami/middleware/assets.rb +21 -0
- data/lib/hanami/middleware/public_errors_app.rb +75 -0
- data/lib/hanami/middleware/render_errors.rb +90 -0
- data/lib/hanami/providers/assets.rb +44 -0
- data/lib/hanami/rake_tasks.rb +19 -18
- data/lib/hanami/settings.rb +1 -1
- data/lib/hanami/slice.rb +48 -2
- data/lib/hanami/slice_configurable.rb +3 -2
- data/lib/hanami/version.rb +1 -1
- data/lib/hanami/web/rack_logger.rb +1 -1
- data/lib/hanami.rb +3 -3
- data/spec/integration/action/view_rendering/view_context_spec.rb +221 -0
- data/spec/integration/action/view_rendering_spec.rb +0 -18
- data/spec/integration/assets/assets_spec.rb +101 -0
- data/spec/integration/assets/serve_static_assets_spec.rb +152 -0
- data/spec/integration/logging/exception_logging_spec.rb +115 -0
- data/spec/integration/logging/notifications_spec.rb +68 -0
- data/spec/integration/logging/request_logging_spec.rb +128 -0
- data/spec/integration/rack_app/middleware_spec.rb +22 -22
- data/spec/integration/rack_app/rack_app_spec.rb +3 -220
- data/spec/integration/rake_tasks_spec.rb +107 -0
- data/spec/integration/view/config/default_context_spec.rb +149 -0
- data/spec/integration/view/{inflector_spec.rb → config/inflector_spec.rb} +1 -1
- data/spec/integration/view/config/part_class_spec.rb +147 -0
- data/spec/integration/view/config/part_namespace_spec.rb +103 -0
- data/spec/integration/view/config/paths_spec.rb +119 -0
- data/spec/integration/view/config/scope_class_spec.rb +147 -0
- data/spec/integration/view/config/scope_namespace_spec.rb +103 -0
- data/spec/integration/view/config/template_spec.rb +38 -0
- data/spec/integration/view/context/assets_spec.rb +3 -9
- data/spec/integration/view/context/request_spec.rb +3 -7
- data/spec/integration/view/helpers/form_helper_spec.rb +174 -0
- data/spec/integration/view/helpers/part_helpers_spec.rb +124 -0
- data/spec/integration/view/helpers/scope_helpers_spec.rb +84 -0
- data/spec/integration/view/helpers/user_defined_helpers/part_helpers_spec.rb +162 -0
- data/spec/integration/view/helpers/user_defined_helpers/scope_helpers_spec.rb +119 -0
- data/spec/integration/view/slice_configuration_spec.rb +9 -9
- data/spec/integration/web/render_detailed_errors_spec.rb +107 -0
- data/spec/integration/web/render_errors_spec.rb +242 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/support/app_integration.rb +46 -2
- data/spec/support/matchers.rb +32 -0
- data/spec/unit/hanami/config/actions/content_security_policy_spec.rb +24 -36
- data/spec/unit/hanami/config/actions/csrf_protection_spec.rb +4 -3
- data/spec/unit/hanami/config/actions/default_values_spec.rb +3 -6
- data/spec/unit/hanami/config/render_detailed_errors_spec.rb +25 -0
- data/spec/unit/hanami/config/render_errors_spec.rb +25 -0
- data/spec/unit/hanami/config/views_spec.rb +0 -18
- data/spec/unit/hanami/env_spec.rb +11 -25
- data/spec/unit/hanami/extensions/view/context_spec.rb +59 -0
- data/spec/unit/hanami/helpers/assets_helper/asset_url_spec.rb +109 -0
- data/spec/unit/hanami/helpers/assets_helper/audio_tag_spec.rb +132 -0
- data/spec/unit/hanami/helpers/assets_helper/favicon_link_tag_spec.rb +91 -0
- data/spec/unit/hanami/helpers/assets_helper/image_tag_spec.rb +92 -0
- data/spec/unit/hanami/helpers/assets_helper/javascript_tag_spec.rb +143 -0
- data/spec/unit/hanami/helpers/assets_helper/stylesheet_link_tag_spec.rb +126 -0
- data/spec/unit/hanami/helpers/assets_helper/video_tag_spec.rb +132 -0
- data/spec/unit/hanami/helpers/form_helper_spec.rb +2826 -0
- data/spec/unit/hanami/router/errors/not_allowed_error_spec.rb +27 -0
- data/spec/unit/hanami/router/errors/not_found_error_spec.rb +22 -0
- data/spec/unit/hanami/slice_configurable_spec.rb +18 -0
- data/spec/unit/hanami/version_spec.rb +1 -1
- data/spec/unit/hanami/web/rack_logger_spec.rb +1 -1
- metadata +95 -35
- data/lib/hanami/assets/app_config.rb +0 -61
- data/lib/hanami/assets/config.rb +0 -53
- data/spec/integration/action/view_integration_spec.rb +0 -165
- data/spec/integration/view/part_namespace_spec.rb +0 -96
- data/spec/integration/view/path_spec.rb +0 -56
- data/spec/integration/view/template_spec.rb +0 -68
- data/spec/isolation/hanami/application/already_configured_spec.rb +0 -19
- data/spec/isolation/hanami/application/inherit_anonymous_class_spec.rb +0 -10
- data/spec/isolation/hanami/application/inherit_concrete_class_spec.rb +0 -14
- data/spec/isolation/hanami/application/not_configured_spec.rb +0 -9
- data/spec/isolation/hanami/application/routes/configured_spec.rb +0 -44
- data/spec/isolation/hanami/application/routes/not_configured_spec.rb +0 -16
- data/spec/isolation/hanami/boot/success_spec.rb +0 -50
@@ -0,0 +1,149 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe "App view / Config / Default context", :app_integration do
|
4
|
+
before do
|
5
|
+
with_directory(@dir = make_tmp_directory) do
|
6
|
+
write "config/app.rb", <<~RUBY
|
7
|
+
module TestApp
|
8
|
+
class App < Hanami::App
|
9
|
+
end
|
10
|
+
end
|
11
|
+
RUBY
|
12
|
+
|
13
|
+
write "app/view.rb", <<~RUBY
|
14
|
+
# auto_register: false
|
15
|
+
|
16
|
+
require "hanami/view"
|
17
|
+
|
18
|
+
module TestApp
|
19
|
+
class View < Hanami::View
|
20
|
+
end
|
21
|
+
end
|
22
|
+
RUBY
|
23
|
+
|
24
|
+
before_prepare if respond_to?(:before_prepare)
|
25
|
+
require "hanami/prepare"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
subject(:default_context) { view_class.config.default_context }
|
30
|
+
|
31
|
+
describe "app view" do
|
32
|
+
let(:view_class) { TestApp::View }
|
33
|
+
|
34
|
+
describe "no concrete context class defined" do
|
35
|
+
it "generates an app context class and configures it as the view's default_context" do
|
36
|
+
expect(default_context).to be_an_instance_of TestApp::Views::Context
|
37
|
+
expect(default_context.class.superclass).to be Hanami::View::Context
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "concrete context class defined" do
|
42
|
+
def before_prepare
|
43
|
+
write "app/views/context.rb", <<~RUBY
|
44
|
+
# auto_register: false
|
45
|
+
|
46
|
+
module TestApp
|
47
|
+
module Views
|
48
|
+
class Context < Hanami::View::Context
|
49
|
+
def concrete?
|
50
|
+
true
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
RUBY
|
56
|
+
end
|
57
|
+
|
58
|
+
it "configures the app scope class as the view's scope_class" do
|
59
|
+
expect(default_context).to be_an_instance_of TestApp::Views::Context
|
60
|
+
expect(default_context).to be_concrete
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "slice view" do
|
66
|
+
let(:view_class) { Main::View }
|
67
|
+
|
68
|
+
def before_prepare
|
69
|
+
write "slices/main/view.rb", <<~RUBY
|
70
|
+
# auto_register: false
|
71
|
+
|
72
|
+
module Main
|
73
|
+
class View < TestApp::View
|
74
|
+
end
|
75
|
+
end
|
76
|
+
RUBY
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "no concrete slice context class defined" do
|
80
|
+
it "generates an app context class and configures it as the view's default_context" do
|
81
|
+
expect(default_context).to be_an_instance_of Main::Views::Context
|
82
|
+
expect(default_context.class.superclass).to be TestApp::Views::Context
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "concrete slice context class defined" do
|
87
|
+
def before_prepare
|
88
|
+
super
|
89
|
+
|
90
|
+
write "slices/main/views/context.rb", <<~RUBY
|
91
|
+
# auto_register: false
|
92
|
+
|
93
|
+
module Main
|
94
|
+
module Views
|
95
|
+
class Context < Hanami::View::Context
|
96
|
+
def concrete?
|
97
|
+
true
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
RUBY
|
103
|
+
end
|
104
|
+
|
105
|
+
it "configures the slice context as the view's default_context" do
|
106
|
+
expect(default_context).to be_an_instance_of Main::Views::Context
|
107
|
+
expect(default_context).to be_concrete
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "view not inheriting from app view, no concrete context class defined" do
|
112
|
+
def before_prepare
|
113
|
+
write "slices/main/view.rb", <<~RUBY
|
114
|
+
# auto_register: false
|
115
|
+
|
116
|
+
module Main
|
117
|
+
class View < Hanami::View
|
118
|
+
end
|
119
|
+
end
|
120
|
+
RUBY
|
121
|
+
end
|
122
|
+
|
123
|
+
it "generates a slice context class, inheriting from the app context class, and configures it as the view's default_context" do
|
124
|
+
expect(default_context).to be_an_instance_of Main::Views::Context
|
125
|
+
expect(default_context.class.superclass).to be TestApp::Views::Context
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe "no app view class defined" do
|
130
|
+
def before_prepare
|
131
|
+
FileUtils.rm "app/view.rb"
|
132
|
+
|
133
|
+
write "slices/main/view.rb", <<~RUBY
|
134
|
+
# auto_register: false
|
135
|
+
|
136
|
+
module Main
|
137
|
+
class View < Hanami::View
|
138
|
+
end
|
139
|
+
end
|
140
|
+
RUBY
|
141
|
+
end
|
142
|
+
|
143
|
+
it "generates a slice context class, inheriting from the app context class, and configures it as the view's default_context" do
|
144
|
+
expect(default_context).to be_an_instance_of Main::Views::Context
|
145
|
+
expect(default_context.class.superclass).to be Hanami::View::Context
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe "App view / Config / Part class", :app_integration do
|
4
|
+
before do
|
5
|
+
with_directory(make_tmp_directory) do
|
6
|
+
write "config/app.rb", <<~RUBY
|
7
|
+
module TestApp
|
8
|
+
class App < Hanami::App
|
9
|
+
end
|
10
|
+
end
|
11
|
+
RUBY
|
12
|
+
|
13
|
+
write "app/view.rb", <<~RUBY
|
14
|
+
# auto_register: false
|
15
|
+
|
16
|
+
require "hanami/view"
|
17
|
+
|
18
|
+
module TestApp
|
19
|
+
class View < Hanami::View
|
20
|
+
end
|
21
|
+
end
|
22
|
+
RUBY
|
23
|
+
|
24
|
+
before_prepare if respond_to?(:before_prepare)
|
25
|
+
require "hanami/prepare"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "app view" do
|
30
|
+
let(:view_class) { TestApp::View }
|
31
|
+
|
32
|
+
context "no concrete app part class defined" do
|
33
|
+
it "generates an app part class and configures it as the view's part_class" do
|
34
|
+
expect(view_class.config.part_class).to be TestApp::Views::Part
|
35
|
+
expect(view_class.config.part_class.superclass).to be Hanami::View::Part
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "concrete app part class defined" do
|
40
|
+
def before_prepare
|
41
|
+
write "app/views/part.rb", <<~RUBY
|
42
|
+
# auto_register: false
|
43
|
+
|
44
|
+
module TestApp
|
45
|
+
module Views
|
46
|
+
class Part < Hanami::View::Part
|
47
|
+
def self.concrete?
|
48
|
+
true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
RUBY
|
54
|
+
end
|
55
|
+
|
56
|
+
it "configures the app part class as the view's part_class" do
|
57
|
+
expect(view_class.config.part_class).to be TestApp::Views::Part
|
58
|
+
expect(view_class.config.part_class).to be_concrete
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "slice view" do
|
64
|
+
let(:view_class) { Main::View }
|
65
|
+
|
66
|
+
def before_prepare
|
67
|
+
write "slices/main/view.rb", <<~RUBY
|
68
|
+
# auto_register: false
|
69
|
+
|
70
|
+
module Main
|
71
|
+
class View < TestApp::View
|
72
|
+
end
|
73
|
+
end
|
74
|
+
RUBY
|
75
|
+
end
|
76
|
+
|
77
|
+
context "no concrete slice part class defined" do
|
78
|
+
it "generates a slice part class, inheriting from the app part class, and configures it as the view's part_class" do
|
79
|
+
expect(view_class.config.part_class).to be Main::Views::Part
|
80
|
+
expect(view_class.config.part_class.superclass).to be TestApp::Views::Part
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context "concrete slice part class defined" do
|
85
|
+
def before_prepare
|
86
|
+
super
|
87
|
+
|
88
|
+
write "slices/main/views/part.rb", <<~RUBY
|
89
|
+
# auto_register: false
|
90
|
+
|
91
|
+
module Main
|
92
|
+
module Views
|
93
|
+
class Part < TestApp::Views::Part
|
94
|
+
def self.concrete?
|
95
|
+
true
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
RUBY
|
101
|
+
end
|
102
|
+
|
103
|
+
it "configures the slice part class as the view's part_class" do
|
104
|
+
expect(view_class.config.part_class).to be Main::Views::Part
|
105
|
+
expect(view_class.config.part_class).to be_concrete
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context "view not inheriting from app view, no concrete part class" do
|
110
|
+
def before_prepare
|
111
|
+
write "slices/main/view.rb", <<~RUBY
|
112
|
+
# auto_register: false
|
113
|
+
|
114
|
+
module Main
|
115
|
+
class View < Hanami::View
|
116
|
+
end
|
117
|
+
end
|
118
|
+
RUBY
|
119
|
+
end
|
120
|
+
|
121
|
+
it "generates a slice part class, inheriting from the app part class, and configures it as the view's part_class" do
|
122
|
+
expect(view_class.config.part_class).to be Main::Views::Part
|
123
|
+
expect(view_class.config.part_class.superclass).to be TestApp::Views::Part
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context "no app view class defined" do
|
128
|
+
def before_prepare
|
129
|
+
FileUtils.rm "app/view.rb"
|
130
|
+
|
131
|
+
write "slices/main/view.rb", <<~RUBY
|
132
|
+
# auto_register: false
|
133
|
+
|
134
|
+
module Main
|
135
|
+
class View < Hanami::View
|
136
|
+
end
|
137
|
+
end
|
138
|
+
RUBY
|
139
|
+
end
|
140
|
+
|
141
|
+
it "generates a slice part class, inheriting from Hanami::View::Part, and configures it as the view's part_class" do
|
142
|
+
expect(view_class.config.part_class).to be Main::Views::Part
|
143
|
+
expect(view_class.config.part_class.superclass).to be Hanami::View::Part
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "hanami"
|
4
|
+
|
5
|
+
RSpec.describe "App view / Config / Part namespace", :app_integration do
|
6
|
+
before do
|
7
|
+
with_directory(make_tmp_directory) do
|
8
|
+
write "config/app.rb", <<~RUBY
|
9
|
+
module TestApp
|
10
|
+
class App < Hanami::App
|
11
|
+
end
|
12
|
+
end
|
13
|
+
RUBY
|
14
|
+
|
15
|
+
write "app/view.rb", <<~RUBY
|
16
|
+
# auto_register: false
|
17
|
+
|
18
|
+
require "hanami/view"
|
19
|
+
|
20
|
+
module TestApp
|
21
|
+
class View < Hanami::View
|
22
|
+
end
|
23
|
+
end
|
24
|
+
RUBY
|
25
|
+
|
26
|
+
before_prepare if respond_to?(:before_prepare)
|
27
|
+
require "hanami/prepare"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
subject(:part_namespace) { view_class.config.part_namespace }
|
32
|
+
|
33
|
+
describe "app view" do
|
34
|
+
let(:view_class) { TestApp::View }
|
35
|
+
|
36
|
+
describe "no part namespace defined" do
|
37
|
+
it "is nil" do
|
38
|
+
expect(part_namespace).to be nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "part namespace defined" do
|
43
|
+
def before_prepare
|
44
|
+
write "app/views/parts/post.rb", <<~RUBY
|
45
|
+
module TestApp
|
46
|
+
module Views
|
47
|
+
module Parts
|
48
|
+
class Post < Hanami::View::Part
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
RUBY
|
54
|
+
end
|
55
|
+
|
56
|
+
it "is the Views::Parts namespace within the app" do
|
57
|
+
expect(part_namespace).to eq TestApp::Views::Parts
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "slice view" do
|
63
|
+
def before_prepare
|
64
|
+
write "slices/main/view.rb", <<~RUBY
|
65
|
+
# auto_register: false
|
66
|
+
|
67
|
+
module Main
|
68
|
+
class View < TestApp::View
|
69
|
+
end
|
70
|
+
end
|
71
|
+
RUBY
|
72
|
+
end
|
73
|
+
|
74
|
+
let(:view_class) { Main::View }
|
75
|
+
|
76
|
+
describe "no part namespace defined" do
|
77
|
+
it "is nil" do
|
78
|
+
expect(part_namespace).to be nil
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "part namespace defined" do
|
83
|
+
def before_prepare
|
84
|
+
super
|
85
|
+
|
86
|
+
write "slices/main/views/parts/post.rb", <<~RUBY
|
87
|
+
module Main
|
88
|
+
module Views
|
89
|
+
module Parts
|
90
|
+
class Post < Hanami::View::Part
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
RUBY
|
96
|
+
end
|
97
|
+
|
98
|
+
it "is the Views::Parts namespace within the slice" do
|
99
|
+
expect(part_namespace).to eq Main::Views::Parts
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "hanami"
|
4
|
+
|
5
|
+
RSpec.describe "App view / Config / Paths", :app_integration do
|
6
|
+
before do
|
7
|
+
with_directory(make_tmp_directory) do
|
8
|
+
write "config/app.rb", <<~RUBY
|
9
|
+
module TestApp
|
10
|
+
class App < Hanami::App
|
11
|
+
end
|
12
|
+
end
|
13
|
+
RUBY
|
14
|
+
|
15
|
+
write "app/view.rb", <<~RUBY
|
16
|
+
# auto_register: false
|
17
|
+
|
18
|
+
require "hanami/view"
|
19
|
+
|
20
|
+
module TestApp
|
21
|
+
class View < Hanami::View
|
22
|
+
end
|
23
|
+
end
|
24
|
+
RUBY
|
25
|
+
|
26
|
+
require "hanami/setup"
|
27
|
+
before_prepare if respond_to?(:before_prepare)
|
28
|
+
require "hanami/prepare"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
subject(:paths) { view_class.config.paths }
|
33
|
+
|
34
|
+
describe "app view" do
|
35
|
+
let(:view_class) { TestApp::View }
|
36
|
+
|
37
|
+
it "is 'app/templates/'" do
|
38
|
+
expect(paths.map(&:dir)).to eq [Hanami.app.root.join("app", "templates")]
|
39
|
+
end
|
40
|
+
|
41
|
+
context "custom config in app" do
|
42
|
+
def before_prepare
|
43
|
+
TestApp::App.config.views.paths = ["/custom/dir"]
|
44
|
+
end
|
45
|
+
|
46
|
+
it "uses the custom config" do
|
47
|
+
expect(paths.map(&:dir)).to eq [Pathname("/custom/dir")]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "slice view" do
|
53
|
+
subject(:view_class) { Main::View }
|
54
|
+
|
55
|
+
def before_prepare
|
56
|
+
write "slices/main/view.rb", <<~RUBY
|
57
|
+
# auto_register: false
|
58
|
+
|
59
|
+
module Main
|
60
|
+
class View < TestApp::View
|
61
|
+
end
|
62
|
+
end
|
63
|
+
RUBY
|
64
|
+
end
|
65
|
+
|
66
|
+
it "is 'templates/' within the slice dir" do
|
67
|
+
expect(paths.map(&:dir)).to eq [Main::Slice.root.join("templates")]
|
68
|
+
end
|
69
|
+
|
70
|
+
context "custom config in app" do
|
71
|
+
def before_prepare
|
72
|
+
super
|
73
|
+
TestApp::App.config.views.paths = ["/custom/dir"]
|
74
|
+
end
|
75
|
+
|
76
|
+
it "uses the custom config" do
|
77
|
+
expect(paths.map(&:dir)).to eq [Pathname("/custom/dir")]
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "custom config in slice" do
|
82
|
+
def before_prepare
|
83
|
+
super
|
84
|
+
|
85
|
+
write "config/slices/main.rb", <<~RUBY
|
86
|
+
module Main
|
87
|
+
class Slice < Hanami::Slice
|
88
|
+
config.views.paths = ["/custom/slice/dir"]
|
89
|
+
end
|
90
|
+
end
|
91
|
+
RUBY
|
92
|
+
end
|
93
|
+
|
94
|
+
it "uses the custom config" do
|
95
|
+
expect(paths.map(&:dir)).to eq [Pathname("/custom/slice/dir")]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context "custom config in app and slice" do
|
100
|
+
def before_prepare
|
101
|
+
super
|
102
|
+
|
103
|
+
TestApp::App.config.views.paths = ["/custom/dir"]
|
104
|
+
|
105
|
+
write "config/slices/main.rb", <<~RUBY
|
106
|
+
module Main
|
107
|
+
class Slice < Hanami::Slice
|
108
|
+
config.views.paths = ["/custom/slice/dir"]
|
109
|
+
end
|
110
|
+
end
|
111
|
+
RUBY
|
112
|
+
end
|
113
|
+
|
114
|
+
it "uses the custom config from the slice" do
|
115
|
+
expect(paths.map(&:dir)).to eq [Pathname("/custom/slice/dir")]
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe "App view / Config / Scope class", :app_integration do
|
4
|
+
before do
|
5
|
+
with_directory(@dir = make_tmp_directory) do
|
6
|
+
write "config/app.rb", <<~RUBY
|
7
|
+
module TestApp
|
8
|
+
class App < Hanami::App
|
9
|
+
end
|
10
|
+
end
|
11
|
+
RUBY
|
12
|
+
|
13
|
+
write "app/view.rb", <<~RUBY
|
14
|
+
# auto_register: false
|
15
|
+
|
16
|
+
require "hanami/view"
|
17
|
+
|
18
|
+
module TestApp
|
19
|
+
class View < Hanami::View
|
20
|
+
end
|
21
|
+
end
|
22
|
+
RUBY
|
23
|
+
|
24
|
+
before_prepare if respond_to?(:before_prepare)
|
25
|
+
require "hanami/prepare"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "app view" do
|
30
|
+
let(:view_class) { TestApp::View }
|
31
|
+
|
32
|
+
describe "no concrete app scope class defined" do
|
33
|
+
it "generates an app scope class and configures it as the view's scope_class" do
|
34
|
+
expect(view_class.config.scope_class).to be TestApp::Views::Scope
|
35
|
+
expect(view_class.config.scope_class.superclass).to be Hanami::View::Scope
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "concrete app scope class defined" do
|
40
|
+
def before_prepare
|
41
|
+
write "app/views/scope.rb", <<~RUBY
|
42
|
+
# auto_register: false
|
43
|
+
|
44
|
+
module TestApp
|
45
|
+
module Views
|
46
|
+
class Scope < Hanami::View::Scope
|
47
|
+
def self.concrete?
|
48
|
+
true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
RUBY
|
54
|
+
end
|
55
|
+
|
56
|
+
it "configures the app scope class as the view's scope_class" do
|
57
|
+
expect(view_class.config.scope_class).to be TestApp::Views::Scope
|
58
|
+
expect(view_class.config.scope_class).to be_concrete
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "slice view" do
|
64
|
+
let(:view_class) { Main::View }
|
65
|
+
|
66
|
+
def before_prepare
|
67
|
+
write "slices/main/view.rb", <<~RUBY
|
68
|
+
# auto_register: false
|
69
|
+
|
70
|
+
module Main
|
71
|
+
class View < TestApp::View
|
72
|
+
end
|
73
|
+
end
|
74
|
+
RUBY
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "no concrete slice scope class defined" do
|
78
|
+
it "generates a slice scope class and configures it as the view's scope_class" do
|
79
|
+
expect(view_class.config.scope_class).to be Main::Views::Scope
|
80
|
+
expect(view_class.config.scope_class.superclass).to be TestApp::Views::Scope
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "concrete slice scope class defined" do
|
85
|
+
def before_prepare
|
86
|
+
super
|
87
|
+
|
88
|
+
write "slices/main/views/scope.rb", <<~RUBY
|
89
|
+
# auto_register: false
|
90
|
+
|
91
|
+
module Main
|
92
|
+
module Views
|
93
|
+
class Scope < TestApp::Views::Scope
|
94
|
+
def self.concrete?
|
95
|
+
true
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
RUBY
|
101
|
+
end
|
102
|
+
|
103
|
+
it "configures the slice scope class as the view's scope_class" do
|
104
|
+
expect(view_class.config.scope_class).to eq Main::Views::Scope
|
105
|
+
expect(view_class.config.scope_class).to be_concrete
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context "view not inheriting from app view, no concrete scope class defined" do
|
110
|
+
def before_prepare
|
111
|
+
write "slices/main/view.rb", <<~RUBY
|
112
|
+
# auto_register: false
|
113
|
+
|
114
|
+
module Main
|
115
|
+
class View < Hanami::View
|
116
|
+
end
|
117
|
+
end
|
118
|
+
RUBY
|
119
|
+
end
|
120
|
+
|
121
|
+
it "generates a slice scope class, inheriting from the app scope class, and configures it as the view's scope_class" do
|
122
|
+
expect(view_class.config.scope_class).to be Main::Views::Scope
|
123
|
+
expect(view_class.config.scope_class.superclass).to be TestApp::Views::Scope
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context "no app view class defined" do
|
128
|
+
def before_prepare
|
129
|
+
FileUtils.rm "app/view.rb"
|
130
|
+
|
131
|
+
write "slices/main/view.rb", <<~RUBY
|
132
|
+
# auto_register: false
|
133
|
+
|
134
|
+
module Main
|
135
|
+
class View < Hanami::View
|
136
|
+
end
|
137
|
+
end
|
138
|
+
RUBY
|
139
|
+
end
|
140
|
+
|
141
|
+
it "generates a slice scope class, inheriting from Hanami::View::Scope, and configures it as the view's scope_class" do
|
142
|
+
expect(view_class.config.scope_class).to be Main::Views::Scope
|
143
|
+
expect(view_class.config.scope_class.superclass).to be Hanami::View::Scope
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|