From d2ee83848661e9374c8736cb7411711ba3862c2d Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Mon, 17 Mar 2008 16:05:33 +0100 Subject: [PATCH] Fix up tests and runner All ruby tests should pass now. --- bin/ebb_rails | 42 +------- ruby_lib/ebb.rb | 14 ++- ruby_lib/ebb/runner.rb | 45 +++++---- ruby_lib/ebb/runner/rails.rb | 34 +++++++ ruby_lib/rack/adapter/rails.rb | 2 + test/basic_test.rb | 10 +- test/ebb_rails_test.rb | 34 +++++++ test/echo_server.rb | 15 --- test/env_test.rb | 17 ++-- test/helper.rb | 45 +++++++-- test/rails_app/app/controllers/application.rb | 10 ++ .../rails_app/app/controllers/simple_controller.rb | 19 ++++ test/rails_app/app/helpers/application_helper.rb | 3 + test/rails_app/app/views/simple/index.html.erb | 15 +++ test/rails_app/config/boot.rb | 109 +++++++++++++++++++++ test/rails_app/config/dispatch.rb | 10 ++ test/rails_app/config/environment.rb | 64 ++++++++++++ test/rails_app/config/environments/development.rb | 18 ++++ test/rails_app/config/environments/production.rb | 19 ++++ test/rails_app/config/environments/test.rb | 22 +++++ test/rails_app/config/initializers/inflections.rb | 10 ++ test/rails_app/config/initializers/mime_types.rb | 5 + test/rails_app/config/routes.rb | 35 +++++++ test/rails_app/public/404.html | 30 ++++++ test/rails_app/public/422.html | 30 ++++++ test/rails_app/public/500.html | 30 ++++++ test/rails_app/public/favicon.ico | 0 test/rails_app/public/images/rails.png | Bin 0 -> 1787 bytes test/rails_app/public/index.html | 13 +++ 29 files changed, 600 insertions(+), 100 deletions(-) rewrite bin/ebb_rails (91%) create mode 100644 ruby_lib/ebb/runner/rails.rb create mode 100644 test/ebb_rails_test.rb delete mode 100644 test/echo_server.rb create mode 100644 test/rails_app/app/controllers/application.rb create mode 100644 test/rails_app/app/controllers/simple_controller.rb create mode 100644 test/rails_app/app/helpers/application_helper.rb create mode 100644 test/rails_app/app/views/simple/index.html.erb create mode 100644 test/rails_app/config/boot.rb create mode 100755 test/rails_app/config/dispatch.rb create mode 100644 test/rails_app/config/environment.rb create mode 100644 test/rails_app/config/environments/development.rb create mode 100644 test/rails_app/config/environments/production.rb create mode 100644 test/rails_app/config/environments/test.rb create mode 100644 test/rails_app/config/initializers/inflections.rb create mode 100644 test/rails_app/config/initializers/mime_types.rb create mode 100644 test/rails_app/config/routes.rb create mode 100644 test/rails_app/public/404.html create mode 100644 test/rails_app/public/422.html create mode 100644 test/rails_app/public/500.html create mode 100644 test/rails_app/public/favicon.ico create mode 100644 test/rails_app/public/images/rails.png create mode 100644 test/rails_app/public/index.html diff --git a/bin/ebb_rails b/bin/ebb_rails dissimilarity index 91% index 005427d..1bf39c8 100755 --- a/bin/ebb_rails +++ b/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 +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../ruby_lib/ebb' + +Ebb::Runner::Rails.new.run(ARGV) diff --git a/ruby_lib/ebb.rb b/ruby_lib/ebb.rb index 2c67964..4378dbb 100644 --- a/ruby_lib/ebb.rb +++ b/ruby_lib/ebb.rb @@ -21,7 +21,7 @@ module Ebb @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 @@ module Ebb 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 diff --git a/ruby_lib/ebb/runner.rb b/ruby_lib/ebb/runner.rb index a62e9fb..1d32293 100644 --- a/ruby_lib/ebb/runner.rb +++ b/ruby_lib/ebb/runner.rb @@ -20,6 +20,10 @@ end 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 @@ module Ebb 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 @@ module Ebb 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 @@ module Ebb } 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 @@ module Ebb @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 @@ module Ebb 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 @@ module Ebb 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 @@ module Ebb end end end + diff --git a/ruby_lib/ebb/runner/rails.rb b/ruby_lib/ebb/runner/rails.rb new file mode 100644 index 0000000..7709354 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/ruby_lib/rack/adapter/rails.rb b/ruby_lib/rack/adapter/rails.rb index e5006e8..8d46735 100644 --- a/ruby_lib/rack/adapter/rails.rb +++ b/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 diff --git a/test/basic_test.rb b/test/basic_test.rb index cea9dc9..46641d1 100644 --- a/test/basic_test.rb +++ b/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 diff --git a/test/ebb_rails_test.rb b/test/ebb_rails_test.rb new file mode 100644 index 0000000..e801ba4 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/test/echo_server.rb b/test/echo_server.rb deleted file mode 100644 index 0bb63fe..0000000 --- a/test/echo_server.rb +++ /dev/null @@ -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) diff --git a/test/env_test.rb b/test/env_test.rb index 654d1be..523af6a 100644 --- a/test/env_test.rb +++ b/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 @@ class HttpParserTest < Test::Unit::TestCase 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 @@ class HttpParserTest < Test::Unit::TestCase 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 diff --git a/test/helper.rb b/test/helper.rb index eecb37a..56866ed 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -5,18 +5,14 @@ require 'net/http' 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 @@ class HelperApp 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 @@ class ServerTest < Test::Unit::TestCase Ebb.stop_server sleep 0.1 while Ebb.running? end + + def default_test + assert true + end end diff --git a/test/rails_app/app/controllers/application.rb b/test/rails_app/app/controllers/application.rb new file mode 100644 index 0000000..cfdb724 --- /dev/null +++ b/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 diff --git a/test/rails_app/app/controllers/simple_controller.rb b/test/rails_app/app/controllers/simple_controller.rb new file mode 100644 index 0000000..2c17427 --- /dev/null +++ b/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 diff --git a/test/rails_app/app/helpers/application_helper.rb b/test/rails_app/app/helpers/application_helper.rb new file mode 100644 index 0000000..22a7940 --- /dev/null +++ b/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 diff --git a/test/rails_app/app/views/simple/index.html.erb b/test/rails_app/app/views/simple/index.html.erb new file mode 100644 index 0000000..7717b8e --- /dev/null +++ b/test/rails_app/app/views/simple/index.html.erb @@ -0,0 +1,15 @@ +

