1. Michael Granger
  2. ruby-mongrel2

Commits

Michael Granger  committed d0e689f

Config introspection and cleanup.

- Add Mongrel2::Config.mimetypes for fetching Mongrel2's mime-types table.
- Add more config introspection to the Mongrel2::Handler class.
- Fix spec syntax deprecated in RSpec 3.

  • Participants
  • Parent commits 243c948
  • Branches default

Comments (0)

Files changed (13)

File .rvm.gems

View file
  • Ignore whitespace
 amalgalite -v1.3.0
-configurability -v2.1.0
+configurability -v2.1.1
 hoe -v3.7.1
 hoe-bundler -v1.2.0
 hoe-deveiate -v0.3.0
 loggability -v0.7.0
-nokogiri -v1.6.0
-rdoc -v4.0.1
-sequel -v4.2.0
-simplecov -v0.7.1
+libxml-ruby -v2.7.0
+rdoc -v4.1.0
+sequel -v4.6.0
+simplecov -v0.8.2
 sqlite3 -v1.3.8
 sysexits -v1.1.0
 tnetstring -v0.3.4

File .simplecov

View file
  • Ignore whitespace
+# -*- ruby -*-
+#encoding: utf-8
+
+$stderr.puts "\n\n>>> Enabling coverage report.\n\n"
+
+SimpleCov.start do
+	add_filter 'spec'
+	add_group "Config Classes" do |file|
+		file.filename =~ %r{lib/mongrel2/config(\.rb|/.*)$}
+	end
+	add_group "Needing tests" do |file|
+		file.covered_percent < 90
+	end
+end

File Manifest.txt

View file
  • Ignore whitespace
 .autotest
 .gemtest
+.simplecov
 ChangeLog
 DSL.rdoc
 History.rdoc
 spec/mongrel2/response_spec.rb
 spec/mongrel2/table_spec.rb
 spec/mongrel2/websocket_spec.rb
+spec/mongrel2/xmlrequest_spec.rb
 spec/mongrel2_spec.rb

File Rakefile

View file
  • Ignore whitespace
 
 	self.developer 'Michael Granger', 'ged@FaerieMUD.org'
 
-	self.dependency 'nokogiri',   '~> 1.5'
-	self.dependency 'sequel',     '~> 4.2'
-	self.dependency 'tnetstring', '~> 0.3'
-	self.dependency 'yajl-ruby',  '~> 1.0'
-	self.dependency 'trollop',    '~> 2.0'
-	self.dependency 'sysexits',   '~> 1.1'
-	self.dependency 'zmq',        '~> 2.1'
-	self.dependency 'loggability','~> 0.5'
-	self.dependency 'sqlite3',    '~> 1.3'
+	self.dependency 'sequel',      '~> 4.2'
+	self.dependency 'tnetstring',  '~> 0.3'
+	self.dependency 'yajl-ruby',   '~> 1.0'
+	self.dependency 'trollop',     '~> 2.0'
+	self.dependency 'sysexits',    '~> 1.1'
+	self.dependency 'zmq',         '~> 2.1'
+	self.dependency 'loggability', '~> 0.5'
+	self.dependency 'sqlite3',     '~> 1.3'
+	self.dependency 'libxml-ruby', '~> 2.7'
 
 	self.dependency 'amalgalite',      '~> 1.3', :developer
 	self.dependency 'configurability', '~> 2.0', :developer

File lib/mongrel2/config.rb

View file
  • Ignore whitespace
 		end
 
 
+		### Return a Hash of current mimetypes from the config database keyed by extension.
+		def self::mimetypes
+			return Mongrel2::Config::Mimetype.to_hash( :extension, :mimetype )
+		end
+
+
 		### Return the contents of the configuration schema SQL file.
 		def self::load_config_schema
 			return CONFIG_SQL.read

File lib/mongrel2/handler.rb

View file
  • Ignore whitespace
 	### Create an instance of the handler using the config from the database with
 	### the given +appid+ and run it.
 	def self::run( appid )
-		self.log.info "Running application %p" % [ appid ]
+		app = self.app_instance_for( appid )
+		self.log.info "Running application %p: %p" % [ appid, app ]
+		app.run
+	end
+
+
+	### Return an instance of the handler configured for the handler in the currently-loaded
+	### Mongrel2 config that corresponds to +appid+.
+	def self::app_instance_for( appid )
 		send_spec, recv_spec = self.connection_info_for( appid )
 		self.log.info "  config specs: %s <-> %s" % [ send_spec, recv_spec ]
-		new( appid, send_spec, recv_spec ).run
+		return new( appid, send_spec, recv_spec )
 	end
 
 
 
 
 	### Return the Mongrel2::Config::Handler that corresponds to this app's
