utopia 1.9.11 → 2.0.0
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/.codeclimate.yml +3 -2
- data/.gitignore +4 -1
- data/.rspec +1 -0
- data/.travis.yml +4 -0
- data/.yardopts +2 -0
- data/Gemfile +8 -1
- data/README.md +2 -2
- data/Rakefile +10 -10
- data/benchmarks/call_vs_check.rb +36 -0
- data/benchmarks/const_vs_hash.rb +33 -0
- data/documentation/Gemfile +5 -0
- data/documentation/Guardfile +20 -0
- data/documentation/config.ru +6 -13
- data/documentation/config/puma.rb +20 -0
- data/documentation/pages/_editor.xnode +64 -0
- data/documentation/pages/_heading.xnode +2 -2
- data/documentation/pages/_page.xnode +1 -2
- data/documentation/pages/errors/exception.xnode +3 -3
- data/documentation/pages/errors/file-not-found.xnode +3 -3
- data/documentation/pages/wiki/bower-integration/content.md +1 -1
- data/documentation/pages/wiki/content.md +6 -8
- data/documentation/pages/wiki/controller.rb +3 -3
- data/documentation/pages/wiki/edit.xnode +7 -19
- data/documentation/pages/wiki/middleware/content/content.md +4 -10
- data/documentation/pages/wiki/{controller → middleware/controller}/actions/content.md +0 -0
- data/documentation/pages/wiki/{controller → middleware/controller}/links.yaml +0 -0
- data/documentation/pages/wiki/{controller → middleware/controller}/rewrite/content.md +3 -3
- data/documentation/pages/wiki/show.xnode +4 -6
- data/documentation/pages/wiki/updating-utopia/content.md +55 -0
- data/documentation/pages/wiki/your-first-page/content.md +5 -3
- data/documentation/public/materials +1 -0
- data/lib/utopia.rb +3 -4
- data/lib/utopia/command.rb +4 -284
- data/lib/utopia/command/server.rb +115 -0
- data/lib/utopia/command/setup.rb +78 -0
- data/lib/utopia/command/site.rb +183 -0
- data/lib/utopia/content.rb +83 -59
- data/lib/utopia/content/{transaction.rb → document.rb} +116 -110
- data/lib/utopia/content/link.rb +7 -2
- data/lib/utopia/content/links.rb +2 -1
- data/lib/utopia/content/markup.rb +7 -2
- data/lib/utopia/{tags/deferred.rb → content/namespace.rb} +25 -6
- data/lib/utopia/content/node.rb +74 -76
- data/lib/utopia/content/response.rb +22 -3
- data/lib/utopia/content/tags.rb +66 -0
- data/lib/utopia/controller.rb +10 -18
- data/lib/utopia/controller/actions.rb +10 -0
- data/lib/utopia/controller/base.rb +2 -1
- data/lib/utopia/controller/respond.rb +1 -1
- data/lib/utopia/controller/rewrite.rb +8 -4
- data/lib/utopia/exceptions.rb +1 -0
- data/lib/utopia/exceptions/handler.rb +7 -2
- data/lib/utopia/exceptions/mailer.rb +33 -12
- data/lib/utopia/{tags/node.rb → extensions/array_split.rb} +11 -9
- data/lib/utopia/{tags/environment.rb → extensions/date_comparisons.rb} +24 -14
- data/lib/utopia/http.rb +2 -0
- data/lib/utopia/locale.rb +1 -0
- data/lib/utopia/localization.rb +37 -28
- data/lib/utopia/logger.rb +1 -0
- data/lib/utopia/logger/compact_formatter.rb +1 -0
- data/lib/utopia/middleware.rb +11 -1
- data/lib/utopia/path.rb +1 -0
- data/lib/utopia/path/matcher.rb +14 -2
- data/lib/utopia/redirection.rb +13 -16
- data/lib/utopia/session.rb +14 -6
- data/lib/utopia/setup.rb +3 -1
- data/lib/utopia/static.rb +11 -12
- data/lib/utopia/version.rb +1 -1
- data/setup/server/git/hooks/post-receive +0 -4
- data/setup/site/.gitignore +9 -0
- data/setup/site/.rspec +1 -0
- data/setup/site/Gemfile +4 -0
- data/setup/site/Guardfile +17 -0
- data/setup/site/Rakefile +2 -2
- data/setup/site/config.ru +5 -12
- data/setup/site/pages/_heading.xnode +2 -2
- data/setup/site/pages/_page.xnode +1 -1
- data/setup/site/pages/errors/exception.xnode +3 -3
- data/setup/site/pages/errors/file-not-found.xnode +3 -3
- data/setup/site/pages/welcome/index.xnode +3 -3
- data/setup/site/public/_static/site.css +4 -0
- data/setup/site/spec/spec_helper.rb +29 -0
- data/setup/site/tasks/deploy.rake +13 -0
- data/setup/site/tasks/development.rake +34 -0
- data/setup/site/tasks/environment.rake +17 -0
- data/spec/mock_node.rb +15 -0
- data/spec/spec_helper.rb +29 -0
- data/{lib/utopia/extensions/date.rb → spec/utopia/content/document_spec.rb} +31 -21
- data/spec/utopia/content/markup_spec.rb +2 -2
- data/spec/utopia/content/{tag_spec.rb → namespace_spec.rb} +17 -10
- data/spec/utopia/content/tags_spec.rb +80 -0
- data/spec/utopia/content_spec.rb +1 -1
- data/spec/utopia/content_spec.ru +1 -6
- data/spec/utopia/content_spec/_heading.xnode +1 -1
- data/spec/utopia/content_spec/content/test-partial.xnode +1 -1
- data/spec/utopia/content_spec/index.xnode +1 -1
- data/spec/utopia/controller/middleware_spec.ru +1 -3
- data/spec/utopia/controller/respond_spec.rb +2 -22
- data/spec/utopia/controller/respond_spec.ru +1 -5
- data/spec/utopia/controller/respond_spec/errors/file-not-found.xnode +7 -6
- data/spec/utopia/exceptions/handler_spec.ru +1 -2
- data/spec/utopia/exceptions/mailer_spec.ru +1 -2
- data/spec/utopia/extensions_spec.rb +2 -2
- data/spec/utopia/localization_spec.ru +1 -2
- data/spec/utopia/performance_spec.rb +2 -6
- data/spec/utopia/performance_spec/config.ru +5 -12
- data/spec/utopia/performance_spec/pages/_heading.xnode +2 -2
- data/spec/utopia/performance_spec/pages/_page.xnode +1 -1
- data/spec/utopia/performance_spec/pages/errors/exception.xnode +3 -3
- data/spec/utopia/performance_spec/pages/errors/file-not-found.xnode +3 -3
- data/spec/utopia/performance_spec/pages/welcome/index.xnode +3 -3
- data/spec/utopia/setup_spec.rb +79 -15
- data/utopia.gemspec +3 -3
- metadata +41 -27
- data/.simplecov +0 -9
- data/documentation/pages/welcome/index.xnode +0 -41
- data/lib/utopia/content/tag.rb +0 -90
- data/lib/utopia/extensions/array.rb +0 -29
- data/lib/utopia/tags/override.rb +0 -33
- data/setup/site/.simplecov +0 -9
- data/setup/site/tasks/test.rake +0 -10
- data/setup/site/tasks/utopia.rake +0 -41
- data/spec/utopia/controller/respond_spec/rewrite/controller.rb +0 -12
data/lib/utopia/redirection.rb
CHANGED
|
@@ -23,6 +23,7 @@ require_relative 'middleware'
|
|
|
23
23
|
module Utopia
|
|
24
24
|
# A middleware which assists with redirecting from one path to another.
|
|
25
25
|
module Redirection
|
|
26
|
+
# An error handler fails to redirect to a valid page.
|
|
26
27
|
class RequestFailure < StandardError
|
|
27
28
|
def initialize(resource_path, resource_status, error_path, error_status)
|
|
28
29
|
@resource_path = resource_path
|
|
@@ -35,30 +36,26 @@ module Utopia
|
|
|
35
36
|
end
|
|
36
37
|
end
|
|
37
38
|
|
|
39
|
+
# A middleware which performs internal redirects based on error status codes.
|
|
38
40
|
class Errors
|
|
39
|
-
#
|
|
41
|
+
# @param codes [Hash<Integer,String>] The redirection path for a given error code.
|
|
40
42
|
def initialize(app, codes = {})
|
|
41
|
-
@codes = codes
|
|
42
|
-
|
|
43
43
|
@app = app
|
|
44
|
+
@codes = codes
|
|
44
45
|
end
|
|
45
46
|
|
|
46
47
|
def freeze
|
|
48
|
+
return self if frozen?
|
|
49
|
+
|
|
47
50
|
@codes.freeze
|
|
48
51
|
|
|
49
52
|
super
|
|
50
53
|
end
|
|
51
54
|
|
|
52
|
-
CONTENT_TYPE = 'Content-Type'.freeze
|
|
53
|
-
|
|
54
|
-
def unhandled_error?(response)
|
|
55
|
-
response[0] >= 400 && !response[1].include?(CONTENT_TYPE)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
55
|
def call(env)
|
|
59
56
|
response = @app.call(env)
|
|
60
57
|
|
|
61
|
-
if
|
|
58
|
+
if response[0] >= 400 and location = @codes[response[0]]
|
|
62
59
|
error_request = env.merge(Rack::PATH_INFO => location, Rack::REQUEST_METHOD => Rack::GET)
|
|
63
60
|
error_response = @app.call(error_request)
|
|
64
61
|
|
|
@@ -75,15 +72,10 @@ module Utopia
|
|
|
75
72
|
end
|
|
76
73
|
end
|
|
77
74
|
|
|
78
|
-
class FileNotFound < Errors
|
|
79
|
-
def initialize(uri = '/errors/file-not-found')
|
|
80
|
-
super(404 => uri)
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
|
|
84
75
|
# We cache 301 redirects for 24 hours.
|
|
85
76
|
DEFAULT_MAX_AGE = 3600*24
|
|
86
77
|
|
|
78
|
+
# A basic client-side redirect.
|
|
87
79
|
class ClientRedirect
|
|
88
80
|
def initialize(app, status: 307, max_age: DEFAULT_MAX_AGE)
|
|
89
81
|
@app = app
|
|
@@ -92,6 +84,8 @@ module Utopia
|
|
|
92
84
|
end
|
|
93
85
|
|
|
94
86
|
def freeze
|
|
87
|
+
return self if frozen?
|
|
88
|
+
|
|
95
89
|
@status.freeze
|
|
96
90
|
@max_age.freeze
|
|
97
91
|
|
|
@@ -129,6 +123,7 @@ module Utopia
|
|
|
129
123
|
end
|
|
130
124
|
end
|
|
131
125
|
|
|
126
|
+
# Redirect urls that end with a `/`, e.g. directories.
|
|
132
127
|
class DirectoryIndex < ClientRedirect
|
|
133
128
|
def initialize(app, index: 'index')
|
|
134
129
|
@app = app
|
|
@@ -144,6 +139,7 @@ module Utopia
|
|
|
144
139
|
end
|
|
145
140
|
end
|
|
146
141
|
|
|
142
|
+
# Rewrite requests that match the given pattern to a single destination.
|
|
147
143
|
class Rewrite < ClientRedirect
|
|
148
144
|
def initialize(app, patterns, status: 301)
|
|
149
145
|
@patterns = patterns
|
|
@@ -158,6 +154,7 @@ module Utopia
|
|
|
158
154
|
end
|
|
159
155
|
end
|
|
160
156
|
|
|
157
|
+
# Rewrite requests that match the given pattern to a new prefix.
|
|
161
158
|
class Moved < ClientRedirect
|
|
162
159
|
def initialize(app, pattern, prefix, status: 301, flatten: false)
|
|
163
160
|
@app = app
|
data/lib/utopia/session.rb
CHANGED
|
@@ -25,8 +25,10 @@ require 'digest/sha2'
|
|
|
25
25
|
require_relative 'session/lazy_hash'
|
|
26
26
|
|
|
27
27
|
module Utopia
|
|
28
|
-
#
|
|
28
|
+
# A middleware which provides a secure client-side session storage using a private symmetric encrpytion key.
|
|
29
29
|
class Session
|
|
30
|
+
SECRET_KEY = 'UTOPIA_SESSION_SECRET'.freeze
|
|
31
|
+
|
|
30
32
|
RACK_SESSION = "rack.session".freeze
|
|
31
33
|
CIPHER_ALGORITHM = "aes-256-cbc"
|
|
32
34
|
|
|
@@ -36,22 +38,26 @@ module Utopia
|
|
|
36
38
|
# At least, the session will be updated every 1 hour:
|
|
37
39
|
DEFAULT_UPDATE_TIMEOUT = 3600
|
|
38
40
|
|
|
39
|
-
|
|
41
|
+
# @param session_name [String] The name of the session cookie.
|
|
42
|
+
# @param secret [Array] The secret text used to generate a symetric encryption key for the coookie data.
|
|
43
|
+
# @param expires_after [String] The cache-control header to set for static content.
|
|
44
|
+
# @param options [Hash<Symbol,Object>] Additional defaults used for generating the cookie by `Rack::Utils.set_cookie_header!`.
|
|
45
|
+
def initialize(app, session_name: RACK_SESSION, secret: nil, expires_after: DEFAULT_EXPIRES_AFTER, update_timeout: DEFAULT_UPDATE_TIMEOUT, **options)
|
|
40
46
|
@app = app
|
|
41
47
|
|
|
42
|
-
@session_name = session_name
|
|
48
|
+
@session_name = session_name
|
|
43
49
|
@cookie_name = @session_name + ".encrypted"
|
|
44
50
|
|
|
45
51
|
if secret.nil? or secret.empty?
|
|
46
52
|
secret = SecureRandom.hex(32)
|
|
47
|
-
warn "#{self.class} secret is #{secret.inspect}, generating transient secret key!"
|
|
53
|
+
warn "#{self.class} secret is #{secret.inspect}, generating transient secret key!" if $VERBOSE
|
|
48
54
|
end
|
|
49
55
|
|
|
50
56
|
# This generates a 32-byte key suitable for aes.
|
|
51
57
|
@key = Digest::SHA2.digest(secret)
|
|
52
58
|
|
|
53
|
-
@expires_after = expires_after
|
|
54
|
-
@update_timeout = update_timeout
|
|
59
|
+
@expires_after = expires_after
|
|
60
|
+
@update_timeout = update_timeout
|
|
55
61
|
|
|
56
62
|
@cookie_defaults = {
|
|
57
63
|
domain: nil,
|
|
@@ -72,6 +78,8 @@ module Utopia
|
|
|
72
78
|
attr :cookie_defaults
|
|
73
79
|
|
|
74
80
|
def freeze
|
|
81
|
+
return self if frozen?
|
|
82
|
+
|
|
75
83
|
@cookie_name.freeze
|
|
76
84
|
@key.freeze
|
|
77
85
|
@expires_after.freeze
|
data/lib/utopia/setup.rb
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
# THE SOFTWARE.
|
|
20
20
|
|
|
21
21
|
module Utopia
|
|
22
|
+
# Used for setting up a Utopia web application, typically via `config/environment.rb`
|
|
22
23
|
class Bootstrap
|
|
23
24
|
def initialize(config_root, external_encoding: Encoding::UTF_8)
|
|
24
25
|
@config_root = config_root
|
|
@@ -44,7 +45,7 @@ module Utopia
|
|
|
44
45
|
def setup_encoding
|
|
45
46
|
# TODO: Deprecate and remove this setup - it should be the responsibility of the server to set this correctly.
|
|
46
47
|
if @external_encoding and Encoding.default_external != @external_encoding
|
|
47
|
-
warn "Updating Encoding.default_external from #{Encoding.default_external} to #{@external_encoding}"
|
|
48
|
+
warn "Updating Encoding.default_external from #{Encoding.default_external} to #{@external_encoding}" if $VERBOSE
|
|
48
49
|
Encoding.default_external = @external_encoding
|
|
49
50
|
end
|
|
50
51
|
end
|
|
@@ -69,6 +70,7 @@ module Utopia
|
|
|
69
70
|
end
|
|
70
71
|
end
|
|
71
72
|
|
|
73
|
+
# The main entry point for `config/environment.rb` for setting up the site.
|
|
72
74
|
def self.setup(config_root = nil, **options)
|
|
73
75
|
# We extract the directory of the caller to get the path to $root/config
|
|
74
76
|
if config_root.nil?
|
data/lib/utopia/static.rb
CHANGED
|
@@ -27,7 +27,7 @@ require 'digest/sha1'
|
|
|
27
27
|
require 'mime/types'
|
|
28
28
|
|
|
29
29
|
module Utopia
|
|
30
|
-
#
|
|
30
|
+
# A middleware which serves static files from the specified root directory.
|
|
31
31
|
class Static
|
|
32
32
|
# Default mime-types which are common for files served over HTTP:
|
|
33
33
|
MIME_TYPES = {
|
|
@@ -219,22 +219,21 @@ module Utopia
|
|
|
219
219
|
|
|
220
220
|
DEFAULT_CACHE_CONTROL = 'public, max-age=3600'.freeze
|
|
221
221
|
|
|
222
|
-
#
|
|
223
|
-
# @
|
|
224
|
-
# @
|
|
225
|
-
|
|
226
|
-
def initialize(app, **options)
|
|
222
|
+
# @param root [String] The root directory to serve files from.
|
|
223
|
+
# @param types [Array] The mime-types (and file extensions) to recognize/serve.
|
|
224
|
+
# @param cache_control [String] The cache-control header to set for static content.
|
|
225
|
+
def initialize(app, root: Utopia::default_root, types: MIME_TYPES[:default], cache_control: DEFAULT_CACHE_CONTROL)
|
|
227
226
|
@app = app
|
|
228
|
-
@root =
|
|
229
|
-
|
|
230
|
-
@extensions = MimeTypeLoader.extensions_for(options[:types] || MIME_TYPES[:default])
|
|
231
|
-
|
|
232
|
-
@cache_control = (options[:cache_control] || DEFAULT_CACHE_CONTROL)
|
|
227
|
+
@root = root
|
|
233
228
|
|
|
234
|
-
|
|
229
|
+
@extensions = MimeTypeLoader.extensions_for(types)
|
|
230
|
+
|
|
231
|
+
@cache_control = cache_control
|
|
235
232
|
end
|
|
236
233
|
|
|
237
234
|
def freeze
|
|
235
|
+
return self if frozen?
|
|
236
|
+
|
|
238
237
|
@root.freeze
|
|
239
238
|
@extensions.freeze
|
|
240
239
|
@cache_control.freeze
|
data/lib/utopia/version.rb
CHANGED
|
@@ -59,10 +59,6 @@ end
|
|
|
59
59
|
|
|
60
60
|
puts "Deploying to #{GIT_WORK_TREE} as #{DEPLOY_USER}:#{DEPLOY_GROUP}..."
|
|
61
61
|
Dir.chdir(GIT_WORK_TREE) do
|
|
62
|
-
# Pass on our rights to the files we just uploaded to the deployment user/group:
|
|
63
|
-
sh %W{chmod -Rf ug+rwX .} rescue nil
|
|
64
|
-
sh %W{chown -Rf #{DEPLOY_USER}:#{DEPLOY_GROUP} .} rescue nil
|
|
65
|
-
|
|
66
62
|
sudo %W{git checkout -f}
|
|
67
63
|
sudo %W{git submodule update -i}
|
|
68
64
|
|
data/setup/site/.rspec
CHANGED
data/setup/site/Gemfile
CHANGED
|
@@ -8,9 +8,13 @@ gem "utopia", "~> $UTOPIA_VERSION"
|
|
|
8
8
|
gem "rake"
|
|
9
9
|
gem "bundler"
|
|
10
10
|
|
|
11
|
+
gem "rack-freeze", "~> 1.2"
|
|
12
|
+
|
|
11
13
|
group :development do
|
|
12
14
|
# For `rake server`:
|
|
13
15
|
gem "puma"
|
|
16
|
+
gem "guard-puma", require: false
|
|
17
|
+
gem 'guard-rspec', require: false
|
|
14
18
|
|
|
15
19
|
# For `rake console`:
|
|
16
20
|
gem "pry"
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
group :development do
|
|
3
|
+
guard :puma, port: 9292 do
|
|
4
|
+
watch('Gemfile.lock')
|
|
5
|
+
watch('config.ru')
|
|
6
|
+
watch(%r{^config|lib|pages/.*})
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
group :test do
|
|
11
|
+
guard :rspec, cmd: 'rspec' do
|
|
12
|
+
watch(%r{^spec/.+_spec\.rb$})
|
|
13
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| 'spec/lib/#{m[1]}_spec.rb' }
|
|
14
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
|
15
|
+
watch(%r{^pages/.*}) { 'spec/website_spec.rb' }
|
|
16
|
+
end
|
|
17
|
+
end
|
data/setup/site/Rakefile
CHANGED
data/setup/site/config.ru
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative 'config/environment'
|
|
4
4
|
|
|
5
|
+
require 'rack/freeze'
|
|
6
|
+
|
|
5
7
|
if RACK_ENV == :production
|
|
6
8
|
# Handle exceptions in production with a error page and send an email notification:
|
|
7
9
|
use Utopia::Exceptions::Handler
|
|
@@ -29,27 +31,18 @@ use Utopia::Redirection::Errors,
|
|
|
29
31
|
use Utopia::Localization,
|
|
30
32
|
:default_locale => 'en',
|
|
31
33
|
:locales => ['en', 'de', 'ja', 'zh'],
|
|
32
|
-
:
|
|
34
|
+
:ignore => ['/_static/', '/_cache/', '/_components/']
|
|
33
35
|
|
|
34
36
|
require 'utopia/session'
|
|
35
37
|
use Utopia::Session,
|
|
36
38
|
:expires_after => 3600 * 24,
|
|
37
39
|
:secret => ENV['UTOPIA_SESSION_SECRET']
|
|
38
40
|
|
|
39
|
-
use Utopia::Controller
|
|
40
|
-
cache_controllers: (RACK_ENV == :production),
|
|
41
|
-
base: Utopia::Controller::Base
|
|
41
|
+
use Utopia::Controller
|
|
42
42
|
|
|
43
43
|
use Utopia::Static
|
|
44
44
|
|
|
45
45
|
# Serve dynamic content
|
|
46
|
-
use Utopia::Content
|
|
47
|
-
cache_templates: (RACK_ENV == :production),
|
|
48
|
-
tags: {
|
|
49
|
-
'deferred' => Utopia::Tags::Deferred,
|
|
50
|
-
'override' => Utopia::Tags::Override,
|
|
51
|
-
'node' => Utopia::Tags::Node,
|
|
52
|
-
'environment' => Utopia::Tags::Environment.for(RACK_ENV)
|
|
53
|
-
}
|
|
46
|
+
use Utopia::Content
|
|
54
47
|
|
|
55
48
|
run lambda { |env| [404, {}, []] }
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
<?r
|
|
2
|
-
<h1><content/></h1>
|
|
1
|
+
<?r document.attributes[:title] ||= content ?>
|
|
2
|
+
<h1><utopia:content/></h1>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
<page class="front">
|
|
2
|
-
<heading>Welcome to Utopia...</heading>
|
|
1
|
+
<content:page class="front">
|
|
2
|
+
<content:heading>Welcome to Utopia...</content:heading>
|
|
3
3
|
|
|
4
4
|
<section class="features">
|
|
5
5
|
<div>
|
|
@@ -32,4 +32,4 @@
|
|
|
32
32
|
<p>Utopia supports the <code>Accept-Language</code> header and transparently selects the correct view to render. Build multi-lingual websites and webapps easily: translate content incrementally as required, or not at all.</p>
|
|
33
33
|
</div>
|
|
34
34
|
</section>
|
|
35
|
-
</page>
|
|
35
|
+
</content:page>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
|
|
2
|
+
if ENV['COVERAGE']
|
|
3
|
+
begin
|
|
4
|
+
require 'simplecov'
|
|
5
|
+
|
|
6
|
+
SimpleCov.start do
|
|
7
|
+
add_filter "/spec/"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
if ENV['TRAVIS']
|
|
11
|
+
require 'coveralls'
|
|
12
|
+
Coveralls.wear!
|
|
13
|
+
end
|
|
14
|
+
rescue LoadError
|
|
15
|
+
warn "Could not load simplecov: #{$!}"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
require 'bundler/setup'
|
|
20
|
+
require 'utopia'
|
|
21
|
+
|
|
22
|
+
RSpec.configure do |config|
|
|
23
|
+
# Enable flags like --only-failures and --next-failure
|
|
24
|
+
config.example_status_persistence_file_path = '.rspec_status'
|
|
25
|
+
|
|
26
|
+
config.expect_with :rspec do |c|
|
|
27
|
+
c.syntax = :expect
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
|
|
2
|
+
desc 'Run by git post-update hook when deployed to a web server'
|
|
3
|
+
task :deploy do
|
|
4
|
+
# This task is typiclly run after the site is updated but before the server is restarted.
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
desc 'Restart the application server'
|
|
8
|
+
task :restart do
|
|
9
|
+
# This task is run after the deployment task above.
|
|
10
|
+
if passenger_config = `which passenger-config`.chomp!
|
|
11
|
+
sh(passenger_config, 'restart-app', '--ignore-passenger-not-running', File.dirname(__dir__))
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
|
|
2
|
+
require "rspec/core/rake_task"
|
|
3
|
+
|
|
4
|
+
RSpec::Core::RakeTask.new(:test) do |task|
|
|
5
|
+
task.rspec_opts = %w{--require simplecov} if ENV['COVERAGE']
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
task :coverage do
|
|
9
|
+
ENV['COVERAGE'] = 'y'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
desc 'Start the development server.'
|
|
13
|
+
task :server => :environment do
|
|
14
|
+
exec('guard', '-g', 'development')
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
desc 'Start the development environment which includes web server and tests.'
|
|
18
|
+
task :development => :environment do
|
|
19
|
+
exec('guard', '-g', 'development,test')
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
desc 'Start an interactive console for your web application'
|
|
23
|
+
task :console => :environment do
|
|
24
|
+
require 'pry'
|
|
25
|
+
require 'rack/test'
|
|
26
|
+
|
|
27
|
+
include Rack::Test::Methods
|
|
28
|
+
|
|
29
|
+
def app
|
|
30
|
+
@app ||= Rack::Builder.parse_file(File.expand_path("../config.ru", __dir__)).first
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
Pry.start
|
|
34
|
+
end
|