mongrel2 0.0.1

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.
Files changed (70) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.gemtest +0 -0
  3. data/History.rdoc +4 -0
  4. data/Manifest.txt +66 -0
  5. data/README.rdoc +169 -0
  6. data/Rakefile +77 -0
  7. data/bin/m2sh.rb +600 -0
  8. data/data/mongrel2/bootstrap.html +25 -0
  9. data/data/mongrel2/config.sql +84 -0
  10. data/data/mongrel2/mimetypes.sql +855 -0
  11. data/examples/README.txt +6 -0
  12. data/examples/config.rb +54 -0
  13. data/examples/helloworld-handler.rb +31 -0
  14. data/examples/request-dumper.rb +45 -0
  15. data/examples/request-dumper.tmpl +71 -0
  16. data/examples/run +17 -0
  17. data/lib/mongrel2.rb +62 -0
  18. data/lib/mongrel2/config.rb +212 -0
  19. data/lib/mongrel2/config/directory.rb +78 -0
  20. data/lib/mongrel2/config/dsl.rb +206 -0
  21. data/lib/mongrel2/config/handler.rb +124 -0
  22. data/lib/mongrel2/config/host.rb +88 -0
  23. data/lib/mongrel2/config/log.rb +48 -0
  24. data/lib/mongrel2/config/mimetype.rb +15 -0
  25. data/lib/mongrel2/config/proxy.rb +15 -0
  26. data/lib/mongrel2/config/route.rb +51 -0
  27. data/lib/mongrel2/config/server.rb +58 -0
  28. data/lib/mongrel2/config/setting.rb +15 -0
  29. data/lib/mongrel2/config/statistic.rb +23 -0
  30. data/lib/mongrel2/connection.rb +212 -0
  31. data/lib/mongrel2/constants.rb +159 -0
  32. data/lib/mongrel2/control.rb +165 -0
  33. data/lib/mongrel2/exceptions.rb +59 -0
  34. data/lib/mongrel2/handler.rb +309 -0
  35. data/lib/mongrel2/httprequest.rb +51 -0
  36. data/lib/mongrel2/httpresponse.rb +187 -0
  37. data/lib/mongrel2/jsonrequest.rb +43 -0
  38. data/lib/mongrel2/logging.rb +241 -0
  39. data/lib/mongrel2/mixins.rb +143 -0
  40. data/lib/mongrel2/request.rb +148 -0
  41. data/lib/mongrel2/response.rb +74 -0
  42. data/lib/mongrel2/table.rb +216 -0
  43. data/lib/mongrel2/xmlrequest.rb +36 -0
  44. data/spec/lib/constants.rb +237 -0
  45. data/spec/lib/helpers.rb +246 -0
  46. data/spec/lib/matchers.rb +50 -0
  47. data/spec/mongrel2/config/directory_spec.rb +91 -0
  48. data/spec/mongrel2/config/dsl_spec.rb +218 -0
  49. data/spec/mongrel2/config/handler_spec.rb +118 -0
  50. data/spec/mongrel2/config/host_spec.rb +30 -0
  51. data/spec/mongrel2/config/log_spec.rb +95 -0
  52. data/spec/mongrel2/config/proxy_spec.rb +30 -0
  53. data/spec/mongrel2/config/route_spec.rb +83 -0
  54. data/spec/mongrel2/config/server_spec.rb +84 -0
  55. data/spec/mongrel2/config/setting_spec.rb +30 -0
  56. data/spec/mongrel2/config/statistic_spec.rb +30 -0
  57. data/spec/mongrel2/config_spec.rb +111 -0
  58. data/spec/mongrel2/connection_spec.rb +172 -0
  59. data/spec/mongrel2/constants_spec.rb +32 -0
  60. data/spec/mongrel2/control_spec.rb +192 -0
  61. data/spec/mongrel2/handler_spec.rb +261 -0
  62. data/spec/mongrel2/httpresponse_spec.rb +232 -0
  63. data/spec/mongrel2/logging_spec.rb +76 -0
  64. data/spec/mongrel2/mixins_spec.rb +62 -0
  65. data/spec/mongrel2/request_spec.rb +157 -0
  66. data/spec/mongrel2/response_spec.rb +81 -0
  67. data/spec/mongrel2/table_spec.rb +176 -0
  68. data/spec/mongrel2_spec.rb +34 -0
  69. metadata +294 -0
  70. metadata.gz.sig +0 -0
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ BEGIN {
4
+ require 'pathname'
5
+ basedir = Pathname.new( __FILE__ ).dirname.parent.parent.parent
6
+
7
+ libdir = basedir + "lib"
8
+
9
+ $LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
10
+ $LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
11
+ }
12
+
13
+ require 'rspec'
14
+
15
+ require 'spec/lib/helpers'
16
+
17
+ require 'mongrel2'
18
+ require 'mongrel2/config'
19
+
20
+
21
+ #####################################################################
22
+ ### C O N T E X T S
23
+ #####################################################################
24
+
25
+ describe Mongrel2::Config::Host do
26
+
27
+ # No functionality outside of Sequel::Model's purview yet
28
+
29
+ end
30
+
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ BEGIN {
4
+ require 'pathname'
5
+ basedir = Pathname.new( __FILE__ ).dirname.parent.parent.parent
6
+
7
+ libdir = basedir + "lib"
8
+
9
+ $LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
10
+ $LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
11
+ }
12
+
13
+ require 'socket'
14
+ require 'rspec'
15
+
16
+ require 'spec/lib/constants'
17
+ require 'spec/lib/helpers'
18
+
19
+ require 'mongrel2'
20
+ require 'mongrel2/config'
21
+
22
+
23
+ #####################################################################
24
+ ### C O N T E X T S
25
+ #####################################################################
26
+
27
+ describe Mongrel2::Config::Log do
28
+
29
+ before( :all ) do
30
+ setup_logging( :fatal )
31
+ setup_config_db()
32
+ end
33
+
34
+ after( :all ) do
35
+ reset_logging()
36
+ end
37
+
38
+
39
+ it "has a convenience method for writing to the commit log" do
40
+ what = 'load etc/mongrel2.conf'
41
+ why = 'updating'
42
+ where = 'localhost'
43
+ how = 'm2sh'
44
+
45
+ log = Mongrel2::Config::Log.log_action( what, why, where, how )
46
+
47
+ log.what.should == what
48
+ log.why.should == why
49
+ log.location.should == where
50
+ log.how.should == how
51
+ end
52
+
53
+ it "has reasonable defaults for 'where' and 'how'" do
54
+ what = 'load etc/mongrel2.conf'
55
+ why = 'updating'
56
+
57
+ log = Mongrel2::Config::Log.log_action( what, why )
58
+
59
+ log.location.should == Socket.gethostname
60
+ log.how.should == File.basename( $0 )
61
+ end
62
+
63
+ describe "an entry" do
64
+
65
+ before( :each ) do
66
+ @log = Mongrel2::Config::Log.new(
67
+ who: 'who',
68
+ what: 'what',
69
+ location: 'location',
70
+ happened_at: Time.at( 1315598592 ),
71
+ how: 'how',
72
+ why: 'why'
73
+ )
74
+ end
75
+
76
+
77
+ it "stringifies as a readable log file line" do
78
+
79
+ # 2011-09-09 20:29:47 -0700 [mgranger] @localhost m2sh: load etc/mongrel2.conf (updating)
80
+ @log.to_s.should =~ %r{
81
+ ^
82
+ (?-x:\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} [\+\-]\d{4} )
83
+ \[who\] \s
84
+ @location \s
85
+ how: \s
86
+ what \s
87
+ \(why\)
88
+ $
89
+ }x
90
+ end
91
+
92
+ end
93
+
94
+ end
95
+
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ BEGIN {
4
+ require 'pathname'
5
+ basedir = Pathname.new( __FILE__ ).dirname.parent.parent.parent
6
+
7
+ libdir = basedir + "lib"
8
+
9
+ $LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
10
+ $LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
11
+ }
12
+
13
+ require 'rspec'
14
+
15
+ require 'spec/lib/helpers'
16
+
17
+ require 'mongrel2'
18
+ require 'mongrel2/config'
19
+
20
+
21
+ #####################################################################
22
+ ### C O N T E X T S
23
+ #####################################################################
24
+
25
+ describe Mongrel2::Config::Proxy do
26
+
27
+ # No functionality outside of Sequel::Model's purview yet
28
+
29
+ end
30
+
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ BEGIN {
4
+ require 'pathname'
5
+ basedir = Pathname.new( __FILE__ ).dirname.parent.parent.parent
6
+
7
+ libdir = basedir + "lib"
8
+
9
+ $LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
10
+ $LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
11
+ }
12
+
13
+ require 'rspec'
14
+
15
+ require 'spec/lib/helpers'
16
+
17
+ require 'mongrel2'
18
+ require 'mongrel2/config'
19
+
20
+
21
+ #####################################################################
22
+ ### C O N T E X T S
23
+ #####################################################################
24
+
25
+ describe Mongrel2::Config::Route do
26
+
27
+ before( :all ) do
28
+ setup_logging()
29
+ Mongrel2::Config.configure( :configdb => ':memory:' )
30
+ Mongrel2::Config.init_database
31
+ end
32
+
33
+ before( :each ) do
34
+ @route = Mongrel2::Config::Route.new( :path => '' )
35
+ end
36
+
37
+ after( :all ) do
38
+ reset_logging()
39
+ end
40
+
41
+ it "returns a Mongrel2::Config::Directory if its target_type is 'dir'" do
42
+ dir = Mongrel2::Config::Directory.create(
43
+ :base => 'var/www/',
44
+ :default_ctype => 'text/plain',
45
+ :index_file => 'index.html' )
46
+
47
+ @route.target_type = 'dir'
48
+ @route.target_id = dir.id
49
+
50
+ @route.target.should == dir
51
+ end
52
+
53
+ it "returns a Mongrel2::Config::Proxy if its target_type is 'proxy'" do
54
+ proxy = Mongrel2::Config::Proxy.create( :addr => '10.2.18.8' )
55
+
56
+ @route.target_type = 'proxy'
57
+ @route.target_id = proxy.id
58
+
59
+ @route.target.should == proxy
60
+ end
61
+
62
+ it "returns a Mongrel2::Config::Handler if its target_type is 'handler'" do
63
+ handler = Mongrel2::Config::Handler.create(
64
+ :send_ident => TEST_UUID,
65
+ :send_spec => 'tcp://127.0.0.1:9998',
66
+ :recv_spec => 'tcp://127.0.0.1:9997' )
67
+
68
+ @route.target_type = 'handler'
69
+ @route.target_id = handler.id
70
+
71
+ @route.target.should == handler
72
+ end
73
+
74
+ it "raises an exception if its target_type is set to something invalid" do
75
+ @route.target_type = 'giraffes'
76
+
77
+ expect {
78
+ @route.target
79
+ }.to raise_error( ArgumentError, /unknown target type/i )
80
+ end
81
+
82
+ end
83
+
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ BEGIN {
4
+ require 'pathname'
5
+ basedir = Pathname.new( __FILE__ ).dirname.parent.parent.parent
6
+
7
+ libdir = basedir + "lib"
8
+
9
+ $LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
10
+ $LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
11
+ }
12
+
13
+ require 'rspec'
14
+
15
+ require 'spec/lib/helpers'
16
+
17
+ require 'mongrel2'
18
+ require 'mongrel2/config'
19
+
20
+
21
+ #####################################################################
22
+ ### C O N T E X T S
23
+ #####################################################################
24
+
25
+ describe Mongrel2::Config::Server do
26
+
27
+ before( :all ) do
28
+ setup_logging( :fatal )
29
+ setup_config_db()
30
+ end
31
+
32
+ before( :each ) do
33
+ @server = Mongrel2::Config::Server.new(
34
+ uuid: TEST_UUID,
35
+ access_log: '/logs/access.log',
36
+ error_log: '/logs/error.log',
37
+ pid_file: '/run/mongrel2.pid',
38
+ default_host: 'localhost',
39
+ port: 8118
40
+ )
41
+ end
42
+
43
+ after( :all ) do
44
+ reset_logging()
45
+ end
46
+
47
+
48
+ it "is valid if its access_log, error_log, pid_file, default_host, and port are all valid" do
49
+ @server.should be_valid()
50
+ end
51
+
52
+ it "isn't valid if it doesn't have an access_log path" do
53
+ @server.access_log = nil
54
+ @server.should_not be_valid()
55
+ @server.errors.full_messages.first.should =~ /missing or nil/i
56
+ end
57
+
58
+ it "isn't valid if it doesn't have an error_log path" do
59
+ @server.error_log = nil
60
+ @server.should_not be_valid()
61
+ @server.errors.full_messages.first.should =~ /missing or nil/i
62
+ end
63
+
64
+ it "isn't valid if it doesn't have an pid_file path" do
65
+ @server.pid_file = nil
66
+ @server.should_not be_valid()
67
+ @server.errors.full_messages.first.should =~ /missing or nil/i
68
+ end
69
+
70
+ it "isn't valid if it doesn't have a default_host" do
71
+ @server.default_host = nil
72
+ @server.should_not be_valid()
73
+ @server.errors.full_messages.first.should =~ /missing or nil/i
74
+ end
75
+
76
+ it "isn't valid if it doesn't specify a port" do
77
+ @server.port = nil
78
+ @server.should_not be_valid()
79
+ @server.errors.full_messages.first.should =~ /missing or nil/i
80
+ end
81
+
82
+
83
+ end
84
+
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ BEGIN {
4
+ require 'pathname'
5
+ basedir = Pathname.new( __FILE__ ).dirname.parent.parent.parent
6
+
7
+ libdir = basedir + "lib"
8
+
9
+ $LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
10
+ $LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
11
+ }
12
+
13
+ require 'rspec'
14
+
15
+ require 'spec/lib/helpers'
16
+
17
+ require 'mongrel2'
18
+ require 'mongrel2/config'
19
+
20
+
21
+ #####################################################################
22
+ ### C O N T E X T S
23
+ #####################################################################
24
+
25
+ describe Mongrel2::Config::Setting do
26
+
27
+ # No functionality outside of Sequel::Model's purview yet
28
+
29
+ end
30
+
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ BEGIN {
4
+ require 'pathname'
5
+ basedir = Pathname.new( __FILE__ ).dirname.parent.parent.parent
6
+
7
+ libdir = basedir + "lib"
8
+
9
+ $LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
10
+ $LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
11
+ }
12
+
13
+ require 'rspec'
14
+
15
+ require 'spec/lib/helpers'
16
+
17
+ require 'mongrel2'
18
+ require 'mongrel2/config'
19
+
20
+
21
+ #####################################################################
22
+ ### C O N T E X T S
23
+ #####################################################################
24
+
25
+ describe Mongrel2::Config::Statistic do
26
+
27
+ # No functionality outside of Sequel::Model's purview yet
28
+
29
+ end
30
+
@@ -0,0 +1,111 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ BEGIN {
4
+ require 'pathname'
5
+ basedir = Pathname.new( __FILE__ ).dirname.parent.parent
6
+
7
+ libdir = basedir + "lib"
8
+
9
+ $LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
10
+ $LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
11
+ }
12
+
13
+ require 'rspec'
14
+
15
+ require 'spec/lib/helpers'
16
+
17
+ require 'mongrel2'
18
+ require 'mongrel2/config'
19
+
20
+
21
+ #####################################################################
22
+ ### C O N T E X T S
23
+ #####################################################################
24
+
25
+ describe Mongrel2::Config do
26
+
27
+ before( :all ) do
28
+ setup_logging()
29
+ setup_config_db()
30
+ end
31
+
32
+ after( :all ) do
33
+ reset_logging()
34
+ end
35
+
36
+
37
+ it "has a factory method for creating derivative classes" do
38
+ begin
39
+ model_class = Mongrel2::Config( :hookers )
40
+ model_class.should < Mongrel2::Config
41
+ model_class.dataset.first_source.should == :hookers
42
+ ensure
43
+ # Remove the example class from the list of subclasses so it
44
+ # doesn't affect later tests
45
+ Mongrel2::Config.subclasses.delete( model_class ) if model_class
46
+ end
47
+ end
48
+
49
+ it "can reset the database handle for the config classes" do
50
+ db = Mongrel2::Config.in_memory_db
51
+ Mongrel2::Config.db = db
52
+ Mongrel2::Config::Directory.db.should equal( db )
53
+ end
54
+
55
+ it "has a convenience method for fetching an Array of all of its configured servers" do
56
+ Mongrel2::Config.init_database
57
+ Mongrel2::Config::Server.dataset.truncate
58
+ s = Mongrel2::Config::Server.create(
59
+ uuid: TEST_UUID,
60
+ access_log: '/log/access.log',
61
+ error_log: '/log/error.log',
62
+ pid_file: '/run/m2.pid',
63
+ default_host: 'localhost',
64
+ port: 8275
65
+ )
66
+ Mongrel2::Config.servers.should have( 1 ).member
67
+ Mongrel2::Config.servers.first.uuid.should == TEST_UUID
68
+ end
69
+
70
+ it "can read the configuration schema from a data file" do
71
+ Mongrel2::Config.load_config_schema.should =~ /create table server/i
72
+ end
73
+
74
+ it "knows whether or not its database has been initialized" do
75
+ Mongrel2::Config.db = Mongrel2::Config.in_memory_db
76
+ Mongrel2::Config.database_initialized?.should be_false()
77
+ Mongrel2::Config.init_database!
78
+ Mongrel2::Config.database_initialized?.should be_true()
79
+ end
80
+
81
+ it "doesn't re-initialize the database if the non-bang version of init_database is used" do
82
+ Mongrel2::Config.db = Mongrel2::Config.in_memory_db
83
+ Mongrel2::Config.init_database
84
+
85
+ Mongrel2::Config.should_not_receive( :load_config_schema )
86
+ Mongrel2::Config.init_database
87
+ end
88
+
89
+ it "can return the path to the config DB as a Pathname if it's pointing at a file" do
90
+ Mongrel2::Config.db = Mongrel2::Config.adapter_method[ 'config-spec.sqlite' ]
91
+ Mongrel2::Config.pathname.should == Pathname( 'config-spec.sqlite' )
92
+ end
93
+
94
+ it "returns nil if asked for the pathname to an in-memory database" do
95
+ Mongrel2::Config.db = Mongrel2::Config.in_memory_db
96
+ Mongrel2::Config.pathname.should be_nil()
97
+ end
98
+
99
+ describe "Configurability support", :if => defined?( Configurability ) do
100
+ require 'configurability/behavior'
101
+
102
+ it_should_behave_like "an object with Configurability"
103
+
104
+ it "uses the 'mongrel2' config section" do
105
+ Mongrel2::Config.config_key.should == :mongrel2
106
+ end
107
+
108
+ end
109
+
110
+ end
111
+