hanami 2.0.0.beta1.1 → 2.0.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +82 -0
  3. data/hanami.gemspec +1 -2
  4. data/lib/hanami/app.rb +76 -16
  5. data/lib/hanami/assets/{application_configuration.rb → app_configuration.rb} +1 -1
  6. data/lib/hanami/configuration/null_configuration.rb +2 -2
  7. data/lib/hanami/configuration.rb +36 -36
  8. data/lib/hanami/extensions/action/slice_configured_action.rb +44 -1
  9. data/lib/hanami/extensions/view/slice_configured_view.rb +47 -7
  10. data/lib/hanami/providers/rack.rb +2 -0
  11. data/lib/hanami/providers/settings.rb +81 -6
  12. data/lib/hanami/routes.rb +48 -21
  13. data/lib/hanami/settings/env_store.rb +32 -0
  14. data/lib/hanami/settings.rb +8 -12
  15. data/lib/hanami/setup.rb +1 -6
  16. data/lib/hanami/slice/routing/middleware/stack.rb +26 -5
  17. data/lib/hanami/slice.rb +38 -45
  18. data/lib/hanami/slice_configurable.rb +14 -1
  19. data/lib/hanami/slice_registrar.rb +65 -5
  20. data/lib/hanami/version.rb +1 -1
  21. data/lib/hanami.rb +53 -2
  22. data/spec/{new_integration → integration}/action/cookies_spec.rb +0 -0
  23. data/spec/{new_integration → integration}/action/csrf_protection_spec.rb +0 -0
  24. data/spec/{new_integration → integration}/action/routes_spec.rb +3 -5
  25. data/spec/{new_integration → integration}/action/sessions_spec.rb +0 -0
  26. data/spec/integration/action/slice_configuration_spec.rb +287 -0
  27. data/spec/{new_integration → integration}/action/view_integration_spec.rb +0 -0
  28. data/spec/{new_integration → integration}/action/view_rendering/automatic_rendering_spec.rb +0 -0
  29. data/spec/{new_integration → integration}/action/view_rendering/paired_view_inference_spec.rb +0 -0
  30. data/spec/{new_integration → integration}/action/view_rendering_spec.rb +0 -0
  31. data/spec/{new_integration → integration}/code_loading/loading_from_app_spec.rb +0 -0
  32. data/spec/integration/code_loading/loading_from_lib_spec.rb +208 -0
  33. data/spec/{new_integration → integration}/code_loading/loading_from_slice_spec.rb +0 -0
  34. data/spec/{new_integration → integration}/container/application_routes_helper_spec.rb +1 -3
  35. data/spec/{new_integration → integration}/container/auto_injection_spec.rb +0 -0
  36. data/spec/{new_integration → integration}/container/auto_registration_spec.rb +0 -0
  37. data/spec/{new_integration → integration}/container/autoloader_spec.rb +0 -0
  38. data/spec/{new_integration → integration}/container/imports_spec.rb +0 -0
  39. data/spec/{new_integration → integration}/container/prepare_container_spec.rb +0 -0
  40. data/spec/{new_integration → integration}/container/shutdown_spec.rb +0 -0
  41. data/spec/{new_integration → integration}/container/standard_bootable_components_spec.rb +0 -0
  42. data/spec/integration/dotenv_loading_spec.rb +137 -0
  43. data/spec/{new_integration → integration}/rack_app/middleware_spec.rb +9 -15
  44. data/spec/{new_integration → integration}/rack_app/non_booted_rack_app_spec.rb +3 -5
  45. data/spec/{new_integration → integration}/rack_app/rack_app_spec.rb +28 -48
  46. data/spec/integration/settings/access_to_constants_spec.rb +169 -0
  47. data/spec/integration/settings/loading_from_env_spec.rb +187 -0
  48. data/spec/integration/settings/settings_component_loading_spec.rb +113 -0
  49. data/spec/integration/settings/using_types_spec.rb +87 -0
  50. data/spec/integration/setup_spec.rb +165 -0
  51. data/spec/{new_integration → integration}/slices/external_slice_spec.rb +2 -4
  52. data/spec/{new_integration → integration}/slices/slice_configuration_spec.rb +0 -0
  53. data/spec/integration/slices/slice_loading_spec.rb +171 -0
  54. data/spec/{new_integration → integration}/slices/slice_routing_spec.rb +5 -13
  55. data/spec/{new_integration → integration}/slices/slice_settings_spec.rb +0 -0
  56. data/spec/{new_integration → integration}/slices_spec.rb +0 -0
  57. data/spec/{new_integration → integration}/view/context/assets_spec.rb +0 -0
  58. data/spec/{new_integration → integration}/view/context/inflector_spec.rb +0 -0
  59. data/spec/{new_integration → integration}/view/context/request_spec.rb +0 -0
  60. data/spec/{new_integration → integration}/view/context/routes_spec.rb +1 -3
  61. data/spec/{new_integration → integration}/view/context/settings_spec.rb +5 -1
  62. data/spec/{new_integration → integration}/view/inflector_spec.rb +0 -0
  63. data/spec/{new_integration → integration}/view/part_namespace_spec.rb +0 -0
  64. data/spec/{new_integration → integration}/view/path_spec.rb +0 -0
  65. data/spec/integration/view/slice_configuration_spec.rb +289 -0
  66. data/spec/{new_integration → integration}/view/template_spec.rb +0 -0
  67. data/spec/{new_integration → integration}/view/views_spec.rb +0 -0
  68. data/spec/support/app_integration.rb +4 -5
  69. data/spec/unit/hanami/configuration/actions_spec.rb +4 -15
  70. data/spec/unit/hanami/configuration/router_spec.rb +45 -0
  71. data/spec/unit/hanami/configuration/slices_spec.rb +34 -0
  72. data/spec/unit/hanami/configuration/views_spec.rb +4 -15
  73. data/spec/unit/hanami/settings/env_store_spec.rb +52 -0
  74. data/spec/unit/hanami/slice_configurable_spec.rb +2 -2
  75. data/spec/unit/hanami/version_spec.rb +1 -1
  76. metadata +105 -250
  77. data/lib/hanami/server.rb +0 -29
  78. data/lib/hanami/settings/dotenv_store.rb +0 -58
  79. data/spec/integration/application_middleware_stack_spec.rb +0 -84
  80. data/spec/integration/assets/cdn_spec.rb +0 -48
  81. data/spec/integration/assets/fingerprint_spec.rb +0 -42
  82. data/spec/integration/assets/helpers_spec.rb +0 -50
  83. data/spec/integration/assets/serve_spec.rb +0 -70
  84. data/spec/integration/assets/subresource_integrity_spec.rb +0 -54
  85. data/spec/integration/body_parsers_spec.rb +0 -50
  86. data/spec/integration/cli/assets/precompile_spec.rb +0 -147
  87. data/spec/integration/cli/assets_spec.rb +0 -14
  88. data/spec/integration/cli/console_spec.rb +0 -105
  89. data/spec/integration/cli/db/apply_spec.rb +0 -74
  90. data/spec/integration/cli/db/console_spec.rb +0 -40
  91. data/spec/integration/cli/db/create_spec.rb +0 -50
  92. data/spec/integration/cli/db/drop_spec.rb +0 -54
  93. data/spec/integration/cli/db/migrate_spec.rb +0 -108
  94. data/spec/integration/cli/db/prepare_spec.rb +0 -36
  95. data/spec/integration/cli/db/rollback_spec.rb +0 -96
  96. data/spec/integration/cli/db/version_spec.rb +0 -38
  97. data/spec/integration/cli/db_spec.rb +0 -21
  98. data/spec/integration/cli/destroy/action_spec.rb +0 -143
  99. data/spec/integration/cli/destroy/app_spec.rb +0 -118
  100. data/spec/integration/cli/destroy/mailer_spec.rb +0 -74
  101. data/spec/integration/cli/destroy/migration_spec.rb +0 -70
  102. data/spec/integration/cli/destroy/model_spec.rb +0 -113
  103. data/spec/integration/cli/destroy_spec.rb +0 -18
  104. data/spec/integration/cli/generate/action_spec.rb +0 -469
  105. data/spec/integration/cli/generate/app_spec.rb +0 -215
  106. data/spec/integration/cli/generate/mailer_spec.rb +0 -189
  107. data/spec/integration/cli/generate/migration_spec.rb +0 -72
  108. data/spec/integration/cli/generate/model_spec.rb +0 -290
  109. data/spec/integration/cli/generate/secret_spec.rb +0 -56
  110. data/spec/integration/cli/generate_spec.rb +0 -19
  111. data/spec/integration/cli/new/database_spec.rb +0 -235
  112. data/spec/integration/cli/new/hanami_head_spec.rb +0 -27
  113. data/spec/integration/cli/new/template_spec.rb +0 -118
  114. data/spec/integration/cli/new/test_spec.rb +0 -274
  115. data/spec/integration/cli/new_spec.rb +0 -970
  116. data/spec/integration/cli/plugins_spec.rb +0 -39
  117. data/spec/integration/cli/routes_spec.rb +0 -49
  118. data/spec/integration/cli/server_spec.rb +0 -626
  119. data/spec/integration/cli/version_spec.rb +0 -85
  120. data/spec/integration/early_hints_spec.rb +0 -35
  121. data/spec/integration/handle_exceptions_spec.rb +0 -244
  122. data/spec/integration/head_spec.rb +0 -89
  123. data/spec/integration/http_headers_spec.rb +0 -29
  124. data/spec/integration/mailer_spec.rb +0 -32
  125. data/spec/integration/middleware_spec.rb +0 -81
  126. data/spec/integration/mount_applications_spec.rb +0 -88
  127. data/spec/integration/project_initializers_spec.rb +0 -40
  128. data/spec/integration/rackup_spec.rb +0 -35
  129. data/spec/integration/rake/with_minitest_spec.rb +0 -67
  130. data/spec/integration/rake/with_rspec_spec.rb +0 -69
  131. data/spec/integration/routing_helpers_spec.rb +0 -61
  132. data/spec/integration/security/content_security_policy_spec.rb +0 -46
  133. data/spec/integration/security/csrf_protection_spec.rb +0 -42
  134. data/spec/integration/security/force_ssl_spec.rb +0 -29
  135. data/spec/integration/security/x_content_type_options_spec.rb +0 -46
  136. data/spec/integration/security/x_frame_options_spec.rb +0 -46
  137. data/spec/integration/security/x_xss_protection_spec.rb +0 -46
  138. data/spec/integration/send_file_spec.rb +0 -51
  139. data/spec/integration/sessions_spec.rb +0 -247
  140. data/spec/integration/static_middleware_spec.rb +0 -21
  141. data/spec/integration/streaming_spec.rb +0 -41
  142. data/spec/integration/unsafe_send_file_spec.rb +0 -52
  143. data/spec/new_integration/action/configuration_spec.rb +0 -26
  144. data/spec/new_integration/settings_spec.rb +0 -115
  145. data/spec/new_integration/view/configuration_spec.rb +0 -49
  146. data/spec/support/fixtures/hanami-plugin/Gemfile +0 -8
  147. data/spec/support/fixtures/hanami-plugin/README.md +0 -35
  148. data/spec/support/fixtures/hanami-plugin/Rakefile +0 -4
  149. data/spec/support/fixtures/hanami-plugin/bin/console +0 -15
  150. data/spec/support/fixtures/hanami-plugin/bin/setup +0 -8
  151. data/spec/support/fixtures/hanami-plugin/hanami-plugin.gemspec +0 -28
  152. data/spec/support/fixtures/hanami-plugin/lib/hanami/plugin/cli.rb +0 -19
  153. data/spec/support/fixtures/hanami-plugin/lib/hanami/plugin/version.rb +0 -7
  154. data/spec/support/fixtures/hanami-plugin/lib/hanami/plugin.rb +0 -8
  155. data/spec/unit/hanami/routes_spec.rb +0 -25
  156. data/spec/unit/hanami/settings/dotenv_store_spec.rb +0 -119
