sinatra-acd 1.4.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +5 -0
  3. data/AUTHORS +61 -0
  4. data/CHANGES +1293 -0
  5. data/Gemfile +76 -0
  6. data/LICENSE +23 -0
  7. data/README.de.md +2864 -0
  8. data/README.es.md +2786 -0
  9. data/README.fr.md +2924 -0
  10. data/README.hu.md +694 -0
  11. data/README.ja.md +2726 -0
  12. data/README.ko.md +2832 -0
  13. data/README.md +2980 -0
  14. data/README.pt-br.md +965 -0
  15. data/README.pt-pt.md +791 -0
  16. data/README.ru.md +2799 -0
  17. data/README.zh.md +2158 -0
  18. data/Rakefile +199 -0
  19. data/examples/chat.rb +61 -0
  20. data/examples/simple.rb +3 -0
  21. data/examples/stream.ru +26 -0
  22. data/lib/sinatra.rb +4 -0
  23. data/lib/sinatra/base.rb +2044 -0
  24. data/lib/sinatra/images/404.png +0 -0
  25. data/lib/sinatra/images/500.png +0 -0
  26. data/lib/sinatra/main.rb +34 -0
  27. data/lib/sinatra/show_exceptions.rb +345 -0
  28. data/lib/sinatra/version.rb +3 -0
  29. data/sinatra.gemspec +19 -0
  30. data/test/asciidoctor_test.rb +72 -0
  31. data/test/base_test.rb +171 -0
  32. data/test/builder_test.rb +91 -0
  33. data/test/coffee_test.rb +90 -0
  34. data/test/compile_test.rb +183 -0
  35. data/test/contest.rb +100 -0
  36. data/test/creole_test.rb +65 -0
  37. data/test/delegator_test.rb +160 -0
  38. data/test/encoding_test.rb +20 -0
  39. data/test/erb_test.rb +116 -0
  40. data/test/extensions_test.rb +98 -0
  41. data/test/filter_test.rb +487 -0
  42. data/test/haml_test.rb +109 -0
  43. data/test/helper.rb +131 -0
  44. data/test/helpers_test.rb +1917 -0
  45. data/test/integration/app.rb +79 -0
  46. data/test/integration_helper.rb +236 -0
  47. data/test/integration_test.rb +104 -0
  48. data/test/less_test.rb +69 -0
  49. data/test/liquid_test.rb +77 -0
  50. data/test/mapped_error_test.rb +285 -0
  51. data/test/markaby_test.rb +80 -0
  52. data/test/markdown_test.rb +82 -0
  53. data/test/mediawiki_test.rb +68 -0
  54. data/test/middleware_test.rb +68 -0
  55. data/test/nokogiri_test.rb +67 -0
  56. data/test/public/favicon.ico +0 -0
  57. data/test/rabl_test.rb +89 -0
  58. data/test/rack_test.rb +45 -0
  59. data/test/radius_test.rb +59 -0
  60. data/test/rdoc_test.rb +66 -0
  61. data/test/readme_test.rb +130 -0
  62. data/test/request_test.rb +97 -0
  63. data/test/response_test.rb +63 -0
  64. data/test/result_test.rb +76 -0
  65. data/test/route_added_hook_test.rb +59 -0
  66. data/test/routing_test.rb +1412 -0
  67. data/test/sass_test.rb +115 -0
  68. data/test/scss_test.rb +88 -0
  69. data/test/server_test.rb +48 -0
  70. data/test/settings_test.rb +582 -0
  71. data/test/sinatra_test.rb +12 -0
  72. data/test/slim_test.rb +102 -0
  73. data/test/static_test.rb +236 -0
  74. data/test/streaming_test.rb +149 -0
  75. data/test/stylus_test.rb +90 -0
  76. data/test/templates_test.rb +382 -0
  77. data/test/textile_test.rb +65 -0
  78. data/test/views/a/in_a.str +1 -0
  79. data/test/views/ascii.erb +2 -0
  80. data/test/views/b/in_b.str +1 -0
  81. data/test/views/calc.html.erb +1 -0
  82. data/test/views/error.builder +3 -0
  83. data/test/views/error.erb +3 -0
  84. data/test/views/error.haml +3 -0
  85. data/test/views/error.sass +2 -0
  86. data/test/views/explicitly_nested.str +1 -0
  87. data/test/views/foo/hello.test +1 -0
  88. data/test/views/hello.asciidoc +1 -0
  89. data/test/views/hello.builder +1 -0
  90. data/test/views/hello.coffee +1 -0
  91. data/test/views/hello.creole +1 -0
  92. data/test/views/hello.erb +1 -0
  93. data/test/views/hello.haml +1 -0
  94. data/test/views/hello.less +5 -0
  95. data/test/views/hello.liquid +1 -0
  96. data/test/views/hello.mab +1 -0
  97. data/test/views/hello.md +1 -0
  98. data/test/views/hello.mediawiki +1 -0
  99. data/test/views/hello.nokogiri +1 -0
  100. data/test/views/hello.rabl +2 -0
  101. data/test/views/hello.radius +1 -0
  102. data/test/views/hello.rdoc +1 -0
  103. data/test/views/hello.sass +2 -0
  104. data/test/views/hello.scss +3 -0
  105. data/test/views/hello.slim +1 -0
  106. data/test/views/hello.str +1 -0
  107. data/test/views/hello.styl +2 -0
  108. data/test/views/hello.test +1 -0
  109. data/test/views/hello.textile +1 -0
  110. data/test/views/hello.wlang +1 -0
  111. data/test/views/hello.yajl +1 -0
  112. data/test/views/layout2.builder +3 -0
  113. data/test/views/layout2.erb +2 -0
  114. data/test/views/layout2.haml +2 -0
  115. data/test/views/layout2.liquid +2 -0
  116. data/test/views/layout2.mab +2 -0
  117. data/test/views/layout2.nokogiri +3 -0
  118. data/test/views/layout2.rabl +3 -0
  119. data/test/views/layout2.radius +2 -0
  120. data/test/views/layout2.slim +3 -0
  121. data/test/views/layout2.str +2 -0
  122. data/test/views/layout2.test +1 -0
  123. data/test/views/layout2.wlang +2 -0
  124. data/test/views/nested.str +1 -0
  125. data/test/views/utf8.erb +2 -0
  126. data/test/wlang_test.rb +87 -0
  127. data/test/yajl_test.rb +86 -0
  128. metadata +280 -0
