Permalink
Browse files

Ensure that associations have a symbol argument.

Fixes #7418.
  • Loading branch information...
steveklabnik committed Nov 28, 2012
1 parent 3e965e2 commit 22df38ca3306684033039fd0bc20b1025f4f8e2a
@@ -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
@@ -13,6 +13,8 @@ def self.build(*args, &block)
end
def initialize(model, name, scope, options)
+ raise ArgumentError, "association names must be a Symbol" unless name.kind_of?(Symbol)
+
@model = model
@name = name
@@ -289,6 +289,14 @@ def test_has_one_association_redefinition_reflections_should_differ_and_not_inhe
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

3 comments on commit 22df38c

@sobrinho

This comment has been minimized.

Show comment
Hide comment
@sobrinho

sobrinho Nov 28, 2012

Contributor

Just curious, what's the problem with using string here?

Calling String#intern won't make more sense instead of preventing to use a string?

Contributor

sobrinho replied Nov 28, 2012

Just curious, what's the problem with using string here?

Calling String#intern won't make more sense instead of preventing to use a string?

@sobrinho

This comment has been minimized.

Show comment
Hide comment
@sobrinho

sobrinho Nov 28, 2012

Contributor

Forget, discussion on #7418 :)

Contributor

sobrinho replied Nov 28, 2012

Forget, discussion on #7418 :)

@steveklabnik

This comment has been minimized.

Show comment
Hide comment
@steveklabnik

steveklabnik Nov 28, 2012

Member

@jonleighton said this: #7418 (comment)

I just do his bidding. ;)

Member

steveklabnik replied Nov 28, 2012

@jonleighton said this: #7418 (comment)

I just do his bidding. ;)

Please sign in to comment.