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,6 +1,7 @@
module UserEvents module UserEvents
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do
# EPP requires a server defined creator ID, which should be registrar code if we have one # EPP requires a server defined creator ID, which should be registrar code if we have one
def cr_id def cr_id
# try this, rebuild user for registrar before searching history? really? # try this, rebuild user for registrar before searching history? really?
@ -8,11 +9,12 @@ module UserEvents
if registrar.present? # Did creator return a kind of User that has a registrar? if registrar.present? # Did creator return a kind of User that has a registrar?
registrar.code registrar.code
else else
if versions.first.object.nil? if self.versions.first.try(:object).nil?
cr_registrar_id =versions.first.object_changes['registrar_id'].second changes = self.versions.first.try(:object_changes)
cr_registrar_id = changes['registrar_id'].second if changes.present?
else else
# untested, expected never to execute # untested, expected never to execute
cr_registrar_id = versions.first.object['registrar_id'] cr_registrar_id = self.versions.first.object['registrar_id']
end end
if cr_registrar_id.present? if cr_registrar_id.present?
@ -23,5 +25,6 @@ module UserEvents
end end
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

@ -3,7 +3,5 @@ class ContactVersion < PaperTrail::Version
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