Skip to content

Commit ff68712

Browse files
committed
DS-4969 Update data_works gem for Rails 5.2.6; Allow ApplicationRecord abstract class
1 parent 621b463 commit ff68712

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ rdoc
1616
spec/reports
1717
test/tmp
1818
test/version_tmp
19-
tmp
19+
tmp/*
20+
!tmp/.gitkeep
2021
*.bundle
2122
*.so
2223
*.o

lib/data_works/stale_relationship_checker.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def filepath
7878
def all_active_record_classes
7979
@all_classes ||= begin
8080
Rails.application.eager_load!
81-
ActiveRecord::Base.send(:descendants)
81+
ActiveRecord::Base.send(:descendants).reject{ |model| model.name == 'ApplicationRecord' } # for Rails 5+
8282
end
8383
end
8484

spec/helper/test_models.rb

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#*******************************************************************************
22
# For testing basic associations.
33
#*******************************************************************************
4+
class ApplicationRecord < ActiveRecord::Base
5+
self.abstract_class = true
6+
end
47

5-
class Pet < ActiveRecord::Base
8+
class Pet < ApplicationRecord
69
has_many :toys
710
has_one :pet_tag
811
has_one :pet_profile
@@ -13,23 +16,23 @@ class Pet < ActiveRecord::Base
1316
has_many :pet_sitters, through: :pet_sitting_patronages
1417
end
1518

16-
class Toy < ActiveRecord::Base
19+
class Toy < ApplicationRecord
1720
validates :name, length: { minimum: 3 }
1821
belongs_to :pet
1922
end
2023

21-
class PetTag < ActiveRecord::Base
24+
class PetTag < ApplicationRecord
2225
belongs_to :pet
2326
end
2427

25-
class PetFood < ActiveRecord::Base
28+
class PetFood < ApplicationRecord
2629
# Rails 3 expects the join table to be called pet_foods_pets
2730
# Rails 4 expects the join table to be called pet_foods_pets
2831
# We explicitly name the join table so that this code works with both Rails 3 and Rails 4.
2932
has_and_belongs_to_many :pets, join_table: 'pet_foods_pets'
3033
end
3134

32-
class Agency < ActiveRecord::Base
35+
class Agency < ApplicationRecord
3336
has_many :pet_sitters
3437
end
3538

@@ -40,42 +43,42 @@ class Kind < ActiveHash::Base
4043
]
4144
end
4245

43-
class PetSitter < ActiveRecord::Base
46+
class PetSitter < ApplicationRecord
4447
extend ActiveHash::Associations::ActiveRecordExtensions
4548
belongs_to :kind
4649
belongs_to :agency
4750
has_many :pet_sitting_patronages
4851
has_many :pets, through: :pet_sitting_patronages
4952
end
5053

51-
class PetSittingPatronage < ActiveRecord::Base
54+
class PetSittingPatronage < ApplicationRecord
5255
belongs_to :pet
5356
belongs_to :pet_sitter
5457
end
5558

56-
class PetProfile < ActiveRecord::Base
59+
class PetProfile < ApplicationRecord
5760
belongs_to :pet
5861
has_one :address
5962
end
6063

61-
class Address < ActiveRecord::Base
64+
class Address < ApplicationRecord
6265
belongs_to :pet_profile
6366
end
6467

6568
#*******************************************************************************
6669
# For testing polymorphic associations and custom-named foreign keys.
6770
#
6871

69-
class Picture < ActiveRecord::Base
72+
class Picture < ApplicationRecord
7073
belongs_to :imageable, polymorphic: true
7174
belongs_to :album, foreign_key: 'picture_album_id'
7275
end
7376

74-
class Product < ActiveRecord::Base
77+
class Product < ApplicationRecord
7578
has_many :pictures, as: :imageable
7679
end
7780

78-
class Album < ActiveRecord::Base
81+
class Album < ApplicationRecord
7982
has_many :pictures, foreign_key: 'picture_album_id'
8083
end
8184

@@ -85,22 +88,22 @@ class Album < ActiveRecord::Base
8588
# # For testing denormalized data structures.
8689
# #
8790

88-
# class Owner < ActiveRecord::Base
91+
# class Owner < ApplicationRecord
8992
# has_many :vehicles
9093
# has_many :amenities # this is not normalized, you wouldn't normally do this
9194
# end
9295

93-
# class Vehicle < ActiveRecord::Base
96+
# class Vehicle < ApplicationRecord
9497
# has_many :amenities
9598
# belongs_to :owner
9699
# end
97100

98-
# class Amenity < ActiveRecord::Base
101+
# class Amenity < ApplicationRecord
99102
# belongs_to :vehicle
100103
# belongs_to :owner # this is not normalized, you wouldn't normally do this
101104
# has_one :warranty
102105
# end
103106

104-
# class Warranty < ActiveRecord::Base
107+
# class Warranty < ApplicationRecord
105108
# belongs_to :amenity
106109
# end

tmp/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)