1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge commit 'rails/master'

This commit is contained in:
Emilio Tagua 2009-10-05 11:30:18 -03:00
commit 9a71b6d29d
50 changed files with 391 additions and 390 deletions

View file

@ -34,22 +34,21 @@ end
desc "Run all unit tests"
task :test => [:test_action_pack, :test_active_record_integration]
TESTS_GLOB = "test/{abstract,controller,dispatch,new_base,template,html-scanner,view}/**/*_test.rb"
Rake::TestTask.new(:test_action_pack) do |t|
t.libs << 'test'
# make sure we include the tests in alphabetical order as on some systems
# this will not happen automatically and the tests (as a whole) will error
t.test_files = Dir.glob(TESTS_GLOB).sort
t.test_files = Dir.glob('test/{abstract,controller,dispatch,template}/**/*_test.rb').sort
t.verbose = true
# t.warning = true
end
task :isolated_test do
ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME'))
Dir.glob(TESTS_GLOB).all? { |file| system(ruby, '-Ilib:test', file) } or raise "Failures"
namespace :test do
Rake::TestTask.new(:isolated) do |t|
t.pattern = 'test/ts_isolated.rb'
end
end
desc 'ActiveRecord Integration Tests'

View file

@ -1,3 +1,4 @@
require 'active_support/core_ext/big_decimal/conversions'
require 'active_support/core_ext/float/rounding'
module ActionView

View file

@ -51,23 +51,72 @@ I18n.backend.store_translations 'pt-BR', {}
ORIGINAL_LOCALES = I18n.available_locales.map {|locale| locale.to_s }.sort
FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures')
FIXTURES = Pathname.new(FIXTURE_LOAD_PATH)
class ActionController::IntegrationTest < ActiveSupport::TestCase
@@app = ActionDispatch::MiddlewareStack.new { |middleware|
middleware.use "ActionDispatch::ShowExceptions"
middleware.use "ActionDispatch::Callbacks"
middleware.use "ActionDispatch::ParamsParser"
middleware.use "Rack::Head"
}.build(ActionController::Routing::Routes)
end
module SetupOnce
extend ActiveSupport::Concern
module ActionView
class TestCase
setup do
ActionController::Routing::Routes.draw do |map|
map.connect ':controller/:action/:id'
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
end
class ActiveSupport::TestCase
include SetupOnce
# Hold off drawing routes until all the possible controller classes
# have been loaded.
setup_once do
ActionController::Routing::Routes.draw do |map|
map.connect ':controller/:action/:id'
end
end
end
class ActionController::IntegrationTest < ActiveSupport::TestCase
def self.build_app(routes = nil)
ActionDispatch::MiddlewareStack.new { |middleware|
middleware.use "ActionDispatch::ShowExceptions"
middleware.use "ActionDispatch::Callbacks"
middleware.use "ActionDispatch::ParamsParser"
middleware.use "Rack::Head"
}.build(routes || ActionController::Routing::Routes)
end
self.app = build_app
def with_routing(&block)
real_routes = ActionController::Routing::Routes
ActionController::Routing.module_eval { remove_const :Routes }
temporary_routes = ActionController::Routing::RouteSet.new
self.class.app = self.class.build_app(temporary_routes)
ActionController::Routing.module_eval { const_set :Routes, temporary_routes }
yield temporary_routes
ensure
if ActionController::Routing.const_defined? :Routes
ActionController::Routing.module_eval { remove_const :Routes }
end
ActionController::Routing.const_set(:Routes, real_routes) if real_routes
self.class.app = self.class.build_app
end
end
@ -138,18 +187,12 @@ module ActionController
super
end
end
Base.view_paths = FIXTURE_LOAD_PATH
class TestCase
include TestProcess
setup do
ActionController::Routing::Routes.draw do |map|
map.connect ':controller/:action/:id'
end
end
def assert_template(options = {}, message = nil)
validate_request!
@ -192,11 +235,3 @@ module ActionController
end
end
end
class SimpleRouteCase < Rack::TestCase
setup do
ActionController::Routing::Routes.draw do |map|
map.connect ':controller/:action/:id'
end
end
end

View file

@ -158,7 +158,6 @@ class ActiveRecordStoreTest < ActionController::IntegrationTest
map.connect "/:action", :controller => "active_record_store_test/test"
end
@app = ActiveRecord::SessionStore.new(set, options.reverse_merge(:key => '_session_id'))
reset!
yield
end
end

View file

@ -46,14 +46,8 @@ end
class PageCachingTest < ActionController::TestCase
def setup
super
ActionController::Base.perform_caching = true
ActionController::Routing::Routes.draw do |map|
map.main '', :controller => 'posts', :format => nil
map.formatted_posts 'posts.:format', :controller => 'posts'
map.resources :posts
map.connect ':controller/:action/:id'
end
ActionController::Base.perform_caching = true
@request = ActionController::TestRequest.new
@request.host = 'hostname.com'
@ -74,10 +68,16 @@ class PageCachingTest < ActionController::TestCase
end
def test_page_caching_resources_saves_to_correct_path_with_extension_even_if_default_route
@params[:format] = 'rss'
assert_equal '/posts.rss', @rewriter.rewrite(@params)
@params[:format] = nil
assert_equal '/', @rewriter.rewrite(@params)
with_routing do |set|
set.draw do |map|
map.main '', :controller => 'posts', :format => nil
map.formatted_posts 'posts.:format', :controller => 'posts'
end
@params[:format] = 'rss'
assert_equal '/posts.rss', @rewriter.rewrite(@params)
@params[:format] = nil
assert_equal '/', @rewriter.rewrite(@params)
end
end
def test_should_cache_get_with_ok_status

