Skip to content

Commit

Permalink
chore: add ApplicationRecord for test
Browse files Browse the repository at this point in the history
  • Loading branch information
seuros committed Jan 17, 2024
1 parent 194de58 commit b362c22
Showing 1 changed file with 43 additions and 36 deletions.
79 changes: 43 additions & 36 deletions spec/support/models.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
class Tag < ActiveRecord::Base
has_closure_tree :dependent => :destroy, :order => :name
# frozen_string_literal: true

class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end

class Tag < ApplicationRecord
has_closure_tree dependent: :destroy, order: :name
before_destroy :add_destroyed_tag

def to_s
Expand All @@ -8,11 +14,11 @@ def to_s

def add_destroyed_tag
# Proof for the tests that the destroy rather than the delete method was called:
DestroyedTag.create(:name => name)
DestroyedTag.create(name:)
end
end

class UUIDTag < ActiveRecord::Base
class UUIDTag < ApplicationRecord
self.primary_key = :uuid
before_create :set_uuid
has_closure_tree dependent: :destroy, order: 'name', parent_column_name: 'parent_uuid'
Expand All @@ -28,62 +34,62 @@ def to_s

def add_destroyed_tag
# Proof for the tests that the destroy rather than the delete method was called:
DestroyedTag.create(:name => name)
DestroyedTag.create(name:)
end
end

class DestroyedTag < ActiveRecord::Base
class DestroyedTag < ApplicationRecord
end

class Group < ActiveRecord::Base
class Group < ApplicationRecord
has_closure_tree_root :root_user
end

class Grouping < ActiveRecord::Base
has_closure_tree_root :root_person, class_name: "User", foreign_key: :group_id
class Grouping < ApplicationRecord
has_closure_tree_root :root_person, class_name: 'User', foreign_key: :group_id
end

class UserSet < ActiveRecord::Base
has_closure_tree_root :root_user, class_name: "Useur"
class UserSet < ApplicationRecord
has_closure_tree_root :root_user, class_name: 'Useur'
end

class Team < ActiveRecord::Base
has_closure_tree_root :root_user, class_name: "User", foreign_key: :grp_id
class Team < ApplicationRecord
has_closure_tree_root :root_user, class_name: 'User', foreign_key: :grp_id
end

class User < ActiveRecord::Base
acts_as_tree :parent_column_name => "referrer_id",
:name_column => 'email',
:hierarchy_class_name => 'ReferralHierarchy',
:hierarchy_table_name => 'referral_hierarchies'
class User < ApplicationRecord
acts_as_tree parent_column_name: 'referrer_id',
name_column: 'email',
hierarchy_class_name: 'ReferralHierarchy',
hierarchy_table_name: 'referral_hierarchies'

has_many :contracts, inverse_of: :user
belongs_to :group # Can't use and don't need inverse_of here when using has_closure_tree_root.

def indirect_contracts
Contract.where(:user_id => descendant_ids)
Contract.where(user_id: descendant_ids)
end

def to_s
email
end
end

class Contract < ActiveRecord::Base
class Contract < ApplicationRecord
belongs_to :user, inverse_of: :contracts
belongs_to :contract_type, inverse_of: :contracts
end

class ContractType < ActiveRecord::Base
class ContractType < ApplicationRecord
has_many :contracts, inverse_of: :contract_type
end

class Label < ActiveRecord::Base
class Label < ApplicationRecord
# make sure order doesn't matter
acts_as_tree :order => :column_whereby_ordering_is_inferred, # <- symbol, and not "sort_order"
:numeric_order => true,
:parent_column_name => "mother_id",
:dependent => :destroy
acts_as_tree order: :column_whereby_ordering_is_inferred, # <- symbol, and not "sort_order"
numeric_order: true,
parent_column_name: 'mother_id',
dependent: :destroy

def to_s
"#{self.class}: #{name}"
Expand All @@ -99,13 +105,13 @@ class DateLabel < Label
class DirectoryLabel < Label
end

class LabelWithoutRootOrdering < ActiveRecord::Base
class LabelWithoutRootOrdering < ApplicationRecord
# make sure order doesn't matter
acts_as_tree :order => :column_whereby_ordering_is_inferred, # <- symbol, and not "sort_order"
:numeric_order => true,
:dont_order_roots => true,
:parent_column_name => "mother_id",
:hierarchy_table_name => "label_hierarchies"
acts_as_tree order: :column_whereby_ordering_is_inferred, # <- symbol, and not "sort_order"
numeric_order: true,
dont_order_roots: true,
parent_column_name: 'mother_id',
hierarchy_table_name: 'label_hierarchies'

self.table_name = "#{table_name_prefix}labels#{table_name_suffix}"

Expand All @@ -114,20 +120,21 @@ def to_s
end
end

class CuisineType < ActiveRecord::Base
class CuisineType < ApplicationRecord
acts_as_tree
end

module Namespace
def self.table_name_prefix
'namespace_'
end
class Type < ActiveRecord::Base

class Type < ApplicationRecord
has_closure_tree dependent: :destroy
end
end

class Metal < ActiveRecord::Base
class Metal < ApplicationRecord
self.table_name = "#{table_name_prefix}metal#{table_name_suffix}"
has_closure_tree order: 'sort_order', name_column: 'value'
self.inheritance_column = 'metal_type'
Expand All @@ -139,6 +146,6 @@ class Adamantium < Metal
class Unobtanium < Metal
end

class MenuItem < ActiveRecord::Base
class MenuItem < ApplicationRecord
has_closure_tree touch: true, with_advisory_lock: false
end

0 comments on commit b362c22

Please sign in to comment.