Permalink
Browse files

Make it up to date with Rails 3.

1 parent 7d22296 commit 7d02b8ad57db693f74606b9cf3693cd73caf18d6 @josevalim josevalim committed Apr 10, 2010
Showing with 89 additions and 130 deletions.
  1. +1 −1 lib/action_controller/verification.rb
  2. +7 −48 test/test_helper.rb
  3. +81 −81 test/verification_test.rb
@@ -108,7 +108,7 @@ def verify_presence_of_keys_in_hash_flash_or_params(options) # :nodoc:
end
def verify_method(options) # :nodoc:
- [*options[:method]].all? { |v| request.method != v.to_sym } if options[:method]
+ [*options[:method]].all? { |v| request.method_symbol != v.to_sym } if options[:method]
end
def verify_request_xhr_status(options) # :nodoc:
View
@@ -4,56 +4,15 @@
require 'action_controller'
require File.dirname(__FILE__) + '/../lib/action_controller/verification'
-# Extracted this code from action_controller/abstract_unit.rb
-module SetupOnce
- extend ActiveSupport::Concern
-
- included do
- cattr_accessor :setup_once_block
- self.setup_once_block = nil
-
- setup :run_setup_once
- end
-
- module ClassMethods
- def setup_once(&block)
- self.setup_once_block = block
- end
- end
-
- private
- def run_setup_once
- if self.setup_once_block
- self.setup_once_block.call
- self.setup_once_block = nil
- end
- end
+SharedTestRoutes = ActionDispatch::Routing::RouteSet.new
+SharedTestRoutes.draw do |map|
+ map.connect ":controller/:action/:id"
end
-class ActiveSupport::TestCase
- include SetupOnce
+ActionController::Base.send :include, SharedTestRoutes.url_helpers
- # Hold off drawing routes until all the possible controller classes
- # have been loaded.
- setup_once do
- ActionController::Routing::Routes.draw do |map|
- match ':controller(/:action(/:id))'
- end
+module ActionController
+ class TestCase
+ setup { @routes = SharedTestRoutes }
end
end
-
-class ActionController::IntegrationTest < ActiveSupport::TestCase
- def self.build_app(routes = nil)
- ActionDispatch::Flash
- ActionDispatch::MiddlewareStack.new { |middleware|
- middleware.use "ActionDispatch::ShowExceptions"
- middleware.use "ActionDispatch::Callbacks"
- middleware.use "ActionDispatch::ParamsParser"
- middleware.use "ActionDispatch::Cookies"
- middleware.use "ActionDispatch::Flash"
- middleware.use "ActionDispatch::Head"
- }.build(routes || ActionController::Routing::Routes)
- end
-
- self.app = build_app
-end
@@ -1,115 +1,115 @@
require 'test_helper'
-class VerificationTest < ActionController::TestCase
- class TestController < ActionController::Base
- verify :only => :guarded_one, :params => "one",
- :add_flash => { :error => 'unguarded' },
- :redirect_to => { :action => "unguarded" }
+class VerificationTestController < ActionController::Base
+ verify :only => :guarded_one, :params => "one",
+ :add_flash => { :error => 'unguarded' },
+ :redirect_to => { :action => "unguarded" }
- verify :only => :guarded_two, :params => %w( one two ),
- :redirect_to => { :action => "unguarded" }
+ verify :only => :guarded_two, :params => %w( one two ),
+ :redirect_to => { :action => "unguarded" }
- verify :only => :guarded_with_flash, :params => "one",
- :add_flash => { :notice => "prereqs failed" },
- :redirect_to => { :action => "unguarded" }
+ verify :only => :guarded_with_flash, :params => "one",
+ :add_flash => { :notice => "prereqs failed" },
+ :redirect_to => { :action => "unguarded" }
- verify :only => :guarded_in_session, :session => "one",
- :redirect_to => { :action => "unguarded" }
+ verify :only => :guarded_in_session, :session => "one",
+ :redirect_to => { :action => "unguarded" }
- verify :only => [:multi_one, :multi_two], :session => %w( one two ),
- :redirect_to => { :action => "unguarded" }
+ verify :only => [:multi_one, :multi_two], :session => %w( one two ),
+ :redirect_to => { :action => "unguarded" }
- verify :only => :guarded_by_method, :method => :post,
- :redirect_to => { :action => "unguarded" }
+ verify :only => :guarded_by_method, :method => :post,
+ :redirect_to => { :action => "unguarded" }
- verify :only => :guarded_by_xhr, :xhr => true,
- :redirect_to => { :action => "unguarded" }
+ verify :only => :guarded_by_xhr, :xhr => true,
+ :redirect_to => { :action => "unguarded" }
- verify :only => :guarded_by_not_xhr, :xhr => false,
- :redirect_to => { :action => "unguarded" }
+ verify :only => :guarded_by_not_xhr, :xhr => false,
+ :redirect_to => { :action => "unguarded" }
- before_filter :unconditional_redirect, :only => :two_redirects
- verify :only => :two_redirects, :method => :post,
- :redirect_to => { :action => "unguarded" }
+ before_filter :unconditional_redirect, :only => :two_redirects
+ verify :only => :two_redirects, :method => :post,
+ :redirect_to => { :action => "unguarded" }
- verify :only => :must_be_post, :method => :post, :render => { :status => 405, :text => "Must be post" }, :add_headers => { "Allow" => "POST" }
+ verify :only => :must_be_post, :method => :post, :render => { :status => 405, :text => "Must be post" }, :add_headers => { "Allow" => "POST" }
- verify :only => :guarded_one_for_named_route_test, :params => "one",
- :redirect_to => :foo_url
+ verify :only => :guarded_one_for_named_route_test, :params => "one",
+ :redirect_to => :foo_url
- verify :only => :no_default_action, :params => "santa"
+ verify :only => :no_default_action, :params => "santa"
- verify :only => :guarded_with_back, :method => :post,
- :redirect_to => :back
+ verify :only => :guarded_with_back, :method => :post,
+ :redirect_to => :back
- def guarded_one
- render :text => "#{params[:one]}"
- end
+ def guarded_one
+ render :text => "#{params[:one]}"
+ end
- def guarded_one_for_named_route_test
- render :text => "#{params[:one]}"
- end
+ def guarded_one_for_named_route_test
+ render :text => "#{params[:one]}"
+ end
- def guarded_with_flash
- render :text => "#{params[:one]}"
- end
+ def guarded_with_flash
+ render :text => "#{params[:one]}"
+ end
- def guarded_two
- render :text => "#{params[:one]}:#{params[:two]}"
- end
+ def guarded_two
+ render :text => "#{params[:one]}:#{params[:two]}"
+ end
- def guarded_in_session
- render :text => "#{session["one"]}"
- end
+ def guarded_in_session
+ render :text => "#{session["one"]}"
+ end
- def multi_one
- render :text => "#{session["one"]}:#{session["two"]}"
- end
+ def multi_one
+ render :text => "#{session["one"]}:#{session["two"]}"
+ end
- def multi_two
- render :text => "#{session["two"]}:#{session["one"]}"
- end
+ def multi_two
+ render :text => "#{session["two"]}:#{session["one"]}"
+ end
- def guarded_by_method
- render :text => "#{request.method}"
- end
+ def guarded_by_method
+ render :text => "#{request.method}"
+ end
- def guarded_by_xhr
- render :text => "#{request.xhr?}"
- end
+ def guarded_by_xhr
+ render :text => "#{request.xhr?}"
+ end
- def guarded_by_not_xhr
- render :text => "#{request.xhr?}"
- end
+ def guarded_by_not_xhr
+ render :text => "#{request.xhr?}"
+ end
- def unguarded
- render :text => "#{params[:one]}"
- end
+ def unguarded
+ render :text => "#{params[:one]}"
+ end
- def two_redirects
- render :nothing => true
- end
+ def two_redirects
+ render :nothing => true
+ end
- def must_be_post
- render :text => "Was a post!"
- end
+ def must_be_post
+ render :text => "Was a post!"
+ end
- def guarded_with_back
- render :text => "#{params[:one]}"
- end
+ def guarded_with_back
+ render :text => "#{params[:one]}"
+ end
- def no_default_action
- # Will never run
- end
+ def no_default_action
+ # Will never run
+ end
- protected
+ protected
- def unconditional_redirect
- redirect_to :action => "unguarded"
- end
+ def unconditional_redirect
+ redirect_to :action => "unguarded"
end
+end
- tests TestController
+class VerificationTest < ActionController::TestCase
+ tests ::VerificationTestController
def test_using_symbol_back_with_no_referrer
assert_raise(ActionController::RedirectBackError) { get :guarded_with_back }
@@ -126,7 +126,7 @@ def test_no_deprecation_warning_for_named_route
with_routing do |set|
set.draw do |map|
match 'foo', :to => 'test#foo', :as => :foo
- match 'verification_test/:action', :to => ::VerificationTest::TestController
+ match 'verification_test/:action', :to => ::VerificationTestController
end
get :guarded_one_for_named_route_test, :two => "not one"
assert_redirected_to '/foo'
@@ -219,7 +219,7 @@ def test_multi_two_without_prereqs
def test_guarded_by_method_with_prereqs
post :guarded_by_method
- assert_equal "post", @response.body
+ assert_equal "POST", @response.body
end
def test_guarded_by_method_without_prereqs

0 comments on commit 7d02b8a

Please sign in to comment.