View file

@ -372,11 +372,8 @@ class IntegrationProcessTest < ActionController::IntegrationTest
def with_test_route_set
with_routing do |set|
set.draw do |map|
map.with_options :controller => "IntegrationProcessTest::Integration" do |c|
c.connect "/:action"
end
map.connect "/:action", :controller => "integration_process_test/integration"
end
reset!
yield
end
end

View file

@ -527,12 +527,6 @@ class RespondWithControllerTest < ActionController::TestCase
super
ActionController::Base.use_accept_header = true
@request.host = "www.example.com"
ActionController::Routing::Routes.draw do |map|
map.resources :customers
map.resources :quiz_stores, :has_many => :customers
map.connect ":controller/:action/:id"
end
end
def teardown
@ -593,53 +587,59 @@ class RespondWithControllerTest < ActionController::TestCase
end
def test_using_resource_for_post_with_html
post :using_resource
assert_equal "text/html", @response.content_type
assert_equal 302, @response.status
assert_equal "http://www.example.com/customers/13", @response.location
assert @response.redirect?
with_test_route_set do
post :using_resource
assert_equal "text/html", @response.content_type
assert_equal 302, @response.status
assert_equal "http://www.example.com/customers/13", @response.location
assert @response.redirect?
errors = { :name => :invalid }
Customer.any_instance.stubs(:errors).returns(errors)
post :using_resource
assert_equal "text/html", @response.content_type
assert_equal 200, @response.status
assert_equal "New world!\n", @response.body
assert_nil @response.location
errors = { :name => :invalid }
Customer.any_instance.stubs(:errors).returns(errors)
post :using_resource
assert_equal "text/html", @response.content_type
assert_equal 200, @response.status
assert_equal "New world!\n", @response.body
assert_nil @response.location
end
end
def test_using_resource_for_post_with_xml
@request.accept = "application/xml"
with_test_route_set do
@request.accept = "application/xml"
post :using_resource
assert_equal "application/xml", @response.content_type
assert_equal 201, @response.status
assert_equal "<name>david</name>", @response.body
assert_equal "http://www.example.com/customers/13", @response.location
post :using_resource
assert_equal "application/xml", @response.content_type
assert_equal 201, @response.status
assert_equal "<name>david</name>", @response.body
assert_equal "http://www.example.com/customers/13", @response.location
errors = { :name => :invalid }
Customer.any_instance.stubs(:errors).returns(errors)
post :using_resource
assert_equal "application/xml", @response.content_type
assert_equal 422, @response.status
assert_equal errors.to_xml, @response.body
assert_nil @response.location
errors = { :name => :invalid }
Customer.any_instance.stubs(:errors).returns(errors)
post :using_resource
assert_equal "application/xml", @response.content_type
assert_equal 422, @response.status
assert_equal errors.to_xml, @response.body
assert_nil @response.location
end
end
def test_using_resource_for_put_with_html
put :using_resource
assert_equal "text/html", @response.content_type
assert_equal 302, @response.status
assert_equal "http://www.example.com/customers/13", @response.location
assert @response.redirect?
with_test_route_set do
put :using_resource
assert_equal "text/html", @response.content_type
assert_equal 302, @response.status
assert_equal "http://www.example.com/customers/13", @response.location
assert @response.redirect?
errors = { :name => :invalid }
Customer.any_instance.stubs(:errors).returns(errors)
put :using_resource
assert_equal "text/html", @response.content_type
assert_equal 200, @response.status
assert_equal "Edit world!\n", @response.body
assert_nil @response.location
errors = { :name => :invalid }
Customer.any_instance.stubs(:errors).returns(errors)
put :using_resource
assert_equal "text/html", @response.content_type
assert_equal 200, @response.status
assert_equal "Edit world!\n", @response.body
assert_nil @response.location
end
end
def test_using_resource_for_put_with_xml
@ -660,11 +660,13 @@ class RespondWithControllerTest < ActionController::TestCase
end
def test_using_resource_for_delete_with_html
Customer.any_instance.stubs(:destroyed?).returns(true)
delete :using_resource
assert_equal "text/html", @response.content_type
assert_equal 302, @response.status
assert_equal "http://www.example.com/customers", @response.location
with_test_route_set do
Customer.any_instance.stubs(:destroyed?).returns(true)
delete :using_resource
assert_equal "text/html", @response.content_type
assert_equal 302, @response.status
assert_equal "http://www.example.com/customers", @response.location
end
end
def test_using_resource_for_delete_with_xml
@ -685,21 +687,23 @@ class RespondWithControllerTest < ActionController::TestCase
end
def test_using_resource_with_parent_for_post
@request.accept = "application/xml"
with_test_route_set do
@request.accept = "application/xml"
post :using_resource_with_parent
assert_equal "application/xml", @response.content_type
assert_equal 201, @response.status
assert_equal "<name>david</name>", @response.body
assert_equal "http://www.example.com/quiz_stores/11/customers/13", @response.location
post :using_resource_with_parent
assert_equal "application/xml", @response.content_type
assert_equal 201, @response.status
assert_equal "<name>david</name>", @response.body
assert_equal "http://www.example.com/quiz_stores/11/customers/13", @response.location
errors = { :name => :invalid }
Customer.any_instance.stubs(:errors).returns(errors)
post :using_resource
assert_equal "application/xml", @response.content_type
assert_equal 422, @response.status
assert_equal errors.to_xml, @response.body
assert_nil @response.location
errors = { :name => :invalid }
Customer.any_instance.stubs(:errors).returns(errors)
post :using_resource
assert_equal "application/xml", @response.content_type
assert_equal 422, @response.status
assert_equal errors.to_xml, @response.body
assert_nil @response.location
end
end
def test_using_resource_with_collection
@ -773,6 +777,18 @@ class RespondWithControllerTest < ActionController::TestCase
get :default_overwritten
assert_equal 406, @response.status
end
private
def with_test_route_set
with_routing do |set|
set.draw do |map|
map.resources :customers
map.resources :quiz_stores, :has_many => :customers
map.connect ":controller/:action/:id"
end
yield
end
end
end
class AbstractPostController < ActionController::Base

