From 3b44f35e242cc372749f43f0f24dea0138e6ab8d Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 17 Dec 2009 21:41:07 -0600 Subject: Don't need response prepare! --- actionpack/test/dispatch/response_test.rb | 8 -------- 1 file changed, 8 deletions(-) (limited to 'actionpack/test/dispatch') diff --git a/actionpack/test/dispatch/response_test.rb b/actionpack/test/dispatch/response_test.rb index 256ed06a45..a0250088a5 100644 --- a/actionpack/test/dispatch/response_test.rb +++ b/actionpack/test/dispatch/response_test.rb @@ -7,7 +7,6 @@ class ResponseTest < ActiveSupport::TestCase test "simple output" do @response.body = "Hello, World!" - @response.prepare! status, headers, body = @response.to_a assert_equal 200, status @@ -25,7 +24,6 @@ class ResponseTest < ActiveSupport::TestCase test "utf8 output" do @response.body = [1090, 1077, 1089, 1090].pack("U*") - @response.prepare! status, headers, body = @response.to_a assert_equal 200, status @@ -41,7 +39,6 @@ class ResponseTest < ActiveSupport::TestCase @response.body = Proc.new do |response, output| 5.times { |n| output.write(n) } end - @response.prepare! status, headers, body = @response.to_a assert_equal 200, status @@ -59,14 +56,12 @@ class ResponseTest < ActiveSupport::TestCase test "content type" do [204, 304].each do |c| @response.status = c.to_s - @response.prepare! status, headers, body = @response.to_a assert !headers.has_key?("Content-Type"), "#{c} should not have Content-Type header" end [200, 302, 404, 500].each do |c| @response.status = c.to_s - @response.prepare! status, headers, body = @response.to_a assert headers.has_key?("Content-Type"), "#{c} did not have Content-Type header" end @@ -74,7 +69,6 @@ class ResponseTest < ActiveSupport::TestCase test "does not include Status header" do @response.status = "200 OK" - @response.prepare! status, headers, body = @response.to_a assert !headers.has_key?('Status') end @@ -114,13 +108,11 @@ class ResponseTest < ActiveSupport::TestCase test "cookies" do @response.set_cookie("user_name", :value => "david", :path => "/") - @response.prepare! status, headers, body = @response.to_a assert_equal "user_name=david; path=/", headers["Set-Cookie"] assert_equal({"user_name" => "david"}, @response.cookies) @response.set_cookie("login", :value => "foo&bar", :path => "/", :expires => Time.utc(2005, 10, 10,5)) - @response.prepare! status, headers, body = @response.to_a assert_equal "user_name=david; path=/\nlogin=foo%26bar; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT", headers["Set-Cookie"] assert_equal({"login" => "foo&bar", "user_name" => "david"}, @response.cookies) -- cgit v1.2.3 From 2419fae092ec207185f9ed69c2aa1ba1cd53fffe Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 17 Dec 2009 22:10:06 -0600 Subject: Pending tests for AD Response --- actionpack/test/dispatch/response_test.rb | 113 ++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) (limited to 'actionpack/test/dispatch') diff --git a/actionpack/test/dispatch/response_test.rb b/actionpack/test/dispatch/response_test.rb index a0250088a5..59ad2e48bd 100644 --- a/actionpack/test/dispatch/response_test.rb +++ b/actionpack/test/dispatch/response_test.rb @@ -117,4 +117,117 @@ class ResponseTest < ActiveSupport::TestCase assert_equal "user_name=david; path=/\nlogin=foo%26bar; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT", headers["Set-Cookie"] assert_equal({"login" => "foo&bar", "user_name" => "david"}, @response.cookies) end + + test "read cache control" do + resp = ActionDispatch::Response.new.tap { |resp| + resp.cache_control[:public] = true + resp.etag = '123' + resp.body = 'Hello' + } + resp.to_a + + assert_equal('"202cb962ac59075b964b07152d234b70"', resp.etag) + assert_equal({:public => true}, resp.cache_control) + + assert_equal('public', resp.headers['Cache-Control']) + assert_equal('"202cb962ac59075b964b07152d234b70"', resp.headers['ETag']) + end + + test "read charset and content type" do + resp = ActionDispatch::Response.new.tap { |resp| + resp.charset = 'utf-16' + resp.content_type = Mime::XML + resp.body = 'Hello' + } + resp.to_a + + assert_equal('utf-16', resp.charset) + assert_equal(Mime::XML, resp.content_type) + + assert_equal('application/xml; charset=utf-16', resp.headers['Content-Type']) + end +end + +class ResponseIntegrationTest < ActionDispatch::IntegrationTest + def app + @app + end + + test "response cache control from railsish app" do + @app = lambda { |env| + ActionDispatch::Response.new.tap { |resp| + resp.cache_control[:public] = true + resp.etag = '123' + resp.body = 'Hello' + }.to_a + } + + get '/' + assert_response :success + + assert_equal('public', @response.headers['Cache-Control']) + assert_equal('"202cb962ac59075b964b07152d234b70"', @response.headers['ETag']) + + pending do + assert_equal('"202cb962ac59075b964b07152d234b70"', @response.etag) + assert_equal({:public => true}, @response.cache_control) + end + end + + test "response cache control from rackish app" do + @app = lambda { |env| + [200, + {'ETag' => '"202cb962ac59075b964b07152d234b70"', + 'Cache-Control' => 'public'}, 'Hello'] + } + + get '/' + assert_response :success + + assert_equal('public', @response.headers['Cache-Control']) + assert_equal('"202cb962ac59075b964b07152d234b70"', @response.headers['ETag']) + + pending do + assert_equal('"202cb962ac59075b964b07152d234b70"', @response.etag) + assert_equal({:public => true}, @response.cache_control) + end + end + + test "response charset and content type from railsish app" do + @app = lambda { |env| + ActionDispatch::Response.new.tap { |resp| + resp.charset = 'utf-16' + resp.content_type = Mime::XML + resp.body = 'Hello' + }.to_a + } + + get '/' + assert_response :success + + pending do + assert_equal('utf-16', @response.charset) + assert_equal(Mime::XML, @response.content_type) + end + + assert_equal('application/xml; charset=utf-16', @response.headers['Content-Type']) + end + + test "response charset and content type from rackish app" do + @app = lambda { |env| + [200, + {'Content-Type' => 'application/xml; charset=utf-16'}, + 'Hello'] + } + + get '/' + assert_response :success + + pending do + assert_equal('utf-16', @response.charset) + assert_equal(Mime::XML, @response.content_type) + end + + assert_equal('application/xml; charset=utf-16', @response.headers['Content-Type']) + end end -- cgit v1.2.3 From e48b4c2dd01877ace901e1c186d04605b53b40d0 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Sun, 20 Dec 2009 14:07:19 -0800 Subject: :to => redirect() can take a String using 1.9-style interpolation or proc that takes the path parameters as a Hash --- actionpack/test/dispatch/routing_test.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'actionpack/test/dispatch') diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 425796b460..7145a0c530 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -24,6 +24,9 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest match 'account/login', :to => redirect("/login") + match 'account/modulo/:name', :to => redirect("/%{name}s") + match 'account/proc/:name', :to => redirect {|params| "/#{params[:name].pluralize}" } + match 'openid/login', :via => [:get, :post], :to => "openid#login" controller(:global) do @@ -145,6 +148,24 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + def test_redirect_modulo + with_test_routes do + get '/account/modulo/name' + assert_equal 301, @response.status + assert_equal 'http://www.example.com/names', @response.headers['Location'] + assert_equal 'Moved Permanently', @response.body + end + end + + def test_redirect_proc + with_test_routes do + get '/account/proc/person' + assert_equal 301, @response.status + assert_equal 'http://www.example.com/people', @response.headers['Location'] + assert_equal 'Moved Permanently', @response.body + end + end + def test_openid with_test_routes do get '/openid/login' -- cgit v1.2.3 From 3ff9e9ee147b682cb13aed4c057e750228892f42 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 20 Dec 2009 20:37:36 -0800 Subject: Its now possible to use match 'stuff' => 'what#stuff' instead of using the :to for simple routes --- actionpack/test/dispatch/routing_test.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'actionpack/test/dispatch') diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 7145a0c530..7058bc2ea0 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -22,6 +22,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest delete 'logout', :to => :destroy, :as => :logout end + match 'account/logout' => redirect("/logout") match 'account/login', :to => redirect("/login") match 'account/modulo/:name', :to => redirect("/%{name}s") @@ -37,11 +38,11 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end constraints(:ip => /192\.168\.1\.\d\d\d/) do - get 'admin', :to => "queenbee#index" + get 'admin' => "queenbee#index" end constraints ::TestRoutingMapper::IpRestrictor do - get 'admin/accounts', :to => "queenbee#accounts" + get 'admin/accounts' => "queenbee#accounts" end resources :projects, :controller => :project do @@ -85,7 +86,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - match 'sprockets.js', :to => ::TestRoutingMapper::SprocketsApp + match 'sprockets.js' => ::TestRoutingMapper::SprocketsApp match 'people/:id/update', :to => 'people#update', :as => :update_person match '/projects/:project_id/people/:id/update', :to => 'people#update', :as => :update_project_person @@ -148,6 +149,15 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + def test_logout_redirect_without_to + with_test_routes do + get '/account/logout' + assert_equal 301, @response.status + assert_equal 'http://www.example.com/logout', @response.headers['Location'] + assert_equal 'Moved Permanently', @response.body + end + end + def test_redirect_modulo with_test_routes do get '/account/modulo/name' -- cgit v1.2.3 From 8e48a5ef0ca488b2264acd2b38bdae14970c011f Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 21 Dec 2009 21:49:36 -0800 Subject: Add test for root --- actionpack/test/dispatch/routing_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'actionpack/test/dispatch') diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 7058bc2ea0..1c7822358d 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -109,6 +109,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest scope ':access_token', :constraints => { :access_token => /\w{5,5}/ } do resources :rooms end + + root :to => 'projects#index' end end @@ -458,6 +460,13 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + def test_root + with_test_routes do + get '/' + assert_equal 'projects#index', @response.body + end + end + private def with_test_routes real_routes, temp_routes = ActionController::Routing::Routes, Routes -- cgit v1.2.3 From 24e1b5560806be54a931922f109f50800dcbbdf5 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 23 Dec 2009 13:06:53 -0800 Subject: Fix bare string Rack response bodies --- actionpack/test/dispatch/response_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/test/dispatch') diff --git a/actionpack/test/dispatch/response_test.rb b/actionpack/test/dispatch/response_test.rb index 59ad2e48bd..02f63f7006 100644 --- a/actionpack/test/dispatch/response_test.rb +++ b/actionpack/test/dispatch/response_test.rb @@ -178,7 +178,7 @@ class ResponseIntegrationTest < ActionDispatch::IntegrationTest @app = lambda { |env| [200, {'ETag' => '"202cb962ac59075b964b07152d234b70"', - 'Cache-Control' => 'public'}, 'Hello'] + 'Cache-Control' => 'public'}, ['Hello']] } get '/' @@ -217,7 +217,7 @@ class ResponseIntegrationTest < ActionDispatch::IntegrationTest @app = lambda { |env| [200, {'Content-Type' => 'application/xml; charset=utf-16'}, - 'Hello'] + ['Hello']] } get '/' -- cgit v1.2.3 From 4d3602a8c4b38052c70655cd7d9dea42ae10ea8d Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 23 Dec 2009 17:42:30 -0800 Subject: Routing: fix that route shorthand shouldn't ignore other options. Raise if :as option is given to root method since its name is always 'root' --- actionpack/test/dispatch/routing_test.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'actionpack/test/dispatch') diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 1c7822358d..7ca85a4201 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -22,7 +22,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest delete 'logout', :to => :destroy, :as => :logout end - match 'account/logout' => redirect("/logout") + match 'account/logout' => redirect("/logout"), :as => :logout_redirect match 'account/login', :to => redirect("/login") match 'account/modulo/:name', :to => redirect("/%{name}s") @@ -109,7 +109,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest scope ':access_token', :constraints => { :access_token => /\w{5,5}/ } do resources :rooms end - + root :to => 'projects#index' end end @@ -153,6 +153,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_logout_redirect_without_to with_test_routes do + assert_equal '/account/logout', logout_redirect_path get '/account/logout' assert_equal 301, @response.status assert_equal 'http://www.example.com/logout', @response.headers['Location'] @@ -462,6 +463,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_root with_test_routes do + assert_equal '/', root_path get '/' assert_equal 'projects#index', @response.body end -- cgit v1.2.3 From aa3565f3a6327c947ded314525ba1d0674d5a71e Mon Sep 17 00:00:00 2001 From: Sam Ruby Date: Wed, 23 Dec 2009 23:33:14 -0500 Subject: Allow named_routes to be used with root, and with new DSL short-form. The real use case it to make all of the following act the same: root 'store#index', :as => 'store' match '/' => 'store#index', :as => 'store' match '/', :to => 'store#index', :as => 'store' The test case provided deviates from this in order to demonstrate all three forms in a single set of test routes. Signed-off-by: Jeremy Kemper --- actionpack/test/dispatch/routing_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'actionpack/test/dispatch') diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 7ca85a4201..82231cb3d9 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -111,6 +111,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end root :to => 'projects#index' + match '/info' => 'projects#info', :as => 'info' end end @@ -469,6 +470,14 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + def test_index + with_test_routes do + assert_equal '/info', info_path + get '/info' + assert_equal 'projects#info', @response.body + end + end + private def with_test_routes real_routes, temp_routes = ActionController::Routing::Routes, Routes -- cgit v1.2.3 From 2b7256a42e63640d6e94fe80ee67093ed0f06e4c Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 24 Dec 2009 15:23:39 -0800 Subject: Extract Mapping class from monster match method --- actionpack/test/dispatch/routing_test.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'actionpack/test/dispatch') diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 1c7822358d..f7f93290df 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -22,7 +22,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest delete 'logout', :to => :destroy, :as => :logout end - match 'account/logout' => redirect("/logout") + match 'account/logout' => redirect("/logout"), :as => :logout_redirect match 'account/login', :to => redirect("/login") match 'account/modulo/:name', :to => redirect("/%{name}s") @@ -110,6 +110,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest resources :rooms end + match '/info' => 'projects#info', :as => 'info' root :to => 'projects#index' end end @@ -153,6 +154,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_logout_redirect_without_to with_test_routes do + assert_equal '/account/logout', logout_redirect_path get '/account/logout' assert_equal 301, @response.status assert_equal 'http://www.example.com/logout', @response.headers['Location'] @@ -462,10 +464,19 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest def test_root with_test_routes do + assert_equal '/', root_path get '/' assert_equal 'projects#index', @response.body end end + + def test_index + with_test_routes do + assert_equal '/info', info_path + get '/info' + assert_equal 'projects#info', @response.body + end + end private def with_test_routes -- cgit v1.2.3 From f53c36350d46a27f4859d82b07e48528fa4f2c74 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 26 Dec 2009 11:40:07 -0600 Subject: Expect Rack 1.1 --- actionpack/test/dispatch/test_request_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test/dispatch') diff --git a/actionpack/test/dispatch/test_request_test.rb b/actionpack/test/dispatch/test_request_test.rb index 5da02b2ea6..e42ade73d1 100644 --- a/actionpack/test/dispatch/test_request_test.rb +++ b/actionpack/test/dispatch/test_request_test.rb @@ -18,7 +18,7 @@ class TestRequestTest < ActiveSupport::TestCase assert_equal "0.0.0.0", env.delete("REMOTE_ADDR") assert_equal "Rails Testing", env.delete("HTTP_USER_AGENT") - assert_equal [1, 0], env.delete("rack.version") + assert_equal [1, 1], env.delete("rack.version") assert_equal "", env.delete("rack.input").string assert_kind_of StringIO, env.delete("rack.errors") assert_equal true, env.delete("rack.multithread") -- cgit v1.2.3