Skip to content

Commit 73e3b4c

Browse files
wangjohnrafaelfranca
authored andcommitted
Class.new in AR test subclass ApplicationRecord
Before they were subclassing ActiveRecord::Base. With the introduction of ApplicationRecord, these tests should actually be subclassing ApplicationRecord.
1 parent 7f3205a commit 73e3b4c

20 files changed

+48
-48
lines changed

activerecord/test/cases/adapters/mysql/schema_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def setup
1313
table = Post.table_name
1414
@db_name = db
1515

16-
@omgpost = Class.new(ActiveRecord::Base) do
16+
@omgpost = Class.new(ApplicationRecord) do
1717
self.table_name = "#{db}.#{table}"
1818
def self.name; 'Post'; end
1919
end

activerecord/test/cases/adapters/mysql2/schema_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def setup
1313
table = Post.table_name
1414
@db_name = db
1515

16-
@omgpost = Class.new(ActiveRecord::Base) do
16+
@omgpost = Class.new(ApplicationRecord) do
1717
self.table_name = "#{db}.#{table}"
1818
def self.name; 'Post'; end
1919
end

activerecord/test/cases/associations/has_many_associations_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ def test_sti_subselect_count
110110
end
111111

112112
def test_anonymous_has_many
113-
developer = Class.new(ActiveRecord::Base) {
113+
developer = Class.new(ApplicationRecord) {
114114
self.table_name = 'developers'
115115
dev = self
116116

117-
developer_project = Class.new(ActiveRecord::Base) {
117+
developer_project = Class.new(ApplicationRecord) {
118118
self.table_name = 'developers_projects'
119119
belongs_to :developer, :class => dev
120120
}

activerecord/test/cases/associations/has_many_through_associations_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def test_preload_sti_middle_relation
6060
end
6161

6262
def make_model(name)
63-
Class.new(ActiveRecord::Base) { define_singleton_method(:name) { name } }
63+
Class.new(ApplicationRecord) { define_singleton_method(:name) { name } }
6464
end
6565

6666
def test_ordered_habtm

activerecord/test/cases/associations/inverse_associations_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,15 @@ def test_polymorphic_relationships_should_still_not_have_inverses_when_non_polym
128128
class InverseAssociationTests < ActiveRecord::TestCase
129129
def test_should_allow_for_inverse_of_options_in_associations
130130
assert_nothing_raised(ArgumentError, 'ActiveRecord should allow the inverse_of options on has_many') do
131-
Class.new(ActiveRecord::Base).has_many(:wheels, :inverse_of => :car)
131+
Class.new(ApplicationRecord).has_many(:wheels, :inverse_of => :car)
132132
end
133133

134134
assert_nothing_raised(ArgumentError, 'ActiveRecord should allow the inverse_of options on has_one') do
135-
Class.new(ActiveRecord::Base).has_one(:engine, :inverse_of => :car)
135+
Class.new(ApplicationRecord).has_one(:engine, :inverse_of => :car)
136136
end
137137

138138
assert_nothing_raised(ArgumentError, 'ActiveRecord should allow the inverse_of options on belongs_to') do
139-
Class.new(ActiveRecord::Base).belongs_to(:car, :inverse_of => :driver)
139+
Class.new(ApplicationRecord).belongs_to(:car, :inverse_of => :driver)
140140
end
141141
end
142142

activerecord/test/cases/associations/join_model_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ def test_has_many_with_pluralize_table_names_false
743743
def find_post_with_dependency(post_id, association, association_name, dependency)
744744
class_name = "PostWith#{association.to_s.classify}#{dependency.to_s.classify}"
745745
Post.find(post_id).update_columns type: class_name
746-
klass = Object.const_set(class_name, Class.new(ActiveRecord::Base))
746+
klass = Object.const_set(class_name, Class.new(ApplicationRecord))
747747
klass.table_name = 'posts'
748748
klass.send(association, association_name, :as => :taggable, :dependent => dependency)
749749
klass.find(post_id)

activerecord/test/cases/associations_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def test_include_with_order_works
9090

9191
def test_bad_collection_keys
9292
assert_raise(ArgumentError, 'ActiveRecord should have barked on bad collection keys') do
93-
Class.new(ActiveRecord::Base).has_many(:wheels, :name => 'wheels')
93+
Class.new(ApplicationRecord).has_many(:wheels, :name => 'wheels')
9494
end
9595
end
9696

activerecord/test/cases/attribute_methods_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
1919

2020
def setup
2121
@old_matchers = ActiveRecord::Base.send(:attribute_method_matchers).dup
22-
@target = Class.new(ActiveRecord::Base)
22+
@target = Class.new(ApplicationRecord)
2323
@target.table_name = 'topics'
2424
end
2525

@@ -523,7 +523,7 @@ def test_typecast_attribute_from_select_to_true
523523

524524
def test_raises_dangerous_attribute_error_when_defining_activerecord_method_in_model
525525
%w(save create_or_update).each do |method|
526-
klass = Class.new ActiveRecord::Base
526+
klass = Class.new ApplicationRecord
527527
klass.class_eval "def #{method}() 'defined #{method}' end"
528528
assert_raise ActiveRecord::DangerousAttributeError do
529529
klass.instance_method_already_implemented?(method)

activerecord/test/cases/base_test.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ def test_set_table_name_symbol_converted_to_string
10561056
end
10571057

10581058
def test_quoted_table_name_after_set_table_name
1059-
klass = Class.new(ActiveRecord::Base)
1059+
klass = Class.new(ApplicationRecord)
10601060

10611061
klass.table_name = "foo"
10621062
assert_equal "foo", klass.table_name
@@ -1068,14 +1068,14 @@ def test_quoted_table_name_after_set_table_name
10681068
end
10691069

10701070
def test_set_table_name_with_inheritance
1071-
k = Class.new( ActiveRecord::Base )
1071+
k = Class.new(ApplicationRecord)
10721072
def k.name; "Foo"; end
10731073
def k.table_name; super + "ks"; end
10741074
assert_equal "foosks", k.table_name
10751075
end
10761076

10771077
def test_sequence_name_with_abstract_class
1078-
ak = Class.new(ActiveRecord::Base)
1078+
ak = Class.new(ApplicationRecord)
10791079
ak.abstract_class = true
10801080
k = Class.new(ak)
10811081
k.table_name = "projects"
@@ -1303,7 +1303,7 @@ def test_clear_cache!
13031303
end
13041304

13051305
def test_current_scope_is_reset
1306-
Object.const_set :UnloadablePost, Class.new(ActiveRecord::Base)
1306+
Object.const_set :UnloadablePost, Class.new(ApplicationRecord)
13071307
UnloadablePost.send(:current_scope=, UnloadablePost.all)
13081308

13091309
UnloadablePost.unloadable
@@ -1457,12 +1457,12 @@ def test_default_values_are_deeply_dupped
14571457
end
14581458

14591459
test "scoped can take a values hash" do
1460-
klass = Class.new(ActiveRecord::Base)
1460+
klass = Class.new(ApplicationRecord)
14611461
assert_equal ['foo'], klass.all.merge!(select: 'foo').select_values
14621462
end
14631463

14641464
test "connection_handler can be overridden" do
1465-
klass = Class.new(ActiveRecord::Base)
1465+
klass = Class.new(ApplicationRecord)
14661466
orig_handler = klass.connection_handler
14671467
new_handler = ActiveRecord::ConnectionAdapters::ConnectionHandler.new
14681468
thread_connection_handler = nil
@@ -1478,7 +1478,7 @@ def test_default_values_are_deeply_dupped
14781478
end
14791479

14801480
test "new threads get default the default connection handler" do
1481-
klass = Class.new(ActiveRecord::Base)
1481+
klass = Class.new(ApplicationRecord)
14821482
orig_handler = klass.connection_handler
14831483
handler = nil
14841484

@@ -1493,7 +1493,7 @@ def test_default_values_are_deeply_dupped
14931493
end
14941494

14951495
test "changing a connection handler in a main thread does not poison the other threads" do
1496-
klass = Class.new(ActiveRecord::Base)
1496+
klass = Class.new(ApplicationRecord)
14971497
orig_handler = klass.connection_handler
14981498
new_handler = ActiveRecord::ConnectionAdapters::ConnectionHandler.new
14991499
after_handler = nil

activerecord/test/cases/connection_pool_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ def test_pool_sets_connection_visitor
334334
# make sure exceptions are thrown when establish_connection
335335
# is called with an anonymous class
336336
def test_anonymous_class_exception
337-
anonymous = Class.new(ActiveRecord::Base)
337+
anonymous = Class.new(ApplicationRecord)
338338
handler = ActiveRecord::Base.connection_handler
339339

340340
assert_raises(RuntimeError) {

0 commit comments

Comments
 (0)