Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Remove deprecated support to passing a class to :class_name on asso…
…ciations
  • Loading branch information
rafaelfranca committed Oct 23, 2017
1 parent 8f5b34d commit e65aff7
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 25 deletions.
4 changes: 4 additions & 0 deletions activerecord/CHANGELOG.md
@@ -1,3 +1,7 @@
* Remove deprecated support to passing a class to `:class_name` on associations.

*Rafael Mendonça França*

* Remove deprecated argument `default` from `index_name_exists?`.

*Rafael Mendonça França*
Expand Down
4 changes: 2 additions & 2 deletions activerecord/lib/active_record/associations.rb
Expand Up @@ -1848,7 +1848,7 @@ def has_and_belongs_to_many(name, scope = nil, **options, &extension)

builder = Builder::HasAndBelongsToMany.new name, self, options

join_model = ActiveSupport::Deprecation.silence { builder.through_model }
join_model = builder.through_model

const_set join_model.name, join_model
private_constant join_model.name
Expand Down Expand Up @@ -1877,7 +1877,7 @@ def destroy_associations
hm_options[k] = options[k] if options.key? k
end

ActiveSupport::Deprecation.silence { has_many name, scope, hm_options, &extension }
has_many name, scope, hm_options, &extension
_reflections[name.to_s].parent_reflection = habtm_reflection
end
end
Expand Down
9 changes: 1 addition & 8 deletions activerecord/lib/active_record/reflection.rb
Expand Up @@ -431,14 +431,7 @@ def initialize(name, scope, options, active_record)
@association_scope_cache = Concurrent::Map.new

if options[:class_name] && options[:class_name].class == Class
ActiveSupport::Deprecation.warn(<<-MSG.squish)
Passing a class to the `class_name` is deprecated and will raise
an ArgumentError in Rails 5.2. It eagerloads more classes than
necessary and potentially creates circular dependencies.
Please pass the class name as a string:
`#{macro} :#{name}, class_name: '#{options[:class_name]}'`
MSG
raise ArgumentError, "A class was passed to `:class_name` but we are expecting a string."
end
end

Expand Down
Expand Up @@ -88,12 +88,6 @@ class DeveloperWithSymbolClassName < Developer
has_and_belongs_to_many :projects, class_name: :ProjectWithSymbolsForKeys
end

ActiveSupport::Deprecation.silence do
class DeveloperWithConstantClassName < Developer
has_and_belongs_to_many :projects, class_name: ProjectWithSymbolsForKeys
end
end

class DeveloperWithExtendOption < Developer
module NamedExtension
def category
Expand Down Expand Up @@ -954,13 +948,6 @@ def test_with_symbol_class_name
end
end

def test_with_constant_class_name
assert_nothing_raised do
developer = DeveloperWithConstantClassName.new
developer.projects
end
end

def test_alternate_database
professor = Professor.create(name: "Plum")
course = Course.create(name: "Forensics")
Expand Down
5 changes: 3 additions & 2 deletions activerecord/test/cases/reflection_test.rb
Expand Up @@ -432,9 +432,10 @@ def test_symbol_for_class_name
end

def test_class_for_class_name
assert_deprecated do
assert_predicate ActiveRecord::Reflection.create(:has_many, :clients, nil, { class_name: Client }, Firm), :validate?
error = assert_raises(ArgumentError) do
ActiveRecord::Reflection.create(:has_many, :clients, nil, { class_name: Client }, Firm)
end
assert_equal "A class was passed to `:class_name` but we are expecting a string.", error.message
end

def test_join_table
Expand Down

0 comments on commit e65aff7

Please sign in to comment.