+	### appid, and its connection's send_spec and recv_spec.
+	def handler_config
+		return self.configured_handlers.where(
+			send_spec: self.conn.sub_addr,
+			recv_spec: self.conn.pub_addr
+		).first
+	end
+
+
+	### Return the Mongrel2::Config::Handlers that corresponds to this app's
 	### appid.
-	def handler_config
-		return Mongrel2::Config::Handler.by_send_ident( self.app_id ).first
+	def configured_handlers
+		return Mongrel2::Config::Handler.by_send_ident( self.app_id )
+	end
+
+
+	### Return the Mongre2::Config::Routes for this Handler.
+	def configured_routes
+		handlers = self.configured_handlers
+		return Mongrel2::Config::Route.where( target_id: handlers.select(:id) )
+	end
+
+
+	### Return the Mongrel2::Config::Hosts that have routes that point to this
+	### Handler.
+	def configured_hosts
+		routes = self.configured_routes
+		return Mongrel2::Config::Host.where( id: routes.select(:host_id) )
+	end
+
+
+	### Return the Mongrel2::Config::Servers that have hosts that have routes that
+	### point to this Handler.
+	def configured_servers
+		hosts = self.configured_hosts
+		return Mongrel2::Config::Server.where( id: hosts.select(:server_id) )
 	end
 
 

File spec/helpers.rb

View file
  • Ignore whitespace
 require_relative 'matchers'
 
 # SimpleCov test coverage reporting; enable this using the :coverage rake task
-if ENV['COVERAGE']
-	$stderr.puts "\n\n>>> Enabling coverage report.\n\n"
-	require 'simplecov'
-	SimpleCov.start do
-		add_filter 'spec'
-		add_group "Config Classes" do |file|
-			file.filename =~ %r{lib/mongrel2/config(\.rb|/.*)$}
-		end
-		add_group "Needing tests" do |file|
-			file.covered_percent < 90
-		end
-	end
-end
+require 'simplecov' if ENV['COVERAGE']
 
 begin
 	require 'configurability'

File spec/mongrel2/config/dsl_spec.rb

View file
  • Ignore whitespace
 			end
 
 			expect( result ).to be_a( Mongrel2::Config::Server )
-			expect( result.hosts ).to have( 1 ).member
+			expect( result.hosts.size ).to eq(  1  )
 			host = result.hosts.first
 
 			expect( host ).to be_a( Mongrel2::Config::Host )
 			end
 
 			expect( result ).to be_a( Mongrel2::Config::Server )
-			expect( result.hosts ).to have( 2 ).members
+			expect( result.hosts.size ).to eq(  2  )
 			host1, host2 = result.hosts
 
 			expect( host1 ).to be_a( Mongrel2::Config::Host )
 			expect( host1.name ).to eq( 'brillianttaste' )
 			expect( host1.matching ).to eq( '*.brillianttasteinthefoodmouth.com' )
-			expect( host1.routes ).to have( 6 ).members
+			expect( host1.routes.size ).to eq(  6  )
 			expect( host1.routes ).to all_be_a( Mongrel2::Config::Route )
 
 			expect( host1.routes[0].path ).to eq( '/images' )
 
 			expect( host2 ).to be_a( Mongrel2::Config::Host )
 			expect( host2.name ).to eq( 'deveiate.org' )
-			expect( host2.routes ).to have( 1 ).member
+			expect( host2.routes.size ).to eq(  1  )
 			expect( host2.routes.first ).to be_a( Mongrel2::Config::Route )
 		end
 
 			)
 
 			expect( result ).to be_an( Array )
-			expect( result ).to have( 3 ).members
+			expect( result.size ).to eq(  3  )
 			expect( result ).to all_be_a( Mongrel2::Config::Setting )
 			expect( result[0].key ).to eq( 'zeromq.threads' )
 			expect( result[0].value ).to eq( '8' )
 			)
 
 			expect( result ).to be_an( Array )
-			expect( result ).to have( 2 ).members
+			expect( result.size ).to eq(  2  )
 			expect( result ).to all_be_a( Mongrel2::Config::Mimetype )
 			expect( result[0].extension ).to eq( '.md' )
 			expect( result[0].mimetype ).to eq( 'text/x-markdown' )
 				filter '/usr/lib/mongrel2/null.so'
 			end
 
-			expect( result.filters ).to have( 1 ).member
+			expect( result.filters.size ).to eq(  1  )
 			expect( result.filters.first ).to be_a( Mongrel2::Config::Filter )
 			expect( result.filters.first.settings ).to eq( {} )
 		end
 					min_size: 1000
 			end
 
