Skip to content

Commit fc75775

Browse files
authored
Add dummy Hanami application for integration testing. (#7)
* Add dummy test app. * Remove unsupported ruby versions from Travis.
1 parent 0cfc050 commit fc75775

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+561
-4
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@ Gemfile.lock
3232

3333
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
3434
.rvmrc
35+
36+
## Dummy application
37+
spec/dummy/db/*.sqlite
38+
spec/dummy/tmp

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ language: ruby
22
sudo: false
33
before_install:
44
- bundle update
5+
before_script:
6+
- '$(cd spec/dummy HANAMI_ENV=test bundle exec hanami db create)'
7+
- '$(cd spec/dummy HANAMI_ENV=test bundle exec hanami db migrate)'
58
rvm:
6-
- 2.1
7-
- 2.2
89
- 2.3.0
910
- ruby-head
1011
matrix:

jsonapi-hanami.gemspec

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ Gem::Specification.new do |spec|
1616

1717
spec.add_dependency 'jsonapi-rb', '~> 0.1.1'
1818

19-
spec.add_development_dependency 'rake', '~> 11.3'
20-
spec.add_development_dependency 'rspec', '~> 3.5'
19+
spec.add_development_dependency 'rake', '~> 11.3'
20+
spec.add_development_dependency 'rspec', '~> 3.5'
21+
spec.add_development_dependency 'hanami', '~> 1.0'
22+
spec.add_development_dependency 'hanami-model', '~> 1.0'
23+
spec.add_development_dependency 'sqlite3'
24+
spec.add_development_dependency 'dotenv'
2125
end

spec/dummy/.env.development

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Define ENV variables for development environment
2+
DATABASE_URL="sqlite://db/dummy_development.sqlite"
3+
SERVE_STATIC_ASSETS="true"
4+
API_SESSIONS_SECRET="33f5c30be87c43665bc7907f62cfd1096541056cf23e001aa95454b966b27439"

spec/dummy/.env.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Define ENV variables for test environment
2+
DATABASE_URL="sqlite://db/dummy_test.sqlite"
3+
SERVE_STATIC_ASSETS="true"
4+
API_SESSIONS_SECRET="89e71edc5f4fab26e6f7bc3d2097e7039e40ffdfadef7234a90f10e0718307a1"

spec/dummy/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/db/*.sqlite
2+
/public/assets*
3+
/tmp

spec/dummy/.hanamirc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
project=dummy
2+
architecture=container
3+
test=minitest
4+
template=erb

spec/dummy/apps/api/application.rb

Lines changed: 330 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,330 @@
1+
require 'hanami/helpers'
2+
require 'hanami/assets'
3+
4+
module Api
5+
class Application < Hanami::Application
6+
configure do
7+
##
8+
# BASIC
9+
#
10+
11+
# Define the root path of this application.
12+
# All paths specified in this configuration are relative to path below.
13+
#
14+
root __dir__
15+
16+
# Relative load paths where this application will recursively load the
17+
# code.
18+
#
19+
# When you add new directories, remember to add them here.
20+
#
21+
load_paths << [
22+
'controllers',
23+
'views',
24+
'resources'
25+
]
26+
27+
# Handle exceptions with HTTP statuses (true) or don't catch them (false).
28+
# Defaults to true.
29+
# See: http://www.rubydoc.info/gems/hanami-controller/#Exceptions_management
30+
#
31+
# handle_exceptions true
32+
33+
##
34+
# HTTP
35+
#
36+
37+
# Routes definitions for this application
38+
# See: http://www.rubydoc.info/gems/hanami-router#Usage
39+
#
40+
routes 'config/routes'
41+
42+
# URI scheme used by the routing system to generate absolute URLs
43+
# Defaults to "http"
44+
#
45+
# scheme 'https'
46+
47+
# URI host used by the routing system to generate absolute URLs
48+
# Defaults to "localhost"
49+
#
50+
# host 'example.org'
51+
52+
# URI port used by the routing system to generate absolute URLs
53+
# Argument: An object coercible to integer, defaults to 80 if the scheme
54+
# is http and 443 if it's https
55+
#
56+
# This should only be configured if app listens to non-standard ports
57+
#
58+
# port 443
59+
60+
# Enable cookies
61+
# Argument: boolean to toggle the feature
62+
# A Hash with options
63+
#
64+
# Options:
65+
# :domain - The domain (String - nil by default, not required)
66+
# :path - Restrict cookies to a relative URI
67+
# (String - nil by default)
68+
# :max_age - Cookies expiration expressed in seconds
69+
# (Integer - nil by default)
70+
# :secure - Restrict cookies to secure connections
71+
# (Boolean - Automatically true when using HTTPS)
72+
# See #scheme and #ssl?
73+
# :httponly - Prevent JavaScript access (Boolean - true by default)
74+
#
75+
# cookies true
76+
# or
77+
# cookies max_age: 300
78+
79+
# Enable sessions
80+
# Argument: Symbol the Rack session adapter
81+
# A Hash with options
82+
#
83+
# See: http://www.rubydoc.info/gems/rack/Rack/Session/Cookie
84+
#
85+
# sessions :cookie, secret: ENV['API_SESSIONS_SECRET']
86+
87+
# Configure Rack middleware for this application
88+
#
89+
# middleware.use Rack::Protection
90+
91+
# Default format for the requests that don't specify an HTTP_ACCEPT header
92+
# Argument: A symbol representation of a mime type, defaults to :html
93+
#
94+
# default_request_format :html
95+
96+
# Default format for responses that don't consider the request format
97+
# Argument: A symbol representation of a mime type, defaults to :html
98+
#
99+
# default_response_format :html
100+
101+
# HTTP Body parsers
102+
# Parse non GET responses body for a specific mime type
103+
# Argument: Symbol, which represent the format of the mime type
104+
# (only `:json` is supported)
105+
# Object, the parser
106+
#
107+
body_parsers :json
108+
109+
# When it's true and the router receives a non-encrypted request (http),
110+
# it redirects to the secure equivalent (https). Disabled by default.
111+
#
112+
# force_ssl true
113+
114+
##
115+
# TEMPLATES
116+
#
117+
118+
# The layout to be used by all views
119+
#
120+
layout :application # It will load Api::Views::ApplicationLayout
121+
122+
# The relative path to templates
123+
#
124+
templates 'templates'
125+
126+
##
127+
# ASSETS
128+
#
129+
assets do
130+
# JavaScript compressor
131+
#
132+
# Supported engines:
133+
#
134+
# * :builtin
135+
# * :uglifier
136+
# * :yui
137+
# * :closure
138+
#
139+
# See: http://hanamirb.org/guides/assets/compressors
140+
#
141+
# In order to skip JavaScript compression comment the following line
142+
javascript_compressor :builtin
143+
144+
# Stylesheet compressor
145+
#
146+
# Supported engines:
147+
#
148+
# * :builtin
149+
# * :yui
150+
# * :sass
151+
#
152+
# See: http://hanamirb.org/guides/assets/compressors
153+
#
154+
# In order to skip stylesheet compression comment the following line
155+
stylesheet_compressor :builtin
156+
157+
# Specify sources for assets
158+
#
159+
sources << [
160+
'assets'
161+
]
162+
end
163+
164+
##
165+
# SECURITY
166+
#
167+
168+
# X-Frame-Options is a HTTP header supported by modern browsers.
169+
# It determines if a web page can or cannot be included via <frame> and
170+
# <iframe> tags by untrusted domains.
171+
#
172+
# Web applications can send this header to prevent Clickjacking attacks.
173+
#
174+
# Read more at:
175+
#
176+
# * https://developer.mozilla.org/en-US/docs/Web/HTTP/X-Frame-Options
177+
# * https://www.owasp.org/index.php/Clickjacking
178+
#
179+
security.x_frame_options 'DENY'
180+
181+
# X-Content-Type-Options prevents browsers from interpreting files as
182+
# something else than declared by the content type in the HTTP headers.
183+
#
184+
# Read more at:
185+
#
186+
# * https://www.owasp.org/index.php/OWASP_Secure_Headers_Project#X-Content-Type-Options
187+
# * https://msdn.microsoft.com/en-us/library/gg622941%28v=vs.85%29.aspx
188+
# * https://blogs.msdn.microsoft.com/ie/2008/09/02/ie8-security-part-vi-beta-2-update
189+
#
190+
security.x_content_type_options 'nosniff'
191+
192+
# X-XSS-Protection is a HTTP header to determine the behavior of the
193+
# browser in case an XSS attack is detected.
194+
#
195+
# Read more at:
196+
#
197+
# * https://www.owasp.org/index.php/Cross-site_Scripting_(XSS)
198+
# * https://www.owasp.org/index.php/OWASP_Secure_Headers_Project#X-XSS-Protection
199+
#
200+
security.x_xss_protection '1; mode=block'
201+
202+
# Content-Security-Policy (CSP) is a HTTP header supported by modern
203+
# browsers. It determines trusted sources of execution for dynamic
204+
# contents (JavaScript) or other web related assets: stylesheets, images,
205+
# fonts, plugins, etc.
206+
#
207+
# Web applications can send this header to mitigate Cross Site Scripting
208+
# (XSS) attacks.
209+
#
210+
# The default value allows images, scripts, AJAX, fonts and CSS from the
211+
# same origin, and does not allow any other resources to load (eg object,
212+
# frame, media, etc).
213+
#
214+
# Inline JavaScript is NOT allowed. To enable it, please use:
215+
# "script-src 'unsafe-inline'".
216+
#
217+
# Content Security Policy introduction:
218+
#
219+
# * http://www.html5rocks.com/en/tutorials/security/content-security-policy/
220+
# * https://www.owasp.org/index.php/Content_Security_Policy
221+
# * https://www.owasp.org/index.php/Cross-site_Scripting_%28XSS%29
222+
#
223+
# Inline and eval JavaScript risks:
224+
#
225+
# * http://www.html5rocks.com/en/tutorials/security/content-security-policy/#inline-code-considered-harmful
226+
# * http://www.html5rocks.com/en/tutorials/security/content-security-policy/#eval-too
227+
#
228+
# Content Security Policy usage:
229+
#
230+
# * http://content-security-policy.com/
231+
# * https://developer.mozilla.org/en-US/docs/Web/Security/CSP/Using_Content_Security_Policy
232+
#
233+
# Content Security Policy references:
234+
#
235+
# * https://developer.mozilla.org/en-US/docs/Web/Security/CSP/CSP_policy_directives
236+
#
237+
security.content_security_policy %{
238+
form-action 'self';
239+
frame-ancestors 'self';
240+
base-uri 'self';
241+
default-src 'none';
242+
script-src 'self';
243+
connect-src 'self';
244+
img-src 'self' https: data:;
245+
style-src 'self' 'unsafe-inline' https:;
246+
font-src 'self';
247+
object-src 'none';
248+
plugin-types application/pdf;
249+
child-src 'self';
250+
frame-src 'self';
251+
media-src 'self'
252+
}
253+
254+
##
255+
# FRAMEWORKS
256+
#
257+
258+
# Configure the code that will yield each time Api::Action is included
259+
# This is useful for sharing common functionality
260+
#
261+
# See: http://www.rubydoc.info/gems/hanami-controller#Configuration
262+
controller.prepare do
263+
# include MyAuthentication # included in all the actions
264+
# before :authenticate! # run an authentication before callback
265+
end
266+
267+
# Register the JSON API MIME type.
268+
controller.format jsonapi: 'application/vnd.api+json'
269+
270+
# Configure the code that will yield each time Api::View is included
271+
# This is useful for sharing common functionality
272+
#
273+
# See: http://www.rubydoc.info/gems/hanami-view#Configuration
274+
view.prepare do
275+
include Hanami::Helpers
276+
include Api::Assets::Helpers
277+
end
278+
end
279+
280+
##
281+
# DEVELOPMENT
282+
#
283+
configure :development do
284+
# Don't handle exceptions, render the stack trace
285+
handle_exceptions false
286+
end
287+
288+
##
289+
# TEST
290+
#
291+
configure :test do
292+
# Don't handle exceptions, render the stack trace
293+
handle_exceptions false
294+
end
295+
296+
##
297+
# PRODUCTION
298+
#
299+
configure :production do
300+
# scheme 'https'
301+
# host 'example.org'
302+
# port 443
303+
304+
assets do
305+
# Don't compile static assets in production mode (eg. Sass, ES6)
306+
#
307+
# See: http://www.rubydoc.info/gems/hanami-assets#Configuration
308+
compile false
309+
310+
# Use fingerprint file name for asset paths
311+
#
312+
# See: http://hanamirb.org/guides/assets/overview
313+
fingerprint true
314+
315+
# Content Delivery Network (CDN)
316+
#
317+
# See: http://hanamirb.org/guides/assets/content-delivery-network
318+
#
319+
# scheme 'https'
320+
# host 'cdn.example.org'
321+
# port 443
322+
323+
# Subresource Integrity
324+
#
325+
# See: http://hanamirb.org/guides/assets/content-delivery-network/#subresource-integrity
326+
subresource_integrity :sha256
327+
end
328+
end
329+
end
330+
end
14.7 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#

0 commit comments

Comments
 (0)