Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix up tests and runner

All ruby tests should pass now.
  • Loading branch information...
commit d2ee83848661e9374c8736cb7411711ba3862c2d 1 parent 7dcfc53
Ryan Dahl authored
Showing with 597 additions and 97 deletions.
  1. +1 −35 bin/ebb_rails
  2. +11 −3 ruby_lib/ebb.rb
  3. +27 −18 ruby_lib/ebb/runner.rb
  4. +34 −0 ruby_lib/ebb/runner/rails.rb
  5. +2 −0  ruby_lib/rack/adapter/rails.rb
  6. +5 −5 test/basic_test.rb
  7. +34 −0 test/ebb_rails_test.rb
  8. +0 −15 test/echo_server.rb
  9. +6 −11 test/env_test.rb
  10. +35 −10 test/helper.rb
  11. +10 −0 test/rails_app/app/controllers/application.rb
  12. +19 −0 test/rails_app/app/controllers/simple_controller.rb
  13. +3 −0  test/rails_app/app/helpers/application_helper.rb
  14. +15 −0 test/rails_app/app/views/simple/index.html.erb
  15. +109 −0 test/rails_app/config/boot.rb
  16. +10 −0 test/rails_app/config/dispatch.rb
  17. +64 −0 test/rails_app/config/environment.rb
  18. +18 −0 test/rails_app/config/environments/development.rb
  19. +19 −0 test/rails_app/config/environments/production.rb
  20. +22 −0 test/rails_app/config/environments/test.rb
  21. +10 −0 test/rails_app/config/initializers/inflections.rb
  22. +5 −0 test/rails_app/config/initializers/mime_types.rb
  23. +35 −0 test/rails_app/config/routes.rb
  24. +30 −0 test/rails_app/public/404.html
  25. +30 −0 test/rails_app/public/422.html
  26. +30 −0 test/rails_app/public/500.html
  27. 0  test/rails_app/public/favicon.ico
  28. BIN  test/rails_app/public/images/rails.png
  29. +13 −0 test/rails_app/public/index.html
