Skip to content

Commit cc5cea2

Browse files
committed
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 dfb5540 commit cc5cea2

20 files changed

+56
-56
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
@@ -46,11 +46,11 @@ def setup
4646
end
4747

4848
def test_anonymous_has_many
49-
developer = Class.new(ActiveRecord::Base) {
49+
developer = Class.new(ApplicationRecord) {
5050
self.table_name = 'developers'
5151
dev = self
5252

53-
developer_project = Class.new(ActiveRecord::Base) {
53+
developer_project = Class.new(ApplicationRecord) {
5454
self.table_name = 'developers_projects'
5555
belongs_to :developer, :class => dev
5656
}

activerecord/test/cases/associations/has_many_through_associations_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def setup
3838
end
3939

4040
def make_model(name)
41-
Class.new(ActiveRecord::Base) { define_singleton_method(:name) { name } }
41+
Class.new(ApplicationRecord) { define_singleton_method(:name) { name } }
4242
end
4343

4444
def test_singleton_has_many_through

activerecord/test/cases/associations/inverse_associations_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,15 @@ def test_polymorphic_and_has_many_through_relationships_should_not_have_inverses
105105
class InverseAssociationTests < ActiveRecord::TestCase
106106
def test_should_allow_for_inverse_of_options_in_associations
107107
assert_nothing_raised(ArgumentError, 'ActiveRecord should allow the inverse_of options on has_many') do
108-
Class.new(ActiveRecord::Base).has_many(:wheels, :inverse_of => :car)
108+
Class.new(ApplicationRecord).has_many(:wheels, :inverse_of => :car)
109109
end
110110

111111
assert_nothing_raised(ArgumentError, 'ActiveRecord should allow the inverse_of options on has_one') do
112-
Class.new(ActiveRecord::Base).has_one(:engine, :inverse_of => :car)
112+
Class.new(ApplicationRecord).has_one(:engine, :inverse_of => :car)
113113
end
114114

115115
assert_nothing_raised(ArgumentError, 'ActiveRecord should allow the inverse_of options on belongs_to') do
116-
Class.new(ActiveRecord::Base).belongs_to(:car, :inverse_of => :driver)
116+
Class.new(ApplicationRecord).belongs_to(:car, :inverse_of => :driver)
117117
end
118118
end
119119

activerecord/test/cases/associations/join_model_test.rb

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

activerecord/test/cases/associations_test.rb

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

8383
def test_bad_collection_keys
8484
assert_raise(ArgumentError, 'ActiveRecord should have barked on bad collection keys') do
85-
Class.new(ActiveRecord::Base).has_many(:wheels, :name => 'wheels')
85+
Class.new(ApplicationRecord).has_many(:wheels, :name => 'wheels')
8686
end
8787
end
8888

activerecord/test/cases/attribute_methods_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
1818

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

@@ -507,7 +507,7 @@ def test_typecast_attribute_from_select_to_true
507507

508508
def test_raises_dangerous_attribute_error_when_defining_activerecord_method_in_model
509509
%w(save create_or_update).each do |method|
510-
klass = Class.new ActiveRecord::Base
510+
klass = Class.new ApplicationRecord
511511
klass.class_eval "def #{method}() 'defined #{method}' end"
512512
assert_raise ActiveRecord::DangerousAttributeError do
513513
klass.instance_method_already_implemented?(method)
@@ -767,7 +767,7 @@ def test_read_attribute_with_nil_should_not_asplode
767767
# that by defining a 'foo' method in the generated methods module for B.
768768
# (That module will be inserted between the two, e.g. [B, <GeneratedAttributes>, A].)
769769
def test_inherited_custom_accessors
770-
klass = Class.new(ActiveRecord::Base) do
770+
klass = Class.new(ApplicationRecord) do
771771
self.table_name = "topics"
772772
self.abstract_class = true
773773
def title; "omg"; end

activerecord/test/cases/base_test.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,7 @@ def test_set_table_name_symbol_converted_to_string
10641064
end
10651065

10661066
def test_quoted_table_name_after_set_table_name
1067-
klass = Class.new(ActiveRecord::Base)
1067+
klass = Class.new(ApplicationRecord)
10681068

10691069
klass.table_name = "foo"
10701070
assert_equal "foo", klass.table_name
@@ -1076,14 +1076,14 @@ def test_quoted_table_name_after_set_table_name
10761076
end
10771077

10781078
def test_set_table_name_with_inheritance
1079-
k = Class.new( ActiveRecord::Base )
1079+
k = Class.new(ApplicationRecord)
10801080
def k.name; "Foo"; end
10811081
def k.table_name; super + "ks"; end
10821082
assert_equal "foosks", k.table_name
10831083
end
10841084

10851085
def test_sequence_name_with_abstract_class
1086-
ak = Class.new(ActiveRecord::Base)
1086+
ak = Class.new(ApplicationRecord)
10871087
ak.abstract_class = true
10881088
k = Class.new(ak)
10891089
k.table_name = "projects"
@@ -1288,7 +1288,7 @@ def test_clear_cache!
12881288
end
12891289

12901290
def test_current_scope_is_reset
1291-
Object.const_set :UnloadablePost, Class.new(ActiveRecord::Base)
1291+
Object.const_set :UnloadablePost, Class.new(ApplicationRecord)
12921292
UnloadablePost.send(:current_scope=, UnloadablePost.all)
12931293

12941294
UnloadablePost.unloadable
@@ -1332,7 +1332,7 @@ def test_marshal_between_processes
13321332
flunk "there should be no post constant"
13331333
end
13341334

1335-
self.class.const_set("Post", Class.new(ActiveRecord::Base) {
1335+
self.class.const_set("Post", Class.new(ApplicationRecord) {
13361336
has_many :comments
13371337
})
13381338

@@ -1447,20 +1447,20 @@ def test_default_values_are_deeply_dupped
14471447
scope = mock
14481448
scope.expects(meth).with(:foo, :bar).returns(record)
14491449

1450-
klass = Class.new(ActiveRecord::Base)
1450+
klass = Class.new(ApplicationRecord)
14511451
klass.stubs(:all => scope)
14521452

14531453
assert_equal record, klass.public_send(meth, :foo, :bar)
14541454
end
14551455
end
14561456

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

14621462
test "connection_handler can be overridden" do
1463-
klass = Class.new(ActiveRecord::Base)
1463+
klass = Class.new(ApplicationRecord)
14641464
orig_handler = klass.connection_handler
14651465
new_handler = ActiveRecord::ConnectionAdapters::ConnectionHandler.new
14661466
thread_connection_handler = nil
@@ -1476,7 +1476,7 @@ def test_default_values_are_deeply_dupped
14761476
end
14771477

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

@@ -1491,7 +1491,7 @@ def test_default_values_are_deeply_dupped
14911491
end
14921492

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

activerecord/test/cases/connection_pool_test.rb

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

338338
assert_raises(RuntimeError) {

activerecord/test/cases/defaults_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def test_mysql_text_not_null_defaults_strict
130130
end
131131

132132
def with_text_blob_not_null_table
133-
klass = Class.new(ActiveRecord::Base)
133+
klass = Class.new(ApplicationRecord)
134134
klass.table_name = 'test_mysql_text_not_null_defaults'
135135
klass.connection.create_table klass.table_name do |t|
136136
t.column :non_null_text, :text, :null => false
@@ -147,7 +147,7 @@ def with_text_blob_not_null_table
147147
# MySQL uses an implicit default 0 rather than NULL unless in strict mode.
148148
# We use an implicit NULL so schema.rb is compatible with other databases.
149149
def test_mysql_integer_not_null_defaults
150-
klass = Class.new(ActiveRecord::Base)
150+
klass = Class.new(ApplicationRecord)
151151
klass.table_name = 'test_integer_not_null_default_zero'
152152
klass.connection.create_table klass.table_name do |t|
153153
t.column :zero, :integer, :null => false, :default => 0

activerecord/test/cases/dirty_test.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def test_attribute_changes
5959

6060
def test_time_attributes_changes_with_time_zone
6161
in_time_zone 'Paris' do
62-
target = Class.new(ActiveRecord::Base)
62+
target = Class.new(ApplicationRecord)
6363
target.table_name = 'pirates'
6464

6565
# New record - no changes.
@@ -86,7 +86,7 @@ def test_time_attributes_changes_with_time_zone
8686

8787
def test_setting_time_attributes_with_time_zone_field_to_itself_should_not_be_marked_as_a_change
8888
in_time_zone 'Paris' do
89-
target = Class.new(ActiveRecord::Base)
89+
target = Class.new(ApplicationRecord)
9090
target.table_name = 'pirates'
9191

9292
pirate = target.create
@@ -97,7 +97,7 @@ def test_setting_time_attributes_with_time_zone_field_to_itself_should_not_be_ma
9797

9898
def test_time_attributes_changes_without_time_zone_by_skip
9999
in_time_zone 'Paris' do
100-
target = Class.new(ActiveRecord::Base)
100+
target = Class.new(ApplicationRecord)
101101
target.table_name = 'pirates'
102102

103103
target.skip_time_zone_conversion_for_attributes = [:created_on]
@@ -125,7 +125,7 @@ def test_time_attributes_changes_without_time_zone_by_skip
125125
end
126126

127127
def test_time_attributes_changes_without_time_zone
128-
target = Class.new(ActiveRecord::Base)
128+
target = Class.new(ApplicationRecord)
129129
target.table_name = 'pirates'
130130

131131
target.time_zone_aware_attributes = false
@@ -207,7 +207,7 @@ def test_nullable_float_not_marked_as_changed_if_new_value_is_blank
207207

208208
def test_nullable_datetime_not_marked_as_changed_if_new_value_is_blank
209209
in_time_zone 'Edinburgh' do
210-
target = Class.new(ActiveRecord::Base)
210+
target = Class.new(ApplicationRecord)
211211
target.table_name = 'topics'
212212

213213
topic = target.create
@@ -572,7 +572,7 @@ def test_field_named_field
572572

573573
def test_datetime_attribute_can_be_updated_with_fractional_seconds
574574
in_time_zone 'Paris' do
575-
target = Class.new(ActiveRecord::Base)
575+
target = Class.new(ApplicationRecord)
576576
target.table_name = 'topics'
577577

578578
written_on = Time.utc(2012, 12, 1, 12, 0, 0).in_time_zone('Paris')

activerecord/test/cases/fixtures_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def test_inserts_with_pre_and_suffix
132132
ActiveRecord::Base.table_name_prefix = 'prefix_'
133133
ActiveRecord::Base.table_name_suffix = '_suffix'
134134

135-
other_topic_klass = Class.new(ActiveRecord::Base) do
135+
other_topic_klass = Class.new(ApplicationRecord) do
136136
def self.name
137137
"OtherTopic"
138138
end
@@ -271,7 +271,7 @@ def test_fixtures
271271

272272
class HasManyThroughFixture < ActiveSupport::TestCase
273273
def make_model(name)
274-
Class.new(ActiveRecord::Base) { define_singleton_method(:name) { name } }
274+
Class.new(ApplicationRecord) { define_singleton_method(:name) { name } }
275275
end
276276

277277
def test_has_many_through

activerecord/test/cases/hot_compatibility_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class HotCompatibilityTest < ActiveRecord::TestCase
44
self.use_transactional_fixtures = false
55

66
setup do
7-
@klass = Class.new(ActiveRecord::Base) do
7+
@klass = Class.new(ApplicationRecord) do
88
connection.create_table :hot_compatibilities do |t|
99
t.string :foo
1010
t.string :bar

activerecord/test/cases/migration/change_schema_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def test_keeping_default_and_notnull_constraints_on_change
268268
connection.create_table :testings do |t|
269269
t.column :title, :string
270270
end
271-
person_klass = Class.new(ActiveRecord::Base)
271+
person_klass = Class.new(ApplicationRecord)
272272
person_klass.table_name = 'testings'
273273

274274
person_klass.connection.add_column "testings", "wealth", :integer, :null => false, :default => 99

activerecord/test/cases/primary_keys_test.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,18 +143,18 @@ def test_primary_key_returns_nil_if_it_does_not_exist
143143
end
144144

145145
def test_quoted_primary_key_after_set_primary_key
146-
k = Class.new( ActiveRecord::Base )
146+
k = Class.new(ApplicationRecord)
147147
assert_equal k.connection.quote_column_name("id"), k.quoted_primary_key
148148
k.primary_key = "foo"
149149
assert_equal k.connection.quote_column_name("foo"), k.quoted_primary_key
150150
end
151151

152152
def test_two_models_with_same_table_but_different_primary_key
153-
k1 = Class.new(ActiveRecord::Base)
153+
k1 = Class.new(ApplicationRecord)
154154
k1.table_name = 'posts'
155155
k1.primary_key = 'id'
156156

157-
k2 = Class.new(ActiveRecord::Base)
157+
k2 = Class.new(ApplicationRecord)
158158
k2.table_name = 'posts'
159159
k2.primary_key = 'title'
160160

@@ -170,10 +170,10 @@ def test_two_models_with_same_table_but_different_primary_key
170170
end
171171

172172
def test_models_with_same_table_have_different_columns
173-
k1 = Class.new(ActiveRecord::Base)
173+
k1 = Class.new(ApplicationRecord)
174174
k1.table_name = 'posts'
175175

176-
k2 = Class.new(ActiveRecord::Base)
176+
k2 = Class.new(ApplicationRecord)
177177
k2.table_name = 'posts'
178178

179179
k1.columns.zip(k2.columns).each do |col1, col2|
@@ -190,7 +190,7 @@ def test_set_primary_key_with_no_connection
190190

191191
connection = ActiveRecord::Base.remove_connection
192192

193-
model = Class.new(ActiveRecord::Base)
193+
model = Class.new(ApplicationRecord)
194194
model.primary_key = 'foo'
195195

196196
assert_equal 'foo', model.primary_key

activerecord/test/cases/scoping/named_scoping_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_delegates_finds_and_calculations_to_the_base_class
4646
end
4747

4848
def test_method_missing_priority_when_delegating
49-
klazz = Class.new(ActiveRecord::Base) do
49+
klazz = Class.new(ApplicationRecord) do
5050
self.table_name = "topics"
5151
scope :since, Proc.new { where('written_on >= ?', Time.now - 1.day) }
5252
scope :to, Proc.new { where('written_on <= ?', Time.now) }
@@ -270,7 +270,7 @@ def test_should_build_on_top_of_chained_scopes
270270
# has been done by evaluating a string with a plain def statement. For scope
271271
# names which contain spaces this approach doesn't work.
272272
def test_spaces_in_scope_names
273-
klass = Class.new(ActiveRecord::Base) do
273+
klass = Class.new(ApplicationRecord) do
274274
self.table_name = "topics"
275275
scope :"title containing space", -> { where("title LIKE '% %'") }
276276
scope :approved, -> { where(:approved => true) }
@@ -436,7 +436,7 @@ def test_scoped_are_lazy_loaded_if_table_still_does_not_exist
436436
end
437437

438438
def test_eager_default_scope_relations_are_remove
439-
klass = Class.new(ActiveRecord::Base)
439+
klass = Class.new(ApplicationRecord)
440440
klass.table_name = 'posts'
441441

442442
assert_raises(ArgumentError) do

activerecord/test/cases/serialization_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def test_include_root_in_json_allows_inheritance
5454
original_root_in_json = ActiveRecord::Base.include_root_in_json
5555
ActiveRecord::Base.include_root_in_json = true
5656

57-
klazz = Class.new(ActiveRecord::Base)
57+
klazz = Class.new(ApplicationRecord)
5858
klazz.table_name = 'topics'
5959
assert klazz.include_root_in_json
6060

0 commit comments

Comments
 (0)