aldebaran 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/.gitignore +13 -0
  2. data/.travis.yml +16 -0
  3. data/.yardopts +4 -0
  4. data/AUTHORS +4 -0
  5. data/Gemfile +77 -0
  6. data/KNOWN_ISSUES +5 -0
  7. data/LICENSE +22 -0
  8. data/README.rdoc +1900 -0
  9. data/Rakefile +175 -0
  10. data/aldebaran.gemspec +19 -0
  11. data/lib/aldebaran.rb +7 -0
  12. data/lib/aldebaran/base.rb +1600 -0
  13. data/lib/aldebaran/images/404.png +0 -0
  14. data/lib/aldebaran/images/500.png +0 -0
  15. data/lib/aldebaran/main.rb +28 -0
  16. data/lib/aldebaran/showexceptions.rb +340 -0
  17. data/lib/aldebaran/version.rb +3 -0
  18. data/test/aldebaran_test.rb +17 -0
  19. data/test/base_test.rb +160 -0
  20. data/test/builder_test.rb +95 -0
  21. data/test/coffee_test.rb +92 -0
  22. data/test/contest.rb +98 -0
  23. data/test/creole_test.rb +65 -0
  24. data/test/delegator_test.rb +162 -0
  25. data/test/encoding_test.rb +20 -0
  26. data/test/erb_test.rb +104 -0
  27. data/test/extensions_test.rb +100 -0
  28. data/test/filter_test.rb +397 -0
  29. data/test/haml_test.rb +101 -0
  30. data/test/helper.rb +115 -0
  31. data/test/helpers_test.rb +1192 -0
  32. data/test/less_test.rb +67 -0
  33. data/test/liquid_test.rb +59 -0
  34. data/test/mapped_error_test.rb +259 -0
  35. data/test/markaby_test.rb +80 -0
  36. data/test/markdown_test.rb +81 -0
  37. data/test/middleware_test.rb +68 -0
  38. data/test/nokogiri_test.rb +69 -0
  39. data/test/public/favicon.ico +0 -0
  40. data/test/radius_test.rb +59 -0
  41. data/test/rdoc_test.rb +65 -0
  42. data/test/readme_test.rb +136 -0
  43. data/test/request_test.rb +45 -0
  44. data/test/response_test.rb +61 -0
  45. data/test/result_test.rb +98 -0
  46. data/test/route_added_hook_test.rb +59 -0
  47. data/test/routing_test.rb +1096 -0
  48. data/test/sass_test.rb +115 -0
  49. data/test/scss_test.rb +88 -0
  50. data/test/server_test.rb +48 -0
  51. data/test/settings_test.rb +493 -0
  52. data/test/slim_test.rb +98 -0
  53. data/test/static_test.rb +178 -0
  54. data/test/streaming_test.rb +100 -0
  55. data/test/templates_test.rb +298 -0
  56. data/test/textile_test.rb +65 -0
  57. data/test/views/a/in_a.str +1 -0
  58. data/test/views/ascii.erb +2 -0
  59. data/test/views/b/in_b.str +1 -0
  60. data/test/views/calc.html.erb +1 -0
  61. data/test/views/error.builder +3 -0
  62. data/test/views/error.erb +3 -0
  63. data/test/views/error.haml +3 -0
  64. data/test/views/error.sass +2 -0
  65. data/test/views/explicitly_nested.str +1 -0
  66. data/test/views/foo/hello.test +1 -0
  67. data/test/views/hello.builder +1 -0
  68. data/test/views/hello.coffee +1 -0
  69. data/test/views/hello.creole +1 -0
  70. data/test/views/hello.erb +1 -0
  71. data/test/views/hello.haml +1 -0
  72. data/test/views/hello.less +5 -0
  73. data/test/views/hello.liquid +1 -0
  74. data/test/views/hello.mab +1 -0
  75. data/test/views/hello.md +1 -0
  76. data/test/views/hello.nokogiri +1 -0
  77. data/test/views/hello.radius +1 -0
  78. data/test/views/hello.rdoc +1 -0
  79. data/test/views/hello.sass +2 -0
  80. data/test/views/hello.scss +3 -0
  81. data/test/views/hello.slim +1 -0
  82. data/test/views/hello.str +1 -0
  83. data/test/views/hello.test +1 -0
  84. data/test/views/hello.textile +1 -0
  85. data/test/views/layout2.builder +3 -0
  86. data/test/views/layout2.erb +2 -0
  87. data/test/views/layout2.haml +2 -0
  88. data/test/views/layout2.liquid +2 -0
  89. data/test/views/layout2.mab +2 -0
  90. data/test/views/layout2.nokogiri +3 -0
  91. data/test/views/layout2.radius +2 -0
  92. data/test/views/layout2.slim +3 -0
  93. data/test/views/layout2.str +2 -0
  94. data/test/views/layout2.test +1 -0
  95. data/test/views/nested.str +1 -0
  96. data/test/views/utf8.erb +2 -0
  97. metadata +231 -0