View file

@ -26,7 +26,7 @@ module Dispatching
class ContainedEmptyController < ActionController::Base ; end
end
class BaseTest < SimpleRouteCase
class BaseTest < Rack::TestCase
# :api: plugin
test "simple dispatching" do
get "/dispatching/simple/index"

View file

@ -9,7 +9,7 @@ module ContentNegotiation
)]
end
class TestContentNegotiation < SimpleRouteCase
class TestContentNegotiation < Rack::TestCase
test "A */* Accept header will return HTML" do
get "/content_negotiation/basic/hello", {}, "HTTP_ACCEPT" => "*/*"
assert_body "Hello world */*!"

View file

@ -44,7 +44,7 @@ module ContentType
end
end
class ExplicitContentTypeTest < SimpleRouteCase
class ExplicitContentTypeTest < Rack::TestCase
test "default response is HTML and UTF8" do
get "/content_type/base"
@ -67,7 +67,7 @@ module ContentType
end
end
class ImpliedContentTypeTest < SimpleRouteCase
class ImpliedContentTypeTest < Rack::TestCase
test "sets Content-Type as text/html when rendering *.html.erb" do
get "/content_type/implied/i_am_html_erb"
@ -93,7 +93,7 @@ module ContentType
end
end
class ExplicitCharsetTest < SimpleRouteCase
class ExplicitCharsetTest < Rack::TestCase
test "setting the charset of the response directly on the response object" do
get "/content_type/charset/set_on_response_obj"

View file

@ -16,7 +16,7 @@ module Etags
end
end
class EtagTest < SimpleRouteCase
class EtagTest < Rack::TestCase
describe "Rendering without any special etag options returns an etag that is an MD5 hash of its text"
test "an action without a layout" do

View file

@ -45,7 +45,7 @@ module RenderAction
end
class RenderActionTest < SimpleRouteCase
class RenderActionTest < Rack::TestCase
test "rendering an action using :action => <String>" do
get "/render_action/basic/hello_world"
@ -82,7 +82,7 @@ module RenderAction
end
end
class RenderLayoutTest < SimpleRouteCase
class RenderLayoutTest < Rack::TestCase
describe "Both <controller_path>.html.erb and application.html.erb are missing"
test "rendering with layout => true" do
@ -150,7 +150,7 @@ module RenderActionWithApplicationLayout
end
end
class LayoutTest < SimpleRouteCase
class LayoutTest < Rack::TestCase
describe "Only application.html.erb is present and <controller_path>.html.erb is missing"
test "rendering implicit application.html.erb as layout" do
@ -189,7 +189,7 @@ module RenderActionWithApplicationLayout
end
end
class TestLayout < SimpleRouteCase
class TestLayout < Rack::TestCase
testing BasicController
test "builder works with layouts" do
@ -228,7 +228,7 @@ module RenderActionWithControllerLayout
end
end
class ControllerLayoutTest < SimpleRouteCase
class ControllerLayoutTest < Rack::TestCase
describe "Only <controller_path>.html.erb is present and application.html.erb is missing"
test "render hello_world and implicitly use <controller_path>.html.erb as a layout." do
@ -286,7 +286,7 @@ module RenderActionWithBothLayouts
end
end
class ControllerLayoutTest < SimpleRouteCase
class ControllerLayoutTest < Rack::TestCase
describe "Both <controller_path>.html.erb and application.html.erb are present"
test "rendering implicitly use <controller_path>.html.erb over application.html.erb as a layout" do

View file

