Skip to content

Commit

Permalink
Lint: Rails/ApplicationRecord
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredbeck committed Nov 26, 2022
1 parent 71f5212 commit f5e129f
Show file tree
Hide file tree
Showing 54 changed files with 64 additions and 64 deletions.
5 changes: 0 additions & 5 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 56
# Cop supports --auto-correct.
Rails/ApplicationRecord:
Enabled: false

# Offense count: 1
# Cop supports --auto-correct.
Rails/NegateInclude:
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/animal.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class Animal < ActiveRecord::Base
class Animal < ApplicationRecord
has_paper_trail
self.inheritance_column = "species"
end
5 changes: 5 additions & 0 deletions spec/dummy_app/app/models/application_record.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/article.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# Demonstrates the `only` and `ignore` attributes, among other things.
class Article < ActiveRecord::Base
class Article < ApplicationRecord
has_paper_trail(
ignore: [
:title, {
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/authorship.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class Authorship < ActiveRecord::Base
class Authorship < ApplicationRecord
belongs_to :book
belongs_to :author, class_name: "Person"
has_paper_trail
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/bar_habtm.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class BarHabtm < ActiveRecord::Base
class BarHabtm < ApplicationRecord
has_and_belongs_to_many :foo_habtms
has_paper_trail
end
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/book.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class Book < ActiveRecord::Base
class Book < ApplicationRecord
has_many :authorships, dependent: :destroy
has_many :authors, through: :authorships

Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/boolit.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class Boolit < ActiveRecord::Base
class Boolit < ApplicationRecord
default_scope { where(scoped: true) }
has_paper_trail
end
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/callback_modifier.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class CallbackModifier < ActiveRecord::Base
class CallbackModifier < ApplicationRecord
has_paper_trail on: []

def test_destroy
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/chapter.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class Chapter < ActiveRecord::Base
class Chapter < ApplicationRecord
has_many :sections, dependent: :destroy
has_many :paragraphs, through: :sections

Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/citation.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class Citation < ActiveRecord::Base
class Citation < ApplicationRecord
belongs_to :quotation

has_paper_trail
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/custom_primary_key_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "securerandom"

class CustomPrimaryKeyRecord < ActiveRecord::Base
class CustomPrimaryKeyRecord < ApplicationRecord
self.primary_key = :uuid

has_paper_trail versions: { class_name: "CustomPrimaryKeyRecordVersion" }
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/customer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class Customer < ActiveRecord::Base
class Customer < ApplicationRecord
has_many :orders, dependent: :destroy
has_paper_trail
end
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Demonstrates a "custom versions association name". Instead of the association
# being named `versions`, it will be named `paper_trail_versions`.
class Document < ActiveRecord::Base
class Document < ApplicationRecord
has_paper_trail(
versions: { name: :paper_trail_versions },
on: %i[create update]
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/editor.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# to demonstrate a has_through association that does not have paper_trail enabled
class Editor < ActiveRecord::Base
class Editor < ApplicationRecord
has_many :editorships, dependent: :destroy
end
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/editorship.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class Editorship < ActiveRecord::Base
class Editorship < ApplicationRecord
belongs_to :book
belongs_to :editor
has_paper_trail
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/family/family.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Family
class Family < ActiveRecord::Base
class Family < ApplicationRecord
has_paper_trail

has_many :familie_lines, class_name: "::Family::FamilyLine", foreign_key: :parent_id
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/family/family_line.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Family
class FamilyLine < ActiveRecord::Base
class FamilyLine < ApplicationRecord
has_paper_trail
belongs_to :parent,
class_name: "::Family::Family",
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/fluxor.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

class Fluxor < ActiveRecord::Base
class Fluxor < ApplicationRecord
belongs_to :widget, optional: true
end
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/foo_habtm.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class FooHabtm < ActiveRecord::Base
class FooHabtm < ApplicationRecord
has_and_belongs_to_many :bar_habtms
accepts_nested_attributes_for :bar_habtms
has_paper_trail
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/fruit.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# See also `Vegetable` which uses `JsonbVersion`.
class Fruit < ActiveRecord::Base
class Fruit < ApplicationRecord
if ENV["DB"] == "postgres"
has_paper_trail versions: { class_name: "JsonVersion" }
end
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/gadget.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

class Gadget < ActiveRecord::Base
class Gadget < ApplicationRecord
has_paper_trail ignore: [:brand, { color: proc { |obj| obj.color == "Yellow" } }]
end
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/kitchen/banana.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Kitchen
class Banana < ActiveRecord::Base
class Banana < ApplicationRecord
has_paper_trail versions: { class_name: "Kitchen::BananaVersion" }
end
end
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/legacy_widget.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
# The `legacy_widgets` table has a `version` column that would conflict with our
# `version` method. It is configured to define a method named `custom_version`
# instead.
class LegacyWidget < ActiveRecord::Base
class LegacyWidget < ApplicationRecord
has_paper_trail ignore: :version, version: "custom_version"
end
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/line_item.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class LineItem < ActiveRecord::Base
class LineItem < ApplicationRecord
belongs_to :order, dependent: :destroy
has_paper_trail
end
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/no_object.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# Demonstrates a table that omits the `object` column.
class NoObject < ActiveRecord::Base
class NoObject < ApplicationRecord
has_paper_trail(
versions: { class_name: "NoObjectVersion" },
meta: { metadatum: 42 }
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/not_on_update.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# This model does not record versions when updated.
class NotOnUpdate < ActiveRecord::Base
class NotOnUpdate < ApplicationRecord
has_paper_trail on: %i[create destroy]
end
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/on/create.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module On
class Create < ActiveRecord::Base
class Create < ApplicationRecord
self.table_name = :on_create
has_paper_trail on: [:create]
end
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/on/destroy.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module On
class Destroy < ActiveRecord::Base
class Destroy < ApplicationRecord
self.table_name = :on_destroy
has_paper_trail on: [:destroy]
end
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/on/empty_array.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module On
class EmptyArray < ActiveRecord::Base
class EmptyArray < ApplicationRecord
self.table_name = :on_empty_array
has_paper_trail on: []
end
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/on/touch.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module On
class Touch < ActiveRecord::Base
class Touch < ApplicationRecord
self.table_name = :on_touch
has_paper_trail on: [:touch]
end
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/on/update.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module On
class Update < ActiveRecord::Base
class Update < ApplicationRecord
self.table_name = :on_update
has_paper_trail on: [:update]
end
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/order.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class Order < ActiveRecord::Base
class Order < ApplicationRecord
belongs_to :customer, touch: :touched_at
has_many :line_items
has_paper_trail
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/paragraph.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class Paragraph < ActiveRecord::Base
class Paragraph < ApplicationRecord
belongs_to :section

has_paper_trail
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/person.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class Person < ActiveRecord::Base
class Person < ApplicationRecord
has_many :authorships, foreign_key: :author_id, dependent: :destroy
has_many :books, through: :authorships

Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/pet.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class Pet < ActiveRecord::Base
class Pet < ApplicationRecord
belongs_to :owner, class_name: "Person", optional: true
belongs_to :animal, optional: true
has_paper_trail
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/plant.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class Plant < ActiveRecord::Base
class Plant < ApplicationRecord
has_paper_trail
self.inheritance_column = "species"

Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/post.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

class Post < ActiveRecord::Base
class Post < ApplicationRecord
has_paper_trail versions: { class_name: "PostVersion" }
end
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/post_with_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# This model tests ActiveRecord::Enum, which was added in AR 4.1
# http://edgeguides.rubyonrails.org/4_1_release_notes.html#active-record-enums
class PostWithStatus < ActiveRecord::Base
class PostWithStatus < ApplicationRecord
has_paper_trail

enum status: { draft: 0, published: 1, archived: 2 }
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/postgres_user.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

class PostgresUser < ActiveRecord::Base
class PostgresUser < ApplicationRecord
has_paper_trail
end
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/quotation.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class Quotation < ActiveRecord::Base
class Quotation < ApplicationRecord
belongs_to :chapter
has_many :citations, dependent: :destroy
has_paper_trail
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/section.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class Section < ActiveRecord::Base
class Section < ApplicationRecord
belongs_to :chapter
has_many :paragraphs, dependent: :destroy

Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/skipper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

class Skipper < ActiveRecord::Base
class Skipper < ApplicationRecord
has_paper_trail ignore: [:created_at], skip: [:another_timestamp]
end
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/song.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class Song < ActiveRecord::Base
class Song < ApplicationRecord
has_paper_trail
attribute :name, :string

Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/thing.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class Thing < ActiveRecord::Base
class Thing < ApplicationRecord
has_paper_trail versions: {
scope: -> { order("id desc") },
extend: PrefixVersionsInspectWithCount
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/translation.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# Demonstrates the `if` and `unless` configuration options.
class Translation < ActiveRecord::Base
class Translation < ApplicationRecord
has_paper_trail(
if: proc { |t| t.language_code == "US" },
unless: proc { |t| t.draft_status == "DRAFT" }
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/vegetable.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# See also `Fruit` which uses `JsonVersion`.
class Vegetable < ActiveRecord::Base
class Vegetable < ApplicationRecord
has_paper_trail versions: {
class_name: ENV["DB"] == "postgres" ? "JsonbVersion" : "PaperTrail::Version"
}, on: %i[create update]
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/models/vehicle.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class Vehicle < ActiveRecord::Base
class Vehicle < ApplicationRecord
# This STI parent class specifically does not call `has_paper_trail`.
# Of its sub-classes, only `Car` and `Bicycle` are versioned.
belongs_to :owner, class_name: "Person", optional: true
Expand Down
Loading

0 comments on commit f5e129f

Please sign in to comment.