Simple#index

+ +

ENV

+<%= request.env.to_yaml %> + +

Cookies

+<%= request.cookies.to_yaml %> + +

Params

+<%= params.to_yaml %> + +<% form_tag '/simple' do %> + <%= text_field_tag :a %> + <%= submit_tag 'Submit' %> +<% end %> \ No newline at end of file diff --git a/test/rails_app/config/boot.rb b/test/rails_app/config/boot.rb new file mode 100644 index 0000000..5697cc1 --- /dev/null +++ b/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! diff --git a/test/rails_app/config/dispatch.rb b/test/rails_app/config/dispatch.rb new file mode 100755 index 0000000..9b5ae76 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/test/rails_app/config/environment.rb b/test/rails_app/config/environment.rb new file mode 100644 index 0000000..2af27f1 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/test/rails_app/config/environments/development.rb b/test/rails_app/config/environments/development.rb new file mode 100644 index 0000000..191f39c --- /dev/null +++ b/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 \ No newline at end of file diff --git a/test/rails_app/config/environments/production.rb b/test/rails_app/config/environments/production.rb new file mode 100644 index 0000000..91f541c --- /dev/null +++ b/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 diff --git a/test/rails_app/config/environments/test.rb b/test/rails_app/config/environments/test.rb new file mode 100644 index 0000000..58850a7 --- /dev/null +++ b/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 diff --git a/test/rails_app/config/initializers/inflections.rb b/test/rails_app/config/initializers/inflections.rb new file mode 100644 index 0000000..09158b8 --- /dev/null +++ b/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 diff --git a/test/rails_app/config/initializers/mime_types.rb b/test/rails_app/config/initializers/mime_types.rb new file mode 100644 index 0000000..72aca7e --- /dev/null +++ b/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 diff --git a/test/rails_app/config/routes.rb b/test/rails_app/config/routes.rb new file mode 100644 index 0000000..d94afa1 --- /dev/null +++ b/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 diff --git a/test/rails_app/public/404.html b/test/rails_app/public/404.html new file mode 100644 index 0000000..eff660b --- /dev/null +++ b/test/rails_app/public/404.html @@ -0,0 +1,30 @@ + + + + + + + The page you were looking for doesn't exist (404) + + + + + +
+

The page you were looking for doesn't exist.

+

You may have mistyped the address or the page may have moved.

