diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-03-29 17:38:43 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-03-29 17:38:43 -0700 |
commit | 0471fc9f1cf95865a9810b46f1227783fee40ab5 (patch) | |
tree | 50c6a1990e7b97b7960a692c9441e686cbcb4902 /actionpack/test/controller | |
parent | 28c73f012328c8386acfc608f0dfb1a459dbf170 (diff) | |
parent | 58becf116580c37c63b89f4a660ebe293f6e7c4e (diff) | |
download | rails-0471fc9f1cf95865a9810b46f1227783fee40ab5.tar.gz rails-0471fc9f1cf95865a9810b46f1227783fee40ab5.tar.bz2 rails-0471fc9f1cf95865a9810b46f1227783fee40ab5.zip |
Merge branch 'master' into zomg
* master: (51 commits)
order is not guaranteed by this select, so add an order and call first!
oracle stores this with microseconds, so convert to seconds before comparing
make sure that active connections are not cleared during test when an exception happens
clearing active connections in the ConnectionManagement middleware if an exception happens
proxy body responses so we close database connections after body is flushed
Pass the proper method_name instead of hardcoding to action_name.
Quote find_in_batches ORDER BY clause [#6620 state:resolved]
Delegate first!, last!, any? and many? to scoped
Dont call authenticate_or_request_with_http_basic twice
Remove 'warning: ambiguous first argument' when running ActionPack tests
Change exists? so that it doesn't instantiate records [#6127 state:resolved]
Move mapper_test to the appropriate location
Update the wildcard route to be non-greedy by default, therefore be able to match the (.:format) segment [#6605 state:resolved]
Fix examples
Added Base.http_basic_authenticate_with to do simple http basic authentication with a single class method call [DHH]
make sure we have an active database connection before running each connection management test
adding active_connections? to the connection pool for finding open connections
adding active_connection? to the connection pool
testing app delegation from the ConnectionManagement middleware
namespacing connection management tests. :heart:
...
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r-- | actionpack/test/controller/force_ssl_test.rb | 83 | ||||
-rw-r--r-- | actionpack/test/controller/http_basic_authentication_test.rb | 16 |
2 files changed, 99 insertions, 0 deletions
diff --git a/actionpack/test/controller/force_ssl_test.rb b/actionpack/test/controller/force_ssl_test.rb new file mode 100644 index 0000000000..3e723e20d9 --- /dev/null +++ b/actionpack/test/controller/force_ssl_test.rb @@ -0,0 +1,83 @@ +require 'abstract_unit' + +class ForceSSLController < ActionController::Base + def banana + render :text => "monkey" + end + + def cheeseburger + render :text => "sikachu" + end +end + +class ForceSSLControllerLevel < ForceSSLController + force_ssl +end + +class ForceSSLOnlyAction < ForceSSLController + force_ssl :only => :cheeseburger +end + +class ForceSSLExceptAction < ForceSSLController + force_ssl :except => :banana +end + +class ForceSSLControllerLevelTest < ActionController::TestCase + tests ForceSSLControllerLevel + + def test_banana_redirects_to_https + get :banana + assert_response 301 + assert_equal "https://test.host/force_ssl_controller_level/banana", redirect_to_url + end + + def test_cheeseburger_redirects_to_https + get :cheeseburger + assert_response 301 + assert_equal "https://test.host/force_ssl_controller_level/cheeseburger", redirect_to_url + end +end + +class ForceSSLOnlyActionTest < ActionController::TestCase + tests ForceSSLOnlyAction + + def test_banana_not_redirects_to_https + get :banana + assert_response 200 + end + + def test_cheeseburger_redirects_to_https + get :cheeseburger + assert_response 301 + assert_equal "https://test.host/force_ssl_only_action/cheeseburger", redirect_to_url + end +end + +class ForceSSLExceptActionTest < ActionController::TestCase + tests ForceSSLExceptAction + + def test_banana_not_redirects_to_https + get :banana + assert_response 200 + end + + def test_cheeseburger_redirects_to_https + get :cheeseburger + assert_response 301 + assert_equal "https://test.host/force_ssl_except_action/cheeseburger", redirect_to_url + end +end + +class ForceSSLExcludeDevelopmentTest < ActionController::TestCase + tests ForceSSLControllerLevel + + def setup + Rails.env.stubs(:development?).returns(false) + end + + def test_development_environment_not_redirects_to_https + Rails.env.stubs(:development?).returns(true) + get :banana + assert_response 200 + end +end
\ No newline at end of file diff --git a/actionpack/test/controller/http_basic_authentication_test.rb b/actionpack/test/controller/http_basic_authentication_test.rb index 01c650a494..bd3e13e6fa 100644 --- a/actionpack/test/controller/http_basic_authentication_test.rb +++ b/actionpack/test/controller/http_basic_authentication_test.rb @@ -6,6 +6,8 @@ class HttpBasicAuthenticationTest < ActionController::TestCase before_filter :authenticate_with_request, :only => :display before_filter :authenticate_long_credentials, :only => :show + http_basic_authenticate_with :name => "David", :password => "Goliath", :only => :search + def index render :text => "Hello Secret" end @@ -17,6 +19,10 @@ class HttpBasicAuthenticationTest < ActionController::TestCase def show render :text => 'Only for loooooong credentials' end + + def search + render :text => 'All inline' + end private @@ -104,6 +110,16 @@ class HttpBasicAuthenticationTest < ActionController::TestCase assert assigns(:logged_in) assert_equal 'Definitely Maybe', @response.body end + + test "authenticate with class method" do + @request.env['HTTP_AUTHORIZATION'] = encode_credentials('David', 'Goliath') + get :search + assert_response :success + + @request.env['HTTP_AUTHORIZATION'] = encode_credentials('David', 'WRONG!') + get :search + assert_response :unauthorized + end private |