@ -1,110 +1,99 @@
require 'abstract_unit'
module RenderFile
class BasicController < ActionController::Base
self.view_paths = File.dirname(__FILE__)
self.view_paths = File.dirname(__FILE__)
def index
render :file => File.join(File.dirname(__FILE__), *%w[.. fixtures test hello_world])
render :file => File.join(File.dirname(__FILE__), *%w[.. .. fixtures test hello_world])
end
def with_instance_variables
@secret = 'in the sauce'
render :file => File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_ivar.erb')
render :file => File.join(File.dirname(__FILE__), '../../fixtures/test/render_file_with_ivar.erb')
end
def without_file_key
render File.join(File.dirname(__FILE__), *%w[.. fixtures test hello_world])
render File.join(File.dirname(__FILE__), *%w[.. .. fixtures test hello_world])
end
def without_file_key_with_instance_variable
@secret = 'in the sauce'
render File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_ivar.erb')
render File.join(File.dirname(__FILE__), '../../fixtures/test/render_file_with_ivar.erb')
end
def relative_path
@secret = 'in the sauce'
render :file => '../fixtures/test/render_file_with_ivar'
render :file => '../../fixtures/test/render_file_with_ivar'
end
def relative_path_with_dot
@secret = 'in the sauce'
render :file => '../fixtures/test/dot.directory/render_file_with_ivar'
render :file => '../../fixtures/test/dot.directory/render_file_with_ivar'
end
def pathname
@secret = 'in the sauce'
render :file => Pathname.new(File.dirname(__FILE__)).join(*%w[.. fixtures test dot.directory render_file_with_ivar.erb])
render :file => Pathname.new(File.dirname(__FILE__)).join(*%w[.. .. fixtures test dot.directory render_file_with_ivar.erb])
end
def with_locals
path = File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_locals.erb')
path = File.join(File.dirname(__FILE__), '../../fixtures/test/render_file_with_locals.erb')
render :file => path, :locals => {:secret => 'in the sauce'}
end
def without_file_key_with_locals
path = File.expand_path('../fixtures/test/render_file_with_locals.erb')
path = FIXTURES.join('test/render_file_with_locals.erb').to_s
render path, :locals => {:secret => 'in the sauce'}
end
end
class TestBasic < SimpleRouteCase
class TestBasic < Rack::TestCase
testing RenderFile::BasicController
def setup
@old_pwd = Dir.pwd
Dir.chdir(File.dirname(__FILE__))
end
def teardown
Dir.chdir(@old_pwd)
end
test "rendering simple template" do
get :index
assert_response "Hello world!"
end
test "rendering template with ivar" do
get :with_instance_variables
assert_response "The secret is in the sauce\n"
end
test "rendering path without specifying the :file key" do
get :without_file_key
assert_response "Hello world!"
end
test "rendering path without specifying the :file key with ivar" do
get :without_file_key_with_instance_variable
assert_response "The secret is in the sauce\n"
end
test "rendering a relative path" do
get :relative_path
assert_response "The secret is in the sauce\n"
end
test "rendering a relative path with dot" do
get :relative_path_with_dot
assert_response "The secret is in the sauce\n"
end
test "rendering a Pathname" do
get :pathname
assert_response "The secret is in the sauce\n"
end
test "rendering file with locals" do
get :with_locals
assert_response "The secret is in the sauce\n"
end
test "rendering path without specifying the :file key with locals" do
get :without_file_key_with_locals
assert_response "The secret is in the sauce\n"
end
end
end

View file

@ -10,7 +10,7 @@ module RenderImplicitAction
def hello_world() end
end
class RenderImplicitActionTest < SimpleRouteCase
class RenderImplicitActionTest < Rack::TestCase
test "render a simple action with new explicit call to render" do
get "/render_implicit_action/simple/hello_world"

View file

@ -36,7 +36,7 @@ module ControllerLayouts
end
end
class RenderLayoutTest < SimpleRouteCase
class RenderLayoutTest < Rack::TestCase
test "rendering a normal template, but using the implicit layout" do
get "/controller_layouts/implicit/index"
@ -58,7 +58,7 @@ module ControllerLayouts
end
class LayoutOptionsTest < SimpleRouteCase
class LayoutOptionsTest < Rack::TestCase
testing ControllerLayouts::ImplicitController
test "rendering with :layout => false leaves out the implicit layout" do
@ -79,7 +79,7 @@ module ControllerLayouts
end
end
class MismatchFormatTest < SimpleRouteCase
class MismatchFormatTest < Rack::TestCase
testing ControllerLayouts::MismatchFormatController
test "if JS is selected, an HTML template is not also selected" do

View file

@ -15,7 +15,7 @@ module RenderPartial
end
end
class TestPartial < SimpleRouteCase
class TestPartial < Rack::TestCase
testing BasicController
test "rendering a partial in ActionView doesn't pull the ivars again from the controller" do

View file

@ -21,7 +21,7 @@ module RenderRjs
end
end
class TestBasic < SimpleRouteCase
class TestBasic < Rack::TestCase
testing BasicController
def setup

View file

@ -39,7 +39,7 @@ module RenderTemplate
end
end
class TestWithoutLayout < SimpleRouteCase
class TestWithoutLayout < Rack::TestCase
testing RenderTemplate::WithoutLayoutController
test "rendering a normal template with full path without layout" do
@ -107,7 +107,7 @@ module RenderTemplate
end
end
class TestWithLayout < SimpleRouteCase
class TestWithLayout < Rack::TestCase
describe "Rendering with :template using implicit or explicit layout"
test "rendering with implicit layout" do
@ -158,7 +158,7 @@ module RenderTemplate
end
end
class TestTemplateRenderWithForwardSlash < SimpleRouteCase
class TestTemplateRenderWithForwardSlash < Rack::TestCase
test "rendering a normal template with full path starting with a leading slash" do
get "/render_template/compatibility/without_layout/with_forward_slash"

View file

@ -35,7 +35,7 @@ module Render
end
end
class RenderTest < SimpleRouteCase
class RenderTest < Rack::TestCase
test "render with blank" do
get "/render/blank_render"
@ -50,7 +50,7 @@ module Render
end
end
class TestOnlyRenderPublicActions < SimpleRouteCase
class TestOnlyRenderPublicActions < Rack::TestCase
describe "Only public methods on actual controllers are callable actions"
test "raises an exception when a method of Object is called" do
@ -66,7 +66,7 @@ module Render
end
end
class TestVariousObjectsAvailableInView < SimpleRouteCase
class TestVariousObjectsAvailableInView < Rack::TestCase
test "The request object is accessible in the view" do
get "/render/blank_render/access_request"
assert_body "The request: GET"

View file

@ -62,7 +62,7 @@ module RenderText
end
end
class RenderTextTest < SimpleRouteCase
class RenderTextTest < Rack::TestCase
describe "Rendering text using render :text"
test "rendering text from a action with default options renders the text with the layout" do

View file

@ -347,7 +347,6 @@ class RescueTest < ActionController::IntegrationTest
map.connect 'invalid', :controller => "rescue_test/test", :action => 'invalid'
map.connect 'b00m', :controller => "rescue_test/test", :action => 'b00m'
end
reset!
yield
end
end

