diff options
19 files changed, 104 insertions, 61 deletions
@@ -51,7 +51,7 @@ platforms :ruby do group :db do gem 'pg', '>= 0.11.0' - gem 'mysql', '>= 2.8.1' + gem 'mysql', '>= 2.9.0' gem 'mysql2', '>= 0.3.10' end end diff --git a/actionmailer/actionmailer.gemspec b/actionmailer/actionmailer.gemspec index 0177a13e50..e9f979f34b 100644 --- a/actionmailer/actionmailer.gemspec +++ b/actionmailer/actionmailer.gemspec @@ -21,5 +21,5 @@ Gem::Specification.new do |s| s.add_dependency 'actionpack', version - s.add_dependency 'mail', '~> 2.4.4' + s.add_dependency 'mail', '~> 2.5.2' end diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb index cfbe2f1cbd..a9642dc695 100644 --- a/actionmailer/lib/action_mailer.rb +++ b/actionmailer/lib/action_mailer.rb @@ -44,4 +44,5 @@ module ActionMailer autoload :MailHelper autoload :TestCase autoload :TestHelper + autoload :QueuedMessage end diff --git a/activemodel/lib/active_model/deprecated_mass_assignment_security.rb b/activemodel/lib/active_model/deprecated_mass_assignment_security.rb index 2ea69991fc..1f409c87b9 100644 --- a/activemodel/lib/active_model/deprecated_mass_assignment_security.rb +++ b/activemodel/lib/active_model/deprecated_mass_assignment_security.rb @@ -5,14 +5,16 @@ module ActiveModel module ClassMethods # :nodoc: def attr_protected(*args) raise "`attr_protected` is extracted out of Rails into a gem. " \ - "Please use new recommended protection model for params " \ - "or add `protected_attributes` to your Gemfile to use old one." + "Please use new recommended protection model for params" \ + "(strong_parameters) or add `protected_attributes` to your " \ + "Gemfile to use old one." end def attr_accessible(*args) raise "`attr_accessible` is extracted out of Rails into a gem. " \ - "Please use new recommended protection model for params " \ - "or add `protected_attributes` to your Gemfile to use old one." + "Please use new recommended protection model for params" \ + "(strong_parameters) or add `protected_attributes` to your " \ + "Gemfile to use old one." end end end diff --git a/activemodel/lib/active_model/secure_password.rb b/activemodel/lib/active_model/secure_password.rb index 081a49f749..6644b60609 100644 --- a/activemodel/lib/active_model/secure_password.rb +++ b/activemodel/lib/active_model/secure_password.rb @@ -3,6 +3,7 @@ module ActiveModel extend ActiveSupport::Concern class << self; attr_accessor :min_cost; end + self.min_cost = false module ClassMethods # Adds methods to set and authenticate against a BCrypt password. @@ -13,8 +14,8 @@ module ActiveModel # you wish to turn off validations, pass <tt>validations: false</tt> as an # argument. You can add more validations by hand if need be. # - # If you don't need the confirmation validation, just don't set any - # value to the password_confirmation attribute and the the validation + # If you don't need the confirmation validation, just don't set any + # value to the password_confirmation attribute and the the validation # will not be triggered. # # You need to add bcrypt-ruby (~> 3.0.0) to Gemfile to use #has_secure_password: diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 8078974b43..082e3d1089 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,12 +1,20 @@ ## Rails 4.0.0 (unreleased) ## -* Don't change STI type when calling ActiveRecord::Base#becomes, add - ActiveRecord::Base#becomes! +* Don't change STI type when calling `ActiveRecord::Base#becomes`. + Add `ActiveRecord::Base#becomes!` with the previous behavior. - See #3023. + See #3023 for more information. *Thomas Hollstegge* +* `rename_index` can be used inside a `change_table` block. + + change_table :accounts do |t| + t.rename_index :user_id, :account_id + end + + *Jarek Radosz* + * `#pluck` can be used on a relation with `select` clause. Fix #7551 Example: diff --git a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb index 806dc5b1d2..427c61079a 100644 --- a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb +++ b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb @@ -64,8 +64,7 @@ module ActiveRecord private def round_usec(value) - return unless value - value.change(:usec => 0) + value.change(usec: 0) if value end end end diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb index 38960ab873..7ec6abbc45 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb @@ -324,6 +324,7 @@ module ActiveRecord # change_table :table do |t| # t.column # t.index + # t.rename_index # t.timestamps # t.change # t.change_default @@ -386,6 +387,13 @@ module ActiveRecord @base.index_exists?(@table_name, column_name, options) end + # Renames the given index on the table. + # + # t.rename_index(:user_id, :account_id) + def rename_index(index_name, new_index_name) + @base.rename_index(@table_name, index_name, new_index_name) + end + # Adds timestamps (+created_at+ and +updated_at+) columns to the table. See SchemaStatements#add_timestamps # # t.timestamps diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb index 76667616a1..9627aaae3a 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb @@ -2,7 +2,7 @@ require 'active_record/connection_adapters/abstract_mysql_adapter' require 'active_record/connection_adapters/statement_pool' require 'active_support/core_ext/hash/keys' -gem 'mysql', '~> 2.8.1' +gem 'mysql', '~> 2.9.0' require 'mysql' class Mysql diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index c8edadf804..741f94f777 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -1,5 +1,3 @@ -require 'active_support/core_ext/object/try' - module ActiveRecord module Calculations # Count the records. diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb index 8b82b79219..c503c21e27 100644 --- a/activerecord/test/cases/attribute_methods_test.rb +++ b/activerecord/test/cases/attribute_methods_test.rb @@ -12,6 +12,8 @@ require 'models/contact' require 'models/keyboard' class AttributeMethodsTest < ActiveRecord::TestCase + include InTimeZone + fixtures :topics, :developers, :companies, :computers def setup @@ -311,26 +313,17 @@ class AttributeMethodsTest < ActiveRecord::TestCase def test_read_write_boolean_attribute topic = Topic.new - # puts "" - # puts "New Topic" - # puts topic.inspect topic.approved = "false" - # puts "Expecting false" - # puts topic.inspect assert !topic.approved?, "approved should be false" + topic.approved = "false" - # puts "Expecting false" - # puts topic.inspect assert !topic.approved?, "approved should be false" + topic.approved = "true" - # puts "Expecting true" - # puts topic.inspect assert topic.approved?, "approved should be true" + topic.approved = "true" - # puts "Expecting true" - # puts topic.inspect assert topic.approved?, "approved should be true" - # puts "" end def test_overridden_write_attribute @@ -793,27 +786,13 @@ class AttributeMethodsTest < ActiveRecord::TestCase private def cached_columns - Topic.columns.find_all { |column| - !Topic.serialized_attributes.include? column.name - }.map(&:name) + Topic.columns.map(&:name) - Topic.serialized_attributes.keys end def time_related_columns_on_topic Topic.columns.select { |c| [:time, :date, :datetime, :timestamp].include?(c.type) } end - def in_time_zone(zone) - old_zone = Time.zone - old_tz = ActiveRecord::Base.time_zone_aware_attributes - - Time.zone = zone ? ActiveSupport::TimeZone[zone] : nil - ActiveRecord::Base.time_zone_aware_attributes = !zone.nil? - yield - ensure - Time.zone = old_zone - ActiveRecord::Base.time_zone_aware_attributes = old_tz - end - def privatize(method_signature) @target.class_eval(<<-private_method, __FILE__, __LINE__ + 1) private diff --git a/activerecord/test/cases/dirty_test.rb b/activerecord/test/cases/dirty_test.rb index 40f1dbccde..d4fc5f204b 100644 --- a/activerecord/test/cases/dirty_test.rb +++ b/activerecord/test/cases/dirty_test.rb @@ -27,6 +27,8 @@ class NumericData < ActiveRecord::Base end class DirtyTest < ActiveRecord::TestCase + include InTimeZone + # Dummy to force column loads so query counts are clean. def setup Person.create :first_name => 'foo' @@ -121,7 +123,6 @@ class DirtyTest < ActiveRecord::TestCase end def test_time_attributes_changes_without_time_zone - target = Class.new(ActiveRecord::Base) target.table_name = 'pirates' @@ -604,16 +605,4 @@ class DirtyTest < ActiveRecord::TestCase assert_equal %w(parrot_id), pirate.changed assert_nil pirate.parrot_id_was end - - def in_time_zone(zone) - old_zone = Time.zone - old_tz = ActiveRecord::Base.time_zone_aware_attributes - - Time.zone = zone ? ActiveSupport::TimeZone[zone] : nil - ActiveRecord::Base.time_zone_aware_attributes = !zone.nil? - yield - ensure - Time.zone = old_zone - ActiveRecord::Base.time_zone_aware_attributes = old_tz - end end diff --git a/activerecord/test/cases/helper.rb b/activerecord/test/cases/helper.rb index cff6689c15..1bff005510 100644 --- a/activerecord/test/cases/helper.rb +++ b/activerecord/test/cases/helper.rb @@ -135,3 +135,18 @@ module LogIntercepter end end +module InTimeZone + private + + def in_time_zone(zone) + old_zone = Time.zone + old_tz = ActiveRecord::Base.time_zone_aware_attributes + + Time.zone = zone ? ActiveSupport::TimeZone[zone] : nil + ActiveRecord::Base.time_zone_aware_attributes = !zone.nil? + yield + ensure + Time.zone = old_zone + ActiveRecord::Base.time_zone_aware_attributes = old_tz + end +end diff --git a/activerecord/test/cases/migration/change_table_test.rb b/activerecord/test/cases/migration/change_table_test.rb index 4614be9650..8fb03cdee0 100644 --- a/activerecord/test/cases/migration/change_table_test.rb +++ b/activerecord/test/cases/migration/change_table_test.rb @@ -164,6 +164,13 @@ module ActiveRecord end end + def test_rename_index_renames_index + with_change_table do |t| + @connection.expect :rename_index, nil, [:delete_me, :bar, :baz] + t.rename_index :bar, :baz + end + end + def test_change_changes_column with_change_table do |t| @connection.expect :change_column, nil, [:delete_me, :bar, :string, {}] diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index bc6cac0c6c..c34aeaf925 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -157,19 +157,19 @@ class RelationTest < ActiveRecord::TestCase assert_equal 4, topics.to_a.size assert_equal topics(:first).title, topics.first.title end - + def test_finding_with_assoc_order topics = Topic.order(:id => :desc) assert_equal 4, topics.to_a.size assert_equal topics(:fourth).title, topics.first.title end - + def test_finding_with_reverted_assoc_order topics = Topic.order(:id => :asc).reverse_order assert_equal 4, topics.to_a.size assert_equal topics(:fourth).title, topics.first.title end - + def test_raising_exception_on_invalid_hash_params assert_raise(ArgumentError) { Topic.order(:name, "id DESC", :id => :DeSc) } end @@ -1438,4 +1438,18 @@ class RelationTest < ActiveRecord::TestCase end assert_no_queries { relation.to_a } end + + test 'group with select and includes' do + authors_count = Post.select('author_id, COUNT(author_id) AS num_posts'). + group('author_id').order('author_id').includes(:author).to_a + + assert_no_queries do + result = authors_count.map do |post| + [post.num_posts, post.author.try(:name)] + end + + expected = [[1, nil], [5, "David"], [3, "Mary"], [2, "Bob"]] + assert_equal expected, result + end + end end diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index b55a706b2f..504ebcb2fe 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,5 +1,7 @@ ## Rails 4.0.0 (unreleased) ## +* Deprecate `ActiveSupport::TestCase#pending` method, use `skip` from MiniTest instead. *Carlos Antonio da Silva* + * `XmlMini.with_backend` now may be safely used with threads: Thread.new do @@ -270,8 +272,6 @@ * Add html_escape_once to ERB::Util, and delegate escape_once tag helper to it. *Carlos Antonio da Silva* -* Remove ActiveSupport::TestCase#pending method, use `skip` instead. *Carlos Antonio da Silva* - * Deprecates the compatibility method Module#local_constant_names, use Module#local_constants instead (which returns symbols). *fxn* diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb index c96ad17aba..ee7bda9f93 100644 --- a/activesupport/lib/active_support/test_case.rb +++ b/activesupport/lib/active_support/test_case.rb @@ -4,6 +4,7 @@ require 'active_support/testing/tagged_logging' require 'active_support/testing/setup_and_teardown' require 'active_support/testing/assertions' require 'active_support/testing/deprecation' +require 'active_support/testing/pending' require 'active_support/testing/isolation' require 'active_support/testing/constant_lookup' require 'active_support/core_ext/kernel/reporting' @@ -40,6 +41,7 @@ module ActiveSupport include ActiveSupport::Testing::SetupAndTeardown include ActiveSupport::Testing::Assertions include ActiveSupport::Testing::Deprecation + include ActiveSupport::Testing::Pending def self.describe(text) if block_given? diff --git a/activesupport/lib/active_support/testing/pending.rb b/activesupport/lib/active_support/testing/pending.rb new file mode 100644 index 0000000000..944806bb64 --- /dev/null +++ b/activesupport/lib/active_support/testing/pending.rb @@ -0,0 +1,14 @@ +require 'active_support/deprecation' + +module ActiveSupport + module Testing + module Pending + unless defined?(Spec) + def pending(description = "", &block) + ActiveSupport::Deprecation.warn("#pending is deprecated and will be removed in Rails 4.1, please use #skip instead.") + skip(description.blank? ? nil : description) + end + end + end + end +end diff --git a/activesupport/test/test_case_test.rb b/activesupport/test/test_case_test.rb index 64426d02e9..dfe9f3c11c 100644 --- a/activesupport/test/test_case_test.rb +++ b/activesupport/test/test_case_test.rb @@ -108,5 +108,11 @@ module ActiveSupport test = tc.new test_name assert_raises(Interrupt) { test.run fr } end + + def test_pending_deprecation + assert_deprecated do + pending "should use #skip instead" + end + end end end |