@@ -1,247 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe "Sessions", type: :integration do
4
- it "shows welcome page" do
5
- with_project do
6
- server do
7
- visit "/"
8
-
9
- expect(page).to have_title("Hanami | The web, with simplicity")
10
-
11
- expect(page).to have_content("The web, with simplicity.")
12
- expect(page).to have_content("Hanami is Open Source Software for MVC web development with Ruby.")
13
- expect(page).to have_content("bundle exec hanami generate action web 'home#index' --url=/")
14
- end
15
- end
16
- end
17
-
18
- it "is empty by default" do
19
- with_project do
20
- prepare
21
-
22
- server do
23
- visit "/"
24
-
25
- expect(current_path).to eq("/")
26
- expect(page).to have_content("Sign in")
27
- end
28
- end
29
- end
30
-
31
- it "preserves data across requests" do
32
- with_project do
33
- prepare
34
-
35
- server do
36
- visit "/"
37
- expect(current_path).to eq("/")
38
-
39
- click_link("Sign in")
40
- expect(current_path).to eq("/signin")
41
-
42
- within "form#signin-form" do
43
- click_button "Sign in"
44
- end
45
-
46
- visit "/" # Without this, Capybara losts the session.
47
-
48
- expect(current_path).to eq("/")
49
- expect(page).to have_content("Welcome, Luca")
50
- end
51
- end
52
- end
53
-
54
- it "clears the session" do
55
- with_project do
56
- prepare
57
-
58
- server do
59
- given_signedin_user
60
-
61
- click_link "Sign out"
62
-
63
- expect(current_path).to eq("/")
64
- expect(page).to_not have_content("Welcome, Luca")
65
- end
66
- end
67
- end
68
-
69
- context "when sessions aren't enabled" do
70
- it "raises error when trying to use `session'" do
71
- with_project do
72
- generate "action web home#index --url=/"
73
-
74
- rewrite "apps/web/controllers/home/index.rb", <<~EOF
75
- module Web::Controllers::Home
76
- class Index
77
- include Web::Action
78
-
79
- def call(params)
80
- self.body = session[:foo]
81
- end
82
- end
83
- end
84
- EOF
85
- server do
86
- visit "/"
87
- expect(page).to have_content("To use `session', please enable sessions for the current app.")
88
- end
89
- end
90
- end
91
-
92
- it "raises error when trying to use `flash'" do
93
- with_project do
94
- generate "action web home#index --url=/"
95
-
96
- rewrite "apps/web/controllers/home/index.rb", <<~EOF
97
- module Web::Controllers::Home
98
- class Index
99
- include Web::Action
100
-
101
- def call(params)
102
- self.body = flash[:notice]
103
- end
104
- end
105
- end
106
- EOF
107
- server do
108
- visit "/"
109
- expect(page).to have_content("To use `flash', please enable sessions for the current app.")
110
- end
111
- end
112
- end
113
- end
114
-
115
- private
116
-
117
- def prepare
118
- # Enable sessions
119
- replace "apps/web/app.rb", "# sessions :cookie, secret: ENV['WEB_SESSIONS_SECRET']", "sessions :cookie, secret: ENV['WEB_SESSIONS_SECRET']"
120
-
121
- generate_user
122
- generate_actions
123
- end
124
-
125
- def generate_user # rubocop:disable Metrics/MethodLength
126
- generate_model "user"
127
- generate_migration "create_users", <<~EOF
128
- Hanami::Model.migration do
129
- change do
130
- create_table :users do
131
- primary_key :id
132
- column :name, String
133
- end
134
-
135
- execute "INSERT INTO users (name) VALUES('Luca')"
136
- end
137
- end
138
- EOF
139
-
140
- hanami "db prepare"
141
- end
142
-
143
- def generate_actions
144
- generate_home
145
- generate_signin
146
- generate_signout
147
- end
148
-
149
- def generate_home # rubocop:disable Metrics/MethodLength
150
- generate "action web home#index --url=/"
151
- replace "apps/web/config/routes.rb", "home#index", 'root to: "home#index"'
152
-
153
- rewrite "apps/web/controllers/home/index.rb", <<~EOF
154
- module Web::Controllers::Home
155
- class Index
156
- include Web::Action
157
- expose :current_user
158
-
159
- def call(params)
160
- @current_user = UserRepository.new.find(session[:user_id])
161
- end
162
- end
163
- end
164
- EOF
165
-
166
- rewrite "apps/web/templates/home/index.html.erb", <<~EOF
167
- <h1>Bookshelf</h1>
168
-
169
- <% if current_user.nil? %>
170
- <%= link_to "Sign in", "/signin" %>
171
- <% else %>
172
- Welcome, <%= current_user.name %>
173
- <%= link_to "Sign out", "/signout" %>
174
- <% end %>
175
- EOF
176
- end
177
-
178
- def generate_signin
179
- generate_signin_new_action
180
- generate_signin_create_action
181
- end
182
-
183
- def generate_signin_new_action
184
- generate "action web sessions#new --url=/signin --method=GET"
185
- rewrite "apps/web/templates/sessions/new.html.erb", <<~EOF
186
- <h1>Sign in</h1>
187
-
188
- <%=
189
- form_for :signin, "/signin", id: "signin-form" do
190
- div do
191
- button "Sign in"
192
- end
193
- end
194
- %>
195
- EOF
196
- end
197
-
198
- def generate_signin_create_action
199
- generate "action web sessions#create --url=/signin --method=POST"
200
- rewrite "apps/web/controllers/sessions/create.rb", <<~EOF
201
- module Web::Controllers::Sessions
202
- class Create
203
- include Web::Action
204
-
205
- def call(params)
206
- session[:user_id] = UserRepository.new.first.id
207
- redirect_to routes.root_url
208
- end
209
- end
210
- end
211
- EOF
212
- end
213
-
214
- def generate_signout
215
- generate "action web sessions#destroy --url=/signout --method=GET"
216
-
217
- rewrite "apps/web/controllers/sessions/destroy.rb", <<~EOF
218
- module Web::Controllers::Sessions
219
- class Destroy
220
- include Web::Action
221
-
222
- def call(params)
223
- session[:user_id] = nil
224
- redirect_to routes.root_url
225
- end
226
- end
227
- end
228
- EOF
229
- end
230
-
231
- def given_signedin_user # rubocop:disable Metrics/AbcSize
232
- visit "/"
233
- expect(current_path).to eq("/")
234
-
235
- click_link("Sign in")
236
- expect(current_path).to eq("/signin")
237
-
238
- within "form#signin-form" do
239
- click_button "Sign in"
240
- end
241
-
242
- visit "/" # Without this, Capybara losts the session.
243
-
244
- expect(current_path).to eq("/")
245
- expect(page).to have_content("Welcome, Luca")
246
- end
247
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe "Static middleware", type: :integration do
4
- it "serves a public file" do
5
- with_project do
6
- write "public/static.txt", "Static file"
7
-
8
- RSpec::Support::Env["HANAMI_ENV"] = "production"
9
- RSpec::Support::Env["DATABASE_URL"] = "sqlite://#{Pathname.new('db').join('bookshelf.sqlite')}"
10
- RSpec::Support::Env["SERVE_STATIC_ASSETS"] = "true"
11
- RSpec::Support::Env["SMTP_HOST"] = "localhost"
12
- RSpec::Support::Env["SMTP_PORT"] = "25"
13
-
14
- server do
15
- visit "/static.txt"
16
-
17
- expect(page.body).to include("Static file")
18
- end
19
- end
20
- end
21
- end
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe "Streaming", type: :integration do
4
- xit "streams the body" do
5
- with_project do
6
- generate "action web home#index --url=/"
7
-
8
- # Require Rack::Chunked
9
- unshift "apps/web/app.rb", "require 'rack/chunked'"
10
-
11
- # Mount middleware
12
- replace "apps/web/app.rb", "# middleware.use", "middleware.use ::Rack::Chunked"
13
- replace "apps/web/app.rb", "controller.prepare do", "controller.format text: 'text/plain'\ncontroller.prepare do"
14
-
15
- rewrite "apps/web/controllers/home/index.rb", <<~EOF
16
- module Web::Controllers::Home
17
- class Index
18
- include Web::Action
19
-
20
- def call(params)
21
- self.format = :text
22
- self.body = Enumerator.new do |y|
23
- %w(one two three).each { |s| y << s }
24
- end
25
- end
26
- end
27
- end
28
- EOF
29
-
30
- server do
31
- get "/", {}, "HTTP_VERSION" => "HTTP/1.1"
32
-
33
- expect(last_response.headers).to_not have_key("Content-Length")
34
- expect(last_response.headers["Transfer-Encoding"]).to eq("chunked")
35
-
36
- expect(last_response.status).to eq(200)
37
- expect(last_response.body).to eq("3\r\none\r\n3\r\ntwo\r\n5\r\nthree\r\n0\r\n\r\n")
38
- end
39
- end
40
- end
41
- end
@@ -1,52 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe "Unsafe send file", type: :integration do
4
- it "sends file from the public directory" do
5
- with_project do
6
- write "public/static.txt", "Static file"
7
- generate "action web home#index --url=/"
8
- rewrite "apps/web/controllers/home/index.rb", <<~EOF
9
- module Web::Controllers::Home
10
- class Index
11
- include Web::Action
12
-
13
- def call(params)
14
- unsafe_send_file "public/static.txt"
15
- end
16
- end
17
- end
18
- EOF
19
-
20
- server do
21
- get "/"
22
-
23
- expect(last_response.status).to eq(200)
24
- expect(last_response.body).to include("Static file")
25
- end
26
- end
27
- end
28
-
29
- it "sends file outside of the public directory" do
30
- with_project do
31
- generate "action web home#index --url=/"
32
- rewrite "apps/web/controllers/home/index.rb", <<~EOF
33
- module Web::Controllers::Home
34
- class Index
35
- include Web::Action
36
-
37
- def call(params)
38
- unsafe_send_file __FILE__
39
- end
40
- end
41
- end
42
- EOF
43
-
44
- server do
45
- get "/"
46
-
47
- expect(last_response.status).to eq(200)
48
- expect(last_response.body).to include("Web::Controllers::Home")
49
- end
50
- end
51
- end
52
- end
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe "App action / Configuration", :app_integration do
4
- before do
5
- module TestApp
6
- class App < Hanami::App
7
- config.actions.default_response_format = :json
8
- register_slice :main
9
- end
10
- end
11
-
12
- Hanami.app.prepare
13
-
14
- module TestApp
15
- class Action < Hanami::Action
16
- end
17
- end
18
- end
19
-
20
- let(:action_class) { TestApp::Action }
21
- subject(:configuration) { action_class.config }
22
-
23
- it "applies 'config.actions' configuration from the app" do
24
- expect(configuration.default_response_format).to eq :json
25
- end
26
- end
@@ -1,115 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "hanami/settings"
4
-
5
- RSpec.describe "App settings", :app_integration do
6
- before do
7
- @env = ENV.to_h
8
- end
9
-
10
- after do
11
- ENV.replace(@env)
12
- end
13
-
14
- specify "Settings defined in config/settings.rb are loaded from .env" do
15
- with_tmp_directory(Dir.mktmpdir) do
16
- write "config/app.rb", <<~RUBY
17
- require "hanami"
18
-
19
- module TestApp
20
- class App < Hanami::App
21
- end
22
- end
23
- RUBY
24
-
25
- write "config/settings.rb", <<~RUBY
26
- require "hanami/settings"
27
- require "test_app/types"
28
-
29
- module TestApp
30
- class Settings < Hanami::Settings
31
- setting :database_url
32
- setting :redis_url
33
- setting :feature_flag, constructor: TestApp::Types::Params::Bool
34
- setting :feature_flag_with_default, default: false, constructor: TestApp::Types::Params::Bool
35
- end
36
- end
37
- RUBY
38
-
39
- write ".env", <<~RUBY
40
- DATABASE_URL=postgres://localhost/test_app_development
41
- REDIS_URL=redis://localhost:6379
42
- FEATURE_FLAG=true
43
- RUBY
44
-
45
- write "lib/test_app/types.rb", <<~RUBY
46
- require "dry/types"
47
-
48
- module TestApp
49
- module Types
50
- include Dry.Types()
51
- end
52
- end
53
- RUBY
54
-
55
- require "hanami/prepare"
56
-
57
- expect(Hanami.app.settings.database_url).to eq "postgres://localhost/test_app_development"
58
- expect(Hanami.app.settings.redis_url).to eq "redis://localhost:6379"
59
- expect(Hanami.app.settings.feature_flag).to be true
60
- expect(Hanami.app.settings.feature_flag_with_default).to be false
61
-
62
- expect(Hanami.app[:settings]).to eql Hanami.app.settings
63
- end
64
- end
65
-
66
- specify "Errors raised from setting constructors are collected" do
67
- with_tmp_directory(Dir.mktmpdir) do
68
- write "config/app.rb", <<~RUBY
69
- require "hanami"
70
-
71
- module TestApp
72
- class App < Hanami::App
73
- end
74
- end
75
- RUBY
76
-
77
- write "config/settings.rb", <<~RUBY
78
- require "hanami/settings"
79
- require "test_app/types"
80
-
81
- module TestApp
82
- class Settings < Hanami::Settings
83
- setting :numeric_setting, constructor: TestApp::Types::Params::Integer
84
- setting :feature_flag, constructor: TestApp::Types::Params::Bool
85
- end
86
- end
87
- RUBY
88
-
89
- write ".env", <<~RUBY
90
- NUMERIC_SETTING=hello
91
- FEATURE_FLAG=maybe
92
- RUBY
93
-
94
- write "lib/test_app/types.rb", <<~RUBY
95
- require "dry/types"
96
-
97
- module TestApp
98
- module Types
99
- include Dry.Types()
100
- end
101
- end
102
- RUBY
103
-
104
- numeric_setting_error = "numeric_setting: invalid value for Integer"
105
- feature_flag_error = "feature_flag: maybe cannot be coerced"
106
-
107
- expect {
108
- require "hanami/prepare"
109
- }.to raise_error(
110
- Hanami::Settings::InvalidSettingsError,
111
- /#{numeric_setting_error}.+#{feature_flag_error}|#{feature_flag_error}.+#{numeric_setting_error}/m
112
- )
113
- end
114
- end
115
- end
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "hanami"
4
-
5
- RSpec.describe "App view / Configuration", :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(:config) { view_class.config }
26
-
27
- it "applies default view configuration from the app" do
28
- aggregate_failures do
29
- expect(config.layouts_dir).to eq "layouts"
30
- expect(config.layout).to eq "app"
31
- end
32
- end
33
-
34
- context "custom views configuration on app" do
35
- let(:app_hook) {
36
- proc do
37
- config.views.layouts_dir = "custom_layouts"
38
- config.views.layout = "my_layout"
39
- end
40
- }
41
-
42
- it "applies the custom configuration" do
43
- aggregate_failures do
44
- expect(config.layouts_dir).to eq "custom_layouts"
45
- expect(config.layout).to eq "my_layout"
46
- end
47
- end
48
- end
49
- end
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
-
7
- # Specify your gem's dependencies in hanami-plugin.gemspec
8
- gemspec
@@ -1,35 +0,0 @@
1
- # Hanami::Plugin
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/hanami/plugin`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'hanami-plugin'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install hanami-plugin
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/jodosha/hanami-plugin.
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- task default: :spec
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require "bundler/setup"
5
- require "hanami/plugin"
6
-
7
- # You can add fixtures and/or initialization code here to make experimenting
8
- # with your gem easier. You can also use a different console, if you like.
9
-
10
- # (If you use this, don't forget to add pry to your Gemfile!)
11
- # require "pry"
12
- # Pry.start
13
-
14
- require "irb"
15
- IRB.start(__FILE__)
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- lib = File.expand_path("../lib", __FILE__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require "hanami/plugin/version"
6
-
7
- Gem::Specification.new do |spec|
8
- spec.name = "hanami-plugin"
9
- spec.version = Hanami::Plugin::VERSION
10
- spec.authors = ["Luca Guidi"]
11
- spec.email = ["me@lucaguidi.com"]
12
-
13
- spec.summary = "Hanami Plugin"
14
- spec.description = "Extend Hanami with super powers"
15
- spec.homepage = "http://hanamirb.org"
16
-
17
- spec.metadata["allowed_push_host"] = "http://fakegemserver.hanamirb.org"
18
-
19
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
- f.match(%r{^(test|spec|features)/})
21
- end
22
- spec.bindir = "exe"
23
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
- spec.require_paths = ["lib"]
25
-
26
- spec.add_development_dependency "bundler", "~> 1.15"
27
- spec.add_development_dependency "rake", "~> 10.0"
28
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "hanami/cli/commands"
4
-
5
- module Hanami
6
- module Plugin
7
- module CLI
8
- class Version < Hanami::CLI::Command
9
- desc "Print Hanami plugin version"
10
-
11
- def call(*)
12
- puts "v#{Hanami::Plugin::VERSION}"
13
- end
14
- end
15
- end
16
- end
17
- end
18
-
19
- Hanami::CLI.register "plugin version", Hanami::Plugin::CLI::Version
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Hanami
4
- module Plugin
5
- VERSION = "0.1.0"
6
- end
7
- end