Fixed double versioning on domains

This commit is contained in:
Andres Keskküla 2014-10-20 13:50:17 +03:00
parent 6b783fd45e
commit 7c3740acba
5 changed files with 20 additions and 10 deletions

View file

@ -66,8 +66,8 @@ class Contact < ActiveRecord::Base
def domains_snapshot def domains_snapshot
(domains + domains_owned).uniq.each do |domain| (domains + domains_owned).uniq.each do |domain|
next unless domain.is_a?(Domain) next unless domain.is_a?(Domain)
next if domain.versions.last == domain.create_snapshot #next if domain.versions.last == domain.create_snapshot
domain.touch_with_version # Method from paper_trail domain.create_version # Method from paper_trail
end end
end end

View file

@ -61,10 +61,25 @@ class Domain < ActiveRecord::Base
attr_accessor :owner_contact_typeahead, :update_me attr_accessor :owner_contact_typeahead, :update_me
# archiving # archiving
has_paper_trail class_name: 'DomainVersion', meta: { snapshot: :create_snapshot } has_paper_trail class_name: 'DomainVersion', meta: { snapshot: :create_snapshot }, if: Proc.new{ |t| t.new_version }
def new_version
#versions.try(:last).try(:snapshot) != create_snapshot
return false if versions.try(:last).try(:snapshot) == create_snapshot
true
end
def create_version
return true unless PaperTrail.enabled?
# We don't create a version unless domain is valid, is that a good idea?
return true unless valid?
#return true if versions.try(:last).try(:snapshot) == create_snapshot
touch_with_version
end
def track_nameserver_add(nameserver) def track_nameserver_add(nameserver)
# if we are not adding nameservers on create ( we don't care about ms so to_i ) # if we are not adding nameservers on create ( we don't care about ms so to_i )
#return true if versions.try(:last).try(:snapshot) == create_snapshot
touch_with_version if nameserver.created_at.to_i != created_at.to_i && valid? touch_with_version if nameserver.created_at.to_i != created_at.to_i && valid?
end end

View file

@ -39,12 +39,8 @@ class DomainContact < ActiveRecord::Base
end end
def domain_snapshot def domain_snapshot
# We don't create a version unless domain is valid, is that a good idea?
return true unless PaperTrail.enabled?
return true if domain.nil? return true if domain.nil?
return true if contact.nil? domain.create_version
return true if domain.versions.last.try(:snapshot) == domain.try(:create_snapshot)
domain.touch_with_version if domain.valid?
true true
end end
end end

View file

@ -47,7 +47,7 @@ class Nameserver < ActiveRecord::Base
end end
def domain_version def domain_version
domain.touch_with_version if domain.valid? domain.create_version
end end
def to_s def to_s

View file

@ -2,7 +2,6 @@ require 'rails_helper'
describe DomainVersion do describe DomainVersion do
with_versioning do with_versioning do
# before(:each) { Fabricate(:domain_validation_setting_group); Fabricate(:dnskeys_setting_group) }
before(:each) do before(:each) do
Setting.ns_min_count = 1 Setting.ns_min_count = 1
Fabricate(:domain, name: 'version.ee', dnskeys: []) do Fabricate(:domain, name: 'version.ee', dnskeys: []) do