View file

@ -669,21 +669,13 @@ class LegacyRouteSetTests < Test::Unit::TestCase
%w(GET POST PUT DELETE).each do |request_method|
define_method("test_request_method_recognized_with_#{request_method}") do
begin
Object.const_set(:BooksController, Class.new(ActionController::Base))
setup_request_method_routes_for(request_method)
assert_nothing_raised { rs.recognize(@request) }
assert_equal request_method.downcase, @request.path_parameters[:action]
ensure
Object.send(:remove_const, :BooksController) rescue nil
end
setup_request_method_routes_for(request_method)
assert_nothing_raised { rs.recognize(@request) }
assert_equal request_method.downcase, @request.path_parameters[:action]
end
end
def test_recognize_array_of_methods
Object.const_set(:BooksController, Class.new(ActionController::Base))
rs.draw do |r|
r.connect '/match', :controller => 'books', :action => 'get_or_post', :conditions => { :method => [:get, :post] }
r.connect '/match', :controller => 'books', :action => 'not_get_or_post'
@ -701,13 +693,9 @@ class LegacyRouteSetTests < Test::Unit::TestCase
@request.request_uri = "/match"
assert_nothing_raised { rs.recognize(@request) }
assert_equal 'not_get_or_post', @request.path_parameters[:action]
ensure
Object.send(:remove_const, :BooksController) rescue nil
end
def test_subpath_recognized
Object.const_set(:SubpathBooksController, Class.new(ActionController::Base))
rs.draw do |r|
r.connect '/books/:id/edit', :controller => 'subpath_books', :action => 'edit'
r.connect '/items/:id/:action', :controller => 'subpath_books'
@ -730,13 +718,9 @@ class LegacyRouteSetTests < Test::Unit::TestCase
hash = rs.recognize_path "/posts/7"
assert_not_nil hash
assert_equal %w(subpath_books show 7), [hash[:controller], hash[:action], hash[:id]]
ensure
Object.send(:remove_const, :SubpathBooksController) rescue nil
end
def test_subpath_generated
Object.const_set(:SubpathBooksController, Class.new(ActionController::Base))
rs.draw do |r|
r.connect '/books/:id/edit', :controller => 'subpath_books', :action => 'edit'
r.connect '/items/:id/:action', :controller => 'subpath_books'
@ -746,8 +730,6 @@ class LegacyRouteSetTests < Test::Unit::TestCase
assert_equal "/books/7/edit", rs.generate(:controller => "subpath_books", :id => 7, :action => "edit")
assert_equal "/items/15/complete", rs.generate(:controller => "subpath_books", :id => 15, :action => "complete")
assert_equal "/posts/new/preview", rs.generate(:controller => "subpath_books", :action => "preview")
ensure
Object.send(:remove_const, :SubpathBooksController) rescue nil
end
def test_failed_requirements_raises_exception_with_violated_requirements
@ -1122,8 +1104,6 @@ class RouteSetTest < ActiveSupport::TestCase
end
def test_recognize_with_conditions
Object.const_set(:PeopleController, Class.new)
set.draw do |map|
map.with_options(:controller => "people") do |people|
people.people "/people", :action => "index", :conditions => { :method => :get }
@ -1183,14 +1163,9 @@ class RouteSetTest < ActiveSupport::TestCase
assert_equal [:get, :put, :delete], e.allowed_methods
end
request.recycle!
ensure
Object.send(:remove_const, :PeopleController)
end
def test_recognize_with_alias_in_conditions
Object.const_set(:PeopleController, Class.new)
set.draw do |map|
map.people "/people", :controller => 'people', :action => "index",
:conditions => { :method => :get }
@ -1208,13 +1183,9 @@ class RouteSetTest < ActiveSupport::TestCase
assert_nothing_raised { set.recognize(request) }
assert_equal("people", request.path_parameters[:controller])
assert_equal("index", request.path_parameters[:action])
ensure
Object.send(:remove_const, :PeopleController)
end
def test_typo_recognition
Object.const_set(:ArticlesController, Class.new)
set.draw do |map|
map.connect 'articles/:year/:month/:day/:title',
:controller => 'articles', :action => 'permalink',
@ -1229,9 +1200,6 @@ class RouteSetTest < ActiveSupport::TestCase
assert_equal("11", request.path_parameters[:month])
assert_equal("05", request.path_parameters[:day])
assert_equal("a-very-interesting-article", request.path_parameters[:title])
ensure
Object.send(:remove_const, :ArticlesController)
end
def test_routing_traversal_does_not_load_extra_classes
@ -1248,8 +1216,6 @@ class RouteSetTest < ActiveSupport::TestCase
end
def test_recognize_with_conditions_and_format
Object.const_set(:PeopleController, Class.new)
set.draw do |map|
map.with_options(:controller => "people") do |people|
people.person "/people/:id", :action => "show", :conditions => { :method => :get }
@ -1276,8 +1242,6 @@ class RouteSetTest < ActiveSupport::TestCase
assert_equal("show", request.path_parameters[:action])
assert_equal("5", request.path_parameters[:id])
assert_equal("png", request.path_parameters[:_format])
ensure
Object.send(:remove_const, :PeopleController)
end
def test_generate_with_default_action
@ -1291,8 +1255,6 @@ class RouteSetTest < ActiveSupport::TestCase
end
def test_root_map
Object.const_set(:PeopleController, Class.new)
set.draw { |map| map.root :controller => "people" }
request.path = ""
@ -1300,13 +1262,9 @@ class RouteSetTest < ActiveSupport::TestCase
assert_nothing_raised { set.recognize(request) }
assert_equal("people", request.path_parameters[:controller])
assert_equal("index", request.path_parameters[:action])
ensure
Object.send(:remove_const, :PeopleController)
end
def test_namespace
Object.const_set(:Api, Module.new { |m| m.const_set(:ProductsController, Class.new) })
set.draw do |map|
map.namespace 'api' do |api|
@ -1320,13 +1278,9 @@ class RouteSetTest < ActiveSupport::TestCase
assert_nothing_raised { set.recognize(request) }
assert_equal("api/products", request.path_parameters[:controller])
assert_equal("inventory", request.path_parameters[:action])
ensure
Object.send(:remove_const, :Api)
end
def test_namespaced_root_map
Object.const_set(:Api, Module.new { |m| m.const_set(:ProductsController, Class.new) })
set.draw do |map|
map.namespace 'api' do |api|
@ -1340,13 +1294,9 @@ class RouteSetTest < ActiveSupport::TestCase
assert_nothing_raised { set.recognize(request) }
assert_equal("api/products", request.path_parameters[:controller])
assert_equal("index", request.path_parameters[:action])
ensure
Object.send(:remove_const, :Api)
end
def test_namespace_with_path_prefix
Object.const_set(:Api, Module.new { |m| m.const_set(:ProductsController, Class.new) })
set.draw do |map|
map.namespace 'api', :path_prefix => 'prefix' do |api|
api.route 'inventory', :controller => "products", :action => 'inventory'
@ -1358,13 +1308,9 @@ class RouteSetTest < ActiveSupport::TestCase
assert_nothing_raised { set.recognize(request) }
assert_equal("api/products", request.path_parameters[:controller])
assert_equal("inventory", request.path_parameters[:action])
ensure
Object.send(:remove_const, :Api)
end
def test_namespace_with_blank_path_prefix
Object.const_set(:Api, Module.new { |m| m.const_set(:ProductsController, Class.new) })
set.draw do |map|
map.namespace 'api', :path_prefix => '' do |api|
api.route 'inventory', :controller => "products", :action => 'inventory'
@ -1376,8 +1322,6 @@ class RouteSetTest < ActiveSupport::TestCase
assert_nothing_raised { set.recognize(request) }
assert_equal("api/products", request.path_parameters[:controller])
assert_equal("inventory", request.path_parameters[:action])
ensure
Object.send(:remove_const, :Api)
end
def test_generate_changes_controller_module

