Story #109367694 - refactor: move UserEvents include up, wrap method in included block, say self

This commit is contained in:
Matt Farnsworth 2015-12-14 11:28:26 +02:00
parent b7e560aacc
commit 7b2767eb08
5 changed files with 23 additions and 22 deletions

View file

@ -1,25 +1,28 @@
module UserEvents module UserEvents
extend ActiveSupport::Concern extend ActiveSupport::Concern
# EPP requires a server defined creator ID, which should be registrar code if we have one included do
def cr_id # EPP requires a server defined creator ID, which should be registrar code if we have one
# try this, rebuild user for registrar before searching history? really? def cr_id
registrar = self.creator.try(:registrar) # try this, rebuild user for registrar before searching history? really?
if registrar.present? # Did creator return a kind of User that has a registrar? registrar = self.creator.try(:registrar)
registrar.code if registrar.present? # Did creator return a kind of User that has a registrar?
else registrar.code
if versions.first.object.nil?
cr_registrar_id =versions.first.object_changes['registrar_id'].second
else else
# untested, expected never to execute if self.versions.first.try(:object).nil?
cr_registrar_id = versions.first.object['registrar_id'] changes = self.versions.first.try(:object_changes)
end cr_registrar_id = changes['registrar_id'].second if changes.present?
else
# untested, expected never to execute
cr_registrar_id = self.versions.first.object['registrar_id']
end
if cr_registrar_id.present? if cr_registrar_id.present?
Registrar.find(cr_registrar_id).code Registrar.find(cr_registrar_id).code
else else
# cr_id optional for domain, but required for contact; but we want something here anyway # cr_id optional for domain, but required for contact; but we want something here anyway
self.creator_str # Fallback if we failed, maybe we can find a string here self.creator_str # Fallback if we failed, maybe we can find a string here
end
end end
end end
end end

View file

@ -1,6 +1,7 @@
class Contact < ActiveRecord::Base class Contact < ActiveRecord::Base
include Versions # version/contact_version.rb include Versions # version/contact_version.rb
include EppErrors include EppErrors
include UserEvents
belongs_to :registrar belongs_to :registrar
has_many :domain_contacts has_many :domain_contacts

View file

@ -1,5 +1,6 @@
# rubocop: disable Metrics/ClassLength # rubocop: disable Metrics/ClassLength
class Domain < ActiveRecord::Base class Domain < ActiveRecord::Base
include UserEvents
include Versions # version/domain_version.rb include Versions # version/domain_version.rb
include Statuses include Statuses
has_paper_trail class_name: "DomainVersion", meta: { children: :children_log } has_paper_trail class_name: "DomainVersion", meta: { children: :children_log }

View file

@ -2,8 +2,6 @@ class ContactVersion < PaperTrail::Version
include VersionSession include VersionSession
self.table_name = :log_contacts self.table_name = :log_contacts
self.sequence_name = :log_contacts_id_seq self.sequence_name = :log_contacts_id_seq
include UserEvents
# scope :deleted, -> { where(event: 'destroy') } # scope :deleted, -> { where(event: 'destroy') }
end end

View file

@ -4,7 +4,5 @@ class DomainVersion < PaperTrail::Version
self.table_name = :log_domains self.table_name = :log_domains
self.sequence_name = :log_domains_id_seq self.sequence_name = :log_domains_id_seq
include UserEvents
scope :deleted, -> { where(event: 'destroy') } scope :deleted, -> { where(event: 'destroy') }
end end