@@ -0,0 +1,100 @@
1
+ # Copyright (c) 2009 Damian Janowski and Michel Martens for Citrusbyte
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+ require "test/unit"
21
+
22
+ # Test::Unit loads a default test if the suite is empty, whose purpose is to
23
+ # fail. Since having empty contexts is a common practice, we decided to
24
+ # overwrite TestSuite#empty? in order to allow them. Having a failure when no
25
+ # tests have been defined seems counter-intuitive.
26
+ class Test::Unit::TestSuite
27
+ def empty?
28
+ false
29
+ end
30
+ end
31
+
32
+ # Contest adds +teardown+, +test+ and +context+ as class methods, and the
33
+ # instance methods +setup+ and +teardown+ now iterate on the corresponding
34
+ # blocks. Note that all setup and teardown blocks must be defined with the
35
+ # block syntax. Adding setup or teardown instance methods defeats the purpose
36
+ # of this library.
37
+ class Test::Unit::TestCase
38
+ def self.setup(&block) setup_blocks << block end
39
+ def self.teardown(&block) teardown_blocks << block end
40
+ def self.setup_blocks() @setup_blocks ||= [] end
41
+ def self.teardown_blocks() @teardown_blocks ||= [] end
42
+
43
+ def setup_blocks(base = self.class)
44
+ setup_blocks base.superclass if base.superclass.respond_to? :setup_blocks
45
+ base.setup_blocks.each do |block|
46
+ instance_eval(&block)
47
+ end
48
+ end
49
+
50
+ def teardown_blocks(base = self.class)
51
+ teardown_blocks base.superclass if base.superclass.respond_to? :teardown_blocks
52
+ base.teardown_blocks.each do |block|
53
+ instance_eval(&block)
54
+ end
55
+ end
56
+
57
+ alias setup setup_blocks
58
+ alias teardown teardown_blocks
59
+
60
+ def self.context(*name, &block)
61
+ subclass = Class.new(self)
62
+ remove_tests(subclass)
63
+ subclass.class_eval(&block) if block_given?
64
+ const_set(context_name(name.join(" ")), subclass)
65
+ end
66
+
67
+ def self.test(name, &block)
68
+ define_method(test_name(name), &block)
69
+ end
70
+
71
+ class << self
72
+ alias_method :should, :test
73
+ alias_method :describe, :context
74
+ end
75
+
76
+ private
77
+
78
+ def self.context_name(name)
79
+ # "Test#{sanitize_name(name).gsub(/(^| )(\w)/) { $2.upcase }}".to_sym
80
+ name = "Test#{sanitize_name(name).gsub(/(^| )(\w)/) { $2.upcase }}"
81
+ name.tr(" ", "_").to_sym
82
+ end
83
+
84
+ def self.test_name(name)
85
+ name = "test_#{sanitize_name(name).gsub(/\s+/,'_')}_0"
86
+ name = name.succ while method_defined? name
87
+ name.to_sym
88
+ end
89
+
90
+ def self.sanitize_name(name)
91
+ # name.gsub(/\W+/, ' ').strip
92
+ name.gsub(/\W+/, ' ')
93
+ end
94
+
95
+ def self.remove_tests(subclass)
96
+ subclass.public_instance_methods.grep(/^test_/).each do |meth|
97
+ subclass.send(:undef_method, meth.to_sym)
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,65 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ begin
4
+ require 'creole'
5
+
6
+ class CreoleTest < Test::Unit::TestCase
7
+ def creole_app(&block)
8
+ mock_app do
9
+ set :views, File.dirname(__FILE__) + '/views'
10
+ get('/', &block)
11
+ end
12
+ get '/'
13
+ end
14
+
15
+ it 'renders inline creole strings' do
16
+ creole_app { creole '= Hiya' }
17
+ assert ok?
18
+ assert_body "<h1>Hiya</h1>"
19
+ end
20
+
21
+ it 'renders .creole files in views path' do
22
+ creole_app { creole :hello }
23
+ assert ok?
24
+ assert_body "<h1>Hello From Creole</h1>"
25
+ end
26
+
27
+ it "raises error if template not found" do
28
+ mock_app { get('/') { creole :no_such_template } }
29
+ assert_raise(Errno::ENOENT) { get('/') }
30
+ end
31
+
32
+ it "renders with inline layouts" do
33
+ mock_app do
34
+ layout { 'THIS. IS. #{yield.upcase}!' }
35
+ get('/') { creole 'Sparta', :layout_engine => :str }
36
+ end
37
+ get '/'
38
+ assert ok?
39
+ assert_like 'THIS. IS. <P>SPARTA</P>!', body
40
+ end
41
+
42
+ it "renders with file layouts" do
43
+ creole_app do
44
+ creole 'Hello World', :layout => :layout2, :layout_engine => :erb
45
+ end
46
+ assert ok?
47
+ assert_body "ERB Layout!\n<p>Hello World</p>"
48
+ end
49
+
50
+ it "can be used in a nested fashion for partials and whatnot" do
51
+ mock_app do
52
+ template(:inner) { "hi" }
53
+ template(:outer) { "<outer><%= creole :inner %></outer>" }
54
+ get('/') { erb :outer }
55
+ end
56
+
57
+ get '/'
58
+ assert ok?
59
+ assert_like '<outer><p>hi</p></outer>', body
60
+ end
61
+ end
62
+
63
+ rescue LoadError
64
+ warn "#{$!.to_s}: skipping creole tests"
65
+ end
@@ -0,0 +1,160 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class DelegatorTest < Test::Unit::TestCase
4
+ class Mirror
5
+ attr_reader :last_call
6
+ def method_missing(*a, &b)
7
+ @last_call = [*a.map(&:to_s)]
8
+ @last_call << b if b
9
+ end
10
+ end
11
+
12
+ def self.delegates(name)
13
+ it "delegates #{name}" do
14
+ m = mirror { send name }
15
+ assert_equal [name.to_s], m.last_call
16
+ end
17
+
18
+ it "delegates #{name} with arguments" do
19
+ m = mirror { send name, "foo", "bar" }
20
+ assert_equal [name.to_s, "foo", "bar"], m.last_call
21
+ end
22
+
23
+ it "delegates #{name} with block" do
24
+ block = proc { }
25
+ m = mirror { send(name, &block) }
26
+ assert_equal [name.to_s, block], m.last_call
27
+ end
28
+ end
29
+
30
+ setup do
31
+ @target_was = Sinatra::Delegator.target
32
+ end
33
+
34
+ def teardown
35
+ Sinatra::Delegator.target = @target_was
36
+ end
37
+
38
+ def delegation_app(&block)
39
+ mock_app { Sinatra::Delegator.target = self }
40
+ delegate(&block)
41
+ end
42
+
43
+ def mirror(&block)
44
+ mirror = Mirror.new
45
+ Sinatra::Delegator.target = mirror
46
+ delegate(&block)
47
+ end
48
+
49
+ def delegate(&block)
50
+ assert Sinatra::Delegator.target != Sinatra::Application
51
+ Object.new.extend(Sinatra::Delegator).instance_eval(&block) if block
52
+ Sinatra::Delegator.target
53
+ end
54
+
55
+ def target
56
+ Sinatra::Delegator.target
57
+ end
58
+
59
+ it 'defaults to Sinatra::Application as target' do
60
+ assert_equal Sinatra::Application, Sinatra::Delegator.target
61
+ end
62
+
63
+ %w[get put post delete options patch link unlink].each do |verb|
64
+ it "delegates #{verb} correctly" do
65
+ delegation_app do
66
+ send(verb, '/hello') { 'Hello World' }
67
+ end
68
+
69
+ request = Rack::MockRequest.new(@app)
70
+ response = request.request(verb.upcase, '/hello', {})
71
+ assert response.ok?
72
+ assert_equal 'Hello World', response.body
73
+ end
74
+ end
75
+
76
+ it "delegates head correctly" do
77
+ delegation_app do
78
+ head '/hello' do
79
+ response['X-Hello'] = 'World!'
80
+ 'remove me'
81
+ end
82
+ end
83
+
84
+ request = Rack::MockRequest.new(@app)
85
+ response = request.request('HEAD', '/hello', {})
86
+ assert response.ok?
87
+ assert_equal 'World!', response['X-Hello']
88
+ assert_equal '', response.body
89
+ end
90
+
91
+ it "registers extensions with the delegation target" do
92
+ app, mixin = mirror, Module.new
93
+ Sinatra.register mixin
94
+ assert_equal ["register", mixin.to_s], app.last_call
95
+ end
96
+
97
+ it "registers helpers with the delegation target" do
98
+ app, mixin = mirror, Module.new
99
+ Sinatra.helpers mixin
100
+ assert_equal ["helpers", mixin.to_s], app.last_call
101
+ end
102
+
103
+ it "registers middleware with the delegation target" do
104
+ app, mixin = mirror, Module.new
105
+ Sinatra.use mixin
106
+ assert_equal ["use", mixin.to_s], app.last_call
107
+ end
108
+
109
+ it "should work with method_missing proxies for options" do
110
+ mixin = Module.new do
111
+ def respond_to?(method, *)
112
+ method.to_sym == :options or super
113
+ end
114
+
115
+ def method_missing(method, *args, &block)
116
+ return super unless method.to_sym == :options
117
+ {:some => :option}
118
+ end
119
+ end
120
+
121
+ value = nil
122
+ mirror do
123
+ extend mixin
124
+ value = options
125
+ end
126
+
127
+ assert_equal({:some => :option}, value)
128
+ end
129
+
130
+ it "delegates crazy method names" do
131
+ Sinatra::Delegator.delegate "foo:bar:"
132
+ method = mirror { send "foo:bar:" }.last_call.first
133
+ assert_equal "foo:bar:", method
134
+ end
135
+
136
+ delegates 'get'
137
+ delegates 'patch'
138
+ delegates 'put'
139
+ delegates 'post'
140
+ delegates 'delete'
141
+ delegates 'head'
142
+ delegates 'options'
143
+ delegates 'template'
144
+ delegates 'layout'
145
+ delegates 'before'
146
+ delegates 'after'
147
+ delegates 'error'
148
+ delegates 'not_found'
149
+ delegates 'configure'
150
+ delegates 'set'
151
+ delegates 'mime_type'
152
+ delegates 'enable'
153
+ delegates 'disable'
154
+ delegates 'use'
155
+ delegates 'development?'
156
+ delegates 'test?'
157
+ delegates 'production?'
158
+ delegates 'helpers'
159
+ delegates 'settings'
160
+ end
@@ -0,0 +1,20 @@
1
+ # encoding: UTF-8
2
+ require File.expand_path('../helper', __FILE__)
3
+ require 'erb'
4
+
5
+ class BaseTest < Test::Unit::TestCase
6
+ setup do
7
+ @base = Sinatra.new(Sinatra::Base)
8
+ @base.set :views, File.dirname(__FILE__) + "/views"
9
+ end
10
+
11
+ it 'allows unicode strings in ascii templates per default (1.9)' do
12
+ next unless defined? Encoding
13
+ @base.new!.erb(File.read(@base.views + "/ascii.erb").encode("ASCII"), {}, :value => "åkej")
14
+ end
15
+
16
+ it 'allows ascii strings in unicode templates per default (1.9)' do
17
+ next unless defined? Encoding
18
+ @base.new!.erb(:utf8, {}, :value => "Some Lyrics".encode("ASCII"))
19
+ end
20
+ end
@@ -0,0 +1,116 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class ERBTest < Test::Unit::TestCase
4
+ def engine
5
+ Tilt::ERBTemplate
6
+ end
7
+
8
+ def setup
9
+ Tilt.prefer engine, :erb
10
+ super
11
+ end
12
+
13
+ def erb_app(&block)
14
+ mock_app do
15
+ set :views, File.dirname(__FILE__) + '/views'
16
+ get('/', &block)
17
+ end
18
+ get '/'
19
+ end
20
+
21
+ it 'uses the correct engine' do
22
+ assert_equal engine, Tilt[:erb]
23
+ end
24
+
25
+ it 'renders inline ERB strings' do
26
+ erb_app { erb '<%= 1 + 1 %>' }
27
+ assert ok?
28
+ assert_equal '2', body
29
+ end
30
+
31
+ it 'renders .erb files in views path' do
32
+ erb_app { erb :hello }
33
+ assert ok?
34
+ assert_equal "Hello World\n", body
35
+ end
36
+
37
+ it 'takes a :locals option' do
38
+ erb_app do
39
+ locals = {:foo => 'Bar'}
40
+ erb '<%= foo %>', :locals => locals
41
+ end
42
+ assert ok?
43
+ assert_equal 'Bar', body
44
+ end
45
+
46
+ it "renders with inline layouts" do
47
+ mock_app do
48
+ layout { 'THIS. IS. <%= yield.upcase %>!' }
49
+ get('/') { erb 'Sparta' }
50
+ end
51
+ get '/'
52
+ assert ok?
53
+ assert_equal 'THIS. IS. SPARTA!', body
54
+ end
55
+
56
+ it "renders with file layouts" do
57
+ erb_app { erb 'Hello World', :layout => :layout2 }
58
+ assert ok?
59
+ assert_body "ERB Layout!\nHello World"
60
+ end
61
+
62
+ it "renders erb with blocks" do
63
+ mock_app do
64
+ def container
65
+ @_out_buf << "THIS."
66
+ yield
67
+ @_out_buf << "SPARTA!"
68
+ end
69
+ def is; "IS." end
70
+ get('/') { erb '<% container do %> <%= is %> <% end %>' }
71
+ end
72
+ get '/'
73
+ assert ok?
74
+ assert_equal 'THIS. IS. SPARTA!', body
75
+ end
76
+
77
+ it "can be used in a nested fashion for partials and whatnot" do
78
+ mock_app do
79
+ template(:inner) { "<inner><%= 'hi' %></inner>" }
80
+ template(:outer) { "<outer><%= erb :inner %></outer>" }
81
+ get('/') { erb :outer }
82
+ end
83
+
84
+ get '/'
85
+ assert ok?
86
+ assert_equal '<outer><inner>hi</inner></outer>', body
87
+ end
88
+
89
+ it "can render truly nested layouts by accepting a layout and a block with the contents" do
90
+ mock_app do
91
+ template(:main_outer_layout) { "<h1>Title</h1>\n<%= yield %>" }
92
+ template(:an_inner_layout) { "<h2>Subtitle</h2>\n<%= yield %>" }
93
+ template(:a_page) { "<p>Contents.</p>\n" }
94
+ get('/') do
95
+ erb :main_outer_layout, :layout => false do
96
+ erb :an_inner_layout do
97
+ erb :a_page
98
+ end
99
+ end
100
+ end
101
+ end
102
+ get '/'
103
+ assert ok?
104
+ assert_body "<h1>Title</h1>\n<h2>Subtitle</h2>\n<p>Contents.</p>\n"
105
+ end
106
+ end
107
+
108
+
109
+ begin
110
+ require 'erubis'
111
+ class ErubisTest < ERBTest
112
+ def engine; Tilt::ErubisTemplate end
113
+ end
114
+ rescue LoadError
115
+ warn "#{$!.to_s}: skipping erubis tests"
116
+ end