aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/application/metal_test.rb
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2010-01-10 22:33:34 -0600
committerJoshua Peek <josh@joshpeek.com>2010-01-10 22:33:34 -0600
commit39215860912e4a29def2973b684d0830fc8b9904 (patch)
tree6b7e65ed2336b3157131551bcf519957d9c321be /railties/test/application/metal_test.rb
parent2c2b84f93c6eb1a170467c1340a4eeddfa13f7da (diff)
downloadrails-39215860912e4a29def2973b684d0830fc8b9904.tar.gz
rails-39215860912e4a29def2973b684d0830fc8b9904.tar.bz2
rails-39215860912e4a29def2973b684d0830fc8b9904.zip
Rewrite Metal tests
Diffstat (limited to 'railties/test/application/metal_test.rb')
-rw-r--r--railties/test/application/metal_test.rb86
1 files changed, 86 insertions, 0 deletions
diff --git a/railties/test/application/metal_test.rb b/railties/test/application/metal_test.rb
new file mode 100644
index 0000000000..d3dfb79e8a
--- /dev/null
+++ b/railties/test/application/metal_test.rb
@@ -0,0 +1,86 @@
+require 'isolation/abstract_unit'
+
+module ApplicationTests
+ class MetalTest < Test::Unit::TestCase
+ include ActiveSupport::Testing::Isolation
+
+ def setup
+ build_app
+ boot_rails
+
+ require 'rack/test'
+ extend Rack::Test::Methods
+ end
+
+ def app
+ @app ||= begin
+ require "#{app_path}/config/environment"
+ Rails.application
+ end
+ end
+
+ test "single metal endpoint" do
+ app_file 'app/metal/foo_metal.rb', <<-RUBY
+ class FooMetal
+ def self.call(env)
+ [200, { "Content-Type" => "text/html"}, ["FooMetal"]]
+ end
+ end
+ RUBY
+
+ get "/"
+ assert_equal 200, last_response.status
+ assert_equal "FooMetal", last_response.body
+ end
+
+ test "multiple metal endpoints" do
+ app_file 'app/metal/metal_a.rb', <<-RUBY
+ class MetalA
+ def self.call(env)
+ [404, { "Content-Type" => "text/html"}, ["Metal A"]]
+ end
+ end
+ RUBY
+
+ app_file 'app/metal/metal_b.rb', <<-RUBY
+ class MetalB
+ def self.call(env)
+ [200, { "Content-Type" => "text/html"}, ["Metal B"]]
+ end
+ end
+ RUBY
+
+ get "/"
+ assert_equal 200, last_response.status
+ assert_equal "Metal B", last_response.body
+ end
+
+ test "pass through to application" do
+ app_file 'app/metal/foo_metal.rb', <<-RUBY
+ class FooMetal
+ def self.call(env)
+ [404, { "Content-Type" => "text/html"}, ["Not Found"]]
+ end
+ end
+ RUBY
+
+ controller :foo, <<-RUBY
+ class FooController < ActionController::Base
+ def index
+ render :text => "foo"
+ end
+ end
+ RUBY
+
+ app_file 'config/routes.rb', <<-RUBY
+ AppTemplate::Application.routes.draw do |map|
+ match ':controller(/:action)'
+ end
+ RUBY
+
+ get "/foo"
+ assert_equal 200, last_response.status
+ assert_equal "foo", last_response.body
+ end
+ end
+end