aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Klabnik <steve@steveklabnik.com>2012-11-28 12:43:09 -0800
committerSteve Klabnik <steve@steveklabnik.com>2012-11-28 13:39:42 -0800
commit22df38ca3306684033039fd0bc20b1025f4f8e2a (patch)
tree19da0cd01bd200374bcc491293dcdb6a1015b20a
parent3e965e2144d515499c3c94de7973cf0bd84649e2 (diff)
downloadrails-22df38ca3306684033039fd0bc20b1025f4f8e2a.tar.gz
rails-22df38ca3306684033039fd0bc20b1025f4f8e2a.tar.bz2
rails-22df38ca3306684033039fd0bc20b1025f4f8e2a.zip
Ensure that associations have a symbol argument.
Fixes #7418.
-rw-r--r--activerecord/CHANGELOG.md2
-rw-r--r--activerecord/lib/active_record/associations/builder/association.rb2
-rw-r--r--activerecord/test/cases/associations_test.rb8
3 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index ee99e86157..23e38c55d2 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,5 +1,7 @@
## Rails 4.0.0 (unreleased) ##
+* Ensure that associations take a symbol argument. *Steve Klabnik*
+
* Fix dirty attribute checks for `TimeZoneConversion` with nil and blank
datetime attributes. Setting a nil datetime to a blank string should not
result in a change being flagged. Fix #8310
diff --git a/activerecord/lib/active_record/associations/builder/association.rb b/activerecord/lib/active_record/associations/builder/association.rb
index 1df876bf62..5c37f42794 100644
--- a/activerecord/lib/active_record/associations/builder/association.rb
+++ b/activerecord/lib/active_record/associations/builder/association.rb
@@ -13,6 +13,8 @@ module ActiveRecord::Associations::Builder
end
def initialize(model, name, scope, options)
+ raise ArgumentError, "association names must be a Symbol" unless name.kind_of?(Symbol)
+
@model = model
@name = name
diff --git a/activerecord/test/cases/associations_test.rb b/activerecord/test/cases/associations_test.rb
index c0f1945cec..d7f25f760e 100644
--- a/activerecord/test/cases/associations_test.rb
+++ b/activerecord/test/cases/associations_test.rb
@@ -289,6 +289,14 @@ class OverridingAssociationsTest < ActiveRecord::TestCase
DifferentPeopleList.reflect_on_association(:has_one)
)
end
+
+ def test_requires_symbol_argument
+ assert_raises ArgumentError do
+ Class.new(Post) do
+ belongs_to "author"
+ end
+ end
+ end
end
class GeneratedMethodsTest < ActiveRecord::TestCase