Merge branch 'master' of git://github.com/rails/rails

This commit is contained in:
José Valim
2009-07-02 10:25:18 +02:00
62 changed files with 493 additions and 133 deletions

View File

@@ -60,7 +60,7 @@ spec = Gem::Specification.new do |s|
s.rubyforge_project = "actionmailer"
s.homepage = "http://www.rubyonrails.org"
s.add_dependency('actionpack', '= 2.3.2' + PKG_BUILD)
s.add_dependency('actionpack', '= 3.0.pre' + PKG_BUILD)
s.has_rdoc = true
s.requirements << 'none'

View File

@@ -1,8 +1,8 @@
module ActionMailer
module VERSION #:nodoc:
MAJOR = 2
MINOR = 3
TINY = 2
MAJOR = 3
MINOR = 0
TINY = "pre"
STRING = [MAJOR, MINOR, TINY].join('.')
end

View File

@@ -1,9 +1,6 @@
require 'rubygems'
require 'test/unit'
gem 'mocha', '>= 0.9.5'
require 'mocha'
$:.unshift "#{File.dirname(__FILE__)}/../lib"
$:.unshift "#{File.dirname(__FILE__)}/../../activesupport/lib"
$:.unshift "#{File.dirname(__FILE__)}/../../actionpack/lib"

View File

@@ -115,7 +115,7 @@ spec = Gem::Specification.new do |s|
s.has_rdoc = true
s.requirements << 'none'
s.add_dependency('activesupport', '= 2.3.2' + PKG_BUILD)
s.add_dependency('activesupport', '= 3.0.pre' + PKG_BUILD)
s.require_path = 'lib'
s.autorequire = 'action_controller'

View File

@@ -436,7 +436,7 @@ module ActionController
def recognize(request)
params = recognize_path(request.path, extract_request_environment(request))
request.path_parameters = params.with_indifferent_access
"#{params[:controller].camelize}Controller".constantize
"#{params[:controller].to_s.camelize}Controller".constantize
end
def recognize_path(path, environment={})

View File

@@ -1,8 +1,8 @@
module ActionPack #:nodoc:
module VERSION #:nodoc:
MAJOR = 2
MINOR = 3
TINY = 2
MAJOR = 3
MINOR = 0
TINY = "pre"
STRING = [MAJOR, MINOR, TINY].join('.')
end

View File

@@ -451,10 +451,10 @@ module ActionView
''
when /^post$/i, "", nil
html_options["method"] = "post"
protect_against_forgery? ? content_tag(:div, token_tag, :style => 'margin:0;padding:0') : ''
protect_against_forgery? ? content_tag(:div, token_tag, :style => 'margin:0;padding:0;display:inline') : ''
else
html_options["method"] = "post"
content_tag(:div, tag(:input, :type => "hidden", :name => "_method", :value => method) + token_tag, :style => 'margin:0;padding:0')
content_tag(:div, tag(:input, :type => "hidden", :name => "_method", :value => method) + token_tag, :style => 'margin:0;padding:0;display:inline')
end
end

View File