View file

@ -111,13 +111,6 @@ class VerificationTest < ActionController::TestCase
tests TestController
setup do
ActionController::Routing::Routes.draw do |map|
map.foo '/foo', :controller => 'test', :action => 'foo'
map.connect ":controller/:action/:id"
end
end
def test_using_symbol_back_with_no_referrer
assert_raise(ActionController::RedirectBackError) { get :guarded_with_back }
end
@ -130,8 +123,14 @@ class VerificationTest < ActionController::TestCase
def test_no_deprecation_warning_for_named_route
assert_not_deprecated do
get :guarded_one_for_named_route_test, :two => "not one"
assert_redirected_to '/foo'
with_routing do |set|
set.draw do |map|
map.foo '/foo', :controller => 'test', :action => 'foo'
map.connect ":controller/:action/:id"
end
get :guarded_one_for_named_route_test, :two => "not one"
assert_redirected_to '/foo'
end
end
end

View file

@ -259,7 +259,6 @@ class WebServiceTest < ActionController::IntegrationTest
c.connect "/", :action => "assign_parameters"
end
end
reset!
yield
end
end

View file

@ -59,7 +59,6 @@ class JsonParamsParsingTest < ActionController::IntegrationTest
set.draw do |map|
map.connect ':action', :controller => "json_params_parsing_test/test"
end
reset!
yield
end
end

View file

@ -153,7 +153,6 @@ class MultipartParamsParsingTest < ActionController::IntegrationTest
set.draw do |map|
map.connect ':action', :controller => "multipart_params_parsing_test/test"
end
reset!
yield
end
end

View file

@ -111,7 +111,6 @@ class QueryStringParsingTest < ActionController::IntegrationTest
set.draw do |map|
map.connect ':action', :controller => "query_string_parsing_test/test"
end
reset!
get "/parse", actual
assert_response :ok

View file

@ -132,7 +132,6 @@ class UrlEncodedParamsParsingTest < ActionController::IntegrationTest
set.draw do |map|
map.connect ':action', :controller => "url_encoded_params_parsing_test/test"
end
reset!
yield
end
end

View file

@ -86,7 +86,6 @@ class XmlParamsParsingTest < ActionController::IntegrationTest
set.draw do |map|
map.connect ':action', :controller => "xml_params_parsing_test/test"
end
reset!
yield
end
end

View file

@ -223,7 +223,6 @@ class CookieStoreTest < ActionController::IntegrationTest
end
options = {:key => SessionKey, :secret => SessionSecret}.merge(options)
@app = ActionDispatch::Session::CookieStore.new(set, options)
reset!
yield
end
end

View file

@ -115,7 +115,6 @@ class MemCacheStoreTest < ActionController::IntegrationTest
map.connect "/:action", :controller => "mem_cache_store_test/test"
end
@app = ActionDispatch::Session::MemCacheStore.new(set, :key => '_session_id')
reset!
yield
end
end

View file

