diff options
32 files changed, 292 insertions, 52 deletions
diff --git a/.travis.yml b/.travis.yml index 18b0100c62..257a6dc7e7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ script: 'ci/travis.rb' before_install: - - gem install bundler + - gem install bundler --pre rvm: - 1.9.3 - 2.0.0 diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb index fbb47f60a2..035f08d2f4 100644 --- a/actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb +++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb @@ -1,6 +1,6 @@ <% unless @exception.blamed_files.blank? %> <% if (hide = @exception.blamed_files.length > 8) %> - <a href="#" onclick="s = document.getElementById('blame_trace').style; s.display = s.display == 'none' ? 'block' : 'none'; return false;">Toggle blamed files</a> + <a href="#" onclick="toggleTrace()">Toggle blamed files</a> <% end %> <pre id="blame_trace" <%='style="display:none"' if hide %>><code><%=h @exception.describe_blame %></code></pre> <% end %> @@ -21,12 +21,12 @@ <p><b>Parameters</b>:</p> <pre><%=h request_dump %></pre> <div class="details"> - <div class="summary"><a href="#" onclick="s = document.getElementById('session_dump').style; s.display = s.display == 'none' ? 'block' : 'none'; return false;">Toggle session dump</a></div> + <div class="summary"><a href="#" onclick="toggleSessionDump()">Toggle session dump</a></div> <div id="session_dump" style="display:none"><pre><%= debug_hash @request.session %></pre></div> </div> <div class="details"> - <div class="summary"><a href="#" onclick="s = document.getElementById('env_dump').style; s.display = s.display == 'none' ? 'block' : 'none'; return false;">Toggle env dump</a></div> + <div class="summary"><a href="#" onclick="toggleEnvDump()">Toggle env dump</a></div> <div id="env_dump" style="display:none"><pre><%= debug_hash @request.env.slice(*@request.class::ENV_METHODS) %></pre></div> </div> diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb index 8771b5fd6d..463ca39563 100644 --- a/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb +++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb @@ -12,8 +12,8 @@ <div id="traces"> <% names.each do |name| %> <% - show = "document.getElementById('#{name.gsub(/\s/, '-')}').style.display='block';" - hide = (names - [name]).collect {|hide_name| "document.getElementById('#{hide_name.gsub(/\s/, '-')}').style.display='none';"} + show = "show('#{name.gsub(/\s/, '-')}');" + hide = (names - [name]).collect {|hide_name| "hide('#{hide_name.gsub(/\s/, '-')}');"} %> <a href="#" onclick="<%= hide.join %><%= show %>; return false;"><%= name %></a> <%= '|' unless names.last == name %> <% end %> diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/layout.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/layout.erb index ff33430532..1aeff6c1b9 100644 --- a/actionpack/lib/action_dispatch/middleware/templates/rescues/layout.erb +++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/layout.erb @@ -114,6 +114,28 @@ a:visited { color: #666; } a:hover { color: #C52F24; } </style> + + <script> + var toggle = function(id) { + var s = document.getElementById(id).style; + s.display = s.display == 'none' ? 'block' : 'none'; + } + var show = function(id) { + document.getElementById(id).style.display = 'block'; + } + var hide = function(id) { + document.getElementById(id).style.display = 'none'; + } + var toggleTrace = function() { + toggle('blame_trace'); + } + var toggleSessionDump = function() { + toggle('session_dump'); + } + var toggleEnvDump = function() { + toggle('env_dump'); + } + </script> </head> <body> diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index db8fa303be..49473dc92a 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,6 +1,11 @@ ## Rails 4.0.0 (unreleased) ## -* Rename `update_attributes` to `update`, keep `update_attributes` as an alias for `update` method. +* Fix undefined method `to_i` when calling `new` on a scope that uses an Array. + Fixes #8718, #8734. + + *Jason Stirk* + +* Rename `update_attributes` to `update`, keep `update_attributes` as an alias for `update` method. This is a soft-deprecation for `update_attributes`, although it will still work without any deprecation message in 4.0 is recommended to start using `update` since `update_attributes` will be deprecated and removed in future versions of Rails. diff --git a/activerecord/lib/active_record/connection_adapters/column.rb b/activerecord/lib/active_record/connection_adapters/column.rb index fd36a5b075..51d3acaff8 100644 --- a/activerecord/lib/active_record/connection_adapters/column.rb +++ b/activerecord/lib/active_record/connection_adapters/column.rb @@ -206,7 +206,11 @@ module ActiveRecord when TrueClass, FalseClass value ? 1 : 0 else - value.to_i + if value.respond_to?(:to_i) + value.to_i + else + nil + end end end diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb index 18ea83ce42..0a69e062f0 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb @@ -82,7 +82,7 @@ module ActiveRecord def type_cast(value) return if value.nil? - value.to_i rescue value ? 1 : 0 + ConnectionAdapters::Column.value_to_integer value end end diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb index 97a3d57fe0..3a6da0e59f 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -63,6 +63,13 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase assert_equal apple.id, citibank.firm_id end + def test_id_assignment + apple = Firm.create("name" => "Apple") + citibank = Account.create("credit_limit" => 10) + citibank.firm_id = apple + assert_nil citibank.firm_id + end + def test_natural_assignment_with_primary_key apple = Firm.create("name" => "Apple") citibank = Client.create("name" => "Primary key client") @@ -567,6 +574,11 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase assert_equal new_firm.name, "Apple" end + def test_attributes_are_set_without_error_when_initialized_from_belongs_to_association_with_array_in_where_clause + new_account = Account.where(:credit_limit => [ 50, 60 ]).new + assert_nil new_account.credit_limit + end + def test_reassigning_the_parent_id_updates_the_object client = companies(:second_client) diff --git a/activerecord/test/cases/column_test.rb b/activerecord/test/cases/column_test.rb index 2124c256fa..dc1b30261c 100644 --- a/activerecord/test/cases/column_test.rb +++ b/activerecord/test/cases/column_test.rb @@ -1,4 +1,5 @@ require "cases/helper" +require 'models/company' module ActiveRecord module ConnectionAdapters @@ -40,13 +41,20 @@ module ActiveRecord def test_type_cast_non_integer_to_integer column = Column.new("field", nil, "integer") - assert_raises(NoMethodError) do - column.type_cast([]) - end + assert_nil column.type_cast([1,2]) + assert_nil column.type_cast({1 => 2}) + assert_nil column.type_cast((1..2)) + end - assert_raises(NoMethodError) do - column.type_cast(Object.new) - end + def test_type_cast_activerecord_to_integer + column = Column.new("field", nil, "integer") + firm = Firm.create(:name => 'Apple') + assert_nil column.type_cast(firm) + end + + def test_type_cast_object_without_to_i_to_integer + column = Column.new("field", nil, "integer") + assert_nil column.type_cast(Object.new) end def test_type_cast_time diff --git a/activerecord/test/cases/persistence_test.rb b/activerecord/test/cases/persistence_test.rb index 85b069b593..b936cca875 100644 --- a/activerecord/test/cases/persistence_test.rb +++ b/activerecord/test/cases/persistence_test.rb @@ -242,7 +242,7 @@ class PersistencesTest < ActiveRecord::TestCase assert_equal "David", topic2.author_name end - def test_update + def test_update_object topic = Topic.new topic.title = "Another New Topic" topic.written_on = "2003-12-12 23:23:00" @@ -646,7 +646,7 @@ class PersistencesTest < ActiveRecord::TestCase assert !topic.approved? assert_equal "The First Topic", topic.title end - + def test_update_attributes topic = Topic.find(1) assert !topic.approved? diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 6917be7efc..bee93ebfbc 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,5 +1,18 @@ ## Rails 4.0.0 (unreleased) ## +* It's now possible to compare Date, DateTime, Time and TimeWithZone with Infinity + This allows to create date/time ranges with one infinite bound. + Example: + + range = Range.new(Date.today, Float::INFINITY) + + Also it's possible to check inclusion of date/time in range with conversion. + + range.include?(Time.now + 1.year) # => true + range.include?(DateTime.now + 1.year) # => true + + *Alexander Grebennik* + * Remove meaningless `ActiveSupport::FrozenObjectError`, which was just an alias of `RuntimeError`. *Akira Matsuda* diff --git a/activesupport/lib/active_support/core_ext/date.rb b/activesupport/lib/active_support/core_ext/date.rb index 465fedda80..5f13f5f70f 100644 --- a/activesupport/lib/active_support/core_ext/date.rb +++ b/activesupport/lib/active_support/core_ext/date.rb @@ -2,4 +2,5 @@ require 'active_support/core_ext/date/acts_like' require 'active_support/core_ext/date/calculations' require 'active_support/core_ext/date/conversions' require 'active_support/core_ext/date/zones' +require 'active_support/core_ext/date/infinite_comparable' diff --git a/activesupport/lib/active_support/core_ext/date/infinite_comparable.rb b/activesupport/lib/active_support/core_ext/date/infinite_comparable.rb new file mode 100644 index 0000000000..ca5d793942 --- /dev/null +++ b/activesupport/lib/active_support/core_ext/date/infinite_comparable.rb @@ -0,0 +1,5 @@ +require 'active_support/core_ext/infinite_comparable' + +class Date + include InfiniteComparable +end diff --git a/activesupport/lib/active_support/core_ext/date_time.rb b/activesupport/lib/active_support/core_ext/date_time.rb index e8a27b9f38..024af91738 100644 --- a/activesupport/lib/active_support/core_ext/date_time.rb +++ b/activesupport/lib/active_support/core_ext/date_time.rb @@ -2,3 +2,4 @@ require 'active_support/core_ext/date_time/acts_like' require 'active_support/core_ext/date_time/calculations' require 'active_support/core_ext/date_time/conversions' require 'active_support/core_ext/date_time/zones' +require 'active_support/core_ext/date_time/infinite_comparable' diff --git a/activesupport/lib/active_support/core_ext/date_time/calculations.rb b/activesupport/lib/active_support/core_ext/date_time/calculations.rb index fca5d4d679..4e4852a5e6 100644 --- a/activesupport/lib/active_support/core_ext/date_time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date_time/calculations.rb @@ -142,11 +142,4 @@ class DateTime def utc_offset (offset * 86400).to_i end - - # Layers additional behavior on DateTime#<=> so that Time and - # ActiveSupport::TimeWithZone instances can be compared with a DateTime. - def <=>(other) - super other.to_datetime - end - end diff --git a/activesupport/lib/active_support/core_ext/date_time/infinite_comparable.rb b/activesupport/lib/active_support/core_ext/date_time/infinite_comparable.rb new file mode 100644 index 0000000000..8a282b19f2 --- /dev/null +++ b/activesupport/lib/active_support/core_ext/date_time/infinite_comparable.rb @@ -0,0 +1,5 @@ +require 'active_support/core_ext/infinite_comparable' + +class DateTime + include InfiniteComparable +end diff --git a/activesupport/lib/active_support/core_ext/infinite_comparable.rb b/activesupport/lib/active_support/core_ext/infinite_comparable.rb new file mode 100644 index 0000000000..df9cde7db0 --- /dev/null +++ b/activesupport/lib/active_support/core_ext/infinite_comparable.rb @@ -0,0 +1,34 @@ +require 'active_support/concern' +require 'active_support/core_ext/object/try' + +module InfiniteComparable + extend ActiveSupport::Concern + + included do + alias_method_chain :<=>, :infinity + end + + define_method :'<=>_with_infinity' do |other| + if other.class == self.class + public_send :'<=>_without_infinity', other + else + infinite = try(:infinite?) + other_infinite = other.try(:infinite?) + + # inf <=> inf + if infinite && other_infinite + infinite <=> other_infinite + # not_inf <=> inf + elsif other_infinite + -other_infinite + # inf <=> not_inf + elsif infinite + infinite + else + conversion = "to_#{self.class.name.downcase}" + other = other.public_send(conversion) if other.respond_to?(conversion) + public_send :'<=>_without_infinity', other + end + end + end +end diff --git a/activesupport/lib/active_support/core_ext/numeric.rb b/activesupport/lib/active_support/core_ext/numeric.rb index a6bc0624be..d5cfc2ece4 100644 --- a/activesupport/lib/active_support/core_ext/numeric.rb +++ b/activesupport/lib/active_support/core_ext/numeric.rb @@ -1,3 +1,4 @@ require 'active_support/core_ext/numeric/bytes' require 'active_support/core_ext/numeric/time' require 'active_support/core_ext/numeric/conversions' +require 'active_support/core_ext/numeric/infinite_comparable' diff --git a/activesupport/lib/active_support/core_ext/numeric/infinite_comparable.rb b/activesupport/lib/active_support/core_ext/numeric/infinite_comparable.rb new file mode 100644 index 0000000000..b5f1b0487b --- /dev/null +++ b/activesupport/lib/active_support/core_ext/numeric/infinite_comparable.rb @@ -0,0 +1,9 @@ +require 'active_support/core_ext/infinite_comparable' + +class Float + include InfiniteComparable +end + +class BigDecimal + include InfiniteComparable +end diff --git a/activesupport/lib/active_support/core_ext/time.rb b/activesupport/lib/active_support/core_ext/time.rb index 32cffe237d..af6b589b71 100644 --- a/activesupport/lib/active_support/core_ext/time.rb +++ b/activesupport/lib/active_support/core_ext/time.rb @@ -3,3 +3,4 @@ require 'active_support/core_ext/time/calculations' require 'active_support/core_ext/time/conversions' require 'active_support/core_ext/time/marshal' require 'active_support/core_ext/time/zones' +require 'active_support/core_ext/time/infinite_comparable' diff --git a/activesupport/lib/active_support/core_ext/time/infinite_comparable.rb b/activesupport/lib/active_support/core_ext/time/infinite_comparable.rb new file mode 100644 index 0000000000..63795885f5 --- /dev/null +++ b/activesupport/lib/active_support/core_ext/time/infinite_comparable.rb @@ -0,0 +1,5 @@ +require 'active_support/core_ext/infinite_comparable' + +class Time + include InfiniteComparable +end diff --git a/activesupport/lib/active_support/railtie.rb b/activesupport/lib/active_support/railtie.rb index 133aa6a054..72ac597d99 100644 --- a/activesupport/lib/active_support/railtie.rb +++ b/activesupport/lib/active_support/railtie.rb @@ -13,20 +13,6 @@ module ActiveSupport end end - # Sets the default value for Time.zone - # If assigned value cannot be matched to a TimeZone, an exception will be raised. - initializer "active_support.initialize_time_zone" do |app| - require 'active_support/core_ext/time/zones' - zone_default = Time.find_zone!(app.config.time_zone) - - unless zone_default - raise 'Value assigned to config.time_zone not recognized. ' \ - 'Run "rake -D time" for a list of tasks for finding appropriate time zone names.' - end - - Time.zone_default = zone_default - end - # Sets the default week start # If assigned value is not a valid day symbol (e.g. :sunday, :monday, ...), an exception will be raised. initializer "active_support.initialize_beginning_of_week" do |app| @@ -42,5 +28,21 @@ module ActiveSupport ActiveSupport.send(k, v) if ActiveSupport.respond_to? k end end + + # Sets the default value for Time.zone after initialization since the default configuration + # lives in application initializers. + # If assigned value cannot be matched to a TimeZone, an exception will be raised. + config.after_initialize do |app| + require 'active_support/core_ext/time/zones' + zone_default = Time.find_zone!(app.config.time_zone) + + unless zone_default + raise 'Value assigned to config.time_zone not recognized. ' \ + 'Run "rake -D time" for a list of tasks for finding appropriate time zone names.' + end + + Time.zone_default = zone_default + end + end end diff --git a/activesupport/test/core_ext/date_ext_test.rb b/activesupport/test/core_ext/date_ext_test.rb index 5e89a6e00b..ec47d0632c 100644 --- a/activesupport/test/core_ext/date_ext_test.rb +++ b/activesupport/test/core_ext/date_ext_test.rb @@ -353,6 +353,11 @@ class DateExtBehaviorTest < ActiveSupport::TestCase Date.today.freeze.freeze end end + + def test_compare_with_infinity + assert_equal(-1, Date.today <=> Float::INFINITY) + assert_equal(1, Date.today <=> -Float::INFINITY) + end end class DateExtConversionsTest < ActiveSupport::TestCase diff --git a/activesupport/test/core_ext/date_time_ext_test.rb b/activesupport/test/core_ext/date_time_ext_test.rb index dfad3a90f8..54bbdbb18f 100644 --- a/activesupport/test/core_ext/date_time_ext_test.rb +++ b/activesupport/test/core_ext/date_time_ext_test.rb @@ -317,3 +317,10 @@ class DateTimeExtCalculationsTest < ActiveSupport::TestCase old_tz ? ENV['TZ'] = old_tz : ENV.delete('TZ') end end + +class DateTimeExtBehaviorTest < ActiveSupport::TestCase + def test_compare_with_infinity + assert_equal(-1, DateTime.now <=> Float::INFINITY) + assert_equal(1, DateTime.now <=> -Float::INFINITY) + end +end diff --git a/activesupport/test/core_ext/numeric_ext_test.rb b/activesupport/test/core_ext/numeric_ext_test.rb index 435f4aa5a1..8c7d00cae1 100644 --- a/activesupport/test/core_ext/numeric_ext_test.rb +++ b/activesupport/test/core_ext/numeric_ext_test.rb @@ -203,7 +203,7 @@ class NumericExtFormattingTest < ActiveSupport::TestCase def terabytes(number) gigabytes(number) * 1024 end - + def test_to_s__phone assert_equal("555-1234", 5551234.to_s(:phone)) assert_equal("800-555-1212", 8005551212.to_s(:phone)) @@ -217,7 +217,7 @@ class NumericExtFormattingTest < ActiveSupport::TestCase assert_equal("22-555-1212", 225551212.to_s(:phone)) assert_equal("+45-22-555-1212", 225551212.to_s(:phone, :country_code => 45)) end - + def test_to_s__currency assert_equal("$1,234,567,890.50", 1234567890.50.to_s(:currency)) assert_equal("$1,234,567,890.51", 1234567890.506.to_s(:currency)) @@ -228,8 +228,8 @@ class NumericExtFormattingTest < ActiveSupport::TestCase assert_equal("$1,234,567,890.5", 1234567890.50.to_s(:currency, :precision => 1)) assert_equal("£1234567890,50", 1234567890.50.to_s(:currency, :unit => "£", :separator => ",", :delimiter => "")) end - - + + def test_to_s__rounded assert_equal("-111.235", -111.2346.to_s(:rounded)) assert_equal("111.235", 111.2346.to_s(:rounded)) @@ -246,7 +246,7 @@ class NumericExtFormattingTest < ActiveSupport::TestCase assert_equal("11.00", 10.995.to_s(:rounded, :precision => 2)) assert_equal("0.00", -0.001.to_s(:rounded, :precision => 2)) end - + def test_to_s__percentage assert_equal("100.000%", 100.to_s(:percentage)) assert_equal("100%", 100.to_s(:percentage, :precision => 0)) @@ -274,7 +274,7 @@ class NumericExtFormattingTest < ActiveSupport::TestCase assert_equal '12.345.678,05', 12345678.05.to_s(:delimited, :separator => ',', :delimiter => '.') assert_equal '12.345.678,05', 12345678.05.to_s(:delimited, :delimiter => '.', :separator => ',') end - + def test_to_s__rounded_with_custom_delimiter_and_separator assert_equal '31,83', 31.825.to_s(:rounded, :precision => 2, :separator => ',') @@ -350,7 +350,7 @@ class NumericExtFormattingTest < ActiveSupport::TestCase assert_equal '1.23 GB', 1234567890.to_s(:human_size, :prefix => :si) assert_equal '1.23 TB', 1234567890123.to_s(:human_size, :prefix => :si) end - + def test_to_s__human_size_with_options_hash assert_equal '1.2 MB', 1234567.to_s(:human_size, :precision => 2) assert_equal '3 Bytes', 3.14159265.to_s(:human_size, :precision => 4) @@ -366,13 +366,13 @@ class NumericExtFormattingTest < ActiveSupport::TestCase assert_equal '1.012 KB', kilobytes(1.0123).to_s(:human_size, :precision => 3, :significant => false) assert_equal '1 KB', kilobytes(1.0123).to_s(:human_size, :precision => 0, :significant => true) #ignores significant it precision is 0 end - + def test_to_s__human_size_with_custom_delimiter_and_separator assert_equal '1,01 KB', kilobytes(1.0123).to_s(:human_size, :precision => 3, :separator => ',') assert_equal '1,01 KB', kilobytes(1.0100).to_s(:human_size, :precision => 4, :separator => ',') assert_equal '1.000,1 TB', terabytes(1000.1).to_s(:human_size, :precision => 5, :delimiter => '.', :separator => ',') end - + def test_number_to_human assert_equal '-123', -123.to_s(:human) assert_equal '-0.5', -0.5.to_s(:human) @@ -436,7 +436,7 @@ class NumericExtFormattingTest < ActiveSupport::TestCase def test_to_s__injected_on_proper_types assert_equal Fixnum, 1230.class assert_equal '1.23 Thousand', 1230.to_s(:human) - + assert_equal Float, Float(1230).class assert_equal '1.23 Thousand', Float(1230).to_s(:human) @@ -447,3 +447,57 @@ class NumericExtFormattingTest < ActiveSupport::TestCase assert_equal '1 Million', BigDecimal("1000010").to_s(:human) end end + +class NumericExtBehaviorTest < ActiveSupport::TestCase + def setup + @inf = BigDecimal.new('Infinity') + end + + def test_compare_infinity_with_date + assert_equal(-1, -Float::INFINITY <=> Date.today) + assert_equal(1, Float::INFINITY <=> Date.today) + assert_equal(-1, -@inf <=> Date.today) + assert_equal(1, @inf <=> Date.today) + end + + def test_compare_infinty_with_infinty + assert_equal(-1, -Float::INFINITY <=> Float::INFINITY) + assert_equal(1, Float::INFINITY <=> -Float::INFINITY) + assert_equal(0, Float::INFINITY <=> Float::INFINITY) + assert_equal(0, -Float::INFINITY <=> -Float::INFINITY) + + assert_equal(-1, -Float::INFINITY <=> BigDecimal::INFINITY) + assert_equal(1, Float::INFINITY <=> -BigDecimal::INFINITY) + assert_equal(0, Float::INFINITY <=> BigDecimal::INFINITY) + assert_equal(0, -Float::INFINITY <=> -BigDecimal::INFINITY) + + assert_equal(-1, -BigDecimal::INFINITY <=> Float::INFINITY) + assert_equal(1, BigDecimal::INFINITY <=> -Float::INFINITY) + assert_equal(0, BigDecimal::INFINITY <=> Float::INFINITY) + assert_equal(0, -BigDecimal::INFINITY <=> -Float::INFINITY) + end + + def test_compare_infinity_with_time + assert_equal(-1, -Float::INFINITY <=> Time.now) + assert_equal(1, Float::INFINITY <=> Time.now) + assert_equal(-1, -@inf <=> Time.now) + assert_equal(1, @inf <=> Time.now) + end + + def test_compare_infinity_with_datetime + assert_equal(-1, -Float::INFINITY <=> DateTime.now) + assert_equal(1, Float::INFINITY <=> DateTime.now) + assert_equal(-1, -@inf <=> DateTime.now) + assert_equal(1, @inf <=> DateTime.now) + end + + def test_compare_infinity_with_twz + time_zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + twz = ActiveSupport::TimeWithZone.new(Time.now, time_zone) + + assert_equal(-1, -Float::INFINITY <=> twz) + assert_equal(1, Float::INFINITY <=> twz) + assert_equal(-1, -@inf <=> twz) + assert_equal(1, @inf <=> twz) + end +end diff --git a/activesupport/test/core_ext/range_ext_test.rb b/activesupport/test/core_ext/range_ext_test.rb index f0cdc0bfd4..0051c48984 100644 --- a/activesupport/test/core_ext/range_ext_test.rb +++ b/activesupport/test/core_ext/range_ext_test.rb @@ -1,6 +1,7 @@ require 'abstract_unit' require 'active_support/time' require 'active_support/core_ext/range' +require 'active_support/core_ext/numeric' class RangeTest < ActiveSupport::TestCase def test_to_s_from_dates @@ -85,4 +86,28 @@ class RangeTest < ActiveSupport::TestCase time_range_2 = Time.utc(2005, 12, 10, 17, 31)..Time.utc(2005, 12, 10, 18, 00) assert !time_range_1.overlaps?(time_range_2) end + + def test_infinite_bounds + time_zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + + time = Time.now + date = Date.today + datetime = DateTime.now + twz = ActiveSupport::TimeWithZone.new(time, time_zone) + + infinity1 = Float::INFINITY + infinity2 = BigDecimal.new('Infinity') + + [infinity1, infinity2].each do |infinity| + [time, date, datetime, twz].each do |bound| + [time, date, datetime, twz].each do |value| + assert Range.new(bound, infinity).include?(value + 10.years) + assert Range.new(-infinity, bound).include?(value - 10.years) + + assert !Range.new(bound, infinity).include?(value - 10.years) + assert !Range.new(-infinity, bound).include?(value + 10.years) + end + end + end + end end diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb index 70e07cefd1..a2fefee3b8 100644 --- a/activesupport/test/core_ext/time_ext_test.rb +++ b/activesupport/test/core_ext/time_ext_test.rb @@ -843,3 +843,10 @@ class TimeExtMarshalingTest < ActiveSupport::TestCase assert_equal Time.local(2004, 2, 29), Time.local(2004, 5, 31).last_quarter end end + +class TimeExtBehaviorTest < ActiveSupport::TestCase + def test_compare_with_infinity + assert_equal(-1, Time.now <=> Float::INFINITY) + assert_equal(1, Time.now <=> -Float::INFINITY) + end +end diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index 56020da035..6c773770f0 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -1081,3 +1081,13 @@ class TimeWithZoneMethodsForString < ActiveSupport::TestCase Time.zone = old_tz end end + +class TimeWithZoneExtBehaviorTest < ActiveSupport::TestCase + def test_compare_with_infinity + time_zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + twz = ActiveSupport::TimeWithZone.new(Time.now, time_zone) + + assert_equal(-1, twz <=> Float::INFINITY) + assert_equal(1, twz <=> -Float::INFINITY) + end +end diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index aa41e57928..a1e5db6a2e 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -361,7 +361,7 @@ class InflectorTest < ActiveSupport::TestCase inflect.singular(/s$/, '') inflect.singular(/es$/, '') - + inflect.irregular('el', 'los') end diff --git a/rails.gemspec b/rails.gemspec index ba94354bf1..128b312424 100644 --- a/rails.gemspec +++ b/rails.gemspec @@ -26,6 +26,6 @@ Gem::Specification.new do |s| s.add_dependency 'actionmailer', version s.add_dependency 'railties', version - s.add_dependency 'bundler', '>= 1.2.2', '< 2.0' + s.add_dependency 'bundler', '>= 1.3.0.pre.4', '< 2.0' s.add_dependency 'sprockets-rails', '~> 2.0.0.rc1' end diff --git a/railties/lib/rails/templates/rails/welcome/index.html.erb b/railties/lib/rails/templates/rails/welcome/index.html.erb index 9a62d206dc..b102561848 100644 --- a/railties/lib/rails/templates/rails/welcome/index.html.erb +++ b/railties/lib/rails/templates/rails/welcome/index.html.erb @@ -173,7 +173,8 @@ </style> <script> function about() { - info = document.getElementById('about-content'); + var info = document.getElementById('about-content'); + var xhr; if (window.XMLHttpRequest) { xhr = new XMLHttpRequest(); } else diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 53109cb041..920798c930 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -407,7 +407,17 @@ module ApplicationTests require "#{app_path}/config/environment" - assert_equal "Wellington", Rails.application.config.time_zone + assert_equal Time.find_zone!("Wellington"), Time.zone_default + end + + test "timezone can be set on initializers" do + app_file "config/initializers/locale.rb", <<-RUBY + Rails.application.config.time_zone = "Central Time (US & Canada)" + RUBY + + require "#{app_path}/config/environment" + + assert_equal Time.find_zone!("Central Time (US & Canada)"), Time.zone_default end test "raises when an invalid timezone is defined in the config" do |