+
+ + \ No newline at end of file diff --git a/test/rails_app/public/422.html b/test/rails_app/public/422.html new file mode 100644 index 0000000..b54e4a3 --- /dev/null +++ b/test/rails_app/public/422.html @@ -0,0 +1,30 @@ + + + + + + + The change you wanted was rejected (422) + + + + + +
+

The change you wanted was rejected.

+

Maybe you tried to change something you didn't have access to.

+
+ + \ No newline at end of file diff --git a/test/rails_app/public/500.html b/test/rails_app/public/500.html new file mode 100644 index 0000000..0e9c14f --- /dev/null +++ b/test/rails_app/public/500.html @@ -0,0 +1,30 @@ + + + + + + + We're sorry, but something went wrong (500) + + + + + +
+

We're sorry, but something went wrong.

+

We've been notified about this issue and we'll take a look at it shortly.

+
+ + \ No newline at end of file diff --git a/test/rails_app/public/favicon.ico b/test/rails_app/public/favicon.ico new file mode 100644 index 0000000..e69de29 diff --git a/test/rails_app/public/images/rails.png b/test/rails_app/public/images/rails.png new file mode 100644 index 0000000000000000000000000000000000000000..b8441f182e06974083cf08f0acaf0e2fd612bd40 GIT binary patch literal 1787 zcwPbf1_b$uP)CLdthj)A!BBmWB&y|X`RY;f`BJ<_ju%@N||NoLFD~mQl$aHGjq>;5dG_D{h(5s}0 z6&=HANU$m__3PuddU(lvR_xWj`}Oho@9EyQt-n!E*P(KhM@X_VFV2l&>deNZJT%y8iwA zoG>u1B`p2=_u9k4v1Mud`1+qvOZoHg#bITJ9U`qBAek?40RR96!AV3xRCwBy*IQ$v zN(=yC9IhRft9V64L`77pqF_Cx@c;kSNoGK)`?Ps*cP(EtGlYZ{D5cxspMQvjKH)Oh6X(pa|J{ zGy1J$Ej7=Z{uvmMfRRsE;v`p;45B~6*ep#hM^ji zl$+7qoWq~}ewG=61uFw0He{tJurMU&4Iv?=B^eR(wAHk!miA)O7p_+YR>lbmU3rmn ze?+ze(+sEd6foB&*l9+?zkr_a-5*v&p*?c}HOGtyHg6r{WFYpQ=#z0Hc7VWLx$>M3|b0|Gn z+5t#z6*ffSVc6DjpmB2?AAR@@vB!wCK?9Yl;33;Q7^%(401QW|k=R8b!OwtLJPjjm zO9Ia;qCq)rOq!1Ia*6#A%#xb}yDx1P*pWla>9j$bnMn3CBqe4`TRll_Iy29kmG?4fbKuF=XqU|?3b@B zA`&a?KIgZ|KJx5eND_c3Em=WZn@xW8hRJ^G&sY^b(FW?WC9W_sb;+lAPdLTdBaKIK;-f}*h4|1aTjw7qX_k~e{TWO7jqcekERN;Jyh%67)q4rKpL*CEYL;|#GY{B@5 zi52XoC?xsoorJKxsliugF#z38MJqrYCWV(t<=G&f;^Me13&AiI9{3jUZ$ zFM`*L(9qc^VMxkz1oaDH!1pcD^IXp>Z0Jb=_qs?Vsrs{mp<^{$N!EC9o+`CO-(o}E zJ`y{*;9s|wr22-QoJ87y^~;)Q@b%P4UgSSsx>2$o@Vd{%Pk0@4qZ^fhB(vt$c1TG> z*{Ad;foraENbld`=MCNm4?9kvlgK~&J>ialpJ7nua zx0oRzwG5;}Qne)Fg(N3kf?JVmB;}y&5(0+~r*aL$0Zof8fe!AtHWH>A^1Y)@G@GsA zup`R{Qg?{+MaxTq#2n{6w|)c&yaJ7{U4ngAH5v6I)*;@rEBE*ehIPBwKBQU)YKE8F0lR!Sm?sE4Xk-sj&E$|A-9n dP56HS1^^A-61FoN)nxzx002ovPDHLkV1kw_Sd9Px literal 0 HcwPel00001 diff --git a/test/rails_app/public/index.html b/test/rails_app/public/index.html new file mode 100644 index 0000000..4968a2d --- /dev/null +++ b/test/rails_app/public/index.html @@ -0,0 +1,13 @@ + + + +

hello world!

+
+ simplecontroller + +
+
+ can you see this image? + + -- 2.11.4.GIT