@ -1,22 +1,32 @@
class << Object; alias_method :const_available?, :const_defined?; end
class ContentController < ActionController::Base
end
class NotAController
end
class ContentController < ActionController::Base; end
class NotAController; end
module Admin
class << self; alias_method :const_available?, :const_defined?; end
class UserController < ActionController::Base; end
class NewsFeedController < ActionController::Base; end
end
class ElsewhereController < ActionController::Base; end
module Api
class ProductsController < ActionController::Base; end
end
# TODO: Reduce the number of test controllers we use
class AddressesController < ActionController::Base; end
class SessionsController < ActionController::Base; end
class FooController < ActionController::Base; end
class CController < ActionController::Base; end
class HiController < ActionController::Base; end
class ArticlesController < ActionController::Base; end
class BarController < ActionController::Base; end
class BooksController < ActionController::Base; end
class BraveController < ActionController::Base; end
class CController < ActionController::Base; end
class ElsewhereController < ActionController::Base; end
class FooController < ActionController::Base; end
class HiController < ActionController::Base; end
class ImageController < ActionController::Base; end
class PeopleController < ActionController::Base; end
class SessionsController < ActionController::Base; end
class SubpathBooksController < ActionController::Base; end
class WeblogController < ActionController::Base; end
# For speed test
@ -34,8 +44,3 @@ class ChannelsController < SpeedController; end
class ChannelVideosController < SpeedController; end
class LostPasswordsController < SpeedController; end
class PagesController < SpeedController; end
ActionController::Routing::Routes.draw do |map|
map.route_one 'route_one', :controller => 'elsewhere', :action => 'flash_me'
map.connect ':controller/:action/:id'
end

View file

@ -51,3 +51,99 @@ module Quiz
end
end
class Post < Struct.new(:title, :author_name, :body, :secret, :written_on, :cost)
extend ActiveModel::Naming
include ActiveModel::Conversion
alias_method :secret?, :secret
def new_record=(boolean)
@new_record = boolean
end
def new_record?
@new_record
end
attr_accessor :author
def author_attributes=(attributes); end
attr_accessor :comments
def comments_attributes=(attributes); end
attr_accessor :tags
def tags_attributes=(attributes); end
end
class Comment
extend ActiveModel::Naming
include ActiveModel::Conversion
attr_reader :id
attr_reader :post_id
def initialize(id = nil, post_id = nil); @id, @post_id = id, post_id end
def save; @id = 1; @post_id = 1 end
def new_record?; @id.nil? end
def to_param; @id; end
def name
@id.nil? ? "new #{self.class.name.downcase}" : "#{self.class.name.downcase} ##{@id}"
end
attr_accessor :relevances
def relevances_attributes=(attributes); end
end
class Tag
extend ActiveModel::Naming
include ActiveModel::Conversion
attr_reader :id
attr_reader :post_id
def initialize(id = nil, post_id = nil); @id, @post_id = id, post_id end
def save; @id = 1; @post_id = 1 end
def new_record?; @id.nil? end
def to_param; @id; end
def value
@id.nil? ? "new #{self.class.name.downcase}" : "#{self.class.name.downcase} ##{@id}"
end
attr_accessor :relevances
def relevances_attributes=(attributes); end
end
class CommentRelevance
extend ActiveModel::Naming
include ActiveModel::Conversion
attr_reader :id
attr_reader :comment_id
def initialize(id = nil, comment_id = nil); @id, @comment_id = id, comment_id end
def save; @id = 1; @comment_id = 1 end
def new_record?; @id.nil? end
def to_param; @id; end
def value
@id.nil? ? "new #{self.class.name.downcase}" : "#{self.class.name.downcase} ##{@id}"
end
end
class TagRelevance
extend ActiveModel::Naming
include ActiveModel::Conversion
attr_reader :id
attr_reader :tag_id
def initialize(id = nil, tag_id = nil); @id, @tag_id = id, tag_id end
def save; @id = 1; @tag_id = 1 end
def new_record?; @id.nil? end
def to_param; @id; end
def value
@id.nil? ? "new #{self.class.name.downcase}" : "#{self.class.name.downcase} ##{@id}"
end
end
class Author < Comment
attr_accessor :post
def post_attributes=(attributes); end
end

View file

@ -32,7 +32,7 @@ class LinkToRemoteTest < AjaxTestCase
end
test "with no update" do
assert_html link, %w(href="/blog/destroy/3" Delete\ this\ post data-remote="true")
assert_html link, %w(href="/blog/destroy/4" Delete\ this\ post data-remote="true")
end
test "basic" do
@ -46,7 +46,7 @@ class LinkToRemoteTest < AjaxTestCase
end
test "with :html options" do
expected = %{<a href="/blog/destroy/3" data-custom="me" data-update-success="#posts">Delete this post</a>}
expected = %{<a href="/blog/destroy/4" data-custom="me" data-remote="true" data-update-success="#posts">Delete this post</a>}
assert_equal expected, link(:update => "#posts", :html => {"data-custom" => "me"})
end
@ -74,7 +74,7 @@ class LinkToRemoteTest < AjaxTestCase
end
test "basic link_to_remote with :url =>" do
expected = %{<a href="/blog/destroy/3" data-update-success="#posts">Delete this post</a>}
expected = %{<a href="/blog/destroy/3" data-remote="true" data-update-success="#posts">Delete this post</a>}
assert_equal expected,
link_to_remote("Delete this post", :url => "/blog/destroy/3", :update => "#posts")
end
@ -93,7 +93,7 @@ class ButtonToRemoteTest < AjaxTestCase
def url_for(*)
"/whatnot"
end
class StandardTest < ButtonToRemoteTest
test "basic" do
button = button({:url => {:action => "whatnot"}}, {:class => "fine"})
@ -103,13 +103,12 @@ class ButtonToRemoteTest < AjaxTestCase
end
end
end
class LegacyButtonToRemoteTest < ButtonToRemoteTest
include ActionView::Helpers::AjaxHelper::Rails2Compatibility
assert_callbacks_work do |callback|
button(callback => "undoRequestCompleted(request)")
end
end
end
end