@@ -17,7 +17,7 @@ module ActionView
def compile(template)
require 'erb'
magic = $1 if template.source =~ /\A(<%#.*coding:\s*(\S+)\s*-?%>)/
magic = $1 if template.source =~ /\A(<%#.*coding[:=]\s*(\S+)\s*-?%>)/
erb = "#{magic}<% __in_erb_template=true %>#{template.source}"
::ERB.new(erb, nil, erb_trim_mode, '@output_buffer').src
end

View File

@@ -1667,6 +1667,17 @@ class RouteSetTest < Test::Unit::TestCase
assert_equal 1, set.routes.size
end
def test_draw_symbol_controller_name
assert_equal 0, set.routes.size
set.draw do |map|
map.connect '/users/index', :controller => :users, :action => :index
end
@request = ActionController::TestRequest.new
@request.request_uri = '/users/index'
assert_nothing_raised { set.recognize(@request) }
assert_equal 1, set.routes.size
end
def test_named_draw
assert_equal 0, set.routes.size
set.draw do |map|

View File

@@ -12,9 +12,6 @@ require 'yaml'
require 'stringio'
require 'test/unit'
gem 'mocha', '>= 0.9.5'
require 'mocha'
begin
require 'ruby-debug'
Debugger.settings[:autoeval] = true

View File

@@ -10,8 +10,6 @@ ActiveSupport::Deprecation.debug = true
require 'rubygems'
require 'test/unit'
gem 'mocha', '>= 0.9.5'
require 'mocha'
begin
require 'ruby-debug'

View File

@@ -187,7 +187,7 @@ spec = Gem::Specification.new do |s|
s.files = s.files + Dir.glob( "#{dir}/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
end
s.add_dependency('activesupport', '= 2.3.2' + PKG_BUILD)
s.add_dependency('activesupport', '= 3.0.pre' + PKG_BUILD)
s.files.delete FIXTURES_ROOT + "/fixture_database.sqlite"
s.files.delete FIXTURES_ROOT + "/fixture_database_2.sqlite"

View File

@@ -351,7 +351,19 @@ module ActiveRecord
protected
def construct_find_options!(options)
end
def construct_counter_sql
if @reflection.options[:counter_sql]
@counter_sql = interpolate_sql(@reflection.options[:counter_sql])
elsif @reflection.options[:finder_sql]
# replace the SELECT clause with COUNT(*), preserving any hints within /* ... */
@reflection.options[:counter_sql] = @reflection.options[:finder_sql].sub(/SELECT\b(\/\*.*?\*\/ )?(.*)\bFROM\b/im) { "SELECT #{$1}COUNT(*) FROM" }
@counter_sql = interpolate_sql(@reflection.options[:counter_sql])
else
@counter_sql = @finder_sql
end
end
def load_target
if !@owner.new_record? || foreign_key_present
begin

View File

@@ -85,15 +85,7 @@ module ActiveRecord
@join_sql = "INNER JOIN #{@owner.connection.quote_table_name @reflection.options[:join_table]} ON #{@reflection.quoted_table_name}.#{@reflection.klass.primary_key} = #{@owner.connection.quote_table_name @reflection.options[:join_table]}.#{@reflection.association_foreign_key}"
if @reflection.options[:counter_sql]
@counter_sql = interpolate_sql(@reflection.options[:counter_sql])
elsif @reflection.options[:finder_sql]
# replace the SELECT clause with COUNT(*), preserving any hints within /* ... */
@reflection.options[:counter_sql] = @reflection.options[:finder_sql].sub(/SELECT (\/\*.*?\*\/ )?(.*)\bFROM\b/im) { "SELECT #{$1}COUNT(*) FROM" }
@counter_sql = interpolate_sql(@reflection.options[:counter_sql])
else
@counter_sql = @finder_sql
end
construct_counter_sql
end
def construct_scope

View File

@@ -97,15 +97,7 @@ module ActiveRecord
@finder_sql << " AND (#{conditions})" if conditions
end
if @reflection.options[:counter_sql]
@counter_sql = interpolate_sql(@reflection.options[:counter_sql])
elsif @reflection.options[:finder_sql]
# replace the SELECT clause with COUNT(*), preserving any hints within /* ... */
@reflection.options[:counter_sql] = @reflection.options[:finder_sql].sub(/SELECT (\/\*.*?\*\/ )?(.*)\bFROM\b/im) { "SELECT #{$1}COUNT(*) FROM" }
@counter_sql = interpolate_sql(@reflection.options[:counter_sql])
else
@counter_sql = @finder_sql
end
construct_counter_sql
end
def construct_scope

View File

@@ -90,15 +90,7 @@ module ActiveRecord
@finder_sql = construct_conditions
end
if @reflection.options[:counter_sql]
@counter_sql = interpolate_sql(@reflection.options[:counter_sql])
elsif @reflection.options[:finder_sql]
# replace the SELECT clause with COUNT(*), preserving any hints within /* ... */
@reflection.options[:counter_sql] = @reflection.options[:finder_sql].sub(/SELECT (\/\*.*?\*\/ )?(.*)\bFROM\b/im) { "SELECT #{$1}COUNT(*) FROM" }
@counter_sql = interpolate_sql(@reflection.options[:counter_sql])
else
@counter_sql = @finder_sql
end
construct_counter_sql
end
def has_cached_counter?

View File

@@ -1404,14 +1404,14 @@ module ActiveRecord #:nodoc:
end
# Transform the modelname into a more humane format, using I18n.
# Defaults to the basic humanize method.
# By default, it will underscore then humanize the class name (BlogPost.human_name #=> "Blog post").
# Default scope of the translation is activerecord.models
# Specify +options+ with additional translating options.
def human_name(options = {})
defaults = self_and_descendants_from_active_record.map do |klass|
:"#{klass.name.underscore}"
end
defaults << self.name.humanize
end
defaults << self.name.underscore.humanize
I18n.translate(defaults.shift, {:scope => [:activerecord, :models], :count => 1, :default => defaults}.merge(options))
end
@@ -2870,6 +2870,13 @@ module ActiveRecord #:nodoc:
@attributes.frozen?
end
# Returns duplicated record with unfreezed attributes.
def dup
obj = super
obj.instance_variable_set('@attributes', instance_variable_get('@attributes').dup)
obj
end
# Returns +true+ if the record is read only. Records loaded through joins with piggy-back
# attributes will be marked as read only since they cannot be saved.
def readonly?

View File

@@ -1,8 +1,8 @@
module ActiveRecord
module VERSION #:nodoc:
MAJOR = 2
MINOR = 3
TINY = 2
MAJOR = 3
MINOR = 0
TINY = "pre"
STRING = [MAJOR, MINOR, TINY].join('.')
end

View File

@@ -803,6 +803,13 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
assert_equal 1, developer.projects.count
end
unless current_adapter?(:PostgreSQLAdapter)
def test_count_with_finder_sql
assert_equal 3, projects(:active_record).developers_with_finder_sql.count
assert_equal 3, projects(:active_record).developers_with_multiline_finder_sql.count
end
end
def test_association_proxy_transaction_method_starts_transaction_in_association_class
Post.expects(:transaction)
Category.find(:first).posts.transaction do

View File

@@ -163,6 +163,11 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
assert_equal 0, Firm.find(:first).no_clients_using_counter_sql.size
end
def test_counting_using_finder_sql
assert_equal 2, Firm.find(4).clients_using_sql.count
assert_equal 2, Firm.find(4).clients_using_multiline_sql.count
end
def test_belongs_to_sanity
c = Client.new
assert_nil c.firm

View File

@@ -599,9 +599,9 @@ class BasicsTest < ActiveRecord::TestCase
end
def test_destroy_many
assert_equal 3, Client.count
Client.destroy([2, 3])
assert_equal 1, Client.count
assert_difference('Client.count', -2) do
Client.destroy([2, 3])
end
end
def test_delete_many
@@ -2116,4 +2116,8 @@ class BasicsTest < ActiveRecord::TestCase
assert_equal custom_datetime, parrot[attribute]
end
end
def test_dup
assert !Minimalistic.new.freeze.dup.frozen?
end
end

View File

@@ -203,7 +203,7 @@ class CalculationsTest < ActiveRecord::TestCase
c = Company.count(:all, :group => "UPPER(#{QUOTED_TYPE})")
assert_equal 2, c[nil]
assert_equal 1, c['DEPENDENTFIRM']
assert_equal 3, c['CLIENT']
assert_equal 4, c['CLIENT']
assert_equal 2, c['FIRM']
end
@@ -211,7 +211,7 @@ class CalculationsTest < ActiveRecord::TestCase
c = Company.count(:all, :group => "UPPER(companies.#{QUOTED_TYPE})")
assert_equal 2, c[nil]
assert_equal 1, c['DEPENDENTFIRM']
assert_equal 3, c['CLIENT']
assert_equal 4, c['CLIENT']
assert_equal 2, c['FIRM']
end

View File

@@ -1044,8 +1044,8 @@ class FinderTest < ActiveRecord::TestCase
end
def test_select_values
assert_equal ["1","2","3","4","5","6","7","8","9"], Company.connection.select_values("SELECT id FROM companies ORDER BY id").map! { |i| i.to_s }
assert_equal ["37signals","Summit","Microsoft", "Flamboyant Software", "Ex Nihilo", "RailsCore", "Leetsoft", "Jadedpixel", "Odegy"], Company.connection.select_values("SELECT name FROM companies ORDER BY id")
assert_equal ["1","2","3","4","5","6","7","8","9", "10"], Company.connection.select_values("SELECT id FROM companies ORDER BY id").map! { |i| i.to_s }
assert_equal ["37signals","Summit","Microsoft", "Flamboyant Software", "Ex Nihilo", "RailsCore", "Leetsoft", "Jadedpixel", "Odegy", "Ex Nihilo Part Deux"], Company.connection.select_values("SELECT name FROM companies ORDER BY id")
end
def test_select_rows

View File

@@ -6,8 +6,6 @@ require 'config'
require 'rubygems'
require 'test/unit'
require 'stringio'
gem 'mocha', '>= 0.9.5'
require 'mocha'
require 'active_record'
require 'active_record/test_case'

View File

@@ -112,9 +112,9 @@ class InheritanceTest < ActiveRecord::TestCase
end
def test_inheritance_condition
assert_equal 9, Company.count
assert_equal 10, Company.count
assert_equal 2, Firm.count
assert_equal 3, Client.count
assert_equal 4, Client.count
end
def test_alt_inheritance_condition

View File

@@ -5,14 +5,20 @@ require 'models/company'
require 'models/company_in_module'
require 'models/subscriber'
require 'models/pirate'
require 'models/price_estimate'
class ReflectionTest < ActiveRecord::TestCase
fixtures :topics, :customers, :companies, :subscribers
fixtures :topics, :customers, :companies, :subscribers, :price_estimates
def setup
@first = Topic.find(1)
end
def test_human_name
assert_equal "Price estimate", PriceEstimate.human_name
assert_equal "Subscriber", Subscriber.human_name
end
def test_column_null_not_null
subscriber = Subscriber.find(:first)
assert subscriber.column_for_attribute("name").null
@@ -170,8 +176,8 @@ class ReflectionTest < ActiveRecord::TestCase
def test_reflection_of_all_associations
# FIXME these assertions bust a lot
assert_equal 28, Firm.reflect_on_all_associations.size
assert_equal 21, Firm.reflect_on_all_associations(:has_many).size
assert_equal 29, Firm.reflect_on_all_associations.size
assert_equal 22, Firm.reflect_on_all_associations(:has_many).size
assert_equal 7, Firm.reflect_on_all_associations(:has_one).size
assert_equal 0, Firm.reflect_on_all_associations(:belongs_to).size
end

View File

@@ -35,6 +35,14 @@ another_client:
name: Ex Nihilo
ruby_type: Client
a_third_client:
id: 10
type: Client
firm_id: 4
client_of: 4
name: Ex Nihilo Part Deux
ruby_type: Client
rails_core:
id: 6
name: RailsCore

View File

@@ -48,6 +48,10 @@ class Firm < Company
has_many :clients_with_interpolated_conditions, :class_name => "Client", :conditions => 'rating > #{rating}'
has_many :clients_like_ms_with_hash_conditions, :conditions => { :name => 'Microsoft' }, :class_name => "Client", :order => "id"
has_many :clients_using_sql, :class_name => "Client", :finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}'
has_many :clients_using_multiline_sql, :class_name => "Client", :finder_sql => '
SELECT
companies.*
FROM companies WHERE companies.client_of = #{id}'
has_many :clients_using_counter_sql, :class_name => "Client",
:finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}',
:counter_sql => 'SELECT COUNT(*) FROM companies WHERE client_of = #{id}'

View File

@@ -8,6 +8,12 @@ class Project < ActiveRecord::Base
has_and_belongs_to_many :developers_named_david_with_hash_conditions, :class_name => "Developer", :conditions => { :name => 'David' }, :uniq => true
has_and_belongs_to_many :salaried_developers, :class_name => "Developer", :conditions => "salary > 0"
has_and_belongs_to_many :developers_with_finder_sql, :class_name => "Developer", :finder_sql => 'SELECT t.*, j.* FROM developers_projects j, developers t WHERE t.id = j.developer_id AND j.project_id = #{id} ORDER BY t.id'
has_and_belongs_to_many :developers_with_multiline_finder_sql, :class_name => "Developer", :finder_sql => '
SELECT
t.*, j.*
FROM
developers_projects j,
developers t WHERE t.id = j.developer_id AND j.project_id = #{id} ORDER BY t.id'
has_and_belongs_to_many :developers_by_sql, :class_name => "Developer", :delete_sql => "DELETE FROM developers_projects WHERE project_id = \#{id} AND developer_id = \#{record.id}"
has_and_belongs_to_many :developers_with_callbacks, :class_name => "Developer", :before_add => Proc.new {|o, r| o.developers_log << "before_adding#{r.id || '<new>'}"},
:after_add => Proc.new {|o, r| o.developers_log << "after_adding#{r.id || '<new>'}"},

View File

@@ -73,7 +73,7 @@ spec = Gem::Specification.new do |s|
s.files = s.files + Dir.glob( "#{dir}/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
end
s.add_dependency('activesupport', '= 2.3.2' + PKG_BUILD)
s.add_dependency('activesupport', '= 3.0.pre' + PKG_BUILD)
s.require_path = 'lib'
s.autorequire = 'active_resource'

View File

@@ -1,8 +1,8 @@
module ActiveResource
module VERSION #:nodoc:
MAJOR = 2
MINOR = 3
TINY = 2
MAJOR = 3
MINOR = 0
TINY = "pre"
STRING = [MAJOR, MINOR, TINY].join('.')
end

View File

@@ -1,8 +1,6 @@
require 'rubygems'
require 'test/unit'
gem 'mocha', '>= 0.9.5'
require 'mocha'
require 'active_support/test_case'
$:.unshift "#{File.dirname(__FILE__)}/../lib"
require 'active_resource'

View File

@@ -99,11 +99,16 @@ module ActiveSupport
class Store
cattr_accessor :logger
attr_reader :silence, :logger_off
def silence!
@silence = true
self
end
alias silence? silence
alias logger_off? logger_off
# Fetches data from the cache, using the given key. If there is data in
# the cache with the given key, then that data is returned.
#
@@ -233,11 +238,15 @@ module ActiveSupport
private
def expires_in(options)
(options && options[:expires_in]) || 0
expires_in = options && options[:expires_in]
raise ":expires_in must be a number" if expires_in && !expires_in.is_a?(Numeric)
expires_in || 0
end
def log(operation, key, options)
logger.debug("Cache #{operation}: #{key}#{options ? " (#{options.inspect})" : ""}") if logger && !@silence && !@logger_off
logger.debug("Cache #{operation}: #{key}#{options ? " (#{options.inspect})" : ""}") if logger && !silence? && !logger_off?
end
end
end

View File

@@ -26,7 +26,7 @@ module ActiveSupport
def write(name, value, options = nil)
super
@data[name] = value.freeze
@data[name] = (value.duplicable? ? value.dup : value).freeze
end
def delete(name, options = nil)

View File

@@ -108,14 +108,21 @@ class Module
prefix = options[:prefix] && "#{options[:prefix] == true ? to : options[:prefix]}_"
allow_nil = options[:allow_nil] && "#{to} && "
file, line = caller[0].split(":")
file, line = caller.first.split(':', 2)
line = line.to_i
methods.each do |method|
module_eval(<<-EOS, file, line.to_i)
on_nil =
if options[:allow_nil]
'return'
else
%(raise "#{self}##{prefix}#{method} delegated to #{to}.#{method}, but #{to} is nil: \#{self.inspect}")
end
module_eval(<<-EOS, file, line)
def #{prefix}#{method}(*args, &block) # def customer_name(*args, &block)
#{allow_nil}#{to}.__send__(#{method.inspect}, *args, &block) # client && client.__send__(:name, *args, &block)
#{on_nil} if #{to}.nil?
#{to}.__send__(#{method.inspect}, *args, &block) # client && client.__send__(:name, *args, &block)
end # end
EOS
end

View File

@@ -183,7 +183,7 @@ module ActiveSupport
if first_letter_in_uppercase
lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
else
lower_case_and_underscored_word.first.downcase + camelize(lower_case_and_underscored_word)[1..-1]
lower_case_and_underscored_word.to_s.first.downcase + camelize(lower_case_and_underscored_word)[1..-1]
end
end

View File

@@ -1,5 +1,7 @@
# encoding: binary
# encoding: utf-8
require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/hash/except'
require 'active_support/core_ext/hash/slice'
require 'active_support/core_ext/module/delegation'
require 'active_support/core_ext/object/instance_variables'
require 'active_support/deprecation'
@@ -95,12 +97,14 @@ module ActiveSupport
def escape(string)
string = string.dup.force_encoding(::Encoding::BINARY) if string.respond_to?(:force_encoding)
json = '"' + string.gsub(escape_regex) { |s| ESCAPED_CHARS[s] }
json.gsub(/([\xC0-\xDF][\x80-\xBF]|
json = string.
gsub(escape_regex) { |s| ESCAPED_CHARS[s] }.
gsub(/([\xC0-\xDF][\x80-\xBF]|
[\xE0-\xEF][\x80-\xBF]{2}|
[\xF0-\xF7][\x80-\xBF]{3})+/nx) { |s|
s.unpack("U*").pack("n*").unpack("H*")[0].gsub(/.{4}/, '\\\\u\&')
} + '"'
s.unpack("U*").pack("n*").unpack("H*")[0].gsub(/.{4}/n, '\\\\u\&')
}
%("#{json}")
end
end

View File

@@ -1,18 +1,19 @@
begin
gem 'mocha', '>= 0.9.3'
require 'mocha'
rescue LoadError
# Fake Mocha::ExpectationError so we can rescue it in #run. Bleh.
Object.const_set :Mocha, Module.new
Mocha.const_set :ExpectationError, Class.new(StandardError)
end
require 'test/unit/testcase'
require 'active_support/testing/setup_and_teardown'
require 'active_support/testing/assertions'
require 'active_support/testing/deprecation'
require 'active_support/testing/declarative'
require 'active_support/testing/pending'
require 'active_support/testing/isolation'
begin
gem 'mocha', ">= 0.9.7"
require 'mocha'
rescue LoadError
# Fake Mocha::ExpectationError so we can rescue it in #run. Bleh.
Object.const_set :Mocha, Module.new
Mocha.const_set :ExpectationError, Class.new(StandardError)
end
module ActiveSupport
class TestCase < ::Test::Unit::TestCase

View File

@@ -15,12 +15,6 @@ module ActiveSupport
end
end
if defined?(Spec)
class << self
alias_method :test, :it
end
end
end
end

View File

@@ -0,0 +1,98 @@
module ActiveSupport::Testing
class ProxyTestResult
def initialize
@calls = []
end
def __replay__(result)
@calls.each do |name, args|
result.send(name, *args)
end
end
def method_missing(name, *args)
@calls << [name, args]
end
end
module Isolation
def self.forking_env?
!ENV["NO_FORK"] && RUBY_PLATFORM !~ /mswin|mingw|java/
end
def run(result)
yield(Test::Unit::TestCase::STARTED, name)
@_result = result
proxy = run_in_isolation do |proxy|
super(proxy) { }
end
proxy.__replay__(@_result)
yield(Test::Unit::TestCase::FINISHED, name)
end
module Forking
def run_in_isolation(&blk)
read, write = IO.pipe
pid = fork do
read.close
proxy = ProxyTestResult.new
yield proxy
write.puts [Marshal.dump(proxy)].pack("m")
exit!
end
write.close
result = read.read
Process.wait2(pid)
Marshal.load(result.unpack("m")[0])
end
end
module Subprocess
# Crazy H4X to get this working in windows / jruby with
# no forking.
def run_in_isolation(&blk)
require "tempfile"
if ENV["ISOLATION_TEST"]
proxy = ProxyTestResult.new
yield proxy
File.open(ENV["ISOLATION_OUTPUT"], "w") do |file|
file.puts [Marshal.dump(proxy)].pack("m")
end
exit!
else
Tempfile.open("isolation") do |tmpfile|
ENV["ISOLATION_TEST"] = @method_name
ENV["ISOLATION_OUTPUT"] = tmpfile.path
load_paths = $-I.map {|p| "-I\"#{File.expand_path(p)}\"" }.join(" ")
`#{Gem.ruby} #{load_paths} #{$0} #{ORIG_ARGV.join(" ")} -t\"#{self.class}\"`
ENV.delete("ISOLATION_TEST")
ENV.delete("ISOLATION_OUTPUT")
return Marshal.load(tmpfile.read.unpack("m")[0])
end
end
end
end
include forking_env? ? Forking : Subprocess
end
end
# Only in subprocess for windows / jruby.
if ENV['ISOLATION_TEST']
require "test/unit/collector/objectspace"
class Test::Unit::Collector::ObjectSpace
def include?(test)
super && test.method_name == ENV['ISOLATION_TEST']
end
end
end

View File

@@ -10,8 +10,6 @@ module ActiveSupport
if defined?(MiniTest::Assertions) && TestCase < MiniTest::Assertions
include ForMiniTest
elsif defined? Spec
include ForRspec
else
include ForClassicTestUnit
end

View File

@@ -2,7 +2,6 @@ $:.unshift "lib"
require 'rubygems'
require 'test/unit'
require 'mocha'
require 'i18n'
require 'active_support'

View File

@@ -2,7 +2,6 @@ $:.unshift "lib"
require 'rubygems'
require 'test/unit'
require 'mocha'
require 'i18n'
require 'active_support'

View File

@@ -3,7 +3,6 @@ $:.unshift "lib"
require 'rubygems'
require 'test/unit'
require 'mocha'
require 'i18n'
require 'time'
require 'yaml'

View File

@@ -1,8 +1,8 @@
module ActiveSupport
module VERSION #:nodoc:
MAJOR = 2
MINOR = 3
TINY = 2
MAJOR = 3
MINOR = 0
TINY = "pre"
STRING = [MAJOR, MINOR, TINY].join('.')
end

View File

@@ -1,9 +1,8 @@
ORIG_ARGV = ARGV.dup
require 'rubygems'
require 'test/unit'
gem 'mocha', '>= 0.9.5'
require 'mocha'
ENV['NO_RELOAD'] = '1'
$:.unshift "#{File.dirname(__FILE__)}/../lib"
require 'active_support'

View File

@@ -1,3 +1,4 @@
require 'logger'
require 'abstract_unit'
require 'active_support/cache'
@@ -176,6 +177,12 @@ class MemoryStoreTest < ActiveSupport::TestCase
assert_raise(ActiveSupport::FrozenObjectError) { @cache.read('foo').gsub!(/.*/, 'baz') }
assert_equal 'bar', @cache.read('foo')
end
def test_original_store_objects_should_not_be_immutable
bar = 'bar'
@cache.write('foo', bar)
assert_nothing_raised { bar.gsub!(/.*/, 'baz') }
end
end
uses_memcached 'memcached backed store' do
@@ -184,6 +191,8 @@ uses_memcached 'memcached backed store' do
@cache = ActiveSupport::Cache.lookup_store(:mem_cache_store)
@data = @cache.instance_variable_get(:@data)
@cache.clear
@cache.silence!
@cache.logger = Logger.new("/dev/null")
end
include CacheStoreBehavior
@@ -306,6 +315,22 @@ uses_memcached 'memcached backed store' do
app = @cache.middleware.new(app)
app.call({})
end
def test_expires_in
result = @cache.write('foo', 'bar', :expires_in => 1)
assert_equal 'bar', @cache.read('foo')
sleep 2
assert_equal nil, @cache.read('foo')
end
def test_expires_in_with_invalid_value
@cache.write('baz', 'bat')
assert_raise(RuntimeError) do
@cache.write('foo', 'bar', :expires_in => 'Mon Jun 29 13:10:40 -0700 2150')
end
assert_equal 'bat', @cache.read('baz')
assert_equal nil, @cache.read('foo')
end
end
class CompressedMemCacheStore < ActiveSupport::TestCase

View File

@@ -142,7 +142,7 @@ class ModuleTest < Test::Unit::TestCase
def test_delegation_without_allow_nil_and_nil_value
david = Someone.new("David")
assert_raise(NoMethodError) { david.street }
assert_raise(RuntimeError) { david.street }
end
def test_parent

2
activesupport/test/fixtures/omgomg.rb vendored Normal file
View File

@@ -0,0 +1,2 @@
class OmgOmg
end

View File

@@ -202,6 +202,12 @@ class InflectorTest < Test::Unit::TestCase
end
end
def test_symbol_to_lower_camel
SymbolToLowerCamel.each do |symbol, lower_camel|
assert_equal(lower_camel, ActiveSupport::Inflector.camelize(symbol, false))
end
end
%w{plurals singulars uncountables humans}.each do |inflection_type|
class_eval "
def test_clear_#{inflection_type}

View File

@@ -117,6 +117,13 @@ module InflectorTestCases
"area51_controller" => "area51Controller"
}
SymbolToLowerCamel = {
:product => 'product',
:special_guest => 'specialGuest',
:application_controller => 'applicationController',
:area51_controller => 'area51Controller'
}
CamelToUnderscoreWithoutReverse = {
"HTMLTidy" => "html_tidy",
"HTMLTidyGenerator" => "html_tidy_generator",

View File

@@ -0,0 +1,143 @@
require 'abstract_unit'
# Does awesome
if ENV['CHILD']
class ChildIsolationTest < ActiveSupport::TestCase
include ActiveSupport::Testing::Isolation
def setup
@instance = "HELLO"
end
def teardown
raise if @boom
end
test "runs the test" do
assert true
end
test "captures errors" do
raise
end
test "captures failures" do
assert false
end
test "first runs in isolation" do
assert_nil $x
$x = 1
end
test "second runs in isolation" do
assert_nil $x
$x = 2
end
test "runs with slow tests" do
sleep 0.3
assert true
sleep 0.2
end
test "runs setup" do
assert "HELLO", @instance
end
test "runs teardown" do
@boom = true
end
test "resets requires one" do
assert !defined?(OmgOmg)
assert_equal 0, $LOADED_FEATURES.grep(/fixtures\/omgomg/).size
require File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "omgomg"))
end
test "resets requires two" do
assert !defined?(OmgOmg)
assert_equal 0, $LOADED_FEATURES.grep(/fixtures\/omgomg/).size
require File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "omgomg"))
end
end
else
class ParentIsolationTest < ActiveSupport::TestCase
ENV["CHILD"] = "1"
OUTPUT = `#{Gem.ruby} -I#{File.dirname(__FILE__)} #{File.expand_path(__FILE__)} -v`
ENV.delete("CHILD")
def setup
# Extract the results
@results = {}
OUTPUT[/Started\n\s*(.*)\s*\nFinished/mi, 1].split(/\s*\n\s*/).each do |result|
result =~ %r'^(\w+)\(\w+\):\s*(\.|E|F)$'
@results[$1] = { 'E' => :error, '.' => :success, 'F' => :failure }[$2]
end
# Extract the backtraces
@backtraces = {}
OUTPUT.scan(/^\s*\d+\).*?\n\n/m).each do |backtrace|
# \n 1) Error:\ntest_captures_errors(ChildIsolationTest):
backtrace =~ %r'\s*\d+\)\s*(Error|Failure):\n(\w+)'i
@backtraces[$2] = { :type => $1, :output => backtrace }
end
end
def assert_failing(name)
assert_equal :failure, @results[name.to_s], "Test #{name} did not fail"
end
def assert_passing(name)
assert_equal :success, @results[name.to_s], "Test #{name} did not pass"
end
def assert_erroring(name)
assert_equal :error, @results[name.to_s], "Test #{name} did not error"
end
test "has all tests" do
assert_equal 10, @results.length
end
test "passing tests are still reported" do
assert_passing :test_runs_the_test
assert_passing :test_runs_with_slow_tests
end
test "resets global variables" do
assert_passing :test_first_runs_in_isolation
assert_passing :test_second_runs_in_isolation
end
test "resets requires" do
assert_passing :test_resets_requires_one
assert_passing :test_resets_requires_two
end
test "erroring tests are still reported" do
assert_erroring :test_captures_errors
end
test "runs setup and teardown methods" do
assert_passing :test_runs_setup
assert_erroring :test_runs_teardown
end
test "correct tests fail" do
assert_failing :test_captures_failures
end
test "backtrace is printed for errors" do
assert_equal 'Error', @backtraces["test_captures_errors"][:type]
assert_match %{isolation_test.rb:21:in `test_captures_errors'}, @backtraces["test_captures_errors"][:output]
end
test "backtrace is printed for failures" do
assert_equal 'Failure', @backtraces["test_captures_failures"][:type]
assert_match %{isolation_test.rb:25:in `test_captures_failures'}, @backtraces["test_captures_failures"][:output]
end
end
end

View File

@@ -75,8 +75,13 @@ class TestJSONEncoding < Test::Unit::TestCase
def test_utf8_string_encoded_properly_when_kcode_is_utf8
with_kcode 'UTF8' do
assert_equal '"\\u20ac2.99"', ActiveSupport::JSON.encode('€2.99')
assert_equal '"\\u270e\\u263a"', ActiveSupport::JSON.encode('✎☺')
result = ActiveSupport::JSON.encode('€2.99')
assert_equal '"\\u20ac2.99"', result
assert_equal(Encoding::UTF_8, result.encoding) if result.respond_to?(:encoding)
result = ActiveSupport::JSON.encode('✎☺')
assert_equal '"\\u270e\\u263a"', result
assert_equal(Encoding::UTF_8, result.encoding) if result.respond_to?(:encoding)
end
end

View File

@@ -7,7 +7,7 @@ gems:
- name: memcache-client
version: >= 1.5.0
- name: mocha
version: >= 0.9.5
version: >= 0.9.7
- name: mysql
#version: >= 2.7
version: = 2.7

View File

@@ -317,11 +317,11 @@ spec = Gem::Specification.new do |s|
EOF
s.add_dependency('rake', '>= 0.8.3')
s.add_dependency('activesupport', '= 2.3.2' + PKG_BUILD)
s.add_dependency('activerecord', '= 2.3.2' + PKG_BUILD)
s.add_dependency('actionpack', '= 2.3.2' + PKG_BUILD)
s.add_dependency('actionmailer', '= 2.3.2' + PKG_BUILD)
s.add_dependency('activeresource', '= 2.3.2' + PKG_BUILD)
s.add_dependency('activesupport', '= 3.0.pre' + PKG_BUILD)
s.add_dependency('activerecord', '= 3.0.pre' + PKG_BUILD)
s.add_dependency('actionpack', '= 3.0.pre' + PKG_BUILD)
s.add_dependency('actionmailer', '= 3.0.pre' + PKG_BUILD)
s.add_dependency('activeresource', '= 3.0.pre' + PKG_BUILD)
s.rdoc_options << '--exclude' << '.'
s.has_rdoc = false

View File

@@ -76,7 +76,7 @@ module Rails
@paths.config.locales = "config/locales"
@paths.config.environments = "config/environments"
@paths.app.controllers.push *builtin_directories
@paths.app.controllers.concat builtin_directories
@paths.app.load_path!
@paths.app.metals.load_path!

View File

@@ -80,6 +80,10 @@ module Rails
@paths.unshift path
end
def concat(paths)
@paths.concat paths
end
def load_once!
@load_once = true
@root.load_once.push *self.paths

View File

@@ -1,8 +1,8 @@
module Rails
module VERSION #:nodoc:
MAJOR = 2
MINOR = 3
TINY = 2
MAJOR = 3
MINOR = 0
TINY = "pre"
STRING = [MAJOR, MINOR, TINY].join('.')
end

View File

@@ -3,6 +3,7 @@
silence_warnings { RAILS_ENV = "test" }
require 'test/unit'
require 'active_support/core_ext/kernel/requires'
require 'action_controller/testing/test_case'
require 'action_view/test_case'
require 'action_controller/testing/integration'
@@ -29,7 +30,10 @@ end
begin
require_library_or_gem 'ruby-debug'
Debugger.start
Debugger.settings[:autoeval] = true if Debugger.respond_to?(:settings)
if Debugger.respond_to?(:settings)
Debugger.settings[:autoeval] = true
Debugger.settings[:autolist] = 1
end
rescue LoadError
# ruby-debug wasn't available so neither can the debugging be
end

View File

@@ -1,3 +1,5 @@
ORIG_ARGV = ARGV.dup
$:.unshift File.dirname(__FILE__) + "/../../activesupport/lib"
$:.unshift File.dirname(__FILE__) + "/../../activerecord/lib"
$:.unshift File.dirname(__FILE__) + "/../../actionpack/lib"
@@ -10,9 +12,6 @@ require 'stringio'
require 'rubygems'
require 'test/unit'
gem 'mocha', '>= 0.9.5'
require 'mocha'
require 'active_support'
require 'active_support/test_case'

View File

@@ -14,6 +14,8 @@ Rails::Initializer.run do |config|
end
class PathsTest < ActiveSupport::TestCase
include ActiveSupport::Testing::Isolation
def setup
@paths = Rails::Initializer.default.config.paths
end
@@ -83,4 +85,19 @@ class PathsTest < ActiveSupport::TestCase
assert_not_in_load_path "tmp", "cache"
end
test "controller paths include builtin in development mode" do
RAILS_ENV.replace "development"
assert Rails::Configuration.new.paths.app.controllers.paths.any? { |p| p =~ /builtin/ }
end
test "controller paths does not have builtin_directories in test mode" do
RAILS_ENV.replace "test"
assert !Rails::Configuration.new.paths.app.controllers.paths.any? { |p| p =~ /builtin/ }
end
test "controller paths does not have builtin_directories in production mode" do
RAILS_ENV.replace "production"
assert !Rails::Configuration.new.paths.app.controllers.paths.any? { |p| p =~ /builtin/ }
end
end

View File

@@ -52,6 +52,12 @@ class PathsTest < ActiveSupport::TestCase
assert_equal ["/app", "/app2"], @root.app.to_a
end
test "adding multiple physical paths using concat" do
@root.app = "/app"
@root.app.concat ["/app2", "/app3"]
assert_equal ["/app", "/app2", "/app3"], @root.app.to_a
end
test "adding multiple physical paths using #unshift" do
@root.app = "/app"
@root.app.unshift "/app2"
@@ -62,6 +68,7 @@ class PathsTest < ActiveSupport::TestCase
assert_raise(RuntimeError) { Rails::Application::Root.new(["/fiz", "/biz"]) }
assert_raise(NoMethodError) { @root.push "/biz" }
assert_raise(NoMethodError) { @root.unshift "/biz" }
assert_raise(NoMethodError) { @root.concat ["/biz"]}
assert_raise(NoMethodError) { @root << "/biz" }
end