diff options
| author | Teddy Wing | 2017-11-13 18:27:48 +0100 | 
|---|---|---|
| committer | Teddy Wing | 2017-11-13 18:27:48 +0100 | 
| commit | 51a0898506e9c6bcc379ed8db01d3f14a1dbe110 (patch) | |
| tree | 27351c2fec102efec73daff5b320ad4661f23d97 /app | |
| parent | 336dab9900aee831e73113e400609ec2ebd40c20 (diff) | |
| download | chouette-core-51a0898506e9c6bcc379ed8db01d3f14a1dbe110.tar.bz2 | |
NetexImport: Destroy referential on destroy if ready:false
If the `NetexImport`'s associated `Referential` has `ready: false`, when
the `NetexImport` is destroyed, also destroy the `Referential`.
This prevents a case where users get an invalid `Referential` as a
result of an import, but because of the `ready: false`, it doesn't
display on the website, so they can't see what the problem is.
Refs #4962
Diffstat (limited to 'app')
| -rw-r--r-- | app/models/import.rb | 7 | ||||
| -rw-r--r-- | app/models/netex_import.rb | 9 | 
2 files changed, 9 insertions, 7 deletions
diff --git a/app/models/import.rb b/app/models/import.rb index 68cb62f86..20e7f2d8a 100644 --- a/app/models/import.rb +++ b/app/models/import.rb @@ -22,7 +22,6 @@ class Import < ActiveRecord::Base    validates_format_of :file, with: %r{\.zip\z}i, message: I18n.t('activerecord.errors.models.import.attributes.file.wrong_file_extension')    before_create :initialize_fields -  before_destroy :destroy_non_ready_referential    def self.model_name      ActiveModel::Name.new Import, Import, "Import" @@ -98,12 +97,6 @@ class Import < ActiveRecord::Base      self.token_download = SecureRandom.urlsafe_base64    end -  def destroy_non_ready_referential -    if !referential.ready -      referential.destroy -    end -  end -    def self.symbols_with_indifferent_access(array)      array.flat_map { |symbol| [symbol, symbol.to_s] }    end diff --git a/app/models/netex_import.rb b/app/models/netex_import.rb index 32939a741..3d8ab3809 100644 --- a/app/models/netex_import.rb +++ b/app/models/netex_import.rb @@ -1,6 +1,7 @@  require 'net/http'  class NetexImport < Import    after_commit :launch_java_import, on: :create +  before_destroy :destroy_non_ready_referential    validates_presence_of :parent @@ -16,4 +17,12 @@ class NetexImport < Import        end      end    end + +  private + +  def destroy_non_ready_referential +    if !referential.ready +      referential.destroy +    end +  end  end  | 