View
36 bin/ebb_rails
@@ -1,38 +1,4 @@
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../ruby_lib/ebb'
-require 'optparse'
-require 'rubygems'
-require 'rack'
-module Rack
- module Adapter
- autoload :Rails, Ebb::LIBDIR + '/rack/adapter/rails'
- end
-end
-
-class EbbRails < Ebb::Runner
- def extra_options
- # defaults for ebb_rails
- @options.update(
- :environment => 'development',
- :port => 3000,
- # rails has a mutex lock around each request - threaded processing
- # will only slow things down
- :threaded_processing => false
- )
-
- @parser.on("-e", "--env ENV",
- "Rails environment (default: development)") do |env|
- @options[:environment] = env
- end
- @parser.on("-c", "--chdir DIR", "RAILS_ROOT directory") do |c|
- @options[:root] = c
- end
- end
-
- def app(options)
- Rack::Adapter::Rails.new(options)
- end
-end
-
-EbbRails.new(ARGV).run
+Ebb::Runner::Rails.new.run(ARGV)
View
14 ruby_lib/ebb.rb
@@ -21,7 +21,7 @@ def self.start_server(app, options={})
@running = true
trap('INT') { stop_server }
- puts "Ebb listening at http://0.0.0.0:#{port}/ (#{threaded_processing ? 'threaded' : 'sequential'} processing, PID #{Process.pid})"
+ log.puts "Ebb listening at http://0.0.0.0:#{port}/ (#{threaded_processing ? 'threaded' : 'sequential'} processing, PID #{Process.pid})"
while @running
FFI::server_process_connections()
@@ -74,12 +74,20 @@ def self.process(app, client)
client.body_written()
end
rescue => e
- puts "Ebb Error! #{e.class} #{e.message}"
- puts e.backtrace.join("\n")
+ log.puts "Ebb Error! #{e.class} #{e.message}"
+ log.puts e.backtrace.join("\n")
ensure
client.release
end
+ @@log = STDOUT
+ def self.log=(output)
+ @@log = output
+ end
+ def self.log
+ @@log
+ end
+
# This array is created and manipulated in the C extension.
def FFI.waiting_clients
@waiting_clients
View
45 ruby_lib/ebb/runner.rb
@@ -20,6 +20,10 @@ def daemonize
module Ebb
class Runner
+ # Classes are modules and I hate this 'Base' class pattern. I'm putting
+ # other classes inside this one.
+ autoload :Rails, LIBDIR + '/ebb/runner/rails'
+
# Kill the process which PID is stored in +pid_file+.
def self.kill(pid_file, timeout=60)
raise ArgumentError, 'You must specify a pid_file to stop deamonized server' unless pid_file
@@ -28,12 +32,12 @@ def self.kill(pid_file, timeout=60)
pid = pid.to_i
Process.kill('KILL', pid)
- puts "stopped!"
+ Ebb.log.puts "stopped!"
else
- puts "Can't stop process, no PID found in #{@pid_file}"
+ Ebb.log.puts "Can't stop process, no PID found in #{@pid_file}"
end
rescue Errno::ESRCH # No such process
- puts "process not found!"
+ Ebb.log.puts "process not found!"
ensure
File.delete(pid_file) rescue nil
end
@@ -43,13 +47,14 @@ def self.remove_pid_file(file)
end
def self.write_pid_file(file)
- puts ">> Writing PID to #{file}"
+ Ebb.log.puts ">> Writing PID to #{file}"
open(file,"w+") { |f| f.write(Process.pid) }
File.chmod(0644, file)
end
- def initialize(argv)
- @argv = argv
+ attr_reader :options
+
+ def initialize
@parser = OptionParser.new
@options = {
:port => 4001,
@@ -58,8 +63,7 @@ def initialize(argv)
}
end
-
- def run
+ def parse_options(argv)
@parser.banner = "Usage: #{self.class} [options] start | stop"
@parser.separator ""
extra_options if respond_to?(:extra_options)
@@ -74,22 +78,26 @@ def run
@parser.separator ""
@parser.on_tail("-h", "--help", "Show this message") do
- puts @parser
+ Ebb.log.puts @parser
exit
end
@parser.on_tail('-v', '--version', "Show version") do
- puts "Ebb #{Ebb::VERSION}"
+ Ebb.log.puts "Ebb #{Ebb::VERSION}"
exit
end
- @parser.parse!(@argv)
+ @parser.parse!(argv)
+ end
+
+ def run(argv)
+ parse_options(argv)
- case @argv[0]
+ case argv[0]
when 'start'
- STDOUT.print("Ebb is loading the application...")
- STDOUT.flush()
+ Ebb.log.print("Ebb is loading the application...")
+ Ebb.log.flush()
@app = app(@options)
- STDOUT.puts("loaded")
+ Ebb.log.puts("loaded")
if @options[:daemonize]
pwd = Dir.pwd # Current directory is changed during daemonization, so store it
@@ -105,7 +113,7 @@ def run
if @options[:pid_file]
Runner.write_pid_file(@options[:pid_file])
at_exit do
- puts ">> Exiting!"
+ Ebb.log.puts ">> Exiting!"
Runner.remove_pid_file(@options[:pid_file])
end
end
@@ -114,8 +122,8 @@ def run
when 'stop'
Ebb::Runner.kill @options[:pid_file], @options[:timeout]
when nil
- puts "Command required"
- puts @parser
+ Ebb.log.puts "Command required"
+ Ebb.log.puts @parser
exit 1
else
abort "Invalid command : #{argv[0]}"
@@ -124,3 +132,4 @@ def run
end
end
end
+
View
34 ruby_lib/ebb/runner/rails.rb
@@ -0,0 +1,34 @@
+module Rack
+ module Adapter
+ autoload :Rails, Ebb::LIBDIR + '/rack/adapter/rails'
+ end
+end
+
+module Ebb
+ class Runner
+ class Rails < Runner
+ def extra_options
+ # defaults for ebb_rails
+ @options.update(
+ :environment => 'development',
+ :port => 3000,
+ # rails has a mutex lock around each request - threaded processing
+ # will only slow things down
+ :threaded_processing => false
+ )
+
+ @parser.on("-e", "--env ENV",
+ "Rails environment (default: development)") do |env|
+ @options[:environment] = env
+ end
+ @parser.on("-c", "--chdir DIR", "RAILS_ROOT directory") do |c|
+ @options[:root] = c
+ end
+ end
+
+ def app(options)
+ Rack::Adapter::Rails.new(options)
+ end
+ end
+ end
+end
View
2  ruby_lib/rack/adapter/rails.rb
@@ -1,4 +1,6 @@
require 'cgi'
+require 'rubygems'
+require 'rack'
# Adapter to run a Rails app with any supported Rack handler.
# By default it will try to load the Rails application in the
View
10 test/basic_test.rb
@@ -1,29 +1,29 @@
-require File.dirname(__FILE__) + '/helper'
+require File.dirname(__FILE__) + '/helper'
class BasicTest < ServerTest
def test_get_bytes
[1,10,1000].each do |i|
response = get("/bytes/#{i}")
- assert_equal "#{'C'*i.to_i}", response.body
+ assert_equal "#{'C'*i.to_i}", response['output']
end
end
def test_get_unknown
response = get('/blah')
- assert_equal "Undefined url", response.body
+ assert_equal "Undefined url", response['output']
end
def test_small_posts
[1,10,321,123,1000].each do |i|
response = post("/test_post_length", 'C'*i)
- assert_equal 200, response.code.to_i, response.body
+ assert_equal 200, response['status']
end
end
def test_large_post
[50,60,100].each do |i|
response = post("/test_post_length", 'C'*1024*i)
- assert_equal 200, response.code.to_i, response.body
+ assert_equal 200, response['status']
end
end
end
View
34 test/ebb_rails_test.rb
@@ -0,0 +1,34 @@
+require File.dirname(__FILE__) + '/helper'
+
+APP_DIR = File.dirname(__FILE__) + "/rails_app"
+EBB_RAILS = "#{Ebb::LIBDIR}/../bin/ebb_rails"
+class EbbRailsTest < Test::Unit::TestCase
+ # just to make sure there isn't some load error
+ def test_version
+ out = %x{ruby #{EBB_RAILS} -v}
+ assert_match %r{Ebb #{Ebb::VERSION}}, out
+ end
+
+ def test_parser
+ runner = Ebb::Runner::Rails.new
+ runner.parse_options("start -c #{APP_DIR} -p #{TEST_PORT}".split)
+ assert_equal TEST_PORT, runner.options[:port].to_i
+ assert_equal APP_DIR, runner.options[:root]
+ end
+
+
+ def test_start_app
+ Thread.new do
+ runner = Ebb::Runner::Rails.new
+ runner.run("start -c #{APP_DIR} -p #{TEST_PORT}".split)
+ end
+ sleep 0.1 until Ebb.running?
+
+ response = get '/'
+ assert_equal 200, response.code.to_i
+
+ ensure
+ Ebb.stop_server
+ sleep 0.1 while Ebb.running?
+ end
+end
View
15 test/echo_server.rb
@@ -1,15 +0,0 @@
-require 'rubygems'
-require 'json'
-require File.dirname(__FILE__) + '/../ruby_lib/ebb'
-
-
-class EchoApp
- def call(env)
- env['rack.input'] = env['rack.input'].read(1000000)
- env.delete('rack.errors')
- [200, {'Content-Type' => 'text/json'}, env.to_json]
- end
-end
-
-
-server = Ebb::start_server(EchoApp.new, :port => 4037, :workers => 10)
View
17 test/env_test.rb
@@ -1,16 +1,11 @@
+require File.dirname(__FILE__) + '/helper'
require 'socket'
require 'rubygems'
require 'json'
require 'test/unit'
-PORT = 4037
-
-# This test depends on echo_server running at port 4037. I do this so that
-# I can run a Python server at that port with a similar application and reuse
-# these tests.
-
def send_request(request_string)
- socket = TCPSocket.new("0.0.0.0", PORT)
+ socket = TCPSocket.new("0.0.0.0", TEST_PORT)
socket.write(request_string)
lines = []
out = socket.read(5000000)
@@ -36,7 +31,7 @@ def drops_request?(request_string)
:fail == send_request(request_string)
end
-class HttpParserTest < Test::Unit::TestCase
+class HttpParserTest < ServerTest
def test_parse_simple
env = send_request("GET / HTTP/1.1\r\n\r\n")
@@ -48,14 +43,14 @@ def test_parse_simple
assert_equal 'GET', env['REQUEST_METHOD']
assert_nil env['FRAGMENT']
assert_nil env['QUERY_STRING']
- assert_nil env['rack.input']
+ assert_equal "", env['rack.input']
end
def test_parse_dumbfuck_headers
should_be_good = "GET / HTTP/1.1\r\naaaaaaaaaaaaa:++++++++++\r\n\r\n"
env = send_request(should_be_good)
assert_equal "++++++++++", env["HTTP_AAAAAAAAAAAAA"]
- assert_nil env['rack.input']
+ assert_equal "", env['rack.input']
nasty_pound_header = "GET / HTTP/1.1\r\nX-SSL-Bullshit: -----BEGIN CERTIFICATE-----\r\n\tMIIFbTCCBFWgAwIBAgICH4cwDQYJKoZIhvcNAQEFBQAwcDELMAkGA1UEBhMCVUsx\r\n\tETAPBgNVBAoTCGVTY2llbmNlMRIwEAYDVQQLEwlBdXRob3JpdHkxCzAJBgNVBAMT\r\n\tAkNBMS0wKwYJKoZIhvcNAQkBFh5jYS1vcGVyYXRvckBncmlkLXN1cHBvcnQuYWMu\r\n\tdWswHhcNMDYwNzI3MTQxMzI4WhcNMDcwNzI3MTQxMzI4WjBbMQswCQYDVQQGEwJV\r\n\tSzERMA8GA1UEChMIZVNjaWVuY2UxEzARBgNVBAsTCk1hbmNoZXN0ZXIxCzAJBgNV\r\n\tBAcTmrsogriqMWLAk1DMRcwFQYDVQQDEw5taWNoYWVsIHBhcmQYJKoZIhvcNAQEB\r\n\tBQADggEPADCCAQoCggEBANPEQBgl1IaKdSS1TbhF3hEXSl72G9J+WC/1R64fAcEF\r\n\tW51rEyFYiIeZGx/BVzwXbeBoNUK41OK65sxGuflMo5gLflbwJtHBRIEKAfVVp3YR\r\n\tgW7cMA/s/XKgL1GEC7rQw8lIZT8RApukCGqOVHSi/F1SiFlPDxuDfmdiNzL31+sL\r\n\t0iwHDdNkGjy5pyBSB8Y79dsSJtCW/iaLB0/n8Sj7HgvvZJ7x0fr+RQjYOUUfrePP\r\n\tu2MSpFyf+9BbC/aXgaZuiCvSR+8Snv3xApQY+fULK/xY8h8Ua51iXoQ5jrgu2SqR\r\n\twgA7BUi3G8LFzMBl8FRCDYGUDy7M6QaHXx1ZWIPWNKsCAwEAAaOCAiQwggIgMAwG\r\n\tA1UdEwEB/wQCMAAwEQYJYIZIAYb4QgEBBAQDAgWgMA4GA1UdDwEB/wQEAwID6DAs\r\n\tBglghkgBhvhCAQ0EHxYdVUsgZS1TY2llbmNlIFVzZXIgQ2VydGlmaWNhdGUwHQYD\r\n\tVR0OBBYEFDTt/sf9PeMaZDHkUIldrDYMNTBZMIGaBgNVHSMEgZIwgY+AFAI4qxGj\r\n\tloCLDdMVKwiljjDastqooXSkcjBwMQswCQYDVQQGEwJVSzERMA8GA1UEChMIZVNj\r\n\taWVuY2UxEjAQBgNVBAsTCUF1dGhvcml0eTELMAkGA1UEAxMCQ0ExLTArBgkqhkiG\r\n\t9w0BCQEWHmNhLW9wZXJhdG9yQGdyaWQtc3VwcG9ydC5hYy51a4IBADApBgNVHRIE\r\n\tIjAggR5jYS1vcGVyYXRvckBncmlkLXN1cHBvcnQuYWMudWswGQYDVR0gBBIwEDAO\r\n\tBgwrBgEEAdkvAQEBAQYwPQYJYIZIAYb4QgEEBDAWLmh0dHA6Ly9jYS5ncmlkLXN1\r\n\tcHBvcnQuYWMudmT4sopwqlBWsvcHViL2NybC9jYWNybC5jcmwwPQYJYIZIAYb4QgEDBDAWLmh0\r\n\tdHA6Ly9jYS5ncmlkLXN1cHBvcnQuYWMudWsvcHViL2NybC9jYWNybC5jcmwwPwYD\r\n\tVR0fBDgwNjA0oDKgMIYuaHR0cDovL2NhLmdyaWQt5hYy51ay9wdWIv\r\n\tY3JsL2NhY3JsLmNybDANBgkqhkiG9w0BAQUFAAOCAQEAS/U4iiooBENGW/Hwmmd3\r\n\tXCy6Zrt08YjKCzGNjorT98g8uGsqYjSxv/hmi0qlnlHs+k/3Iobc3LjS5AMYr5L8\r\n\tUO7OSkgFFlLHQyC9JzPfmLCAugvzEbyv4Olnsr8hbxF1MbKZoQxUZtMVu29wjfXk\r\n\thTeApBv7eaKCWpSp7MCbvgzm74izKhu3vlDk9w6qVrxePfGgpKPqfHiOoGhFnbTK\r\n\twTC6o2xq5y0qZ03JonF7OJspEd3I5zKY3E+ov7/ZhW6DqT8UFvsAdjvQbXyhV8Eu\r\n\tYhixw1aKEPzNjNowuIseVogKOLXxWI5vAi5HgXdS0/ES5gDGsABo4fqovUKlgop3\r\n\tRA==\r\n\t-----END CERTIFICATE-----\r\n\r\n"
assert drops_request?(nasty_pound_header) # Correct?
@@ -69,7 +64,7 @@ def test_fragment_in_uri
env = send_request("GET /forums/1/topics/2375?page=1#posts-17408 HTTP/1.1\r\n\r\n")
assert_equal '/forums/1/topics/2375?page=1', env['REQUEST_URI']
assert_equal 'posts-17408', env['FRAGMENT']
- assert_nil env['rack.input']
+ assert_equal "", env['rack.input']
end
# lame random garbage maker
View
45 test/helper.rb
@@ -5,18 +5,14 @@
require 'socket'
require 'rubygems'
require 'json'
+require 'ruby-debug'
+Debugger.start
-include Ebb
+
+Ebb.log = File.open('/dev/null','w')
TEST_PORT = 4044
-def get(path)
- Net::HTTP.get_response(URI.parse("http://0.0.0.0:#{TEST_PORT}#{path}"))
-end
-
-def post(path, data)
- Net::HTTP.post_form(URI.parse("http://0.0.0.0:#{TEST_PORT}#{path}"), data)
-end
class HelperApp
def call(env)
@@ -40,17 +36,42 @@ def call(env)
body = "Content-Length header is #{content_length_header} but body length is #{input_body.length}"
status = 500
end
-
+
else
status = 404
body = "Undefined url"
end
- [status, {'Content-Type' => 'text/plain'}, body]
+ env['rack.input'] = env['rack.input'].read
+ env.delete('rack.errors')
+ env['output'] = body
+ env['status'] = status
+
+ [status, {'Content-Type' => 'text/json'}, env.to_json]
+ end
+end
+
+class Test::Unit::TestCase
+ def get(path)
+ response = Net::HTTP.get_response(URI.parse("http://0.0.0.0:#{TEST_PORT}#{path}"))
+ end
+
+ def post(path, data)
+ response = Net::HTTP.post_form(URI.parse("http://0.0.0.0:#{TEST_PORT}#{path}"), data)
end
end
class ServerTest < Test::Unit::TestCase
+ def get(path)
+ response = Net::HTTP.get_response(URI.parse("http://0.0.0.0:#{TEST_PORT}#{path}"))
+ env = JSON.parse(response.body)
+ end
+
+ def post(path, data)
+ response = Net::HTTP.post_form(URI.parse("http://0.0.0.0:#{TEST_PORT}#{path}"), data)
+ env = JSON.parse(response.body)
+ end
+
def setup
Thread.new { Ebb.start_server(HelperApp.new, :port => TEST_PORT) }
sleep 0.1 until Ebb.running?
@@ -60,4 +81,8 @@ def teardown
Ebb.stop_server
sleep 0.1 while Ebb.running?
end
+
+ def default_test
+ assert true
+ end
end
View
10 test/rails_app/app/controllers/application.rb
@@ -0,0 +1,10 @@
+# Filters added to this controller apply to all controllers in the application.
+# Likewise, all the methods added will be available for all controllers.
+
+class ApplicationController < ActionController::Base
+ helper :all # include all helpers, all the time
+
+ # See ActionController::RequestForgeryProtection for details
+ # Uncomment the :secret if you're not using the cookie session store
+ # protect_from_forgery # :secret => 'a8af303b8dabf2d2d8f1a7912ac04d7d'
+end
View
19 test/rails_app/app/controllers/simple_controller.rb
@@ -0,0 +1,19 @@
+class SimpleController < ApplicationController
+ caches_page :cached
+
+ def index
+ end
+
+ def post_form
+ render :text => params.to_yaml
+ end
+
+ def set_cookie
+ cookies[params[:name]] = params[:value] if params[:name]
+ render :text => cookies.to_yaml
+ end
+
+ def cached
+ render :text => params[:value]
+ end
+end
View
3  test/rails_app/app/helpers/application_helper.rb
@@ -0,0 +1,3 @@
+# Methods added to this helper will be available to all templates in the application.
+module ApplicationHelper
+end
View
15 test/rails_app/app/views/simple/index.html.erb
@@ -0,0 +1,15 @@
+<h1>Simple#index</h1>
+
+<h2>ENV</h2>
+<%= request.env.to_yaml %>
+
+<h2>Cookies</h2>
+<%= request.cookies.to_yaml %>
+
+<h2>Params</h2>
+<%= params.to_yaml %>
+
+<% form_tag '/simple' do %>
+ <%= text_field_tag :a %>
+ <%= submit_tag 'Submit' %>
+<% end %>
View
109 test/rails_app/config/boot.rb
@@ -0,0 +1,109 @@
+# Don't change this file!
+# Configure your app in config/environment.rb and config/environments/*.rb
+
+RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
+
+module Rails
+ class << self
+ def boot!
+ unless booted?
+ preinitialize
+ pick_boot.run
+ end
+ end
+
+ def booted?
+ defined? Rails::Initializer
+ end
+
+ def pick_boot
+ (vendor_rails? ? VendorBoot : GemBoot).new
+ end
+
+ def vendor_rails?
+ File.exist?("#{RAILS_ROOT}/vendor/rails")
+ end
+
+ # FIXME : Ruby 1.9
+ def preinitialize
+ load(preinitializer_path) if File.exists?(preinitializer_path)
+ end
+
+ def preinitializer_path
+ "#{RAILS_ROOT}/config/preinitializer.rb"
+ end
+ end
+
+ class Boot
+ def run
+ load_initializer
+ Rails::Initializer.run(:set_load_path)
+ end
+ end
+
+ class VendorBoot < Boot
+ def load_initializer
+ require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
+ end
+ end
+
+ class GemBoot < Boot
+ def load_initializer
+ self.class.load_rubygems
+ load_rails_gem
+ require 'initializer'
+ end
+
+ def load_rails_gem
+ if version = self.class.gem_version
+ gem 'rails', version
+ else
+ gem 'rails'
+ end
+ rescue Gem::LoadError => load_error
+ $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
+ exit 1
+ end
+
+ class << self
+ def rubygems_version
+ Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion
+ end
+
+ def gem_version
+ if defined? RAILS_GEM_VERSION
+ RAILS_GEM_VERSION
+ elsif ENV.include?('RAILS_GEM_VERSION')
+ ENV['RAILS_GEM_VERSION']
+ else
+ parse_gem_version(read_environment_rb)
+ end
+ end
+
+ def load_rubygems
+ require 'rubygems'
+
+ unless rubygems_version >= '0.9.4'
+ $stderr.puts %(Rails requires RubyGems >= 0.9.4 (you have #{rubygems_version}). Please `gem update --system` and try again.)
+ exit 1
+ end
+
+ rescue LoadError
+ $stderr.puts %(Rails requires RubyGems >= 0.9.4. Please install RubyGems and try again: http://rubygems.rubyforge.org)
+ exit 1
+ end
+
+ def parse_gem_version(text)
+ $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
+ end
+
+ private
+ def read_environment_rb
+ File.read("#{RAILS_ROOT}/config/environment.rb")
+ end
+ end
+ end
+end
+
+# All that for this:
+Rails.boot!
View
10 test/rails_app/config/dispatch.rb
@@ -0,0 +1,10 @@
+#!/usr/local/bin/ruby
+
+require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
+
+# If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like:
+# "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impaired
+require "dispatcher"
+
+ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if File.directory?(dir) } if defined?(Apache::RubyRun)
+Dispatcher.dispatch
View
64 test/rails_app/config/environment.rb
@@ -0,0 +1,64 @@
+# Be sure to restart your server when you modify this file
+
+# Uncomment below to force Rails into production mode when
+# you don't control web/app server and can't set it the proper way
+# ENV['RAILS_ENV'] ||= 'production'
+
+# Specifies gem version of Rails to use when vendor/rails is not present
+RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION
+
+# Bootstrap the Rails environment, frameworks, and default configuration
+require File.join(File.dirname(__FILE__), 'boot')
+
+Rails::Initializer.run do |config|
+ # Settings in config/environments/* take precedence over those specified here.
+ # Application configuration should go into files in config/initializers
+ # -- all .rb files in that directory are automatically loaded.
+ # See Rails::Configuration for more options.
+
+ # Skip frameworks you're not going to use (only works if using vendor/rails).
+ # To use Rails without a database, you must remove the Active Record framework
+ config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
+
+ # Only load the plugins named here, in the order given. By default, all plugins
+ # in vendor/plugins are loaded in alphabetical order.
+ # :all can be used as a placeholder for all plugins not explicitly named
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
+
+ # Add additional load paths for your own custom dirs
+ # config.load_paths += %W( #{RAILS_ROOT}/extras )
+
+ # No need for log files
+ config.logger = Logger.new(nil)
+
+ # Force all environments to use the same logger level
+ # (by default production uses :info, the others :debug)
+ # config.log_level = :debug
+
+ # Your secret key for verifying cookie session data integrity.
+ # If you change this key, all old sessions will become invalid!
+ # Make sure the secret is at least 30 characters and all random,
+ # no regular words or you'll be exposed to dictionary attacks.
+ config.action_controller.session = {
+ :session_key => '_rails_app_session',
+ :secret => 'cb7141365b4443eff37e7122473e704ceae95146a4028930b21300965fe6abec51e3e93b2670a914b3b65d06058b81aadfe6b240d63e7d7713db044b42a6e1c1'
+ }
+
+ config.action_controller.allow_forgery_protection = false
+
+ # Use the database for sessions instead of the cookie-based default,
+ # which shouldn't be used to store highly confidential information
+ # (create the session table with 'rake db:sessions:create')
+ # config.action_controller.session_store = :active_record_store
+
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
+ # like if you have constraints or database-specific column types
+ # config.active_record.schema_format = :sql
+
+ # Activate observers that should always be running
+ # config.active_record.observers = :cacher, :garbage_collector
+
+ # Make Active Record use UTC-base instead of local time
+ # config.active_record.default_timezone = :utc
+end
View
18 test/rails_app/config/environments/development.rb
@@ -0,0 +1,18 @@
+# Settings specified here will take precedence over those in config/environment.rb
+
+# In the development environment your application's code is reloaded on
+# every request. This slows down response time but is perfect for development
+# since you don't have to restart the webserver when you make code changes.
+config.cache_classes = false
+
+# Log error messages when you accidentally call methods on nil.
+config.whiny_nils = true
+
+# Show full error reports and disable caching
+config.action_controller.consider_all_requests_local = true
+config.action_view.debug_rjs = true
+config.action_controller.perform_caching = true
+config.action_view.cache_template_extensions = false
+
+# Don't care if the mailer can't send
+config.action_mailer.raise_delivery_errors = false
View
19 test/rails_app/config/environments/production.rb
@@ -0,0 +1,19 @@
+# Settings specified here will take precedence over those in config/environment.rb
+
+# The production environment is meant for finished, "live" apps.
+# Code is not reloaded between requests
+config.cache_classes = true
+
+# Use a different logger for distributed setups
+# config.logger = SyslogLogger.new
+
+# Full error reports are disabled and caching is turned on
+config.action_controller.consider_all_requests_local = false
+config.action_controller.perform_caching = true
+config.action_view.cache_template_loading = true
+
+# Enable serving of images, stylesheets, and javascripts from an asset server
+# config.action_controller.asset_host = "http://assets.example.com"
+
+# Disable delivery errors, bad email addresses will be ignored
+# config.action_mailer.raise_delivery_errors = false
View
22 test/rails_app/config/environments/test.rb
@@ -0,0 +1,22 @@
+# Settings specified here will take precedence over those in config/environment.rb
+
+# The test environment is used exclusively to run your application's
+# test suite. You never need to work with it otherwise. Remember that
+# your test database is "scratch space" for the test suite and is wiped
+# and recreated between test runs. Don't rely on the data there!
+config.cache_classes = true
+
+# Log error messages when you accidentally call methods on nil.
+config.whiny_nils = true
+
+# Show full error reports and disable caching
+config.action_controller.consider_all_requests_local = true
+config.action_controller.perform_caching = false
+
+# Disable request forgery protection in test environment
+config.action_controller.allow_forgery_protection = false
+
+# Tell ActionMailer not to deliver emails to the real world.
+# The :test delivery method accumulates sent emails in the
+# ActionMailer::Base.deliveries array.
+config.action_mailer.delivery_method = :test
View
10 test/rails_app/config/initializers/inflections.rb
@@ -0,0 +1,10 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new inflection rules using the following format
+# (all these examples are active by default):
+# Inflector.inflections do |inflect|
+# inflect.plural /^(ox)$/i, '\1en'
+# inflect.singular /^(ox)en/i, '\1'
+# inflect.irregular 'person', 'people'
+# inflect.uncountable %w( fish sheep )
+# end
View
5 test/rails_app/config/initializers/mime_types.rb
@@ -0,0 +1,5 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new mime types for use in respond_to blocks:
+# Mime::Type.register "text/richtext", :rtf
+# Mime::Type.register_alias "text/html", :iphone
View
35 test/rails_app/config/routes.rb
@@ -0,0 +1,35 @@
+ActionController::Routing::Routes.draw do |map|
+ # The priority is based upon order of creation: first created -> highest priority.
+
+ # Sample of regular route:
+ # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
+ # Keep in mind you can assign values other than :controller and :action
+
+ # Sample of named route:
+ # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
+ # This route can be invoked with purchase_url(:id => product.id)
+
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
+ # map.resources :products
+
+ # Sample resource route with options:
+ # map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }
+
+ # Sample resource route with sub-resources:
+ # map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller
+
+ # Sample resource route within a namespace:
+ # map.namespace :admin do |admin|
+ # # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
+ # admin.resources :products
+ # end
+
+ # You can have the root of your site routed with map.root -- just remember to delete public/index.html.
+ # map.root :controller => "welcome"
+
+ # See how all your routes lay out with "rake routes"
+
+ # Install the default routes as the lowest priority.
+ map.connect ':controller/:action/:id'
+ map.connect ':controller/:action/:id.:format'
+end
View
30 test/rails_app/public/404.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
+ <title>The page you were looking for doesn't exist (404)</title>
+ <style type="text/css">
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
+ div.dialog {
+ width: 25em;
+ padding: 0 4em;
+ margin: 4em auto 0 auto;
+ border: 1px solid #ccc;
+ border-right-color: #999;
+ border-bottom-color: #999;
+ }
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
+ </style>
+</head>
+
+<body>
+ <!-- This file lives in public/404.html -->
+ <div class="dialog">
+ <h1>The page you were looking for doesn't exist.</h1>
+ <p>You may have mistyped the address or the page may have moved.</p>
+ </div>
+</body>
+</html>
View
30 test/rails_app/public/422.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
+ <title>The change you wanted was rejected (422)</title>
+ <style type="text/css">
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
+ div.dialog {
+ width: 25em;
+ padding: 0 4em;
+ margin: 4em auto 0 auto;
+ border: 1px solid #ccc;
+ border-right-color: #999;
+ border-bottom-color: #999;
+ }
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
+ </style>
+</head>
+
+<body>
+ <!-- This file lives in public/422.html -->
+ <div class="dialog">
+ <h1>The change you wanted was rejected.</h1>
+ <p>Maybe you tried to change something you didn't have access to.</p>
+ </div>
+</body>
+</html>
View
30 test/rails_app/public/500.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
+ <title>We're sorry, but something went wrong (500)</title>
+ <style type="text/css">
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
+ div.dialog {
+ width: 25em;
+ padding: 0 4em;
+ margin: 4em auto 0 auto;
+ border: 1px solid #ccc;
+ border-right-color: #999;
+ border-bottom-color: #999;
+ }
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
+ </style>
+</head>
+
+<body>
+ <!-- This file lives in public/500.html -->
+ <div class="dialog">
+ <h1>We're sorry, but something went wrong.</h1>
+ <p>We've been notified about this issue and we'll take a look at it shortly.</p>
+ </div>
+</body>
+</html>
View
0  test/rails_app/public/favicon.ico
No changes.
View
BIN  test/rails_app/public/images/rails.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
13 test/rails_app/public/index.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html>
+ <body>
+ <h1> hello world! </h1>
+ <br/>
+ <a href="simple">simplecontroller</a>
+
+ <br/>
+ <br/>
+ can you see this image? <img src="images/rails.png">
+ </body>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.