@@ -0,0 +1,115 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ begin
4
+ require 'sass'
5
+
6
+ class SassTest < Test::Unit::TestCase
7
+ def sass_app(options = {}, &block)
8
+ mock_app {
9
+ set :views, File.dirname(__FILE__) + '/views'
10
+ set options
11
+ get '/', &block
12
+ }
13
+ get '/'
14
+ end
15
+
16
+ it 'renders inline Sass strings' do
17
+ sass_app { sass "#sass\n :background-color white\n" }
18
+ assert ok?
19
+ assert_equal "#sass {\n background-color: white; }\n", body
20
+ end
21
+
22
+ it 'defaults content type to css' do
23
+ sass_app { sass "#sass\n :background-color white\n" }
24
+ assert ok?
25
+ assert_equal "text/css;charset=utf-8", response['Content-Type']
26
+ end
27
+
28
+ it 'defaults allows setting content type per route' do
29
+ sass_app do
30
+ content_type :html
31
+ sass "#sass\n :background-color white\n"
32
+ end
33
+ assert ok?
34
+ assert_equal "text/html;charset=utf-8", response['Content-Type']
35
+ end
36
+
37
+ it 'defaults allows setting content type globally' do
38
+ sass_app(:sass => { :content_type => 'html' }) do
39
+ sass "#sass\n :background-color white\n"
40
+ end
41
+ assert ok?
42
+ assert_equal "text/html;charset=utf-8", response['Content-Type']
43
+ end
44
+
45
+ it 'renders .sass files in views path' do
46
+ sass_app { sass :hello }
47
+ assert ok?
48
+ assert_equal "#sass {\n background-color: white; }\n", body
49
+ end
50
+
51
+ it 'ignores the layout option' do
52
+ sass_app { sass :hello, :layout => :layout2 }
53
+ assert ok?
54
+ assert_equal "#sass {\n background-color: white; }\n", body
55
+ end
56
+
57
+ it "raises error if template not found" do
58
+ mock_app {
59
+ get('/') { sass :no_such_template }
60
+ }
61
+ assert_raise(Errno::ENOENT) { get('/') }
62
+ end
63
+
64
+ it "passes SASS options to the Sass engine" do
65
+ sass_app {
66
+ sass "#sass\n :background-color white\n :color black\n",
67
+ :style => :compact
68
+ }
69
+ assert ok?
70
+ assert_equal "#sass { background-color: white; color: black; }\n", body
71
+ end
72
+
73
+ it "passes default SASS options to the Sass engine" do
74
+ mock_app {
75
+ set :sass, {:style => :compact} # default Sass style is :nested
76
+ get '/' do
77
+ sass "#sass\n :background-color white\n :color black\n"
78
+ end
79
+ }
80
+ get '/'
81
+ assert ok?
82
+ assert_equal "#sass { background-color: white; color: black; }\n", body
83
+ end
84
+
85
+ it "merges the default SASS options with the overrides" do
86
+ mock_app {
87
+ # default Sass attribute_syntax is :normal (with : in front)
88
+ set :sass, {:style => :compact, :attribute_syntax => :alternate }
89
+ get '/' do
90
+ sass "#sass\n background-color: white\n color: black\n"
91
+ end
92
+ get '/raised' do
93
+ # retains global attribute_syntax settings
94
+ sass "#sass\n :background-color white\n :color black\n",
95
+ :style => :expanded
96
+ end
97
+ get '/expanded_normal' do
98
+ sass "#sass\n :background-color white\n :color black\n",
99
+ :style => :expanded, :attribute_syntax => :normal
100
+ end
101
+ }
102
+ get '/'
103
+ assert ok?
104
+ assert_equal "#sass { background-color: white; color: black; }\n", body
105
+ assert_raise(Sass::SyntaxError) { get('/raised') }
106
+ get '/expanded_normal'
107
+ assert ok?
108
+ assert_equal "#sass {\n background-color: white;\n color: black;\n}\n",
109
+ body
110
+ end
111
+ end
112
+
113
+ rescue LoadError
114
+ warn "#{$!.to_s}: skipping sass tests"
115
+ end
@@ -0,0 +1,88 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ begin
4
+ require 'sass'
5
+
6
+ class ScssTest < Test::Unit::TestCase
7
+ def scss_app(options = {}, &block)
8
+ mock_app {
9
+ set :views, File.dirname(__FILE__) + '/views'
10
+ set options
11
+ get '/', &block
12
+ }
13
+ get '/'
14
+ end
15
+
16
+ it 'renders inline Scss strings' do
17
+ scss_app { scss "#scss {\n background-color: white; }\n" }
18
+ assert ok?
19
+ assert_equal "#scss {\n background-color: white; }\n", body
20
+ end
21
+
22
+ it 'defaults content type to css' do
23
+ scss_app { scss "#scss {\n background-color: white; }\n" }
24
+ assert ok?
25
+ assert_equal "text/css;charset=utf-8", response['Content-Type']
26
+ end
27
+
28
+ it 'defaults allows setting content type per route' do
29
+ scss_app do
30
+ content_type :html
31
+ scss "#scss {\n background-color: white; }\n"
32
+ end
33
+ assert ok?
34
+ assert_equal "text/html;charset=utf-8", response['Content-Type']
35
+ end
36
+
37
+ it 'defaults allows setting content type globally' do
38
+ scss_app(:scss => { :content_type => 'html' }) do
39
+ scss "#scss {\n background-color: white; }\n"
40
+ end
41
+ assert ok?
42
+ assert_equal "text/html;charset=utf-8", response['Content-Type']
43
+ end
44
+
45
+ it 'renders .scss files in views path' do
46
+ scss_app { scss :hello }
47
+ assert ok?
48
+ assert_equal "#scss {\n background-color: white; }\n", body
49
+ end
50
+
51
+ it 'ignores the layout option' do
52
+ scss_app { scss :hello, :layout => :layout2 }
53
+ assert ok?
54
+ assert_equal "#scss {\n background-color: white; }\n", body
55
+ end
56
+
57
+ it "raises error if template not found" do
58
+ mock_app {
59
+ get('/') { scss :no_such_template }
60
+ }
61
+ assert_raise(Errno::ENOENT) { get('/') }
62
+ end
63
+
64
+ it "passes scss options to the scss engine" do
65
+ scss_app {
66
+ scss "#scss {\n background-color: white;\n color: black\n}",
67
+ :style => :compact
68
+ }
69
+ assert ok?
70
+ assert_equal "#scss { background-color: white; color: black; }\n", body
71
+ end
72
+
73
+ it "passes default scss options to the scss engine" do
74
+ mock_app {
75
+ set :scss, {:style => :compact} # default scss style is :nested
76
+ get '/' do
77
+ scss "#scss {\n background-color: white;\n color: black;\n}"
78
+ end
79
+ }
80
+ get '/'
81
+ assert ok?
82
+ assert_equal "#scss { background-color: white; color: black; }\n", body
83
+ end
84
+ end
85
+
86
+ rescue LoadError
87
+ warn "#{$!.to_s}: skipping scss tests"
88
+ end
@@ -0,0 +1,48 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+ require 'stringio'
3
+
4
+ module Rack::Handler
5
+ class Mock
6
+ extend Test::Unit::Assertions
7
+
8
+ def self.run(app, options={})
9
+ assert(app < aldebaran::Base)
10
+ assert_equal 9001, options[:Port]
11
+ assert_equal 'foo.local', options[:Host]
12
+ yield new
13
+ end
14
+
15
+ def stop
16
+ end
17
+ end
18
+
19
+ register 'mock', 'Rack::Handler::Mock'
20
+ end
21
+
22
+ class ServerTest < Test::Unit::TestCase
23
+ setup do
24
+ mock_app {
25
+ set :server, 'mock'
26
+ set :bind, 'foo.local'
27
+ set :port, 9001
28
+ }
29
+ $stderr = StringIO.new
30
+ end
31
+
32
+ def teardown
33
+ $stderr = STDERR
34
+ end
35
+
36
+ it "locates the appropriate Rack handler and calls ::run" do
37
+ @app.run!
38
+ end
39
+
40
+ it "sets options on the app before running" do
41
+ @app.run! :sessions => true
42
+ assert @app.sessions?
43
+ end
44
+
45
+ it "falls back on the next server handler when not found" do
46
+ @app.run! :server => %w[foo bar mock]
47
+ end
48
+ end
@@ -0,0 +1,493 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class SettingsTest < Test::Unit::TestCase
4
+ setup do
5
+ @base = aldebaran.new(aldebaran::Base)
6
+ @base.set :environment => :foo, :app_file => nil
7
+
8
+ @application = aldebaran.new(aldebaran::Application)
9
+ @application.set :environment => :foo, :app_file => nil
10
+ end
11
+
12
+ it 'sets settings to literal values' do
13
+ @base.set(:foo, 'bar')
14
+ assert @base.respond_to?(:foo)
15
+ assert_equal 'bar', @base.foo
16
+ end
17
+
18
+ it 'sets settings to Procs' do
19
+ @base.set(:foo, Proc.new { 'baz' })
20
+ assert @base.respond_to?(:foo)
21
+ assert_equal 'baz', @base.foo
22
+ end
23
+
24
+ it 'sets settings using a block' do
25
+ @base.set(:foo){ 'baz' }
26
+ assert @base.respond_to?(:foo)
27
+ assert_equal 'baz', @base.foo
28
+ end
29
+
30
+ it 'raises an error with a value and a block' do
31
+ assert_raise ArgumentError do
32
+ @base.set(:fiz, 'boom!'){ 'baz' }
33
+ end
34
+ assert !@base.respond_to?(:fiz)
35
+ end
36
+
37
+ it 'raises an error without value and block' do
38
+ assert_raise(ArgumentError) { @base.set(:fiz) }
39
+ assert !@base.respond_to?(:fiz)
40
+ end
41
+
42
+ it 'allows setting a value to the app class' do
43
+ @base.set :base, @base
44
+ assert @base.respond_to?(:base)
45
+ assert_equal @base, @base.base
46
+ end
47
+
48
+ it 'raises an error with the app class as value and a block' do
49
+ assert_raise ArgumentError do
50
+ @base.set(:fiz, @base) { 'baz' }
51
+ end
52
+ assert !@base.respond_to?(:fiz)
53
+ end
54
+
55
+ it "sets multiple settings with a Hash" do
56
+ @base.set :foo => 1234,
57
+ :bar => 'Hello World',
58
+ :baz => Proc.new { 'bizzle' }
59
+ assert_equal 1234, @base.foo
60
+ assert_equal 'Hello World', @base.bar
61
+ assert_equal 'bizzle', @base.baz
62
+ end
63
+
64
+ it 'sets multiple settings using #each' do
65
+ @base.set [["foo", "bar"]]
66
+ assert_equal "bar", @base.foo
67
+ end
68
+
69
+ it 'inherits settings methods when subclassed' do
70
+ @base.set :foo, 'bar'
71
+ @base.set :biz, Proc.new { 'baz' }
72
+
73
+ sub = Class.new(@base)
74
+ assert sub.respond_to?(:foo)
75
+ assert_equal 'bar', sub.foo
76
+ assert sub.respond_to?(:biz)
77
+ assert_equal 'baz', sub.biz
78
+ end
79
+
80
+ it 'overrides settings in subclass' do
81
+ @base.set :foo, 'bar'
82
+ @base.set :biz, Proc.new { 'baz' }
83
+ sub = Class.new(@base)
84
+ sub.set :foo, 'bling'
85
+ assert_equal 'bling', sub.foo
86
+ assert_equal 'bar', @base.foo
87
+ end
88
+
89
+ it 'creates setter methods when first defined' do
90
+ @base.set :foo, 'bar'
91
+ assert @base.respond_to?('foo=')
92
+ @base.foo = 'biz'
93
+ assert_equal 'biz', @base.foo
94
+ end
95
+
96
+ it 'creates predicate methods when first defined' do
97
+ @base.set :foo, 'hello world'
98
+ assert @base.respond_to?(:foo?)
99
+ assert @base.foo?
100
+ @base.set :foo, nil
101
+ assert !@base.foo?
102
+ end
103
+
104
+ it 'uses existing setter methods if detected' do
105
+ class << @base
106
+ def foo
107
+ @foo
108
+ end
109
+ def foo=(value)
110
+ @foo = 'oops'
111
+ end
112
+ end
113
+
114
+ @base.set :foo, 'bam'
115
+ assert_equal 'oops', @base.foo
116
+ end
117
+
118
+ it 'merges values of multiple set calls if those are hashes' do
119
+ @base.set :foo, :a => 1
120
+ sub = Class.new(@base)
121
+ sub.set :foo, :b => 2
122
+ assert_equal({:a => 1, :b => 2}, sub.foo)
123
+ end
124
+
125
+ it 'merging does not affect the superclass' do
126
+ @base.set :foo, :a => 1
127
+ sub = Class.new(@base)
128
+ sub.set :foo, :b => 2
129
+ assert_equal({:a => 1}, @base.foo)
130
+ end
131
+
132
+ it 'is possible to change a value from a hash to something else' do
133
+ @base.set :foo, :a => 1
134
+ @base.set :foo, :bar
135
+ assert_equal(:bar, @base.foo)
136
+ end
137
+
138
+ it 'merges values with values of the superclass if those are hashes' do
139
+ @base.set :foo, :a => 1
140
+ @base.set :foo, :b => 2
141
+ assert_equal({:a => 1, :b => 2}, @base.foo)
142
+ end
143
+
144
+ it "sets multiple settings to true with #enable" do
145
+ @base.enable :sessions, :foo, :bar
146
+ assert @base.sessions
147
+ assert @base.foo
148
+ assert @base.bar
149
+ end
150
+
151
+ it "sets multiple settings to false with #disable" do
152
+ @base.disable :sessions, :foo, :bar
153
+ assert !@base.sessions
154
+ assert !@base.foo
155
+ assert !@base.bar
156
+ end
157
+
158
+ it 'is accessible from instances via #settings' do
159
+ assert_equal :foo, @base.new!.settings.environment
160
+ end
161
+
162
+ it 'is accessible from class via #settings' do
163
+ assert_equal :foo, @base.settings.environment
164
+ end
165
+
166
+ describe 'methodoverride' do
167
+ it 'is disabled on Base' do
168
+ assert ! @base.method_override?
169
+ end
170
+
171
+ it 'is enabled on Application' do
172
+ assert @application.method_override?
173
+ end
174
+
175
+ it 'enables MethodOverride middleware' do
176
+ @base.set :method_override, true
177
+ @base.put('/') { 'okay' }
178
+ @app = @base
179
+ post '/', {'_method'=>'PUT'}, {}
180
+ assert_equal 200, status
181
+ assert_equal 'okay', body
182
+ end
183
+
184
+ it 'is backward compatible with methodoverride' do
185
+ assert ! @base.methodoverride?
186
+ @base.enable :methodoverride
187
+ assert @base.methodoverride?
188
+ end
189
+ end
190
+
191
+ describe 'run' do
192
+ it 'is disabled on Base' do
193
+ assert ! @base.run?
194
+ end
195
+
196
+ it 'is enabled on Application except in test environment' do
197
+ assert @application.run?
198
+
199
+ @application.set :environment, :test
200
+ assert ! @application.run?
201
+ end
202
+ end
203
+
204
+ describe 'raise_errors' do
205
+ it 'is enabled on Base only in test' do
206
+ assert ! @base.raise_errors?
207
+
208
+ @base.set(:environment, :test)
209
+ assert @base.raise_errors?
210
+ end
211
+
212
+ it 'is enabled on Application only in test' do
213
+ assert ! @application.raise_errors?
214
+
215
+ @application.set(:environment, :test)
216
+ assert @application.raise_errors?
217
+ end
218
+ end
219
+
220
+ describe 'show_exceptions' do
221
+ it 'is disabled on Base except under development' do
222
+ assert ! @base.show_exceptions?
223
+ @base.environment = :development
224
+ assert @base.show_exceptions?
225
+ end
226
+
227
+ it 'is disabled on Application except in development' do
228
+ assert ! @application.show_exceptions?
229
+
230
+ @application.set(:environment, :development)
231
+ assert @application.show_exceptions?
232
+ end
233
+
234
+ it 'returns a friendly 500' do
235
+ klass = aldebaran.new(aldebaran::Application)
236
+ mock_app(klass) {
237
+ enable :show_exceptions
238
+
239
+ get '/' do
240
+ raise StandardError
241
+ end
242
+ }
243
+
244
+ get '/'
245
+ assert_equal 500, status
246
+ assert body.include?("StandardError")
247
+ assert body.include?("<code>show_exceptions</code> setting")
248
+ end
249
+
250
+ it 'does not override app-specified error handling when set to :after_handler' do
251
+ ran = false
252
+ mock_app do
253
+ set :show_exceptions, :after_handler
254
+ error(RuntimeError) { ran = true }
255
+ get('/') { raise RuntimeError }
256
+ end
257
+
258
+ get '/'
259
+ assert_equal 500, status
260
+ assert ran
261
+ end
262
+
263
+ it 'does catch any other exceptions when set to :after_handler' do
264
+ ran = false
265
+ mock_app do
266
+ set :show_exceptions, :after_handler
267
+ error(RuntimeError) { ran = true }
268
+ get('/') { raise ArgumentError }
269
+ end
270
+
271
+ get '/'
272
+ assert_equal 500, status
273
+ assert !ran
274
+ end
275
+ end
276
+
277
+ describe 'dump_errors' do
278
+ it 'is disabled on Base in test' do
279
+ @base.environment = :test
280
+ assert ! @base.dump_errors?
281
+ @base.environment = :development
282
+ assert @base.dump_errors?
283
+ @base.environment = :production
284
+ assert @base.dump_errors?
285
+ end
286
+
287
+ it 'dumps exception with backtrace to rack.errors' do
288
+ klass = aldebaran.new(aldebaran::Application)
289
+
290
+ mock_app(klass) {
291
+ enable :dump_errors
292
+ disable :raise_errors
293
+
294
+ error do
295
+ error = @env['rack.errors'].instance_variable_get(:@error)
296
+ error.rewind
297
+
298
+ error.read
299
+ end
300
+
301
+ get '/' do
302
+ raise
303
+ end
304
+ }
305
+
306
+ get '/'
307
+ assert body.include?("RuntimeError") && body.include?("settings_test.rb")
308
+ end
309
+
310
+ it 'does not dump 404 errors' do
311
+ klass = aldebaran.new(aldebaran::Application)
312
+
313
+ mock_app(klass) {
314
+ enable :dump_errors
315
+ disable :raise_errors
316
+
317
+ error do
318
+ error = @env['rack.errors'].instance_variable_get(:@error)
319
+ error.rewind
320
+
321
+ error.read
322
+ end
323
+
324
+ get '/' do
325
+ raise aldebaran::NotFound
326
+ end
327
+ }
328
+
329
+ get '/'
330
+ assert !body.include?("NotFound") && !body.include?("settings_test.rb")
331
+ end
332
+ end
333
+
334
+ describe 'sessions' do
335
+ it 'is disabled on Base' do
336
+ assert ! @base.sessions?
337
+ end
338
+
339
+ it 'is disabled on Application' do
340
+ assert ! @application.sessions?
341
+ end
342
+ end
343
+
344
+ describe 'logging' do
345
+ it 'is disabled on Base' do
346
+ assert ! @base.logging?
347
+ end
348
+
349
+ it 'is enabled on Application except in test environment' do
350
+ assert @application.logging?
351
+
352
+ @application.set :environment, :test
353
+ assert ! @application.logging
354
+ end
355
+ end
356
+
357
+ describe 'static' do
358
+ it 'is disabled on Base by default' do
359
+ assert ! @base.static?
360
+ end
361
+
362
+ it 'is enabled on Base when public_folder is set and exists' do
363
+ @base.set :environment, :development
364
+ @base.set :public_folder, File.dirname(__FILE__)
365
+ assert @base.static?
366
+ end
367
+
368
+ it 'is enabled on Base when root is set and root/public_folder exists' do
369
+ @base.set :environment, :development
370
+ @base.set :root, File.dirname(__FILE__)
371
+ assert @base.static?
372
+ end
373
+
374
+ it 'is disabled on Application by default' do
375
+ assert ! @application.static?
376
+ end
377
+
378
+ it 'is enabled on Application when public_folder is set and exists' do
379
+ @application.set :environment, :development
380
+ @application.set :public_folder, File.dirname(__FILE__)
381
+ assert @application.static?
382
+ end
383
+
384
+ it 'is enabled on Application when root is set and root/public_folder exists' do
385
+ @application.set :environment, :development
386
+ @application.set :root, File.dirname(__FILE__)
387
+ assert @application.static?
388
+ end
389
+
390
+ it 'is possible to use Module#public' do
391
+ @base.send(:define_method, :foo) { }
392
+ @base.send(:private, :foo)
393
+ assert !@base.public_method_defined?(:foo)
394
+ @base.send(:public, :foo)
395
+ assert @base.public_method_defined?(:foo)
396
+ end
397
+
398
+ it 'is possible to use the keyword public in a aldebaran app' do
399
+ app = aldebaran.new do
400
+ private
401
+ def priv; end
402
+ public
403
+ def pub; end
404
+ end
405
+ assert !app.public_method_defined?(:priv)
406
+ assert app.public_method_defined?(:pub)
407
+ end
408
+ end
409
+
410
+ describe 'bind' do
411
+ it 'defaults to 0.0.0.0' do
412
+ assert_equal '0.0.0.0', @base.bind
413
+ assert_equal '0.0.0.0', @application.bind
414
+ end
415
+ end
416
+
417
+ describe 'port' do
418
+ it 'defaults to 4567' do
419
+ assert_equal 4567, @base.port
420
+ assert_equal 4567, @application.port
421
+ end
422
+ end
423
+
424
+ describe 'server' do
425
+ it 'is one of thin, mongrel, webrick' do
426
+ assert_equal %w[thin mongrel webrick], @base.server
427
+ assert_equal %w[thin mongrel webrick], @application.server
428
+ end
429
+ end
430
+
431
+ describe 'app_file' do
432
+ it 'is nil for base classes' do
433
+ assert_nil aldebaran::Base.app_file
434
+ assert_nil aldebaran::Application.app_file
435
+ end
436
+
437
+ it 'defaults to the file subclassing' do
438
+ assert_equal __FILE__, aldebaran.new.app_file
439
+ end
440
+ end
441
+
442
+ describe 'root' do
443
+ it 'is nil if app_file is not set' do
444
+ assert @base.root.nil?
445
+ assert @application.root.nil?
446
+ end
447
+
448
+ it 'is equal to the expanded basename of app_file' do
449
+ @base.app_file = __FILE__
450
+ assert_equal File.expand_path(File.dirname(__FILE__)), @base.root
451
+
452
+ @application.app_file = __FILE__
453
+ assert_equal File.expand_path(File.dirname(__FILE__)), @application.root
454
+ end
455
+ end
456
+
457
+ describe 'views' do
458
+ it 'is nil if root is not set' do
459
+ assert @base.views.nil?
460
+ assert @application.views.nil?
461
+ end
462
+
463
+ it 'is set to root joined with views/' do
464
+ @base.root = File.dirname(__FILE__)
465
+ assert_equal File.dirname(__FILE__) + "/views", @base.views
466
+
467
+ @application.root = File.dirname(__FILE__)
468
+ assert_equal File.dirname(__FILE__) + "/views", @application.views
469
+ end
470
+ end
471
+
472
+ describe 'public_folder' do
473
+ it 'is nil if root is not set' do
474
+ assert @base.public_folder.nil?
475
+ assert @application.public_folder.nil?
476
+ end
477
+
478
+ it 'is set to root joined with public/' do
479
+ @base.root = File.dirname(__FILE__)
480
+ assert_equal File.dirname(__FILE__) + "/public", @base.public_folder
481
+
482
+ @application.root = File.dirname(__FILE__)
483
+ assert_equal File.dirname(__FILE__) + "/public", @application.public_folder
484
+ end
485
+ end
486
+
487
+ describe 'lock' do
488
+ it 'is disabled by default' do
489
+ assert ! @base.lock?
490
+ assert ! @application.lock?
491
+ end
492
+ end
493
+ end