View file

@ -1,103 +1,5 @@
require 'abstract_unit'
silence_warnings do
class Post < Struct.new(:title, :author_name, :body, :secret, :written_on, :cost)
extend ActiveModel::Naming
include ActiveModel::Conversion
alias_method :secret?, :secret
def new_record=(boolean)
@new_record = boolean
end
def new_record?
@new_record
end
attr_accessor :author
def author_attributes=(attributes); end
attr_accessor :comments
def comments_attributes=(attributes); end
attr_accessor :tags
def tags_attributes=(attributes); end
end
class Comment
extend ActiveModel::Naming
include ActiveModel::Conversion
attr_reader :id
attr_reader :post_id
def initialize(id = nil, post_id = nil); @id, @post_id = id, post_id end
def save; @id = 1; @post_id = 1 end
def new_record?; @id.nil? end
def to_param; @id; end
def name
@id.nil? ? "new #{self.class.name.downcase}" : "#{self.class.name.downcase} ##{@id}"
end
attr_accessor :relevances
def relevances_attributes=(attributes); end
end
class Tag
extend ActiveModel::Naming
include ActiveModel::Conversion
attr_reader :id
attr_reader :post_id
def initialize(id = nil, post_id = nil); @id, @post_id = id, post_id end
def save; @id = 1; @post_id = 1 end
def new_record?; @id.nil? end
def to_param; @id; end
def value
@id.nil? ? "new #{self.class.name.downcase}" : "#{self.class.name.downcase} ##{@id}"
end
attr_accessor :relevances
def relevances_attributes=(attributes); end
end
class CommentRelevance
extend ActiveModel::Naming
include ActiveModel::Conversion
attr_reader :id
attr_reader :comment_id
def initialize(id = nil, comment_id = nil); @id, @comment_id = id, comment_id end
def save; @id = 1; @comment_id = 1 end
def new_record?; @id.nil? end
def to_param; @id; end
def value
@id.nil? ? "new #{self.class.name.downcase}" : "#{self.class.name.downcase} ##{@id}"
end
end
class TagRelevance
extend ActiveModel::Naming
include ActiveModel::Conversion
attr_reader :id
attr_reader :tag_id
def initialize(id = nil, tag_id = nil); @id, @tag_id = id, tag_id end
def save; @id = 1; @tag_id = 1 end
def new_record?; @id.nil? end
def to_param; @id; end
def value
@id.nil? ? "new #{self.class.name.downcase}" : "#{self.class.name.downcase} ##{@id}"
end
end
class Author < Comment
attr_accessor :post
def post_attributes=(attributes); end
end
end
require 'controller/fake_models'
class FormHelperTest < ActionView::TestCase
tests ActionView::Helpers::FormHelper

View file

@ -1,4 +1,5 @@
require 'abstract_unit'
require 'controller/fake_models'
class Post
extend ActiveModel::Naming

View file

@ -1,4 +1,5 @@
require 'abstract_unit'
require 'controller/fake_controllers'
module ActionView
class TestCase

View file

@ -19,32 +19,41 @@ module PeopleHelper
end
class PeopleHelperTest < ActionView::TestCase
def setup
super
ActionController::Routing::Routes.draw do |map|
map.people 'people', :controller => 'people', :action => 'index'
map.connect ':controller/:action/:id'
end
end
def test_title
assert_equal "<h1>Ruby on Rails</h1>", title("Ruby on Rails")
end
def test_homepage_path
assert_equal "/people", homepage_path
with_test_route_set do
assert_equal "/people", homepage_path
end
end
def test_homepage_url
assert_equal "http://test.host/people", homepage_url
with_test_route_set do
assert_equal "http://test.host/people", homepage_url
end
end
def test_link_to_person
person = mock(:name => "David")
person.class.extend ActiveModel::Naming
expects(:mocha_mock_path).with(person).returns("/people/1")
assert_equal '<a href="/people/1">David</a>', link_to_person(person)
with_test_route_set do
person = mock(:name => "David")
person.class.extend ActiveModel::Naming
expects(:mocha_mock_path).with(person).returns("/people/1")
assert_equal '<a href="/people/1">David</a>', link_to_person(person)
end
end
private
def with_test_route_set
with_routing do |set|
set.draw do |map|
map.people 'people', :controller => 'people', :action => 'index'
map.connect ':controller/:action/:id'
end
yield
end
end
end
class CrazyHelperTest < ActionView::TestCase

View file

@ -0,0 +1,17 @@
$:.unshift(File.dirname(__FILE__) + '/../../activesupport/lib')
require 'test/unit'
require 'rbconfig'
require 'active_support/core_ext/kernel/reporting'
class TestIsolated < Test::Unit::TestCase
ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME'))
Dir["#{File.dirname(__FILE__)}/{abstract,controller,dispatch,template}/**/*_test.rb"].each do |file|
define_method("test #{file}") do
command = "#{ruby} -Ilib:test #{file}"
silence_stderr { `#{command}` }
assert_equal 0, $?.to_i, command
end
end
end

View file

@ -66,6 +66,7 @@ cd "#{root_dir}/actionpack" do
puts "[CruiseControl] Building ActionPack"
puts
build_results[:actionpack] = system 'gem bundle && rake'
build_results[:actionpack_isolated] = system 'rake test:isolated'
end
cd "#{root_dir}/actionmailer" do