diff options
15 files changed, 78 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index fe9f30bd2a..0f32ce7bd4 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -60,7 +60,7 @@ module ActiveRecord end end - relation.uniq.pluck(column) + relation.pluck(column) end end diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb index f3200aa78a..399c22fb18 100644 --- a/activerecord/lib/active_record/attribute_methods.rb +++ b/activerecord/lib/active_record/attribute_methods.rb @@ -36,6 +36,18 @@ module ActiveRecord # Generates all the attribute related methods for columns in the database # accessors, mutators and query methods. def define_attribute_methods + unless defined?(@attribute_methods_mutex) + ActiveSupport::Deprecation.warn( + "It looks like something (probably a gem/plugin) is removing or overriding the " \ + "ActiveRecord::Base.inherited method. It is important that this hook executes so " \ + "that your models are set up correctly. A workaround has been added to stop this " \ + "causing an error in 3.2, but future versions will simply not work if the hook is " \ + "overridden." + ) + + @attribute_methods_mutex = Mutex.new + end + # Use a mutex; we don't want two thread simaltaneously trying to define # attribute methods. @attribute_methods_mutex.synchronize do diff --git a/activerecord/lib/active_record/attribute_methods/write.rb b/activerecord/lib/active_record/attribute_methods/write.rb index fde55b95da..8c6fa90a28 100644 --- a/activerecord/lib/active_record/attribute_methods/write.rb +++ b/activerecord/lib/active_record/attribute_methods/write.rb @@ -28,11 +28,14 @@ module ActiveRecord @attributes_cache.delete(attr_name) column = column_for_attribute(attr_name) - if column || @attributes.has_key?(attr_name) - @attributes[attr_name] = type_cast_attribute_for_write(column, value) - else - raise ActiveModel::MissingAttributeError, "can't write unknown attribute `#{attr_name}'" + unless column || @attributes.has_key?(attr_name) + ActiveSupport::Deprecation.warn( + "You're trying to create an attribute `#{attr_name}'. Writing arbitrary " \ + "attributes on a model is deprecated. Please just use `attr_writer` etc." + ) end + + @attributes[attr_name] = type_cast_attribute_for_write(column, value) end alias_method :raw_write_attribute, :write_attribute diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index 560773ca86..0cc5ee2958 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -505,7 +505,7 @@ module ActiveRecord execute_and_free("SHOW CREATE TABLE #{quote_table_name(table)}", 'SCHEMA') do |result| create_table = each_hash(result).first[:"Create Table"] if create_table.to_s =~ /PRIMARY KEY\s+\((.+)\)/ - keys = $1.split(",").map { |key| key.gsub(/`/, "") } + keys = $1.split(",").map { |key| key.gsub(/[`"]/, "") } keys.length == 1 ? [keys.first, nil] : nil else nil diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index f1a341437f..b1b0768aab 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -1253,6 +1253,10 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert company.clients_using_sql.loaded? end + def test_get_ids_for_ordered_association + assert_equal [companies(:second_client).id, companies(:first_client).id], companies(:first_firm).clients_ordered_by_rating_ids + end + def test_assign_ids_ignoring_blanks firm = Firm.create!(:name => 'Apple') firm.client_ids = [companies(:first_client).id, nil, companies(:second_client).id, ''] diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb index 0fbe1813fb..cdff7ef017 100644 --- a/activerecord/test/cases/attribute_methods_test.rb +++ b/activerecord/test/cases/attribute_methods_test.rb @@ -770,6 +770,23 @@ class AttributeMethodsTest < ActiveRecord::TestCase assert_equal "lol", topic.author_name end + def test_inherited_hook_removed + parent = Class.new(ActiveRecord::Base) + parent.table_name = "posts" + def parent.inherited(k) + end + + klass = Class.new(parent) + assert_deprecated { klass.define_attribute_methods } + end + + def test_setting_new_attributes_deprecated + t = Topic.new + assert_deprecated { t[:foo] = "bar" } + assert_equal "bar", t.foo + assert_equal "bar", t[:foo] + end + private def cached_columns @cached_columns ||= time_related_columns_on_topic.map(&:name) diff --git a/activerecord/test/cases/primary_keys_test.rb b/activerecord/test/cases/primary_keys_test.rb index 0669707baf..bf8aacc363 100644 --- a/activerecord/test/cases/primary_keys_test.rb +++ b/activerecord/test/cases/primary_keys_test.rb @@ -200,3 +200,19 @@ class PrimaryKeyWithNoConnectionTest < ActiveRecord::TestCase assert_equal 'foo', model.primary_key end end + +if current_adapter?(:MysqlAdapter) or current_adapter?(:Mysql2Adapter) + class PrimaryKeyWithAnsiQuotesTest < ActiveRecord::TestCase + self.use_transactional_fixtures = false + + def test_primaery_key_method_with_ansi_quotes + con = ActiveRecord::Base.connection + con.execute("SET SESSION sql_mode='ANSI_QUOTES'") + assert_equal "id", con.primary_key("topics") + ensure + con.reconnect! + end + + end +end + diff --git a/activerecord/test/models/company.rb b/activerecord/test/models/company.rb index fe9c465c81..db82f471d2 100644 --- a/activerecord/test/models/company.rb +++ b/activerecord/test/models/company.rb @@ -45,6 +45,7 @@ class Firm < Company has_many :unsorted_clients_with_symbol, :class_name => :Client has_many :clients_sorted_desc, :class_name => "Client", :order => "id DESC" has_many :clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id" + has_many :clients_ordered_by_rating, :order => "rating", :class_name => "Client" has_many :unvalidated_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :validate => false has_many :dependent_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :destroy has_many :exclusively_dependent_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :delete_all diff --git a/activesupport/lib/active_support/base64.rb b/activesupport/lib/active_support/base64.rb index f0cfdedaa0..da141071fb 100644 --- a/activesupport/lib/active_support/base64.rb +++ b/activesupport/lib/active_support/base64.rb @@ -1,3 +1,5 @@ +require 'active_support/deprecation' + begin require 'base64' rescue LoadError diff --git a/activesupport/lib/active_support/concern.rb b/activesupport/lib/active_support/concern.rb index af3da937c7..97fa2db4a9 100644 --- a/activesupport/lib/active_support/concern.rb +++ b/activesupport/lib/active_support/concern.rb @@ -1,3 +1,5 @@ +require 'active_support/deprecation' + module ActiveSupport # A typical module looks like this: # diff --git a/activesupport/lib/active_support/message_verifier.rb b/activesupport/lib/active_support/message_verifier.rb index be5b7ef79f..0d9580abca 100644 --- a/activesupport/lib/active_support/message_verifier.rb +++ b/activesupport/lib/active_support/message_verifier.rb @@ -1,4 +1,5 @@ require 'active_support/base64' +require 'active_support/deprecation' require 'active_support/core_ext/object/blank' module ActiveSupport diff --git a/activesupport/lib/active_support/tagged_logging.rb b/activesupport/lib/active_support/tagged_logging.rb index d71215b447..6af87e85e6 100644 --- a/activesupport/lib/active_support/tagged_logging.rb +++ b/activesupport/lib/active_support/tagged_logging.rb @@ -33,13 +33,14 @@ module ActiveSupport deprecate :silence def add(severity, message = nil, progname = nil, &block) - @logger.add(severity, "#{tags_text}#{message}", progname, &block) + message = (block_given? ? block.call : progname) if message.nil? + @logger.add(severity, "#{tags_text}#{message}", progname) end %w( fatal error warn info debug unknown ).each do |severity| eval <<-EOM, nil, __FILE__, __LINE__ + 1 def #{severity}(progname = nil, &block) - add(Logger::#{severity.upcase}, progname, &block) + add(Logger::#{severity.upcase}, nil, progname, &block) end EOM end diff --git a/activesupport/lib/active_support/whiny_nil.rb b/activesupport/lib/active_support/whiny_nil.rb index a065233679..adf9a35ee6 100644 --- a/activesupport/lib/active_support/whiny_nil.rb +++ b/activesupport/lib/active_support/whiny_nil.rb @@ -1,3 +1,5 @@ +require 'active_support/deprecation' + # Extensions to +nil+ which allow for more helpful error messages for people who # are new to Rails. # diff --git a/activesupport/test/tagged_logging_test.rb b/activesupport/test/tagged_logging_test.rb index 7ecab33a9a..c838c073e6 100644 --- a/activesupport/test/tagged_logging_test.rb +++ b/activesupport/test/tagged_logging_test.rb @@ -70,4 +70,12 @@ class TaggedLoggingTest < ActiveSupport::TestCase assert_nothing_raised { @logger.silence {} } end end + + test "calls block" do + @logger.tagged("BCX") do + @logger.info { "Funky town" } + end + assert_equal "[BCX] Funky town\n", @output.string + end + end diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index 83a442c94e..ad87d8b6ac 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -64,7 +64,7 @@ module ApplicationTests files << Dir["#{app_path}/public/assets/foo/application.js"].first files.each do |file| assert_not_nil file, "Expected application.js asset to be generated, but none found" - assert_equal "alert()", File.read(file) + assert_equal "alert();", File.read(file) end end |