-			expect( result.filters ).to have( 1 ).member
+			expect( result.filters.size ).to eq(  1  )
 			expect( result.filters.first ).to be_a( Mongrel2::Config::Filter )
 			expect( result.filters.first.settings ).
 				to eq({ 'extensions' => ["*.html", "*.txt"], 'min_size' => 1000 })
 				xrequest '/usr/lib/mongrel2/null.so'
 			end
 
-			expect( result.xrequests ).to have( 1 ).member
+			expect( result.xrequests.size ).to eq(  1  )
 			expect( result.xrequests.first ).to be_a( Mongrel2::Config::XRequest )
 			expect( result.xrequests.first.settings ).to eq( {} )
 		end
 					min_size: 1000
 			end
 
-			expect( result.xrequests ).to have( 1 ).member
+			expect( result.xrequests.size ).to eq(  1  )
 			expect( result.xrequests.first ).to be_a( Mongrel2::Config::XRequest )
 			expect( result.xrequests.first.settings ).
 				to eq({ 'extensions' => ["*.html", "*.txt"], 'min_size' => 1000 })

File spec/mongrel2/config/server_spec.rb

View file
  • Ignore whitespace
 	end
 
 	it "has a predicate that understands the use_ssl value" do
-		expect( @server.use_ssl ).to be_false()
+		expect( @server.use_ssl ).to be_falsey()
 		@server.use_ssl = true
-		expect( @server.use_ssl ).to be_true()
+		expect( @server.use_ssl ).to be_truthy()
 	end
 
 end

File spec/mongrel2/config_spec.rb

View file
  • Ignore whitespace
 		Mongrel2::Config.init_database
 		Mongrel2::Config::Server.truncate
 
