aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Gemfile13
-rw-r--r--actionpack/lib/action_view/helpers/number_helper.rb2
-rw-r--r--actionpack/lib/action_view/renderer/partial_renderer.rb18
-rw-r--r--actionpack/lib/sprockets/assets.rake1
-rw-r--r--actionpack/lib/sprockets/helpers/rails_helper.rb2
-rw-r--r--actionpack/test/controller/render_test.rb14
-rw-r--r--actionpack/test/template/sprockets_helper_test.rb9
-rw-r--r--activerecord/CHANGELOG5
-rw-r--r--activerecord/lib/active_record.rb3
-rw-r--r--activerecord/lib/active_record/base.rb11
-rw-r--r--activerecord/lib/active_record/railties/databases.rake3
-rw-r--r--activerecord/test/cases/base_test.rb33
-rw-r--r--activesupport/lib/active_support/cache/file_store.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/class/attribute.rb8
-rw-r--r--activesupport/lib/active_support/core_ext/enumerable.rb22
-rw-r--r--activesupport/lib/active_support/core_ext/string/conversions.rb1
-rw-r--r--activesupport/lib/active_support/multibyte/unicode.rb1
-rw-r--r--activesupport/lib/active_support/ordered_hash.rb2
-rw-r--r--activesupport/test/caching_test.rb7
-rw-r--r--activesupport/test/core_ext/duplicable_test.rb19
-rw-r--r--activesupport/test/core_ext/enumerable_test.rb84
-rw-r--r--activesupport/test/json/decoding_test.rb2
-rw-r--r--railties/guides/rails_guides/generator.rb5
-rw-r--r--railties/guides/rails_guides/textile_extensions.rb5
-rw-r--r--railties/lib/rails/commands.rb2
-rw-r--r--railties/lib/rails/tasks/framework.rake6
-rw-r--r--railties/lib/rails/test_unit/testing.rake4
27 files changed, 177 insertions, 107 deletions
diff --git a/Gemfile b/Gemfile
index a9541b4d1f..ec064bbda8 100644
--- a/Gemfile
+++ b/Gemfile
@@ -9,9 +9,6 @@ else
end
gem "jquery-rails"
-gem "coffee-script"
-gem "sass"
-
# This needs to be with require false to avoid
# it being automatically loaded by sprockets
gem "uglifier", ">= 1.0.0", :require => false
@@ -40,6 +37,12 @@ platforms :mri_19 do
gem "ruby-debug19", :require => "ruby-debug" unless RUBY_VERSION > "1.9.2" || ENV['TRAVIS']
end
+platforms :mri do
+ group :test do
+ gem "ruby-prof" if RUBY_VERSION < "1.9.3"
+ end
+end
+
platforms :ruby do
if ENV["RB_FSEVENT"]
gem "rb-fsevent"
@@ -48,10 +51,6 @@ platforms :ruby do
gem "yajl-ruby"
gem "nokogiri", ">= 1.4.5"
- group :test do
- gem "ruby-prof" if RUBY_VERSION < "1.9.3"
-
- end
# AR
gem "sqlite3", "~> 1.3.3"
diff --git a/actionpack/lib/action_view/helpers/number_helper.rb b/actionpack/lib/action_view/helpers/number_helper.rb
index fe0288521f..ec6c2c8db3 100644
--- a/actionpack/lib/action_view/helpers/number_helper.rb
+++ b/actionpack/lib/action_view/helpers/number_helper.rb
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
require 'active_support/core_ext/big_decimal/conversions'
require 'active_support/core_ext/float/rounding'
require 'active_support/core_ext/object/blank'
diff --git a/actionpack/lib/action_view/renderer/partial_renderer.rb b/actionpack/lib/action_view/renderer/partial_renderer.rb
index 51c784493e..c0ac332c4e 100644
--- a/actionpack/lib/action_view/renderer/partial_renderer.rb
+++ b/actionpack/lib/action_view/renderer/partial_renderer.rb
@@ -362,14 +362,28 @@ module ActionView
def partial_path(object = @object)
@partial_names[object.class.name] ||= begin
object = object.to_model if object.respond_to?(:to_model)
-
object.class.model_name.partial_path.dup.tap do |partial|
path = @lookup_context.prefixes.first
- partial.insert(0, "#{File.dirname(path)}/") if partial.include?(?/) && path.include?(?/)
+ merge_path_into_partial(path, partial)
end
end
end
+ def merge_path_into_partial(path, partial)
+ if path.include?(?/) && partial.include?(?/)
+ overlap = []
+ path_array = File.dirname(path).split('/')
+ partial_array = partial.split('/')[0..-3] # skip model dir & partial
+
+ path_array.each_with_index do |dir, index|
+ overlap << dir if dir == partial_array[index]
+ end
+
+ partial.gsub!(/^#{overlap.join('/')}\//,'')
+ partial.insert(0, "#{File.dirname(path)}/")
+ end
+ end
+
def retrieve_variable(path)
variable = @options[:as].try(:to_sym) || path[%r'_?(\w+)(\.\w+)*$', 1].to_sym
variable_counter = :"#{variable}_counter" if @collection
diff --git a/actionpack/lib/sprockets/assets.rake b/actionpack/lib/sprockets/assets.rake
index a68f0e84f8..424eeae35c 100644
--- a/actionpack/lib/sprockets/assets.rake
+++ b/actionpack/lib/sprockets/assets.rake
@@ -10,6 +10,7 @@ namespace :assets do
Sprockets::Helpers::RailsHelper
assets = Rails.application.config.assets.precompile
+ Rails.application.config.action_controller.perform_caching = true
Rails.application.assets.precompile(*assets)
end
diff --git a/actionpack/lib/sprockets/helpers/rails_helper.rb b/actionpack/lib/sprockets/helpers/rails_helper.rb
index a95e7c0649..ec3d36d5ad 100644
--- a/actionpack/lib/sprockets/helpers/rails_helper.rb
+++ b/actionpack/lib/sprockets/helpers/rails_helper.rb
@@ -72,6 +72,8 @@ module Sprockets
def debug_assets?
params[:debug_assets] == '1' ||
params[:debug_assets] == 'true'
+ rescue NoMethodError
+ false
end
# Override to specify an alternative prefix for asset path generation.
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
index be59da9105..ce4b407c7d 100644
--- a/actionpack/test/controller/render_test.rb
+++ b/actionpack/test/controller/render_test.rb
@@ -14,6 +14,14 @@ module Fun
end
end
+module Quiz
+ class QuestionsController < ActionController::Base
+ def new
+ render :partial => Quiz::Question.new("Namespaced Partial")
+ end
+ end
+end
+
class TestController < ActionController::Base
protect_from_forgery
@@ -1251,6 +1259,12 @@ class RenderTest < ActionController::TestCase
assert_template('fun/games/_form')
end
+ def test_namespaced_object_partial
+ @controller = Quiz::QuestionsController.new
+ get :new
+ assert_equal "Namespaced Partial", @response.body
+ end
+
def test_partial_collection
get :partial_collection
assert_equal "Hello: davidHello: mary", @response.body
diff --git a/actionpack/test/template/sprockets_helper_test.rb b/actionpack/test/template/sprockets_helper_test.rb
index f11d1bba15..1135c55ff0 100644
--- a/actionpack/test/template/sprockets_helper_test.rb
+++ b/actionpack/test/template/sprockets_helper_test.rb
@@ -12,7 +12,6 @@ class SprocketsHelperTest < ActionView::TestCase
super
@controller = BasicController.new
- @controller.stubs(:params).returns({})
@request = Class.new do
def protocol() 'http://' end
@@ -27,10 +26,8 @@ class SprocketsHelperTest < ActionView::TestCase
@assets.paths << FIXTURES.join("sprockets/app/stylesheets")
@assets.paths << FIXTURES.join("sprockets/app/images")
- application = Object.new
+ application = Struct.new(:config, :assets).new(config, @assets)
Rails.stubs(:application).returns(application)
- application.stubs(:config).returns(config)
- application.stubs(:assets).returns(@assets)
@config = config
@config.action_controller ||= ActiveSupport::InheritableOptions.new
@config.perform_caching = true
@@ -54,7 +51,7 @@ class SprocketsHelperTest < ActionView::TestCase
assert_equal "/dir/audio",
asset_path("/dir/audio")
end
-
+
test "asset_path with absolute urls" do
assert_equal "http://www.example.com/video/play",
asset_path("http://www.example.com/video/play")
@@ -74,7 +71,7 @@ class SprocketsHelperTest < ActionView::TestCase
assert_match %r{http://assets-\d.example.com/assets/logo-[0-9a-f]+.png},
asset_path("logo.png")
end
-
+
test "With a proc asset host that returns no protocol the url should be protocol relative" do
@controller.config.asset_host = Proc.new do |asset|
"assets-999.example.com"
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index d24ca2716e..e448609cf4 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,10 @@
*Rails 3.2.0 (unreleased)*
+* If multiple parameters are sent representing a date, and some are blank, the
+resulting object is nil. In previous releases those values defaulted to 1. This
+only affects existing but blank parameters, missing ones still raise an error.
+[Akira Matsuda]
+
* ActiveRecord::Base.establish_connection now takes a string that contains
a URI that specifies the connection configuration. For example:
diff --git a/activerecord/lib/active_record.rb b/activerecord/lib/active_record.rb
index 59cf42a377..d63b9e3f24 100644
--- a/activerecord/lib/active_record.rb
+++ b/activerecord/lib/active_record.rb
@@ -41,7 +41,8 @@ module ActiveRecord
eager_autoload do
autoload :ActiveRecordError, 'active_record/errors'
autoload :ConnectionNotEstablished, 'active_record/errors'
-
+ autoload :ConnectionAdapters, 'active_record/connection_adapters/abstract_adapter'
+
autoload :Aggregations
autoload :Associations
autoload :AttributeMethods
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 99ed273a8a..2c162a6fc8 100644
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -2027,15 +2027,18 @@ MSG
# If Date bits were not provided, error
raise "Missing Parameter" if [1,2,3].any?{|position| !values_hash_from_param.has_key?(position)}
max_position = extract_max_param_for_multiparameter_attributes(values_hash_from_param, 6)
+ # If Date bits were provided but blank, then return nil
+ return nil if (1..3).any? {|position| values_hash_from_param[position].blank?}
+
set_values = (1..max_position).collect{|position| values_hash_from_param[position] }
- # If Date bits were provided but blank, then default to 1
# If Time bits are not there, then default to 0
- [1,1,1,0,0,0].each_with_index{|v,i| set_values[i] = set_values[i].blank? ? v : set_values[i]}
+ (3..5).each {|i| set_values[i] = set_values[i].blank? ? 0 : set_values[i]}
instantiate_time_object(name, set_values)
end
def read_date_parameter_value(name, values_hash_from_param)
- set_values = (1..3).collect{|position| values_hash_from_param[position].blank? ? 1 : values_hash_from_param[position]}
+ return nil if (1..3).any? {|position| values_hash_from_param[position].blank?}
+ set_values = [values_hash_from_param[1], values_hash_from_param[2], values_hash_from_param[3]]
begin
Date.new(*set_values)
rescue ArgumentError # if Date.new raises an exception on an invalid date
@@ -2163,6 +2166,4 @@ MSG
end
end
-# TODO: Remove this and make it work with LAZY flag
-require 'active_record/connection_adapters/abstract_adapter'
ActiveSupport.run_load_hooks(:active_record, ActiveRecord::Base)
diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake
index 44e5520230..0ee7e20cf1 100644
--- a/activerecord/lib/active_record/railties/databases.rake
+++ b/activerecord/lib/active_record/railties/databases.rake
@@ -115,7 +115,8 @@ db_namespace = namespace :db do
end
end
else
- $stderr.puts "#{config['database']} already exists"
+ # Bug with 1.9.2 Calling return within begin still executes else
+ $stderr.puts "#{config['database']} already exists" unless config['adapter'] =~ /sqlite/
end
end
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb
index 607c87beec..8b4e7dd799 100644
--- a/activerecord/test/cases/base_test.rb
+++ b/activerecord/test/cases/base_test.rb
@@ -540,7 +540,7 @@ class BasicsTest < ActiveRecord::TestCase
topic.attributes = attributes
# note that extra #to_date call allows test to pass for Oracle, which
# treats dates/times the same
- assert_date_from_db Date.new(1, 6, 24), topic.last_read.to_date
+ assert_nil topic.last_read
end
def test_multiparameter_attributes_on_date_with_empty_month
@@ -549,7 +549,7 @@ class BasicsTest < ActiveRecord::TestCase
topic.attributes = attributes
# note that extra #to_date call allows test to pass for Oracle, which
# treats dates/times the same
- assert_date_from_db Date.new(2004, 1, 24), topic.last_read.to_date
+ assert_nil topic.last_read
end
def test_multiparameter_attributes_on_date_with_empty_day
@@ -558,7 +558,7 @@ class BasicsTest < ActiveRecord::TestCase
topic.attributes = attributes
# note that extra #to_date call allows test to pass for Oracle, which
# treats dates/times the same
- assert_date_from_db Date.new(2004, 6, 1), topic.last_read.to_date
+ assert_nil topic.last_read
end
def test_multiparameter_attributes_on_date_with_empty_day_and_year
@@ -567,7 +567,7 @@ class BasicsTest < ActiveRecord::TestCase
topic.attributes = attributes
# note that extra #to_date call allows test to pass for Oracle, which
# treats dates/times the same
- assert_date_from_db Date.new(1, 6, 1), topic.last_read.to_date
+ assert_nil topic.last_read
end
def test_multiparameter_attributes_on_date_with_empty_day_and_month
@@ -576,7 +576,7 @@ class BasicsTest < ActiveRecord::TestCase
topic.attributes = attributes
# note that extra #to_date call allows test to pass for Oracle, which
# treats dates/times the same
- assert_date_from_db Date.new(2004, 1, 1), topic.last_read.to_date
+ assert_nil topic.last_read
end
def test_multiparameter_attributes_on_date_with_empty_year_and_month
@@ -585,7 +585,7 @@ class BasicsTest < ActiveRecord::TestCase
topic.attributes = attributes
# note that extra #to_date call allows test to pass for Oracle, which
# treats dates/times the same
- assert_date_from_db Date.new(1, 1, 24), topic.last_read.to_date
+ assert_nil topic.last_read
end
def test_multiparameter_attributes_on_date_with_all_empty
@@ -678,12 +678,7 @@ class BasicsTest < ActiveRecord::TestCase
}
topic = Topic.find(1)
topic.attributes = attributes
- assert_equal 1, topic.written_on.year
- assert_equal 1, topic.written_on.month
- assert_equal 1, topic.written_on.day
- assert_equal 0, topic.written_on.hour
- assert_equal 12, topic.written_on.min
- assert_equal 2, topic.written_on.sec
+ assert_nil topic.written_on
end
def test_multiparameter_attributes_on_time_will_ignore_date_if_empty
@@ -693,12 +688,7 @@ class BasicsTest < ActiveRecord::TestCase
}
topic = Topic.find(1)
topic.attributes = attributes
- assert_equal 1, topic.written_on.year
- assert_equal 1, topic.written_on.month
- assert_equal 1, topic.written_on.day
- assert_equal 16, topic.written_on.hour
- assert_equal 24, topic.written_on.min
- assert_equal 0, topic.written_on.sec
+ assert_nil topic.written_on
end
def test_multiparameter_attributes_on_time_with_seconds_will_ignore_date_if_empty
attributes = {
@@ -707,12 +697,7 @@ class BasicsTest < ActiveRecord::TestCase
}
topic = Topic.find(1)
topic.attributes = attributes
- assert_equal 1, topic.written_on.year
- assert_equal 1, topic.written_on.month
- assert_equal 1, topic.written_on.day
- assert_equal 16, topic.written_on.hour
- assert_equal 12, topic.written_on.min
- assert_equal 02, topic.written_on.sec
+ assert_nil topic.written_on
end
def test_multiparameter_attributes_on_time_with_utc
diff --git a/activesupport/lib/active_support/cache/file_store.rb b/activesupport/lib/active_support/cache/file_store.rb
index c4da04e532..f7c01948b4 100644
--- a/activesupport/lib/active_support/cache/file_store.rb
+++ b/activesupport/lib/active_support/cache/file_store.rb
@@ -16,7 +16,7 @@ module ActiveSupport
def initialize(cache_path, options = nil)
super(options)
- @cache_path = cache_path
+ @cache_path = cache_path.to_s
extend Strategy::LocalCache
end
diff --git a/activesupport/lib/active_support/core_ext/class/attribute.rb b/activesupport/lib/active_support/core_ext/class/attribute.rb
index ca9b2c1b60..45bec264ff 100644
--- a/activesupport/lib/active_support/core_ext/class/attribute.rb
+++ b/activesupport/lib/active_support/core_ext/class/attribute.rb
@@ -110,12 +110,6 @@ class Class
private
def singleton_class?
- # in case somebody is crazy enough to overwrite allocate
- allocate = Class.instance_method(:allocate)
- # object.class always points to a real (non-singleton) class
- allocate.bind(self).call.class != self
- rescue TypeError
- # MRI/YARV/JRuby all disallow creating new instances of a singleton class
- true
+ !name || '' == name
end
end
diff --git a/activesupport/lib/active_support/core_ext/enumerable.rb b/activesupport/lib/active_support/core_ext/enumerable.rb
index 3e05c6eaf2..ddb4f3012f 100644
--- a/activesupport/lib/active_support/core_ext/enumerable.rb
+++ b/activesupport/lib/active_support/core_ext/enumerable.rb
@@ -20,6 +20,7 @@ module Enumerable
# "2006-02-24 -> Transcript, Transcript"
# "2006-02-23 -> Transcript"
def group_by
+ return to_enum :group_by unless block_given?
assoc = ActiveSupport::OrderedHash.new
each do |element|
@@ -75,9 +76,10 @@ module Enumerable
#
# (1..5).each_with_object(1) { |value, memo| memo *= value } # => 1
#
- def each_with_object(memo, &block)
+ def each_with_object(memo)
+ return to_enum :each_with_object, memo unless block_given?
each do |element|
- block.call(element, memo)
+ yield element, memo
end
memo
end unless [].respond_to?(:each_with_object)
@@ -90,14 +92,22 @@ module Enumerable
# => { "Chade- Fowlersburg-e" => <Person ...>, "David Heinemeier Hansson" => <Person ...>, ...}
#
def index_by
+ return to_enum :index_by unless block_given?
Hash[map { |elem| [yield(elem), elem] }]
end
- # Returns true if the collection has more than 1 element. Functionally equivalent to collection.size > 1.
+ # Returns true if the enumerable has more than 1 element. Functionally equivalent to enum.to_a.size > 1.
# Can be called with a block too, much like any?, so people.many? { |p| p.age > 26 } returns true if more than 1 person is over 26.
- def many?(&block)
- size = block_given? ? count(&block) : self.size
- size > 1
+ def many?
+ cnt = 0
+ if block_given?
+ any? do |element|
+ cnt += 1 if yield element
+ cnt > 1
+ end
+ else
+ any?{ (cnt += 1) > 1 }
+ end
end
# The negative of the Enumerable#include?. Returns true if the collection does not include the object.
diff --git a/activesupport/lib/active_support/core_ext/string/conversions.rb b/activesupport/lib/active_support/core_ext/string/conversions.rb
index 664537eea4..0f8933b658 100644
--- a/activesupport/lib/active_support/core_ext/string/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/string/conversions.rb
@@ -1,3 +1,4 @@
+# encoding: utf-8
require 'date'
require 'active_support/core_ext/time/publicize_conversion_methods'
require 'active_support/core_ext/time/calculations'
diff --git a/activesupport/lib/active_support/multibyte/unicode.rb b/activesupport/lib/active_support/multibyte/unicode.rb
index 513f83e445..754ca9290b 100644
--- a/activesupport/lib/active_support/multibyte/unicode.rb
+++ b/activesupport/lib/active_support/multibyte/unicode.rb
@@ -1,3 +1,4 @@
+# encoding: utf-8
module ActiveSupport
module Multibyte
module Unicode
diff --git a/activesupport/lib/active_support/ordered_hash.rb b/activesupport/lib/active_support/ordered_hash.rb
index 68f4bd66da..7f70628933 100644
--- a/activesupport/lib/active_support/ordered_hash.rb
+++ b/activesupport/lib/active_support/ordered_hash.rb
@@ -6,7 +6,7 @@ end
require 'yaml'
YAML.add_builtin_type("omap") do |type, val|
- ActiveSupport::OrderedHash[val.map(&:to_a).map(&:first)]
+ ActiveSupport::OrderedHash[val.map{ |v| v.to_a.first }]
end
module ActiveSupport
diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb
index 8b3e4800c3..402c6695aa 100644
--- a/activesupport/test/caching_test.rb
+++ b/activesupport/test/caching_test.rb
@@ -521,6 +521,7 @@ class FileStoreTest < ActiveSupport::TestCase
Dir.mkdir(cache_dir) unless File.exist?(cache_dir)
@cache = ActiveSupport::Cache.lookup_store(:file_store, cache_dir, :expires_in => 60)
@peek = ActiveSupport::Cache.lookup_store(:file_store, cache_dir, :expires_in => 60)
+ @cache_with_pathname = ActiveSupport::Cache.lookup_store(:file_store, Pathname.new(cache_dir), :expires_in => 60)
end
def teardown
@@ -540,6 +541,12 @@ class FileStoreTest < ActiveSupport::TestCase
key = @cache.send(:key_file_path, "views/index?id=1")
assert_equal "views/index?id=1", @cache.send(:file_path_key, key)
end
+
+ def test_key_transformation_with_pathname
+ FileUtils.touch(File.join(cache_dir, "foo"))
+ key = @cache_with_pathname.send(:key_file_path, "views/index?id=1")
+ assert_equal "views/index?id=1", @cache_with_pathname.send(:file_path_key, key)
+ end
end
class MemoryStoreTest < ActiveSupport::TestCase
diff --git a/activesupport/test/core_ext/duplicable_test.rb b/activesupport/test/core_ext/duplicable_test.rb
index 24e0ccd9b3..e48e6a7c45 100644
--- a/activesupport/test/core_ext/duplicable_test.rb
+++ b/activesupport/test/core_ext/duplicable_test.rb
@@ -4,22 +4,27 @@ require 'active_support/core_ext/object/duplicable'
require 'active_support/core_ext/numeric/time'
class DuplicableTest < Test::Unit::TestCase
- NO = [nil, false, true, :symbol, 1, 2.3, BigDecimal.new('4.56'), Class.new, Module.new, 5.seconds]
+ RAISE_DUP = [nil, false, true, :symbol, 1, 2.3, BigDecimal.new('4.56'), 5.seconds]
YES = ['1', Object.new, /foo/, [], {}, Time.now]
+ NO = [Class.new, Module.new]
def test_duplicable
- NO.each do |v|
+ (RAISE_DUP + NO).each do |v|
assert !v.duplicable?
- begin
- v.dup
- fail
- rescue Exception
- end
end
YES.each do |v|
assert v.duplicable?
+ end
+
+ (YES + NO).each do |v|
assert_nothing_raised { v.dup }
end
+
+ RAISE_DUP.each do |v|
+ assert_raises(TypeError) do
+ v.dup
+ end
+ end
end
end
diff --git a/activesupport/test/core_ext/enumerable_test.rb b/activesupport/test/core_ext/enumerable_test.rb
index 4655bfe519..cdfa991a34 100644
--- a/activesupport/test/core_ext/enumerable_test.rb
+++ b/activesupport/test/core_ext/enumerable_test.rb
@@ -8,6 +8,19 @@ class SummablePayment < Payment
end
class EnumerableTests < Test::Unit::TestCase
+ Enumerator = [].each.class
+
+ class GenericEnumerable
+ include Enumerable
+ def initialize(values = [1, 2, 3])
+ @values = values
+ end
+
+ def each
+ @values.each{|v| yield v}
+ end
+ end
+
def test_group_by
names = %w(marcel sam david jeremy)
klass = Struct.new(:name)
@@ -17,7 +30,8 @@ class EnumerableTests < Test::Unit::TestCase
people << p
end
- grouped = objects.group_by { |object| object.name }
+ enum = GenericEnumerable.new(objects)
+ grouped = enum.group_by { |object| object.name }
grouped.each do |name, group|
assert group.all? { |person| person.name == name }
@@ -25,20 +39,24 @@ class EnumerableTests < Test::Unit::TestCase
assert_equal objects.uniq.map(&:name), grouped.keys
assert({}.merge(grouped), "Could not convert ActiveSupport::OrderedHash into Hash")
+ assert_equal Enumerator, enum.group_by.class
+ assert_equal grouped, enum.group_by.each(&:name)
end
def test_sums
- assert_equal 30, [5, 15, 10].sum
- assert_equal 30, [5, 15, 10].sum { |i| i }
+ enum = GenericEnumerable.new([5, 15, 10])
+ assert_equal 30, enum.sum
+ assert_equal 60, enum.sum { |i| i * 2}
- assert_equal 'abc', %w(a b c).sum
- assert_equal 'abc', %w(a b c).sum { |i| i }
+ enum = GenericEnumerable.new(%w(a b c))
+ assert_equal 'abc', enum.sum
+ assert_equal 'aabbcc', enum.sum { |i| i * 2 }
- payments = [ Payment.new(5), Payment.new(15), Payment.new(10) ]
+ payments = GenericEnumerable.new([ Payment.new(5), Payment.new(15), Payment.new(10) ])
assert_equal 30, payments.sum(&:price)
assert_equal 60, payments.sum { |p| p.price * 2 }
- payments = [ SummablePayment.new(5), SummablePayment.new(15) ]
+ payments = GenericEnumerable.new([ SummablePayment.new(5), SummablePayment.new(15) ])
assert_equal SummablePayment.new(20), payments.sum
assert_equal SummablePayment.new(20), payments.sum { |p| p }
end
@@ -46,21 +64,21 @@ class EnumerableTests < Test::Unit::TestCase
def test_nil_sums
expected_raise = TypeError
- assert_raise(expected_raise) { [5, 15, nil].sum }
+ assert_raise(expected_raise) { GenericEnumerable.new([5, 15, nil]).sum }
- payments = [ Payment.new(5), Payment.new(15), Payment.new(10), Payment.new(nil) ]
+ payments = GenericEnumerable.new([ Payment.new(5), Payment.new(15), Payment.new(10), Payment.new(nil) ])
assert_raise(expected_raise) { payments.sum(&:price) }
assert_equal 60, payments.sum { |p| p.price.to_i * 2 }
end
def test_empty_sums
- assert_equal 0, [].sum
- assert_equal 0, [].sum { |i| i }
- assert_equal Payment.new(0), [].sum(Payment.new(0))
+ assert_equal 0, GenericEnumerable.new([]).sum
+ assert_equal 0, GenericEnumerable.new([]).sum { |i| i + 10 }
+ assert_equal Payment.new(0), GenericEnumerable.new([]).sum(Payment.new(0))
end
- def test_enumerable_sums
+ def test_range_sums
assert_equal 20, (1..4).sum { |i| i * 2 }
assert_equal 10, (1..4).sum
assert_equal 10, (1..4.5).sum
@@ -69,29 +87,43 @@ class EnumerableTests < Test::Unit::TestCase
end
def test_each_with_object
- result = %w(foo bar).each_with_object({}) { |str, hsh| hsh[str] = str.upcase }
+ enum = GenericEnumerable.new(%w(foo bar))
+ result = enum.each_with_object({}) { |str, hsh| hsh[str] = str.upcase }
assert_equal({'foo' => 'FOO', 'bar' => 'BAR'}, result)
+ assert_equal Enumerator, enum.each_with_object({}).class
+ result2 = enum.each_with_object({}).each{|str, hsh| hsh[str] = str.upcase}
+ assert_equal result, result2
end
def test_index_by
- payments = [ Payment.new(5), Payment.new(15), Payment.new(10) ]
- assert_equal({ 5 => payments[0], 15 => payments[1], 10 => payments[2] },
+ payments = GenericEnumerable.new([ Payment.new(5), Payment.new(15), Payment.new(10) ])
+ assert_equal({ 5 => Payment.new(5), 15 => Payment.new(15), 10 => Payment.new(10) },
payments.index_by { |p| p.price })
+ assert_equal Enumerator, payments.index_by.class
+ assert_equal({ 5 => Payment.new(5), 15 => Payment.new(15), 10 => Payment.new(10) },
+ payments.index_by.each { |p| p.price })
end
def test_many
- assert ![].many?
- assert ![ 1 ].many?
- assert [ 1, 2 ].many?
-
- assert ![].many? {|x| x > 1 }
- assert ![ 2 ].many? {|x| x > 1 }
- assert ![ 1, 2 ].many? {|x| x > 1 }
- assert [ 1, 2, 2 ].many? {|x| x > 1 }
+ assert_equal false, GenericEnumerable.new([] ).many?
+ assert_equal false, GenericEnumerable.new([ 1 ] ).many?
+ assert_equal true, GenericEnumerable.new([ 1, 2 ] ).many?
+
+ assert_equal false, GenericEnumerable.new([] ).many? {|x| x > 1 }
+ assert_equal false, GenericEnumerable.new([ 2 ] ).many? {|x| x > 1 }
+ assert_equal false, GenericEnumerable.new([ 1, 2 ] ).many? {|x| x > 1 }
+ assert_equal true, GenericEnumerable.new([ 1, 2, 2 ]).many? {|x| x > 1 }
+ end
+
+ def test_many_iterates_only_on_what_is_needed
+ infinity = 1.0/0.0
+ very_long_enum = 0..infinity
+ assert_equal true, very_long_enum.many?
+ assert_equal true, very_long_enum.many?{|x| x > 100}
end
def test_exclude?
- assert [ 1 ].exclude?(2)
- assert ![ 1 ].exclude?(1)
+ assert_equal true, GenericEnumerable.new([ 1 ]).exclude?(2)
+ assert_equal false, GenericEnumerable.new([ 1 ]).exclude?(1)
end
end
diff --git a/activesupport/test/json/decoding_test.rb b/activesupport/test/json/decoding_test.rb
index 6ccffa59b1..201729a6c2 100644
--- a/activesupport/test/json/decoding_test.rb
+++ b/activesupport/test/json/decoding_test.rb
@@ -1,4 +1,4 @@
-# encoding: UTF-8
+# encoding: utf-8
require 'abstract_unit'
require 'active_support/json'
require 'active_support/time'
diff --git a/railties/guides/rails_guides/generator.rb b/railties/guides/rails_guides/generator.rb
index 2219fcea66..14d671c8f3 100644
--- a/railties/guides/rails_guides/generator.rb
+++ b/railties/guides/rails_guides/generator.rb
@@ -227,13 +227,13 @@ module RailsGuides
end
code_blocks.push(<<HTML)
-&lt;notextile&gt;
+<notextile>
<div class="code_container">
<pre class="brush: #{brush}; gutter: false; toolbar: false">
#{ERB::Util.h($2).strip}
</pre>
</div>
-&lt;/notextile&gt;
+</notextile>
HTML
"\ndirty_workaround_for_notextile_#{code_blocks.size - 1}\n"
end
@@ -280,4 +280,3 @@ HTML
end
end
end
-
diff --git a/railties/guides/rails_guides/textile_extensions.rb b/railties/guides/rails_guides/textile_extensions.rb
index dd51e0d66b..352c5e91dd 100644
--- a/railties/guides/rails_guides/textile_extensions.rb
+++ b/railties/guides/rails_guides/textile_extensions.rb
@@ -25,7 +25,7 @@ module RailsGuides
def plusplus(body)
body.gsub!(/\+(.*?)\+/) do |m|
- "&lt;notextile&gt;<tt>#{$1}</tt>&lt;/notextile&gt;"
+ "<notextile><tt>#{$1}</tt></notextile>"
end
# The real plus sign
@@ -36,9 +36,8 @@ module RailsGuides
body.gsub!(%r{<(yaml|shell|ruby|erb|html|sql|plain)>(.*?)</\1>}m) do |m|
es = ERB::Util.h($2)
css_class = $1.in?(['erb', 'shell']) ? 'html' : $1
- %{&lt;notextile&gt;<div class="code_container"><code class="#{css_class}">#{es}</code></div>&lt;/notextile&gt;}
+ %{<notextile><div class="code_container"><code class="#{css_class}">#{es}</code></div></notextile>}
end
end
end
end
-
diff --git a/railties/lib/rails/commands.rb b/railties/lib/rails/commands.rb
index 5e55aeada9..a21484e5cb 100644
--- a/railties/lib/rails/commands.rb
+++ b/railties/lib/rails/commands.rb
@@ -93,7 +93,7 @@ In addition to those, there are:
plugin Install a plugin
runner Run a piece of code in the application environment (short-cut alias: "r")
-All commands can be run with -h for more information.
+All commands can be run with -h (or --help) for more information.
EOT
exit(1)
end
diff --git a/railties/lib/rails/tasks/framework.rake b/railties/lib/rails/tasks/framework.rake
index 77a5c4dc6c..206ce39773 100644
--- a/railties/lib/rails/tasks/framework.rake
+++ b/railties/lib/rails/tasks/framework.rake
@@ -2,14 +2,14 @@ namespace :rails do
desc "Update configs and some other initially generated files (or use just update:configs, update:scripts, or update:application_controller)"
task :update => [ "update:configs", "update:scripts", "update:application_controller" ]
- desc "Applies the template supplied by LOCATION=/path/to/template"
+ desc "Applies the template supplied by LOCATION=(/path/to/template) or URL"
task :template do
template = ENV["LOCATION"]
+ raise "No LOCATION value given. Please set LOCATION either as path to a file or a URL" if template.blank?
template = File.expand_path(template) if template !~ %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://}
-
require 'rails/generators'
require 'rails/generators/rails/app/app_generator'
- generator = Rails::Generators::AppGenerator.new [ Rails.root ], {}, :destination_root => Rails.root
+ generator = Rails::Generators::AppGenerator.new [Rails.root], {}, :destination_root => Rails.root
generator.apply template, :verbose => false
end
diff --git a/railties/lib/rails/test_unit/testing.rake b/railties/lib/rails/test_unit/testing.rake
index b9877a83b5..33da2c0f5a 100644
--- a/railties/lib/rails/test_unit/testing.rake
+++ b/railties/lib/rails/test_unit/testing.rake
@@ -108,9 +108,9 @@ namespace :test do
Rake::TestTask.new(:uncommitted => "test:prepare") do |t|
def t.file_list
if File.directory?(".svn")
- changed_since_checkin = silence_stderr { `svn status` }.map { |path| path.chomp[7 .. -1] }
+ changed_since_checkin = silence_stderr { `svn status` }.split.map { |path| path.chomp[7 .. -1] }
elsif File.directory?(".git")
- changed_since_checkin = silence_stderr { `git ls-files --modified --others` }.map { |path| path.chomp }
+ changed_since_checkin = silence_stderr { `git ls-files --modified --others` }.split.map { |path| path.chomp }
else
abort "Not a Subversion or Git checkout."
end