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
@@ -1,96 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "hanami"
|
4
|
-
|
5
|
-
RSpec.describe "App view / Part namespace", :app_integration do
|
6
|
-
before do
|
7
|
-
module TestApp
|
8
|
-
class App < Hanami::App
|
9
|
-
config.root = "/test_app"
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
Hanami.app.instance_eval(&app_hook) if respond_to?(:app_hook)
|
14
|
-
Hanami.app.register_slice :main
|
15
|
-
Hanami.app.prepare
|
16
|
-
|
17
|
-
# The parts module (or any related setup) must exist _before_ we subclass
|
18
|
-
# Hanami::View, because the parts_namespace is configured at the time of
|
19
|
-
# subclassing (which happens right below)
|
20
|
-
parts_module! if respond_to?(:parts_module!)
|
21
|
-
|
22
|
-
module TestApp
|
23
|
-
class View < Hanami::View
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
module TestApp
|
28
|
-
module Views
|
29
|
-
module Article
|
30
|
-
class Index < TestApp::View
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
subject(:part_namespace) { view_class.config.part_namespace }
|
38
|
-
|
39
|
-
let(:view_class) { TestApp::Views::Article::Index }
|
40
|
-
|
41
|
-
context "default parts_path" do
|
42
|
-
let(:parts_module!) do
|
43
|
-
module TestApp
|
44
|
-
module Views
|
45
|
-
module Parts
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
it "is View::Parts" do
|
52
|
-
is_expected.to eq TestApp::Views::Parts
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context "custom parts_path configured" do
|
57
|
-
let(:app_hook) {
|
58
|
-
proc do
|
59
|
-
config.views.parts_path = "views/custom_parts"
|
60
|
-
end
|
61
|
-
}
|
62
|
-
|
63
|
-
context "parts module exists" do
|
64
|
-
let(:parts_module!) do
|
65
|
-
module TestApp
|
66
|
-
module Views
|
67
|
-
module CustomParts
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
it "is the matching module within the slice" do
|
74
|
-
is_expected.to eq TestApp::Views::CustomParts
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
context "namespace does not exist" do
|
79
|
-
it "is nil" do
|
80
|
-
is_expected.to be_nil
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
context "nil parts_path configured" do
|
86
|
-
let(:app_hook) {
|
87
|
-
proc do
|
88
|
-
config.views.parts_path = nil
|
89
|
-
end
|
90
|
-
}
|
91
|
-
|
92
|
-
it "is nil" do
|
93
|
-
is_expected.to be_nil
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "hanami"
|
4
|
-
|
5
|
-
RSpec.describe "App view / Path", :app_integration do
|
6
|
-
before do
|
7
|
-
module TestApp
|
8
|
-
class App < Hanami::App
|
9
|
-
config.root = "/test_app"
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
Hanami.app.instance_eval(&app_hook) if respond_to?(:app_hook)
|
14
|
-
Hanami.app.register_slice :main
|
15
|
-
Hanami.app.prepare
|
16
|
-
|
17
|
-
module TestApp
|
18
|
-
class View < Hanami::View
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
let(:view_class) { TestApp::View }
|
24
|
-
|
25
|
-
subject(:paths) { view_class.config.paths }
|
26
|
-
|
27
|
-
context "default path" do
|
28
|
-
it "is 'templates' appended to the slice's root path" do
|
29
|
-
expect(paths.map { |path| path.dir.to_s }).to eq ["/test_app/app/templates"]
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context "relative path provided in app config" do
|
34
|
-
let(:app_hook) {
|
35
|
-
proc do
|
36
|
-
config.views.paths = ["my_templates"]
|
37
|
-
end
|
38
|
-
}
|
39
|
-
|
40
|
-
it "configures the path as the relative path appended to the slice's root path" do
|
41
|
-
expect(paths.map { |path| path.dir.to_s }).to eq ["/test_app/app/my_templates"]
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context "absolute path provided in app config" do
|
46
|
-
let(:app_hook) {
|
47
|
-
proc do
|
48
|
-
config.views.paths = ["/absolute/path"]
|
49
|
-
end
|
50
|
-
}
|
51
|
-
|
52
|
-
it "leaves the absolute path in place" do
|
53
|
-
expect(paths.map { |path| path.dir.to_s }).to eq ["/absolute/path"]
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "hanami"
|
4
|
-
|
5
|
-
RSpec.describe "App view / Template", :app_integration do
|
6
|
-
before do
|
7
|
-
module TestApp
|
8
|
-
class App < Hanami::App
|
9
|
-
config.root = "/test_app"
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
Hanami.app.instance_eval(&app_hook) if respond_to?(:app_hook)
|
14
|
-
Hanami.app.register_slice :main
|
15
|
-
Hanami.app.prepare
|
16
|
-
|
17
|
-
module TestApp
|
18
|
-
class View < Hanami::View
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
subject(:template) { view_class.config.template }
|
24
|
-
|
25
|
-
context "Ordinary app view" do
|
26
|
-
before do
|
27
|
-
module TestApp
|
28
|
-
module Views
|
29
|
-
module Article
|
30
|
-
class Index < TestApp::View
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
let(:view_class) { TestApp::Views::Article::Index }
|
38
|
-
|
39
|
-
it "configures the tempalte to match the class name" do
|
40
|
-
expect(template).to eq "article/index"
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context "Slice view with namespace matching template inference base" do
|
45
|
-
before do
|
46
|
-
module TestApp
|
47
|
-
module MyViews
|
48
|
-
module Users
|
49
|
-
class Show < TestApp::View
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
let(:app_hook) {
|
57
|
-
proc do
|
58
|
-
config.views.template_inference_base = "my_views"
|
59
|
-
end
|
60
|
-
}
|
61
|
-
|
62
|
-
let(:view_class) { TestApp::MyViews::Users::Show }
|
63
|
-
|
64
|
-
it "configures the tempalte to match the class name" do
|
65
|
-
expect(template).to eq "users/show"
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Bookshelf
|
4
|
-
class App < Hanami::App
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
RSpec.describe Hanami do
|
9
|
-
describe ".application" do
|
10
|
-
it "it raises error when already assigned" do
|
11
|
-
expect do
|
12
|
-
module Soundcard
|
13
|
-
class App < Hanami::App
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end.to raise_error("Hanami.app already configured")
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe Hanami do
|
4
|
-
describe ".application" do
|
5
|
-
it "it doesn't assign when anonymous class inherits Hanami::Application" do
|
6
|
-
Class.new(Hanami::Application)
|
7
|
-
expect { Hanami.app }.to raise_error("Hanami.app not configured")
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Bookshelf
|
4
|
-
class App < Hanami::App
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
RSpec.describe Hanami do
|
9
|
-
describe ".application" do
|
10
|
-
it "it assign when concrete class inherits Hanami::Application" do
|
11
|
-
expect(Hanami.app).to eq(Bookshelf::Application)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "hanami/action"
|
4
|
-
|
5
|
-
module Bookshelf
|
6
|
-
class App < Hanami::App
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
module Web
|
11
|
-
end
|
12
|
-
Hanami.app.register_slice :web, namespace: Web
|
13
|
-
|
14
|
-
Hanami.prepare
|
15
|
-
|
16
|
-
module Web
|
17
|
-
class Action < Hanami::Action
|
18
|
-
end
|
19
|
-
|
20
|
-
module Actions
|
21
|
-
module Home
|
22
|
-
class Index < Web::Action
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
Hanami.app.routes do
|
29
|
-
mount :web, at: "/" do
|
30
|
-
root to: "home#index"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
RSpec.describe Hanami::Application do
|
35
|
-
describe ".routes" do
|
36
|
-
subject { Hanami.app.routes }
|
37
|
-
|
38
|
-
it "returns configured routes" do
|
39
|
-
expect(subject).to be_kind_of(Proc)
|
40
|
-
# FIXME: make this expectation to pass
|
41
|
-
# expect(subject.for(:web).url(:root)).to eq("/")
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Bookshelf
|
4
|
-
class App < Hanami::App
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
RSpec.describe Hanami::Application do
|
9
|
-
describe ".routes" do
|
10
|
-
subject { Hanami.app.routes }
|
11
|
-
|
12
|
-
it "raises error when not configured" do
|
13
|
-
expect { subject }.to raise_error("Hanami.app.routes not configured")
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "hanami/action"
|
4
|
-
require "hanami/logger"
|
5
|
-
|
6
|
-
module Bookshelf
|
7
|
-
class App < Hanami::App
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
module Web
|
12
|
-
end
|
13
|
-
slice = Hanami.app.register_slice :web, namespace: Web
|
14
|
-
|
15
|
-
Hanami.prepare
|
16
|
-
|
17
|
-
Hanami.app.routes do
|
18
|
-
mount :web, at: "/" do
|
19
|
-
root to: "home#index"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
module Web
|
24
|
-
class Action < Hanami::Action
|
25
|
-
end
|
26
|
-
|
27
|
-
module Actions
|
28
|
-
module Home
|
29
|
-
class Index < Web::Action
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
slice.register "actions.home.index" do
|
36
|
-
Web::Actions::Home::Index.new
|
37
|
-
end
|
38
|
-
|
39
|
-
RSpec.describe Hanami do
|
40
|
-
describe ".boot" do
|
41
|
-
it "assigns Hanami.app, .root, and .logger" do
|
42
|
-
pending "Failing due to dry-system changes"
|
43
|
-
|
44
|
-
Hanami.boot
|
45
|
-
expect(Hanami.app.ancestors).to include(Hanami::Application)
|
46
|
-
expect(Hanami.app.root).to eq(Dir.pwd)
|
47
|
-
expect(Hanami.logger).to be_kind_of(Dry::Logger::Dispatcher)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|