-		s = Mongrel2::Config::Server.create(
+		Mongrel2::Config::Server.create(
 			uuid: TEST_UUID,
 			access_log: '/log/access.log',
 			error_log: '/log/error.log',
 			default_host: 'localhost',
 			port: 8275
 		  )
-		expect( Mongrel2::Config.servers ).to have( 1 ).member
+		expect( Mongrel2::Config.servers.size ).to eq(  1  )
 		expect( Mongrel2::Config.servers.first.uuid ).to eq( TEST_UUID )
 	end
 
 		Mongrel2::Config::Setting.dataset.truncate
 		Mongrel2::Config::Setting.create( key: 'control_port', value: 'ipc://var/run/control.sock' )
 		expect( Mongrel2::Config.settings ).to respond_to( :[] )
-		expect( Mongrel2::Config.settings ).to have( 1 ).member
+		expect( Mongrel2::Config.settings.size ).to eq(  1  )
 		expect( Mongrel2::Config.settings[ :control_port ] ).to eq( 'ipc://var/run/control.sock' )
 	end
 
 
 	it "knows whether or not its database has been initialized" do
 		Mongrel2::Config.db = Mongrel2::Config.in_memory_db
-		expect( Mongrel2::Config.database_initialized? ).to be_false()
+		expect( Mongrel2::Config.database_initialized? ).to be_falsey()
 		Mongrel2::Config.init_database!
-		expect( Mongrel2::Config.database_initialized? ).to be_true()
+		expect( Mongrel2::Config.database_initialized? ).to be_truthy()
 	end
 
 	it "doesn't re-initialize the database if the non-bang version of init_database is used" do

File spec/mongrel2/handler_spec.rb

View file
  • Ignore whitespace
 
 		res = OneShotHandler.new( TEST_UUID, TEST_SEND_SPEC, TEST_RECV_SPEC ).run
 
-		expect( res.transactions ).to have( 1 ).member
+		expect( res.transactions.size ).to eq(  1  )
 		request, response = res.transactions.first
 		expect( request ).to be_a( Mongrel2::HTTPRequest )
 		expect( response ).to be_a( Mongrel2::HTTPResponse )
 
 		res = OneShotHandler.new( TEST_UUID, TEST_SEND_SPEC, TEST_RECV_SPEC ).run
 
-		expect( res.transactions ).to have( 1 ).member
+		expect( res.transactions.size ).to eq(  1  )
 		request, response = res.transactions.first
 		expect( request ).to be_a( Mongrel2::JSONRequest )
 		expect( response ).to be_nil()
 
 		res = json_handler.new( TEST_UUID, TEST_SEND_SPEC, TEST_RECV_SPEC ).run
 
-		expect( res.transactions ).to have( 1 ).member
+		expect( res.transactions.size ).to eq(  1  )
 		request, response = res.transactions.first
 		expect( request ).to be_a( Mongrel2::JSONRequest )
 		expect( response ).to be_a( Mongrel2::Response )
 
 		res = OneShotHandler.new( TEST_UUID, TEST_SEND_SPEC, TEST_RECV_SPEC ).run
 
-		expect( res.transactions ).to have( 1 ).member
+		expect( res.transactions.size ).to eq(  1  )
 		request, response = res.transactions.first
 		expect( request ).to be_a( Mongrel2::XMLRequest )
 		expect( response ).to be_nil()
 
 		res = xml_handler.new( TEST_UUID, TEST_SEND_SPEC, TEST_RECV_SPEC ).run
 
-		expect( res.transactions ).to have( 1 ).member
+		expect( res.transactions.size ).to eq(  1  )
 		request, response = res.transactions.first
 		expect( request ).to be_a( Mongrel2::XMLRequest )
 		expect( response ).to be_a( Mongrel2::Response )
 
 		res = ws_handler.new( TEST_UUID, TEST_SEND_SPEC, TEST_RECV_SPEC ).run
 
-		expect( res.transactions ).to have( 1 ).member
+		expect( res.transactions.size ).to eq(  1  )
 		request, response = res.transactions.first
 		expect( request ).to be_a( Mongrel2::WebSocket::ClientHandshake )
 		expect( response ).to be_a( Mongrel2::WebSocket::ServerHandshake )
 
 		res = ws_handler.new( TEST_UUID, TEST_SEND_SPEC, TEST_RECV_SPEC ).run
 
-		expect( res.transactions ).to have( 1 ).member
+		expect( res.transactions.size ).to eq(  1  )
 		request, response = res.transactions.first
 		expect( request ).to be_a( Mongrel2::WebSocket::Frame )
 		expect( response ).to be_a( Mongrel2::WebSocket::Frame )
 
 		res = OneShotHandler.new( TEST_UUID, TEST_SEND_SPEC, TEST_RECV_SPEC ).run
 
-		expect( res.transactions ).to have( 1 ).member
+		expect( res.transactions.size ).to eq(  1  )
 		request, response = res.transactions.first
 		expect( request ).to be_a( Mongrel2::HTTPRequest )
 		expect( response ).to be_a( Mongrel2::HTTPResponse )
 
 		res = OneShotHandler.new( TEST_UUID, TEST_SEND_SPEC, TEST_RECV_SPEC ).run
 
-		expect( res.transactions ).to have( 1 ).member
+		expect( res.transactions.size ).to eq(  1  )
 		request, response = res.transactions.first
 		expect( request ).to be_a( Mongrel2::JSONRequest )
 		expect( response ).to be_nil()
 
 		res = disconnect_handler.new( TEST_UUID, TEST_SEND_SPEC, TEST_RECV_SPEC ).run
 
-		expect( res.transactions ).to have( 1 ).member
+		expect( res.transactions.size ).to eq(  1  )
 		request, response = res.transactions.first
 		expect( request ).to be_a( Mongrel2::JSONRequest )
 		expect( response ).to be_nil()
 
 		res = OneShotHandler.new( TEST_UUID, TEST_SEND_SPEC, TEST_RECV_SPEC ).run
 
-		expect( res.transactions ).to have( 1 ).member
+		expect( res.transactions.size ).to eq(  1  )
 		request, response = res.transactions.first
 		expect( response ).to be_nil()
 	end

File spec/mongrel2/httpresponse_spec.rb

View file
  • Ignore whitespace
 		expect( @response ).to_not be_handled()
 		expect( @response.body ).to be_a( StringIO )
 		expect( @response.body.size ).to eq( 0 )
-		expect( @response.headers ).to have(1).keys
+		expect( @response.headers.size ).to eq( 1 )
 	end
 
 	it "sets its status line to 200 OK if the body is set and the status hasn't yet been set" do

File spec/mongrel2/table_spec.rb

View file
  • Ignore whitespace
 	it "should create an array value and append when appending to an existing key" do
 		@table[:indian_meal] = 'pork sausage'
 		@table.append( 'Indian-MEAL' => 'pinecones' )
-		expect( @table['Indian-Meal'] ).to have(2).members
+		expect( @table['Indian-Meal'].size ).to eq( 2 )
 		expect( @table['Indian-Meal'] ).to include('pinecones')
 		expect( @table['Indian-Meal'] ).to include('pork sausage')
 	end
 
 		table = Mongrel2::Table.new({ :bob => :dan, 'Bob' => :dan_too })
 
-		expect( table[:bob] ).to have(2).members
+		expect( table[:bob].size ).to eq( 2 )
 		expect( table['Bob'] ).to include( :dan )
 		expect( table['bob'] ).to include( :dan_too )
 		end
 			values << [ header, value ]
 		end
 
-		expect( values.flatten ).to have(8).members
+		expect( values.flatten.size ).to eq( 8 )
 		expect( values.transpose[0] ).to include( 'Thai-Food', 'With-Absinthe', 'A-Number-Of-Some-Sort' )
 		expect( values.transpose[1] ).to include( 'normally good', 'seldom hot enough', 'questionable', '2' )
 	end