tennpipes-base 3.6.6
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 +7 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +294 -0
- data/Rakefile +1 -0
- data/bin/tennpipes +8 -0
- data/lib/tennpipes-base.rb +196 -0
- data/lib/tennpipes-base/application.rb +175 -0
- data/lib/tennpipes-base/application/application_setup.rb +202 -0
- data/lib/tennpipes-base/application/authenticity_token.rb +25 -0
- data/lib/tennpipes-base/application/flash.rb +229 -0
- data/lib/tennpipes-base/application/params_protection.rb +129 -0
- data/lib/tennpipes-base/application/routing.rb +1002 -0
- data/lib/tennpipes-base/application/show_exceptions.rb +50 -0
- data/lib/tennpipes-base/caller.rb +53 -0
- data/lib/tennpipes-base/cli/adapter.rb +33 -0
- data/lib/tennpipes-base/cli/base.rb +105 -0
- data/lib/tennpipes-base/cli/console.rb +20 -0
- data/lib/tennpipes-base/cli/launcher.rb +103 -0
- data/lib/tennpipes-base/cli/rake.rb +50 -0
- data/lib/tennpipes-base/cli/rake_tasks.rb +72 -0
- data/lib/tennpipes-base/command.rb +38 -0
- data/lib/tennpipes-base/ext/sinatra.rb +29 -0
- data/lib/tennpipes-base/filter.rb +52 -0
- data/lib/tennpipes-base/images/404.png +0 -0
- data/lib/tennpipes-base/images/500.png +0 -0
- data/lib/tennpipes-base/loader.rb +202 -0
- data/lib/tennpipes-base/logger.rb +492 -0
- data/lib/tennpipes-base/module.rb +58 -0
- data/lib/tennpipes-base/mounter.rb +308 -0
- data/lib/tennpipes-base/path_router.rb +119 -0
- data/lib/tennpipes-base/path_router/compiler.rb +110 -0
- data/lib/tennpipes-base/path_router/error_handler.rb +8 -0
- data/lib/tennpipes-base/path_router/matcher.rb +123 -0
- data/lib/tennpipes-base/path_router/route.rb +169 -0
- data/lib/tennpipes-base/reloader.rb +309 -0
- data/lib/tennpipes-base/reloader/rack.rb +26 -0
- data/lib/tennpipes-base/reloader/storage.rb +55 -0
- data/lib/tennpipes-base/router.rb +98 -0
- data/lib/tennpipes-base/server.rb +119 -0
- data/lib/tennpipes-base/tasks.rb +21 -0
- data/lib/tennpipes-base/version.rb +20 -0
- data/lib/tennpipes-base/version.rb~ +20 -0
- data/test/fixtures/app_gem/Gemfile +4 -0
- data/test/fixtures/app_gem/app/app.rb +3 -0
- data/test/fixtures/app_gem/app_gem.gemspec +17 -0
- data/test/fixtures/app_gem/lib/app_gem.rb +7 -0
- data/test/fixtures/app_gem/lib/app_gem/version.rb +3 -0
- data/test/fixtures/apps/complex.rb +32 -0
- data/test/fixtures/apps/demo_app.rb +7 -0
- data/test/fixtures/apps/demo_demo.rb +7 -0
- data/test/fixtures/apps/demo_project/api/app.rb +7 -0
- data/test/fixtures/apps/demo_project/api/lib/api_lib.rb +3 -0
- data/test/fixtures/apps/demo_project/app.rb +7 -0
- data/test/fixtures/apps/external_apps/fake_lib.rb +1 -0
- data/test/fixtures/apps/external_apps/fake_root.rb +2 -0
- data/test/fixtures/apps/helpers/class_methods_helpers.rb +4 -0
- data/test/fixtures/apps/helpers/instance_methods_helpers.rb +4 -0
- data/test/fixtures/apps/helpers/support.rb +1 -0
- data/test/fixtures/apps/helpers/system_helpers.rb +8 -0
- data/test/fixtures/apps/kiq.rb +3 -0
- data/test/fixtures/apps/lib/myklass.rb +2 -0
- data/test/fixtures/apps/lib/myklass/mysubklass.rb +4 -0
- data/test/fixtures/apps/models/child.rb +2 -0
- data/test/fixtures/apps/models/parent.rb +5 -0
- data/test/fixtures/apps/mountable_apps/rack_apps.rb +15 -0
- data/test/fixtures/apps/mountable_apps/static.html +1 -0
- data/test/fixtures/apps/precompiled_app.rb +19 -0
- data/test/fixtures/apps/simple.rb +32 -0
- data/test/fixtures/apps/static.rb +10 -0
- data/test/fixtures/apps/system.rb +13 -0
- data/test/fixtures/apps/system_class_methods_demo.rb +7 -0
- data/test/fixtures/apps/system_instance_methods_demo.rb +7 -0
- data/test/fixtures/dependencies/a.rb +9 -0
- data/test/fixtures/dependencies/b.rb +4 -0
- data/test/fixtures/dependencies/c.rb +1 -0
- data/test/fixtures/dependencies/circular/e.rb +13 -0
- data/test/fixtures/dependencies/circular/f.rb +2 -0
- data/test/fixtures/dependencies/circular/g.rb +2 -0
- data/test/fixtures/dependencies/d.rb +4 -0
- data/test/fixtures/reloadable_apps/external/app/app.rb +6 -0
- data/test/fixtures/reloadable_apps/external/app/controllers/base.rb +6 -0
- data/test/fixtures/reloadable_apps/main/app.rb +10 -0
- data/test/helper.rb +30 -0
- data/test/test_application.rb +185 -0
- data/test/test_core.rb +93 -0
- data/test/test_csrf_protection.rb +208 -0
- data/test/test_dependencies.rb +57 -0
- data/test/test_filters.rb +389 -0
- data/test/test_flash.rb +168 -0
- data/test/test_locale.rb +21 -0
- data/test/test_logger.rb +295 -0
- data/test/test_mounter.rb +302 -0
- data/test/test_params_protection.rb +195 -0
- data/test/test_reloader_complex.rb +74 -0
- data/test/test_reloader_external.rb +21 -0
- data/test/test_reloader_simple.rb +101 -0
- data/test/test_reloader_system.rb +113 -0
- data/test/test_restful_routing.rb +33 -0
- data/test/test_router.rb +281 -0
- data/test/test_routing.rb +2328 -0
- metadata +301 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
FakeLib = 1
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'active_support/logger_silence'
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
|
|
2
|
+
class RackApp
|
|
3
|
+
def self.call(_)
|
|
4
|
+
[200, {}, ["hello rack app"]]
|
|
5
|
+
end
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
RackApp2 = lambda{|_| [200, {}, ["hello rack app2"]] }
|
|
9
|
+
|
|
10
|
+
class SinatraApp < Sinatra::Base
|
|
11
|
+
set :public_folder, File.dirname(__FILE__)
|
|
12
|
+
get "/" do
|
|
13
|
+
"hello sinatra app"
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
hello static file
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
TENNPIPES_ROOT = File.dirname(__FILE__) unless defined? TENNPIPES_ROOT
|
|
2
|
+
|
|
3
|
+
Tennpipes.configure_apps do
|
|
4
|
+
set :precompile_routes, true
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
module PrecompiledApp
|
|
8
|
+
class App < Tennpipes::Application
|
|
9
|
+
10.times{|n| get("/#{n}"){} }
|
|
10
|
+
end
|
|
11
|
+
class SubApp < Tennpipes::Application
|
|
12
|
+
10.times{|n| get("/#{n}"){} }
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
Tennpipes.mount("PrecompiledApp::SubApp").to("/subapp")
|
|
17
|
+
Tennpipes.mount("PrecompiledApp::App").to("/")
|
|
18
|
+
|
|
19
|
+
Tennpipes.load!
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
TENNPIPES_ROOT = File.dirname(__FILE__) unless defined? TENNPIPES_ROOT
|
|
2
|
+
# Remove this comment if you want do some like this: ruby RACK_ENV=test app.rb
|
|
3
|
+
#
|
|
4
|
+
# require 'tennpipes-base'
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
class SimpleDemo < Tennpipes::Application
|
|
8
|
+
set :reload, true
|
|
9
|
+
before { true }
|
|
10
|
+
after { true }
|
|
11
|
+
error(404) { "404" }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
SimpleDemo.controllers do
|
|
15
|
+
get "/" do
|
|
16
|
+
'The magick number is: 2767356926488785838763860464013972991031534522105386787489885890443740254365!' # Change only the number!!!
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
get "/rand" do
|
|
20
|
+
rand(2 ** 256).to_s
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
## If you want use this as a standalone app uncomment:
|
|
25
|
+
#
|
|
26
|
+
# Tennpipes.mount("SimpleDemo").to("/")
|
|
27
|
+
# Tennpipes.run! unless Tennpipes.loaded? # If you enable reloader prevent to re-run the app
|
|
28
|
+
#
|
|
29
|
+
# Then run it from your console: ruby -I"lib" test/fixtures/apps/simple.rb
|
|
30
|
+
#
|
|
31
|
+
|
|
32
|
+
Tennpipes.load!
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# This file will be safe loaded three times.
|
|
2
|
+
# The first one fail because B and C constant are not defined
|
|
3
|
+
# The second one file because B requires C constant so will not be loaded
|
|
4
|
+
# The third one B and C are defined
|
|
5
|
+
|
|
6
|
+
# But here we need some of b.rb
|
|
7
|
+
A_result = [B, C]
|
|
8
|
+
|
|
9
|
+
A = "A"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
C = "C"
|
data/test/helper.rb
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
ENV['RACK_ENV'] = 'test'
|
|
2
|
+
TENNPIPES_ROOT = File.dirname(__FILE__) unless defined?(TENNPIPES_ROOT)
|
|
3
|
+
|
|
4
|
+
require 'minitest/autorun'
|
|
5
|
+
require 'minitest/pride'
|
|
6
|
+
require 'i18n'
|
|
7
|
+
require 'json'
|
|
8
|
+
require 'builder'
|
|
9
|
+
require 'rack/test'
|
|
10
|
+
require 'yaml'
|
|
11
|
+
require 'tennpipes-base'
|
|
12
|
+
|
|
13
|
+
require 'ext/minitest-spec'
|
|
14
|
+
require 'ext/rack-test-methods'
|
|
15
|
+
require 'ext/rack-test-utils'
|
|
16
|
+
|
|
17
|
+
class MiniTest::Spec
|
|
18
|
+
include Rack::Test::Methods
|
|
19
|
+
|
|
20
|
+
# Sets up a Sinatra::Base subclass defined with the block
|
|
21
|
+
# given. Used in setup or individual spec methods to establish
|
|
22
|
+
# the application.
|
|
23
|
+
def mock_app(base=Tennpipes::Application, &block)
|
|
24
|
+
@app = Sinatra.new(base, &block)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def app
|
|
28
|
+
Rack::Lint.new(@app)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
|
2
|
+
require 'haml'
|
|
3
|
+
|
|
4
|
+
class TennpipesPristine < Tennpipes::Application; end
|
|
5
|
+
class TennpipesTestApp < Tennpipes::Application; end
|
|
6
|
+
class TennpipesTestApp2 < Tennpipes::Application; end
|
|
7
|
+
|
|
8
|
+
describe "Application" do
|
|
9
|
+
before { Tennpipes.clear! }
|
|
10
|
+
|
|
11
|
+
describe 'for application functionality' do
|
|
12
|
+
|
|
13
|
+
it 'should check default options' do
|
|
14
|
+
assert File.identical?(__FILE__, TennpipesPristine.app_file)
|
|
15
|
+
assert_equal :tennpipes_pristine, TennpipesPristine.app_name
|
|
16
|
+
assert_equal :test, TennpipesPristine.environment
|
|
17
|
+
assert_equal Tennpipes.root('views'), TennpipesPristine.views
|
|
18
|
+
assert TennpipesPristine.raise_errors
|
|
19
|
+
assert !TennpipesPristine.logging
|
|
20
|
+
assert !TennpipesPristine.sessions
|
|
21
|
+
assert !TennpipesPristine.dump_errors
|
|
22
|
+
assert !TennpipesPristine.show_exceptions
|
|
23
|
+
assert TennpipesPristine.raise_errors
|
|
24
|
+
assert !Tennpipes.configure_apps
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'should check tennpipes specific options' do
|
|
28
|
+
assert !TennpipesPristine.instance_variable_get(:@_configured)
|
|
29
|
+
TennpipesPristine.send(:setup_application!)
|
|
30
|
+
assert_equal :tennpipes_pristine, TennpipesPristine.app_name
|
|
31
|
+
assert_equal 'StandardFormBuilder', TennpipesPristine.default_builder
|
|
32
|
+
assert TennpipesPristine.instance_variable_get(:@_configured)
|
|
33
|
+
assert !TennpipesPristine.reload?
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'should set global project settings' do
|
|
37
|
+
Tennpipes.configure_apps { enable :sessions; set :foo, "bar" }
|
|
38
|
+
TennpipesTestApp.send(:default_configuration!)
|
|
39
|
+
TennpipesTestApp2.send(:default_configuration!)
|
|
40
|
+
assert TennpipesTestApp.sessions, "should have sessions enabled"
|
|
41
|
+
assert_equal "bar", TennpipesTestApp.settings.foo, "should have foo assigned"
|
|
42
|
+
assert_equal TennpipesTestApp.session_secret, TennpipesTestApp2.session_secret
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'should be able to configure_apps multiple times' do
|
|
46
|
+
Tennpipes.configure_apps { set :foo1, "bar" }
|
|
47
|
+
Tennpipes.configure_apps { set :foo1, "bam" }
|
|
48
|
+
Tennpipes.configure_apps { set :foo2, "baz" }
|
|
49
|
+
TennpipesTestApp.send(:default_configuration!)
|
|
50
|
+
assert_equal "bam", TennpipesTestApp.settings.foo1, "should have foo1 assigned to bam"
|
|
51
|
+
assert_equal "baz", TennpipesTestApp.settings.foo2, "should have foo2 assigned to baz"
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it 'should have shared sessions accessible in project' do
|
|
55
|
+
Tennpipes.configure_apps { enable :sessions; set :session_secret, 'secret' }
|
|
56
|
+
Tennpipes.mount("TennpipesTestApp").to("/write")
|
|
57
|
+
Tennpipes.mount("TennpipesTestApp2").to("/read")
|
|
58
|
+
TennpipesTestApp.send :default_configuration!
|
|
59
|
+
TennpipesTestApp.get('/') { session[:foo] = "shared" }
|
|
60
|
+
TennpipesTestApp2.send(:default_configuration!)
|
|
61
|
+
TennpipesTestApp2.get('/') { session[:foo] }
|
|
62
|
+
@app = Tennpipes.application
|
|
63
|
+
get '/write'
|
|
64
|
+
get '/read'
|
|
65
|
+
assert_equal 'shared', body
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it 'should be able to execute the register keyword inside the configure_apps block' do
|
|
69
|
+
Asdf = Module.new
|
|
70
|
+
Tennpipes.configure_apps { register Asdf }
|
|
71
|
+
class GodFather < Tennpipes::Application; end
|
|
72
|
+
assert_includes GodFather.extensions, Asdf
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it 'should able to set custome session management' do
|
|
76
|
+
class TennpipesTestApp3 < Tennpipes::Application
|
|
77
|
+
set :sessions, :use => Rack::Session::Pool
|
|
78
|
+
end
|
|
79
|
+
Tennpipes.mount("TennpipesTestApp3").to("/")
|
|
80
|
+
TennpipesTestApp3.get('/write') { session[:foo] = "pool" }
|
|
81
|
+
TennpipesTestApp3.get('/read') { session[:foo] }
|
|
82
|
+
@app = Tennpipes.application
|
|
83
|
+
get '/write'
|
|
84
|
+
get '/read'
|
|
85
|
+
assert_equal 'pool', body
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it 'should have different session values in different session management' do
|
|
89
|
+
class TennpipesTestApp4 < Tennpipes::Application
|
|
90
|
+
enable :sessions
|
|
91
|
+
end
|
|
92
|
+
class TennpipesTestApp5 < Tennpipes::Application
|
|
93
|
+
set :sessions, :use => Rack::Session::Pool
|
|
94
|
+
end
|
|
95
|
+
Tennpipes.mount("TennpipesTestApp4").to("/write")
|
|
96
|
+
Tennpipes.mount("TennpipesTestApp5").to("/read")
|
|
97
|
+
TennpipesTestApp4.get('/') { session[:foo] = "cookie" }
|
|
98
|
+
TennpipesTestApp5.get('/') { session[:foo] }
|
|
99
|
+
@app = Tennpipes.application
|
|
100
|
+
get '/write'
|
|
101
|
+
get '/read'
|
|
102
|
+
assert_equal '', body
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# compare to: test_routing: allow global provides
|
|
106
|
+
it 'should set content_type to nil if none can be determined' do
|
|
107
|
+
mock_app do
|
|
108
|
+
provides :xml
|
|
109
|
+
|
|
110
|
+
get("/foo"){ "Foo in #{content_type.inspect}" }
|
|
111
|
+
get("/bar"){ "Foo in #{content_type.inspect}" }
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
get '/foo', {}, { 'HTTP_ACCEPT' => 'application/xml' }
|
|
115
|
+
assert_equal 'Foo in :xml', body
|
|
116
|
+
get '/foo'
|
|
117
|
+
assert_equal 'Foo in :xml', body
|
|
118
|
+
|
|
119
|
+
get '/bar', {}, { 'HTTP_ACCEPT' => 'application/xml' }
|
|
120
|
+
assert_equal "Foo in nil", body
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
it 'should resolve views and layouts paths' do
|
|
124
|
+
assert_equal Tennpipes.root('views')+'/users/index', TennpipesPristine.view_path('users/index')
|
|
125
|
+
assert_equal Tennpipes.root('views')+'/layouts/app', TennpipesPristine.layout_path(:app)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
describe "errors" do
|
|
129
|
+
it 'should have not mapped errors on development' do
|
|
130
|
+
mock_app { get('/'){ 'HI' } }
|
|
131
|
+
get "/"
|
|
132
|
+
assert @app.errors.empty?
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
it 'should have mapped errors on production' do
|
|
136
|
+
mock_app { set :environment, :production; get('/'){ 'HI' } }
|
|
137
|
+
get "/"
|
|
138
|
+
assert_equal 1, @app.errors.size
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
it 'should overide errors' do
|
|
142
|
+
mock_app do
|
|
143
|
+
set :environment, :production
|
|
144
|
+
get('/'){ raise }
|
|
145
|
+
error(::Exception){ 'custom error' }
|
|
146
|
+
end
|
|
147
|
+
get "/"
|
|
148
|
+
assert_equal 1, @app.errors.size
|
|
149
|
+
assert_equal 'custom error', body
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
it 'should raise NameError even if Kernel.require is extended' do
|
|
153
|
+
assert_raises NameError do
|
|
154
|
+
ConstTest = Class.new(Tennpipes::Application)
|
|
155
|
+
require 'active_support/dependencies'
|
|
156
|
+
ConstTest::UninitializedConstant
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
describe "pre-compile routes" do
|
|
162
|
+
it "should compile routes before first request if enabled the :precompile_routes option" do
|
|
163
|
+
require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/precompiled_app')
|
|
164
|
+
assert_instance_of Tennpipes::PathRouter::Compiler, PrecompiledApp::App.compiled_router.engine
|
|
165
|
+
assert_instance_of Tennpipes::PathRouter::Compiler, PrecompiledApp::SubApp.compiled_router.engine
|
|
166
|
+
assert_equal true, PrecompiledApp::App.compiled_router.engine.compiled?
|
|
167
|
+
assert_equal true, PrecompiledApp::SubApp.compiled_router.engine.compiled?
|
|
168
|
+
assert_equal 20, PrecompiledApp::App.compiled_router.engine.regexps.length
|
|
169
|
+
assert_equal 20, PrecompiledApp::SubApp.compiled_router.engine.regexps.length
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
describe 'global prerequisites' do
|
|
174
|
+
after do
|
|
175
|
+
Tennpipes::Application.prerequisites.clear
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
it 'should be inherited by children of Tennpipes::Application' do
|
|
179
|
+
Tennpipes::Application.prerequisites << 'my_prerequisites'
|
|
180
|
+
class InheritanceTest < Tennpipes::Application; end
|
|
181
|
+
assert_includes InheritanceTest.prerequisites, 'my_prerequisites'
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
end # application functionality
|
|
185
|
+
end
|